Commit: 482a51aabf596ca1f279ab3b7cb3170c867b4a42
Author: Clément Foucault
Date:   Mon Aug 17 00:34:06 2020 +0200
Branches: master
https://developer.blender.org/rB482a51aabf596ca1f279ab3b7cb3170c867b4a42

Cleanup: GPUState: Remove stack from the state manager and rename it

===================================================================

M       intern/glew-mx/intern/gl-deprecated.h
M       source/blender/gpu/intern/gpu_context.cc
M       source/blender/gpu/intern/gpu_context_private.hh
M       source/blender/gpu/intern/gpu_state.cc
M       source/blender/gpu/intern/gpu_state_private.hh
M       source/blender/gpu/opengl/gl_context.cc
M       source/blender/gpu/opengl/gl_state.cc
M       source/blender/gpu/opengl/gl_state.hh

===================================================================

diff --git a/intern/glew-mx/intern/gl-deprecated.h 
b/intern/glew-mx/intern/gl-deprecated.h
index b6524cd5197..d101591fea3 100644
--- a/intern/glew-mx/intern/gl-deprecated.h
+++ b/intern/glew-mx/intern/gl-deprecated.h
@@ -824,10 +824,12 @@
 #define GL_SOURCE0_ALPHA DO_NOT_USE_GL_SOURCE0_ALPHA
 #undef GL_SOURCE0_RGB
 #define GL_SOURCE0_RGB DO_NOT_USE_GL_SOURCE0_RGB
-#undef GL_SOURCE1_ALPHA
-#define GL_SOURCE1_ALPHA DO_NOT_USE_GL_SOURCE1_ALPHA
-#undef GL_SOURCE1_RGB
-#define GL_SOURCE1_RGB DO_NOT_USE_GL_SOURCE1_RGB
+#if 0 /* Those are reused as new valid enum! GL_SRC1_COLOR etc... */
+#  undef GL_SOURCE1_ALPHA
+#  define GL_SOURCE1_ALPHA DO_NOT_USE_GL_SOURCE1_ALPHA
+#  undef GL_SOURCE1_RGB
+#  define GL_SOURCE1_RGB DO_NOT_USE_GL_SOURCE1_RGB
+#endif
 #undef GL_SOURCE2_ALPHA
 #define GL_SOURCE2_ALPHA DO_NOT_USE_GL_SOURCE2_ALPHA
 #undef GL_SOURCE2_RGB
diff --git a/source/blender/gpu/intern/gpu_context.cc 
b/source/blender/gpu/intern/gpu_context.cc
index da12a58ba87..ef02ec24a00 100644
--- a/source/blender/gpu/intern/gpu_context.cc
+++ b/source/blender/gpu/intern/gpu_context.cc
@@ -70,7 +70,7 @@ GPUContext::GPUContext()
 GPUContext::~GPUContext()
 {
   GPU_matrix_state_discard(matrix_state);
-  delete state_stack;
+  delete state_manager;
 }
 
 bool GPUContext::is_active_on_thread(void)
