Cleanup: GLBackend: Move buf_free and tex_free to GLContext
This makes it easier to follow. Also removes the GL related functions inside gpu_context.cc.
This commit is contained in:
@@ -126,58 +126,6 @@ GPUContext *GPU_context_active_get(void)
|
||||
return active_ctx;
|
||||
}
|
||||
|
||||
GLuint GPU_vao_alloc(void)
|
||||
{
|
||||
GLuint new_vao_id = 0;
|
||||
glGenVertexArrays(1, &new_vao_id);
|
||||
return new_vao_id;
|
||||
}
|
||||
|
||||
GLuint GPU_fbo_alloc(void)
|
||||
{
|
||||
GLuint new_fbo_id = 0;
|
||||
glGenFramebuffers(1, &new_fbo_id);
|
||||
return new_fbo_id;
|
||||
}
|
||||
|
||||
GLuint GPU_buf_alloc(void)
|
||||
{
|
||||
GLuint new_buffer_id = 0;
|
||||
glGenBuffers(1, &new_buffer_id);
|
||||
return new_buffer_id;
|
||||
}
|
||||
|
||||
GLuint GPU_tex_alloc(void)
|
||||
{
|
||||
GLuint new_texture_id = 0;
|
||||
glGenTextures(1, &new_texture_id);
|
||||
return new_texture_id;
|
||||
}
|
||||
|
||||
void GPU_vao_free(GLuint vao_id, GPUContext *ctx)
|
||||
{
|
||||
static_cast<GLContext *>(ctx)->vao_free(vao_id);
|
||||
}
|
||||
|
||||
void GPU_fbo_free(GLuint fbo_id, GPUContext *ctx)
|
||||
{
|
||||
static_cast<GLContext *>(ctx)->fbo_free(fbo_id);
|
||||
}
|
||||
|
||||
void GPU_buf_free(GLuint buf_id)
|
||||
{
|
||||
/* TODO avoid using backend */
|
||||
GPUBackend *backend = GPUBackend::get();
|
||||
static_cast<GLBackend *>(backend)->buf_free(buf_id);
|
||||
}
|
||||
|
||||
void GPU_tex_free(GLuint tex_id)
|
||||
{
|
||||
/* TODO avoid using backend */
|
||||
GPUBackend *backend = GPUBackend::get();
|
||||
static_cast<GLBackend *>(backend)->tex_free(tex_id);
|
||||
}
|
||||
|
||||
struct GPUMatrixState *gpu_context_active_matrix_state_get()
|
||||
{
|
||||
BLI_assert(active_ctx);
|
||||
|
@@ -83,19 +83,6 @@ struct GPUContext {
|
||||
MEM_CXX_CLASS_ALLOC_FUNCS("GPUContext")
|
||||
};
|
||||
|
||||
/* These require a OpenGL ctx bound. */
|
||||
GLuint GPU_buf_alloc(void);
|
||||
GLuint GPU_tex_alloc(void);
|
||||
GLuint GPU_vao_alloc(void);
|
||||
GLuint GPU_fbo_alloc(void);
|
||||
|
||||
/* These can be called any threads even without OpenGL ctx. */
|
||||
void GPU_buf_free(GLuint buf_id);
|
||||
void GPU_tex_free(GLuint tex_id);
|
||||
/* These two need the ctx the id was created with. */
|
||||
void GPU_vao_free(GLuint vao_id, GPUContext *ctx);
|
||||
void GPU_fbo_free(GLuint fbo_id, GPUContext *ctx);
|
||||
|
||||
void gpu_context_active_framebuffer_set(GPUContext *ctx, struct GPUFrameBuffer *fb);
|
||||
struct GPUFrameBuffer *gpu_context_active_framebuffer_get(GPUContext *ctx);
|
||||
|
||||
|
@@ -115,15 +115,10 @@ class GLBackend : public GPUBackend {
|
||||
return new GLVertBuf();
|
||||
};
|
||||
|
||||
/* TODO remove */
|
||||
void buf_free(GLuint buf_id);
|
||||
void tex_free(GLuint tex_id);
|
||||
void orphans_add(Vector<GLuint> &orphan_list, std::mutex &list_mutex, unsigned int id)
|
||||
GLSharedOrphanLists &shared_orphan_list_get(void)
|
||||
{
|
||||
list_mutex.lock();
|
||||
orphan_list.append(id);
|
||||
list_mutex.unlock();
|
||||
}
|
||||
return shared_orphan_list_;
|
||||
};
|
||||
|
||||
private:
|
||||
static void platform_init(void);
|
||||
|
@@ -230,25 +230,27 @@ void GLContext::fbo_free(GLuint fbo_id)
|
||||
}
|
||||
}
|
||||
|
||||
void GLBackend::buf_free(GLuint buf_id)
|
||||
void GLContext::buf_free(GLuint buf_id)
|
||||
{
|
||||
/* Any context can free. */
|
||||
if (GPU_context_active_get()) {
|
||||
glDeleteBuffers(1, &buf_id);
|
||||
}
|
||||
else {
|
||||
orphans_add(shared_orphan_list_.buffers, shared_orphan_list_.lists_mutex, buf_id);
|
||||
GLSharedOrphanLists &orphan_list = GLBackend::get()->shared_orphan_list_get();
|
||||
orphans_add(orphan_list.buffers, orphan_list.lists_mutex, buf_id);
|
||||
}
|
||||
}
|
||||
|
||||
void GLBackend::tex_free(GLuint tex_id)
|
||||
void GLContext::tex_free(GLuint tex_id)
|
||||
{
|
||||
/* Any context can free. */
|
||||
if (GPU_context_active_get()) {
|
||||
glDeleteTextures(1, &tex_id);
|
||||
}
|
||||
else {
|
||||
orphans_add(shared_orphan_list_.textures, shared_orphan_list_.lists_mutex, tex_id);
|
||||
GLSharedOrphanLists &orphan_list = GLBackend::get()->shared_orphan_list_get();
|
||||
orphans_add(orphan_list.textures, orphan_list.lists_mutex, tex_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -105,13 +105,17 @@ class GLContext : public GPUContext {
|
||||
return static_cast<GLStateManager *>(ctx->state_manager);
|
||||
};
|
||||
|
||||
/* TODO(fclem) these needs to become private. */
|
||||
public:
|
||||
void orphans_add(Vector<GLuint> &orphan_list, std::mutex &list_mutex, GLuint id);
|
||||
void orphans_clear(void);
|
||||
|
||||
/* These need to be called with the context the id was created with. */
|
||||
void vao_free(GLuint vao_id);
|
||||
void fbo_free(GLuint fbo_id);
|
||||
/* These can be called by any threads even without OpenGL ctx. Deletion will be delayed. */
|
||||
static void buf_free(GLuint buf_id);
|
||||
static void tex_free(GLuint tex_id);
|
||||
|
||||
/* TODO(fclem) these needs to become private. */
|
||||
public:
|
||||
static void orphans_add(Vector<GLuint> &orphan_list, std::mutex &list_mutex, GLuint id);
|
||||
void orphans_clear(void);
|
||||
void vao_cache_register(GLVaoCache *cache);
|
||||
void vao_cache_unregister(GLVaoCache *cache);
|
||||
};
|
||||
|
@@ -88,10 +88,7 @@ GLDrawList::GLDrawList(int length)
|
||||
|
||||
GLDrawList::~GLDrawList()
|
||||
{
|
||||
/* TODO This ... */
|
||||
static_cast<GLBackend *>(GPUBackend::get())->buf_free(buffer_id_);
|
||||
/* ... should be this. */
|
||||
// context_->buf_free(buffer_id_)
|
||||
GLContext::buf_free(buffer_id_);
|
||||
}
|
||||
|
||||
void GLDrawList::init(void)
|
||||
|
@@ -21,7 +21,7 @@
|
||||
* \ingroup gpu
|
||||
*/
|
||||
|
||||
#include "gl_backend.hh"
|
||||
#include "gl_context.hh"
|
||||
#include "gl_debug.hh"
|
||||
|
||||
#include "gl_index_buffer.hh"
|
||||
@@ -30,7 +30,7 @@ namespace blender::gpu {
|
||||
|
||||
GLIndexBuf::~GLIndexBuf()
|
||||
{
|
||||
GLBackend::get()->buf_free(ibo_id_);
|
||||
GLContext::buf_free(ibo_id_);
|
||||
}
|
||||
|
||||
void GLIndexBuf::bind(void)
|
||||
|
@@ -59,7 +59,7 @@ GLTexture::~GLTexture()
|
||||
/* This avoid errors when the texture is still inside the bound texture array. */
|
||||
ctx->state_manager->texture_unbind(this);
|
||||
}
|
||||
GLBackend::get()->tex_free(tex_id_);
|
||||
GLContext::tex_free(tex_id_);
|
||||
}
|
||||
|
||||
/* Return true on success. */
|
||||
|
@@ -45,7 +45,7 @@ GLUniformBuf::GLUniformBuf(size_t size, const char *name) : UniformBuf(size, nam
|
||||
|
||||
GLUniformBuf::~GLUniformBuf()
|
||||
{
|
||||
GLBackend::get()->buf_free(ubo_id_);
|
||||
GLContext::buf_free(ubo_id_);
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
@@ -21,7 +21,7 @@
|
||||
* \ingroup gpu
|
||||
*/
|
||||
|
||||
#include "gl_backend.hh"
|
||||
#include "gl_context.hh"
|
||||
|
||||
#include "gl_vertex_buffer.hh"
|
||||
|
||||
@@ -42,7 +42,7 @@ void GLVertBuf::resize_data(void)
|
||||
void GLVertBuf::release_data(void)
|
||||
{
|
||||
if (vbo_id_ != 0) {
|
||||
GLBackend::get()->buf_free(vbo_id_);
|
||||
GLContext::buf_free(vbo_id_);
|
||||
vbo_id_ = 0;
|
||||
memory_usage -= vbo_size_;
|
||||
}
|
||||
|
Reference in New Issue
Block a user