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");
66 GL_CHECK(glBindTexture(GL_TEXTURE_2D, Id));
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);
78 static void * olddata =
nullptr;
81 GL_CHECK(glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, Width, Height, Format, GL_UNSIGNED_BYTE, data));
83 GL_CHECK(glBindTexture(GL_TEXTURE_2D, 0));
89 GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, FramebufferId));
90 GL_CHECK(glReadPixels(0, 0, Width, Height, Format, GL_UNSIGNED_BYTE, data));
91 GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, 0));
void setPixels(void const *data)
Copy pixel data from memory location to the texture.
void getPixels(void *data) const
Copy pixel data from the texture to already-allocated memory location.
~GPUtexture()
Destructor, frees the texture in OpenGL.
GPUtexture(GLsizei width, GLsizei height, GLenum format, bool createFramebuffer)
Constructor.