BARE2D
GLContextManager.cpp
Go to the documentation of this file.
1 #include "GLContextManager.hpp"
2 
3 namespace BARE2D {
4 
6  m_boundTextureIDs = new GLuint[GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS]{GL_TEXTURE_2D};
7  }
8 
10  delete[] m_boundTextureIDs;
11  }
12 
13  void GLContext::setActiveTexture(GLenum texture)
14  {
15  // If we already have the same texture active, why bother OpenGL?
16  if(m_activeTexture != texture) {
17  m_activeTexture = texture;
18  glActiveTexture(texture);
19  }
20  }
21 
22  void GLContext::bindTexture(GLenum target, GLenum texture)
23  {
24  // Make sure that the active texture's slot doesn't already have `texture` active
25  unsigned int index = (unsigned int)(m_activeTexture - GL_TEXTURE0);
26  if(m_boundTextureIDs[index] != texture) {
27  m_boundTextureIDs[index] = texture;
28  glBindTexture(target, texture);
29  }
30  }
31 
32  void GLContext::unbindTexture(GLenum target, GLenum textureslot) {
33  setActiveTexture(textureslot);
34  bindTexture(target, 0);
35  }
36 
38  unsigned int index = (unsigned int)(m_activeTexture - GL_TEXTURE0);
39  return m_boundTextureIDs[index];
40  }
41 
43 
45  {
46  if(m_context) {
47  return m_context;
48  } else {
49  m_context = new GLContext();
50  return m_context;
51  }
52  }
53 
54 }
BARE2D
Definition: App.cpp:13
BARE2D::GLContext::m_activeTexture
GLenum m_activeTexture
Definition: GLContextManager.hpp:35
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::GLContext::getBoundTexture
GLuint getBoundTexture()
Definition: GLContextManager.cpp:37
BARE2D::GLContext::unbindTexture
void unbindTexture(GLenum target, GLenum textureslot)
Unbinds a texture.
Definition: GLContextManager.cpp:32
BARE2D::GLContext::GLContext
GLContext()
Definition: GLContextManager.cpp:5
GLContextManager.hpp
BARE2D::GLContext
Definition: GLContextManager.hpp:7
BARE2D::GLContext::setActiveTexture
void setActiveTexture(GLenum texture)
Sets the active texture "slot". This can be GL_TEXTURE0 to GL_TEXTURE8 (I think. Check the literature...
Definition: GLContextManager.cpp:13
BARE2D::GLContextManager::m_context
static GLContext * m_context
Definition: GLContextManager.hpp:48
BARE2D::GLContext::~GLContext
~GLContext()
Definition: GLContextManager.cpp:9
BARE2D::GLContextManager::getContext
static GLContext * getContext()
Definition: GLContextManager.cpp:44
BARE2D::GLContext::m_boundTextureIDs
GLuint * m_boundTextureIDs
Definition: GLContextManager.hpp:38