12void scl::gl_texture_2d::CreateColor(
const image &Image,
bool IsFloatingPoint)
15 glGenTextures(1, &Id);
16 SCL_CORE_ASSERT(Id != 0,
"Error in creation OpenGL texture primitive.");
17 glBindTexture(GL_TEXTURE_2D, Id);
20 int w = Image.GetWidth(), h = Image.GetHeight();
21 int c = Image.GetComponentsCount();
22 GLenum internal_format = IsFloatingPoint ?
23 (c == 3 ? GL_RGB16F : c == 4 ? GL_RGBA16F : GL_R16F) :
24 (c == 3 ? GL_RGB8 : c == 4 ? GL_RGBA8 : GL_R8 );
25 GLenum format = c == 3 ? GL_RGB : c == 4 ? GL_RGBA : GL_RED;
26 GLenum type = IsFloatingPoint ? GL_FLOAT : GL_UNSIGNED_BYTE;
27 glTexStorage2D(GL_TEXTURE_2D, 1, internal_format, w, h);
28 if (Image.GetRawData() !=
nullptr)
29 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, format, type, Image.GetRawData());
30 glGenerateMipmap(GL_TEXTURE_2D);
33 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
34 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
35 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
36 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
38 glBindTexture(GL_TEXTURE_2D, 0);
41void scl::gl_texture_2d::CreateDepth(
const image &Image)
43 glCreateTextures(GL_TEXTURE_2D, 1, &Id);
44 glBindTexture(GL_TEXTURE_2D, Id);
45 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, Image.GetWidth(), Image.GetHeight(),
46 0, GL_DEPTH_COMPONENT, GL_FLOAT,
nullptr);
48 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
49 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
50 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
51 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
52 float borderColor[] = { 1.0f, 1.0f, 1.0f, 1.0f };
53 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
81 glActiveTexture(GL_TEXTURE0 + Slot);
82 glBindTexture(GL_TEXTURE_2D, Id);
87 glActiveTexture(GL_TEXTURE0 + this->Slot);
88 glBindTexture(GL_TEXTURE_2D, 0);
95 glDeleteTextures(1, &Id);
#define SCL_CORE_ASSERT(expr,...)
image GetImage() override
void Unbind() const override
gl_texture_2d(const image &Image, texture_type Type)
~gl_texture_2d() override
void Bind(u32 Slot) const override
OpenGL texture class definition module.
#define SCL_CORE_SUCCES(...)
Sculpto library prehompiled header. Defines common definitions, includes commonly used modules.