22 Width(width), Height(height), Format(format), Id(0), FramebufferId(0), RenderBufferId(0)
27 GL_CHECK(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GLfloat(GL_NEAREST)));
28 GL_CHECK(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GLfloat(GL_NEAREST)));
29 GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
30 GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
31 GL_CHECK(glBindTexture(GL_TEXTURE_2D, 0));
33 if (createFramebuffer)
43 GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
RenderBufferId));
45 GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
Id, 0));
47 if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
48 LERROR(
"Framebuffer creation failed");
70 int const rowlen =
Width * (
Format == GL_RGBA ? 4 : 1);
72 if ((rowlen & 7) == 0) align = 8;
73 else if ((rowlen & 3) == 0) align = 4;
74 else if ((rowlen & 1) == 0) align = 2;
77 glPixelStorei(GL_UNPACK_ALIGNMENT, align);
80 GL_CHECK(glBindTexture(GL_TEXTURE_2D, 0));
void setPixels(void const *data)
Copy pixel data from memory location to the texture.
~GPUtexture()
Destructor, frees the texture in OpenGL.
void getPixels(void *data) const
Copy pixel data from the texture to already-allocated memory location.
GPUtexture(GLsizei width, GLsizei height, GLenum format, bool createFramebuffer)
Constructor.