BARE2D
MutableTexture.cpp
Go to the documentation of this file.
1 #include "MutableTexture.hpp"
2 
3 #include "GLContextManager.hpp"
4 
5 #include "Logger.hpp"
6 
7 namespace BARE2D {
8 
9  void MutableTexture::setData(unsigned char* data) {
10  setData(data, 0, 0, width, height);
11  }
12 
13  void MutableTexture::setData(unsigned char* data,
14  unsigned int xOffset,
15  unsigned int yOffset,
16  unsigned int subWidth,
17  unsigned int subHeight) {
18  GLContextManager::getContext()->bindTexture(GL_TEXTURE_2D, id);
19 
20  if(channels != 4)
21  glPixelStorei(GL_UNPACK_ALIGNMENT, channels);
22 
23  glTexSubImage2D(GL_TEXTURE_2D, 0, xOffset, yOffset, subWidth, subHeight, format, GL_UNSIGNED_BYTE, data);
24 
25  if(channels != 4)
26  glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
27  GLContextManager::getContext()->bindTexture(GL_TEXTURE_2D, 0);
28  }
29 
30 } // namespace BARE2D
BARE2D
Definition: App.cpp:13
BARE2D::GLContext::bindTexture
void bindTexture(GLenum target, GLenum texture)
Binds a texture to target in the currently active texture slot.
Definition: GLContextManager.cpp:22
BARE2D::Texture::height
int height
Definition: Texture.hpp:17
BARE2D::MutableTexture::channels
unsigned int channels
Definition: MutableTexture.hpp:37
BARE2D::Texture::width
int width
Definition: Texture.hpp:16
GLContextManager.hpp
BARE2D::MutableTexture::format
GLenum format
Definition: MutableTexture.hpp:36
MutableTexture.hpp
BARE2D::MutableTexture::setData
void setData(unsigned char *data)
Sets the data of the mutable texture, as well as updates the OpenGL context's texture data for it (us...
Definition: MutableTexture.cpp:9
BARE2D::GLContextManager::getContext
static GLContext * getContext()
Definition: GLContextManager.cpp:44
Logger.hpp