diff --git a/source/blender/gpu/intern/gpu_context_private.hh 
b/source/blender/gpu/intern/gpu_context_private.hh
index 04785187e8b..b774d6b0995 100644
--- a/source/blender/gpu/intern/gpu_context_private.hh
+++ b/source/blender/gpu/intern/gpu_context_private.hh
@@ -46,7 +46,7 @@ struct GPUContext {
   GPUShader *shader = NULL;
   GPUFrameBuffer *current_fbo = NULL;
   GPUMatrixState *matrix_state = NULL;
-  blender::gpu::GPUStateStack *state_stack = NULL;
+  blender::gpu::GPUStateManager *state_manager = NULL;
 
  protected:
   /** Thread on which this context is active. */
diff --git a/source/blender/gpu/intern/gpu_state.cc 
b/source/blender/gpu/intern/gpu_state.cc
index 8a9724e967f..bd581f06462 100644
--- a/source/blender/gpu/intern/gpu_state.cc
+++ b/source/blender/gpu/intern/gpu_state.cc
@@ -38,15 +38,12 @@
 
 #include "gpu_state_private.hh"
 
-/* TODO remove */
-#include "gl_state.hh"
-
 using namespace blender::gpu;
 
 #define SET_STATE(_prefix, _state, _value) \
   do { \
-    GPUStateStack *stack = GPU_context_active_get()->state_stack; \
-    auto &state_object = stack->_prefix##stack_top_get(); \
+    GPUStateManager *stack = GPU_context_active_get()->state_manager; \
+    auto &state_object = stack->_prefix##state; \
     state_object._state = _value; \
     /* TODO remove this and only push state at draw time. */ \
     stack->set_##_prefix##state(state_object); \
@@ -107,8 +104,8 @@ void GPU_write_mask(eGPUWriteMask mask)
 
 void GPU_color_mask(bool r, bool g, bool b, bool a)
 {
-  GPUStateStack *stack = GPU_context_active_get()->state_stack;
-  auto &state = stack->stack_top_get();
+  GPUStateManager *stack = GPU_context_active_get()->state_manager;
+  auto &state = stack->state;
   eGPUWriteMask write_mask = state.write_mask;
   SET_FLAG_FROM_TEST(write_mask, r, GPU_WRITE_RED);
   SET_FLAG_FROM_TEST(write_mask, g, GPU_WRITE_GREEN);
@@ -121,8 +118,8 @@ void GPU_color_mask(bool r, bool g, bool b, bool a)
 
 void GPU_depth_mask(bool depth)
 {
-  GPUStateStack *stack = GPU_context_active_get()->state_stack;
-  auto &state = stack->stack_top_get();
+  GPUStateManager *stack = GPU_context_active_get()->state_manager;
+  auto &state = stack->state;
   eGPUWriteMask write_mask = state.write_mask;
   SET_FLAG_FROM_TEST(write_mask, depth, GPU_WRITE_DEPTH);
   state.write_mask = write_mask;
@@ -143,8 +140,8 @@ void GPU_clip_distances(int distances_enabled)
 
 void GPU_depth_range(float near, float far)
 {
-  GPUStateStack *stack = GPU_context_active_get()->state_stack;
-  auto &state = stack->mutable_stack_top_get();
+  GPUStateManager *stack = GPU_context_active_get()->state_manager;
+  auto &state = stack->mutable_state;
   copy_v2_fl2(state.depth_range, near, far);
   /* TODO remove this and only push state at draw time. */
   stack->set_mutable_state(state);
@@ -166,8 +163,8 @@ void GPU_point_size(float size)
 /* TODO remove and use program point size everywhere */
 void GPU_program_point_size(bool enable)
 {
-  GPUStateStack *stack = GPU_context_active_get()->state_stack;
-  auto &state = stack->mutable_stack_top_get();
+  GPUStateManager *stack = GPU_context_active_get()->state_manager;
+  auto &state = stack->mutable_state;
   /* Set point size sign negative to disable. */
   state.point_size = fabsf(state.point_size) * (enable ? 1 : -1);
   /* TODO remove this and only push state at draw time. */
@@ -176,8 +173,8 @@ void GPU_program_point_size(bool enable)
 
 void GPU_scissor_test(bool enable)
 {
-  GPUStateStack *stack = GPU_context_active_get()->state_stack;
-  auto &state = stack->mutable_stack_top_get();
+  GPUStateManager *stack = GPU_context_active_get()->state_manager;
+  auto &state = stack->mutable_state;
   /* Set point size sign negative to disable. */
   state.scissor_rect[2] = abs(state.scissor_rect[2]) * (enable ? 1 : -1);
   /* TODO remove this and only push state at draw time. */
@@ -186,8 +183,8 @@ void GPU_scissor_test(bool enable)
 
 void GPU_scissor(int x, int y, int width, int height)
 {
-  GPUStateStack *stack = GPU_context_active_get()->state_stack;
-  auto &state = stack->mutable_stack_top_get();
+  GPUStateManager *stack = GPU_context_active_get()->state_manager;
+  auto &state = stack->mutable_state;
   int scissor_rect[4] = {x, y, width, height};
   copy_v4_v4_int(state.scissor_rect, scissor_rect);
   /* TODO remove this and only push state at draw time. */
@@ -196,8 +193,8 @@ void GPU_scissor(int x, int y, int width, int height)
 
 void GPU_viewport(int x, int y, int width, int height)
 {
-  GPUStateStack *stack = GPU_context_active_get()->state_stack;
-  auto &state = stack->mutable_stack_top_get();
+  GPUStateManager *stack = GPU_context_active_get()->state_manager;
+  auto &state = stack->mutable_state;
   int viewport_rect[4] = {x, y, width, height};
   copy_v4_v4_int(state.viewport_rect, viewport_rect);
   /* TODO remove this and only push state at draw time. */
@@ -212,31 +209,31 @@ void GPU_viewport(int x, int y, int width, int height)
 
 eGPUBlend GPU_blend_get()
 {
-  GPUState &state = GPU_context_active_get()->state_stack->stack_top_get();
+  GPUState &state = GPU_context_active_get()->state_manager->state;
   return state.blend;
 }
 
 eGPUWriteMask GPU_write_mask_get()
 {
-  GPUState &state = GPU_context_active_get()->state_stack->stack_top_get();
+  GPUState &state = GPU_context_active_get()->state_manager->state;
   return state.write_mask;
 }
 
 bool GPU_depth_test_enabled()
 {
-  GPUState &state = GPU_context_active_get()->state_stack->stack_top_get();
+  GPUState &state = GPU_context_active_get()->state_manager->state;
   return state.depth_test != GPU_DEPTH_NONE;
 }
 
 void GPU_scissor_get(int coords[4])
 {
-  GPUStateMutable &state = 
GPU_context_active_get()->state_stack->mutable_stack_top_get();
+  GPUStateMutable &state = 
GPU_context_active_get()->state_manager->mutable_state;
   copy_v4_v4_int(coords, state.scissor_rect);
 }
 
 void GPU_viewport_size_get_f(float coords[4])
 {
-  GPUStateMutable &state = 
GPU_context_active_get()->state_stack->mutable_stack_top_get();
+  GPUStateMutable &state = 
GPU_context_active_get()->state_manager->mutable_state;
   for (int i = 0; i < 4; i++) {
     coords[i] = state.viewport_rect[i];
   }
@@ -244,13 +241,13 @@ void GPU_viewport_size_get_f(float coords[4])
 
 void GPU_viewport_size_get_i(int coords[4])
 {
-  GPUStateMutable &state = 
GPU_context_active_get()->state_stack->mutable_stack_top_get();
+  GPUStateMutable &state = 
GPU_context_active_get()->state_manager->mutable_state;
   copy_v4_v4_int(coords, state.viewport_rect);
 }
 
 bool GPU_depth_mask_get(void)
 {
-  GPUState &state = GPU_context_active_get()->state_stack->stack_top_get();
+  GPUState &state = GPU_context_active_get()->state_manager->state;
   return (state.write_mask & GPU_WRITE_DEPTH) != 0;
 }
 
@@ -262,34 +259,6 @@ bool GPU_mipmap_enabled(void)
 
 /** \} */
 
-/* -------------------------------------------------------------------- */
-/** \name GPUStateStack
- * \{ */
-
-void GPUStateStack::push_stack(void)
-{
-  stack[stack_top + 1] = stack[stack_top];
-  stack_top++;
-}
-
-void GPUStateStack::pop_stack(void)
-{
-  stack_top--;
-}
-
-void GPUStateStack::push_mutable_stack(void)
-{
-  mutable_stack[mutable_stack_top + 1] = mutable_stack[mutable_stack_top];
-  mutable_stack_top++;
-}
-
-void GPUStateStack::pop_mutable_stack(void)
-{
-  mutable_stack_top--;
-}
-
-/** \} */
-
 /* -------------------------------------------------------------------- */
 /** \name Context Utils
  * \{ */
diff --git a/source/blender/gpu/intern/gpu_state_private.hh 
b/source/blender/gpu/intern/gpu_state_private.hh
index 31840724ec0..4326c3a73e5 100644
--- a/source/blender/gpu/intern/gpu_state_private.hh
+++ b/source/blender/gpu/intern/gpu_state_private.hh
@@ -79,6 +79,8 @@ inline GPUState operator^(const GPUState &a, const GPUState 
&b)
 /* Mutable state that does not require pipeline change. */
 union GPUStateMutable {
   struct {
+    /* Viewport State */
+    /** TODO put inside GPUFramebuffer. */
     /** Offset + Extent of the drawable region inside the framebuffer. */
     int viewport_rect[4];
     /** Offset + Extent of the scissor region inside the framebuffer. */
@@ -126,41 +128,17 @@ inline GPUStateMutable operator^(const GPUStateMutable 
&a, const GPUStateMutable
   return r;
 }
 
-#define GPU_STATE_STACK_LEN 4
-
-class GPUStateStack {
- private:
-  /** Stack of state for quick temporary modification of the state. */
-  GPUState stack[GPU_STATE_STACK_LEN];
-  GPUStateMutable mutable_stack[GPU_STATE_STACK_LEN];
-  int stack_top = 0;
-  int mutable_stack_top = 0;
-
+class GPUStateManager {
  public:
-  virtual ~GPUStateStack(){};
-
-  virtual void set_state(GPUState &state) = 0;
-  virtual void set_mutable_state(GPUStateMutable &state) = 0;
+  GPUState state;
+  GPUStateMutable mutable_state;
 
-  void push_stack(void);
-  void pop_stack(void);
-
-  void push_mutable_stack(void);
-  void pop_mutable_stack(void);
+ public:
+ 

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to