Manage GPU_matrix stacks per GPUContext
Previously, we had one global `GPU_matrix` stack, so the API was not thread safe. This patch makes the stack be per `GPUContext`, effectively making it local per thread (`GPUContext` is located in thread local storage). Reviewed By: brecht Differential Revision: https://developer.blender.org/D5405
This commit is contained in:
@@ -36,6 +36,7 @@
|
||||
|
||||
#include "gpu_batch_private.h"
|
||||
#include "gpu_context_private.h"
|
||||
#include "gpu_matrix_private.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string.h>
|
||||
@@ -71,6 +72,7 @@ struct GPUContext {
|
||||
std::unordered_set<GPUFrameBuffer *>
|
||||
framebuffers; /* Framebuffers that have FBO from this context */
|
||||
#endif
|
||||
struct GPUMatrixState *matrix_state;
|
||||
std::vector<GLuint> orphaned_vertarray_ids;
|
||||
std::vector<GLuint> orphaned_framebuffer_ids;
|
||||
std::mutex orphans_mutex; /* todo: try spinlock instead */
|
||||
@@ -139,6 +141,7 @@ GPUContext *GPU_context_create(GLuint default_framebuffer)
|
||||
GPUContext *ctx = new GPUContext;
|
||||
glGenVertexArrays(1, &ctx->default_vao);
|
||||
ctx->default_framebuffer = default_framebuffer;
|
||||
ctx->matrix_state = GPU_matrix_state_create();
|
||||
GPU_context_active_set(ctx);
|
||||
return ctx;
|
||||
}
|
||||
@@ -159,6 +162,7 @@ void GPU_context_discard(GPUContext *ctx)
|
||||
/* this removes the array entry */
|
||||
GPU_batch_vao_cache_clear(*ctx->batches.begin());
|
||||
}
|
||||
GPU_matrix_state_discard(ctx->matrix_state);
|
||||
glDeleteVertexArrays(1, &ctx->default_vao);
|
||||
delete ctx;
|
||||
active_ctx = NULL;
|
||||
@@ -333,3 +337,9 @@ GPUFrameBuffer *gpu_context_active_framebuffer_get(GPUContext *ctx)
|
||||
{
|
||||
return ctx->current_fbo;
|
||||
}
|
||||
|
||||
struct GPUMatrixState *gpu_context_active_matrix_state_get()
|
||||
{
|
||||
BLI_assert(active_ctx);
|
||||
return active_ctx->matrix_state;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user