gl_utils: Make it harder to use uinitialized texture

This commit is contained in:
Martin Piatka
2024-01-12 16:00:01 +01:00
parent 2be4452d73
commit 367fd73c81
2 changed files with 16 additions and 4 deletions

View File

@@ -367,6 +367,11 @@ void Texture::init(){
glGenBuffers(1, &pbo);
}
void Texture::bind() {
init();
glBindTexture(GL_TEXTURE_2D, tex_id);
}
void Framebuffer::attach_texture(GLuint tex){
glBindTexture(GL_TEXTURE_2D, tex);
@@ -383,7 +388,7 @@ void Framebuffer::attach_texture(GLuint tex){
void FrameUploader::put_frame(video_frame *f, bool pbo_frame){
assert(tex);
glBindTexture(GL_TEXTURE_2D, tex->get());
tex->bind();
tex->allocate(f->tiles[0].width, f->tiles[0].height, GL_RGB);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

View File

@@ -57,6 +57,7 @@
//#include <SDL2/SDL_opengl.h>
#include <mutex>
#include <memory>
#include <cassert>
#include "types.h"
@@ -149,9 +150,9 @@ public:
~Texture();
/**
* Returns the underlying OpenGL texture id
* Returns the underlying OpenGL texture id.
*/
GLuint get() const { return tex_id; }
GLuint get() const { assert(tex_id); return tex_id; }
/**
* Allocates the the storage for the texture according to requested
@@ -163,6 +164,13 @@ public:
*/
void allocate(int w, int h, GLint internal_fmt);
/**
* Creates the actual OpenGL texture objects if not yet created
*/
void init();
void bind();
/**
* Uploads video frame to the texture
*
@@ -189,7 +197,6 @@ public:
std::swap(pbo, o.pbo);
}
private:
void init();
/**
* Uploads image data to the texture