+Support2DTexture::Support2DTexture()
+{
+ glGenTextures(1, &texnum);
+ check_error();
+ glBindTexture(GL_TEXTURE_2D, texnum);
+ check_error();
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ check_error();
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ check_error();
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ check_error();
+}
+
+Support2DTexture::~Support2DTexture()
+{
+ glDeleteTextures(1, &texnum);
+ check_error();
+}
+
+void Support2DTexture::update(GLint width, GLint height, GLenum internal_format, GLenum format, GLenum type, const GLvoid * data)
+{
+ glBindTexture(GL_TEXTURE_2D, texnum);
+ check_error();
+ if (width == last_texture_width &&
+ height == last_texture_height &&
+ internal_format == last_texture_internal_format) {
+ // Texture dimensions and type are unchanged; it is more efficient
+ // to just update it rather than making an entirely new texture.
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, type, data);
+ check_error();
+ } else {
+ glTexImage2D(GL_TEXTURE_2D, 0, internal_format, width, height, 0, format, type, data);
+ check_error();
+ last_texture_width = width;
+ last_texture_height = height;
+ last_texture_internal_format = internal_format;
+ }
+}
+