Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2020-09-08 05:12:12 +0300
committerClément Foucault <foucault.clem@gmail.com>2020-09-08 05:15:50 +0300
commit48690d967a7731367cda01ab8dca64e7f4c3f6b5 (patch)
tree9295cc0ef083fd50eaab2c62785d54545eb004c6 /source/blender/gpu/opengl
parentd2e9de93b8d1d6cd45abce8164d0f92af8f636d0 (diff)
GPUContext: Move GPUContext to gpu::Context for more consistency
This makes the GPUContext follow the same naming convention as the rest of the module. Also add a static getter for extra bonus style (no need for casts): - Context::get() - GLContext::get()
Diffstat (limited to 'source/blender/gpu/opengl')
-rw-r--r--source/blender/gpu/opengl/gl_backend.hh2
-rw-r--r--source/blender/gpu/opengl/gl_batch.cc10
-rw-r--r--source/blender/gpu/opengl/gl_context.cc10
-rw-r--r--source/blender/gpu/opengl/gl_context.hh13
-rw-r--r--source/blender/gpu/opengl/gl_debug.cc2
-rw-r--r--source/blender/gpu/opengl/gl_drawlist.cc6
-rw-r--r--source/blender/gpu/opengl/gl_framebuffer.cc12
-rw-r--r--source/blender/gpu/opengl/gl_immediate.cc2
-rw-r--r--source/blender/gpu/opengl/gl_shader.cc4
-rw-r--r--source/blender/gpu/opengl/gl_texture.cc6
-rw-r--r--source/blender/gpu/opengl/gl_uniform_buffer.cc6
-rw-r--r--source/blender/gpu/opengl/gl_vertex_array.cc2
-rw-r--r--source/blender/gpu/opengl/gl_vertex_buffer.cc4
13 files changed, 43 insertions, 36 deletions
diff --git a/source/blender/gpu/opengl/gl_backend.hh b/source/blender/gpu/opengl/gl_backend.hh
index 94ac1692108..231e5811b45 100644
--- a/source/blender/gpu/opengl/gl_backend.hh
+++ b/source/blender/gpu/opengl/gl_backend.hh
@@ -71,7 +71,7 @@ class GLBackend : public GPUBackend {
GLTexture::samplers_update();
};
- GPUContext *context_alloc(void *ghost_window) override
+ Context *context_alloc(void *ghost_window) override
{
return new GLContext(ghost_window, shared_orphan_list_);
};
diff --git a/source/blender/gpu/opengl/gl_batch.cc b/source/blender/gpu/opengl/gl_batch.cc
index c28d3e33e65..b25bafad6a3 100644
--- a/source/blender/gpu/opengl/gl_batch.cc
+++ b/source/blender/gpu/opengl/gl_batch.cc
@@ -151,7 +151,7 @@ void GLVaoCache::remove(const GLShaderInterface *interface)
void GLVaoCache::clear(void)
{
- GLContext *ctx = static_cast<GLContext *>(GPU_context_active_get());
+ GLContext *ctx = GLContext::get();
const int count = (is_dynamic_vao_count) ? dynamic_vaos.count : GPU_VAO_STATIC_LEN;
GLuint *vaos = (is_dynamic_vao_count) ? dynamic_vaos.vao_ids : static_vaos.vao_ids;
const GLShaderInterface **interfaces = (is_dynamic_vao_count) ? dynamic_vaos.interfaces :
@@ -209,7 +209,7 @@ GLuint GLVaoCache::lookup(const GLShaderInterface *interface)
* Reset the cache if trying to draw in another context; */
void GLVaoCache::context_check(void)
{
- GLContext *ctx = static_cast<GLContext *>(GPU_context_active_get());
+ GLContext *ctx = GLContext::get();
BLI_assert(ctx);
if (context_ != ctx) {
@@ -228,7 +228,7 @@ GLuint GLVaoCache::base_instance_vao_get(GPUBatch *batch, int i_first)
{
this->context_check();
/* Make sure the interface is up to date. */
- Shader *shader = GPU_context_active_get()->shader;
+ Shader *shader = GLContext::get()->shader;
GLShaderInterface *interface = static_cast<GLShaderInterface *>(shader->interface);
if (interface_ != interface) {
vao_get(batch);
@@ -260,7 +260,7 @@ GLuint GLVaoCache::vao_get(GPUBatch *batch)
{
this->context_check();
- Shader *shader = GPU_context_active_get()->shader;
+ Shader *shader = GLContext::get()->shader;
GLShaderInterface *interface = static_cast<GLShaderInterface *>(shader->interface);
if (interface_ != interface) {
interface_ = interface;
@@ -298,7 +298,7 @@ GLBatch::~GLBatch()
void GLBatch::bind(int i_first)
{
- GPU_context_active_get()->state_manager->apply_state();
+ GLContext::get()->state_manager->apply_state();
if (flag & GPU_BATCH_DIRTY) {
flag &= ~GPU_BATCH_DIRTY;
diff --git a/source/blender/gpu/opengl/gl_context.cc b/source/blender/gpu/opengl/gl_context.cc
index 30279ccade1..6b3b06ef12b 100644
--- a/source/blender/gpu/opengl/gl_context.cc
+++ b/source/blender/gpu/opengl/gl_context.cc
@@ -190,7 +190,7 @@ void GLContext::finish(void)
void GLSharedOrphanLists::orphans_clear(void)
{
/* Check if any context is active on this thread! */
- BLI_assert(GPU_context_active_get());
+ BLI_assert(GLContext::get());
lists_mutex.lock();
if (!buffers.is_empty()) {
@@ -232,7 +232,7 @@ void GLContext::orphans_add(Vector<GLuint> &orphan_list, std::mutex &list_mutex,
void GLContext::vao_free(GLuint vao_id)
{
- if (this == GPU_context_active_get()) {
+ if (this == GLContext::get()) {
glDeleteVertexArrays(1, &vao_id);
}
else {
@@ -242,7 +242,7 @@ void GLContext::vao_free(GLuint vao_id)
void GLContext::fbo_free(GLuint fbo_id)
{
- if (this == GPU_context_active_get()) {
+ if (this == GLContext::get()) {
glDeleteFramebuffers(1, &fbo_id);
}
else {
@@ -253,7 +253,7 @@ void GLContext::fbo_free(GLuint fbo_id)
void GLContext::buf_free(GLuint buf_id)
{
/* Any context can free. */
- if (GPU_context_active_get()) {
+ if (GLContext::get()) {
glDeleteBuffers(1, &buf_id);
}
else {
@@ -265,7 +265,7 @@ void GLContext::buf_free(GLuint buf_id)
void GLContext::tex_free(GLuint tex_id)
{
/* Any context can free. */
- if (GPU_context_active_get()) {
+ if (GLContext::get()) {
glDeleteTextures(1, &tex_id);
}
else {
diff --git a/source/blender/gpu/opengl/gl_context.hh b/source/blender/gpu/opengl/gl_context.hh
index ef0c13719e2..63014903e0a 100644
--- a/source/blender/gpu/opengl/gl_context.hh
+++ b/source/blender/gpu/opengl/gl_context.hh
@@ -53,7 +53,7 @@ class GLSharedOrphanLists {
void orphans_clear(void);
};
-class GLContext : public GPUContext {
+class GLContext : public Context {
public:
/** Capabilities. */
static GLint max_texture_3d_size;
@@ -103,9 +103,14 @@ class GLContext : public GPUContext {
void memory_statistics_get(int *total_mem, int *free_mem) override;
- static inline GLStateManager *state_manager_active_get()
+ static GLContext *get()
{
- GLContext *ctx = static_cast<GLContext *>(GPU_context_active_get());
+ return static_cast<GLContext *>(Context::get());
+ }
+
+ static GLStateManager *state_manager_active_get()
+ {
+ GLContext *ctx = GLContext::get();
return static_cast<GLStateManager *>(ctx->state_manager);
};
@@ -122,6 +127,8 @@ class GLContext : public GPUContext {
private:
static void orphans_add(Vector<GLuint> &orphan_list, std::mutex &list_mutex, GLuint id);
void orphans_clear(void);
+
+ MEM_CXX_CLASS_ALLOC_FUNCS("GLContext")
};
} // namespace gpu
diff --git a/source/blender/gpu/opengl/gl_debug.cc b/source/blender/gpu/opengl/gl_debug.cc
index d54ea0919b6..53a71516018 100644
--- a/source/blender/gpu/opengl/gl_debug.cc
+++ b/source/blender/gpu/opengl/gl_debug.cc
@@ -197,7 +197,7 @@ void check_gl_resources(const char *info)
return;
}
- GLContext *ctx = static_cast<GLContext *>(GPU_context_active_get());
+ GLContext *ctx = GLContext::get();
ShaderInterface *interface = ctx->shader->interface;
/* NOTE: This only check binding. To be valid, the bound ubo needs to
* be big enough to feed the data range the shader awaits. */
diff --git a/source/blender/gpu/opengl/gl_drawlist.cc b/source/blender/gpu/opengl/gl_drawlist.cc
index 039ef18ad72..6e3b1107b9c 100644
--- a/source/blender/gpu/opengl/gl_drawlist.cc
+++ b/source/blender/gpu/opengl/gl_drawlist.cc
@@ -93,7 +93,7 @@ GLDrawList::~GLDrawList()
void GLDrawList::init(void)
{
- BLI_assert(GPU_context_active_get());
+ BLI_assert(GLContext::get());
BLI_assert(MDI_ENABLED);
BLI_assert(data_ == NULL);
batch_ = NULL;
@@ -102,7 +102,7 @@ void GLDrawList::init(void)
if (buffer_id_ == 0) {
/* Allocate on first use. */
glGenBuffers(1, &buffer_id_);
- context_ = static_cast<GLContext *>(GPU_context_active_get());
+ context_ = GLContext::get();
}
glBindBuffer(GL_DRAW_INDIRECT_BUFFER, buffer_id_);
@@ -180,7 +180,7 @@ void GLDrawList::submit(void)
/* Something's wrong if we get here without MDI support. */
BLI_assert(MDI_ENABLED);
BLI_assert(data_);
- BLI_assert(GPU_context_active_get()->shader != NULL);
+ BLI_assert(GLContext::get()->shader != NULL);
/* Only do multi-draw indirect if doing more than 2 drawcall. This avoids the overhead of
* buffer mapping if scene is not very instance friendly. BUT we also need to take into
diff --git a/source/blender/gpu/opengl/gl_framebuffer.cc b/source/blender/gpu/opengl/gl_framebuffer.cc
index 61270fe0acc..85fa973daff 100644
--- a/source/blender/gpu/opengl/gl_framebuffer.cc
+++ b/source/blender/gpu/opengl/gl_framebuffer.cc
@@ -78,7 +78,7 @@ GLFrameBuffer::~GLFrameBuffer()
return;
}
- if (context_ == GPU_context_active_get()) {
+ if (context_ == GLContext::get()) {
/* Context might be partially freed. This happens when destroying the window frame-buffers. */
glDeleteFramebuffers(1, &fbo_id_);
}
@@ -89,14 +89,14 @@ GLFrameBuffer::~GLFrameBuffer()
if (context_->active_fb == this && context_->back_left != this) {
/* If this assert triggers it means the frame-buffer is being freed while in use by another
* context which, by the way, is TOTALLY UNSAFE!!! */
- BLI_assert(context_ == GPU_context_active_get());
+ BLI_assert(context_ == GLContext::get());
GPU_framebuffer_restore();
}
}
void GLFrameBuffer::init(void)
{
- context_ = static_cast<GLContext *>(GPU_context_active_get());
+ context_ = GLContext::get();
state_manager_ = static_cast<GLStateManager *>(context_->state_manager);
glGenFramebuffers(1, &fbo_id_);
@@ -274,7 +274,7 @@ void GLFrameBuffer::bind(bool enabled_srgb)
this->init();
}
- if (context_ != GPU_context_active_get()) {
+ if (context_ != GLContext::get()) {
BLI_assert(!"Trying to use the same frame-buffer in multiple context");
return;
}
@@ -320,7 +320,7 @@ void GLFrameBuffer::clear(eGPUFrameBufferBits buffers,
float clear_depth,
uint clear_stencil)
{
- BLI_assert(GPU_context_active_get() == context_);
+ BLI_assert(GLContext::get() == context_);
BLI_assert(context_->active_fb == this);
/* Save and restore the state. */
@@ -360,7 +360,7 @@ void GLFrameBuffer::clear_attachment(GPUAttachmentType type,
eGPUDataFormat data_format,
const void *clear_value)
{
- BLI_assert(GPU_context_active_get() == context_);
+ BLI_assert(GLContext::get() == context_);
BLI_assert(context_->active_fb == this);
/* Save and restore the state. */
diff --git a/source/blender/gpu/opengl/gl_immediate.cc b/source/blender/gpu/opengl/gl_immediate.cc
index 7f12f41a598..26b1df88b64 100644
--- a/source/blender/gpu/opengl/gl_immediate.cc
+++ b/source/blender/gpu/opengl/gl_immediate.cc
@@ -160,7 +160,7 @@ void GLImmediate::end(void)
GL_CHECK_ERROR("Immediate Post-Unmap");
if (vertex_len > 0) {
- GPU_context_active_get()->state_manager->apply_state();
+ GLContext::get()->state_manager->apply_state();
/* We convert the offset in vertex offset from the buffer's start.
* This works because we added some padding to align the first vertex vertex. */
diff --git a/source/blender/gpu/opengl/gl_shader.cc b/source/blender/gpu/opengl/gl_shader.cc
index a303229fc3c..ca38efe37b5 100644
--- a/source/blender/gpu/opengl/gl_shader.cc
+++ b/source/blender/gpu/opengl/gl_shader.cc
@@ -44,7 +44,7 @@ GLShader::GLShader(const char *name) : Shader(name)
{
#if 0 /* Would be nice to have, but for now the Deferred compilation \
* does not have a GPUContext. */
- BLI_assert(GPU_context_active_get() != NULL);
+ BLI_assert(GLContext::get() != NULL);
#endif
shader_program_ = glCreateProgram();
@@ -61,7 +61,7 @@ GLShader::~GLShader(void)
{
#if 0 /* Would be nice to have, but for now the Deferred compilation \
* does not have a GPUContext. */
- BLI_assert(GPU_context_active_get() != NULL);
+ BLI_assert(GLContext::get() != NULL);
#endif
/* Invalid handles are silently ignored. */
glDeleteShader(vert_shader_);
diff --git a/source/blender/gpu/opengl/gl_texture.cc b/source/blender/gpu/opengl/gl_texture.cc
index b4a8e43c931..ae3923b960f 100644
--- a/source/blender/gpu/opengl/gl_texture.cc
+++ b/source/blender/gpu/opengl/gl_texture.cc
@@ -44,7 +44,7 @@ namespace blender::gpu {
GLTexture::GLTexture(const char *name) : Texture(name)
{
- BLI_assert(GPU_context_active_get() != NULL);
+ BLI_assert(GLContext::get() != NULL);
glGenTextures(1, &tex_id_);
}
@@ -54,7 +54,7 @@ GLTexture::~GLTexture()
if (framebuffer_) {
GPU_framebuffer_free(framebuffer_);
}
- GPUContext *ctx = GPU_context_active_get();
+ GLContext *ctx = GLContext::get();
if (ctx != NULL && is_bound_) {
/* This avoid errors when the texture is still inside the bound texture array. */
ctx->state_manager->texture_unbind(this);
@@ -662,7 +662,7 @@ void GLTexture::check_feedback_loop(void)
if (GPU_mip_render_workaround()) {
return;
}
- GLFrameBuffer *fb = static_cast<GLFrameBuffer *>(GPU_context_active_get()->active_fb);
+ GLFrameBuffer *fb = static_cast<GLFrameBuffer *>(GLContext::get()->active_fb);
for (int i = 0; i < ARRAY_SIZE(fb_); i++) {
if (fb_[i] == fb) {
GPUAttachmentType type = fb_attachment_[i];
diff --git a/source/blender/gpu/opengl/gl_uniform_buffer.cc b/source/blender/gpu/opengl/gl_uniform_buffer.cc
index a06fadf4785..62c590d289f 100644
--- a/source/blender/gpu/opengl/gl_uniform_buffer.cc
+++ b/source/blender/gpu/opengl/gl_uniform_buffer.cc
@@ -56,7 +56,7 @@ GLUniformBuf::~GLUniformBuf()
void GLUniformBuf::init(void)
{
- BLI_assert(GPU_context_active_get());
+ BLI_assert(GLContext::get());
glGenBuffers(1, &ubo_id_);
glBindBuffer(GL_UNIFORM_BUFFER, ubo_id_);
@@ -112,7 +112,7 @@ void GLUniformBuf::bind(int slot)
#ifdef DEBUG
BLI_assert(slot < 16);
- static_cast<GLContext *>(GPU_context_active_get())->bound_ubo_slots |= 1 << slot;
+ GLContext::get()->bound_ubo_slots |= 1 << slot;
#endif
}
@@ -122,7 +122,7 @@ void GLUniformBuf::unbind(void)
/* NOTE: This only unbinds the last bound slot. */
glBindBufferBase(GL_UNIFORM_BUFFER, slot_, 0);
/* Hope that the context did not change. */
- static_cast<GLContext *>(GPU_context_active_get())->bound_ubo_slots &= ~(1 << slot_);
+ GLContext::get()->bound_ubo_slots &= ~(1 << slot_);
#endif
slot_ = 0;
}
diff --git a/source/blender/gpu/opengl/gl_vertex_array.cc b/source/blender/gpu/opengl/gl_vertex_array.cc
index 4e49828d39d..732221cfab3 100644
--- a/source/blender/gpu/opengl/gl_vertex_array.cc
+++ b/source/blender/gpu/opengl/gl_vertex_array.cc
@@ -138,7 +138,7 @@ void GLVertArray::update_bindings(const GLuint vao,
if (attr_mask != 0 && GLEW_ARB_vertex_attrib_binding) {
for (uint16_t mask = 1, a = 0; a < 16; a++, mask <<= 1) {
if (attr_mask & mask) {
- GLContext *ctx = static_cast<GLContext *>(GPU_context_active_get());
+ GLContext *ctx = GLContext::get();
/* This replaces glVertexAttrib4f(a, 0.0f, 0.0f, 0.0f, 1.0f); with a more modern style.
* Fix issues for some drivers (see T75069). */
glBindVertexBuffer(a, ctx->default_attr_vbo_, (intptr_t)0, (intptr_t)0);
diff --git a/source/blender/gpu/opengl/gl_vertex_buffer.cc b/source/blender/gpu/opengl/gl_vertex_buffer.cc
index d56f5d1aa52..a724c94775e 100644
--- a/source/blender/gpu/opengl/gl_vertex_buffer.cc
+++ b/source/blender/gpu/opengl/gl_vertex_buffer.cc
@@ -52,7 +52,7 @@ void GLVertBuf::release_data(void)
void GLVertBuf::duplicate_data(VertBuf *dst_)
{
- BLI_assert(GPU_context_active_get() != NULL);
+ BLI_assert(GLContext::get() != NULL);
GLVertBuf *src = this;
GLVertBuf *dst = static_cast<GLVertBuf *>(dst_);
@@ -82,7 +82,7 @@ void GLVertBuf::upload_data(void)
void GLVertBuf::bind(void)
{
- BLI_assert(GPU_context_active_get() != NULL);
+ BLI_assert(GLContext::get() != NULL);
if (vbo_id_ == 0) {
glGenBuffers(1, &vbo_id_);