Blender  V2.93
gl_state.hh
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * Copyright 2020, Blender Foundation.
17  */
18 
23 #pragma once
24 
25 #include "MEM_guardedalloc.h"
26 
27 #include "BLI_utildefines.h"
28 
29 #include "gpu_state_private.hh"
30 
31 #include "glew-mx.h"
32 
33 namespace blender {
34 namespace gpu {
35 
36 class GLFrameBuffer;
37 class GLTexture;
38 
43 class GLStateManager : public StateManager {
44  public:
47 
48  private:
50  GPUState current_;
51  GPUStateMutable current_mutable_;
53  float line_width_range_[2];
54 
62  GLuint targets_[64] = {GL_TEXTURE_2D};
63  GLuint textures_[64] = {0};
64  GLuint samplers_[64] = {0};
65  uint64_t dirty_texture_binds_ = 0;
66 
67  GLuint images_[8] = {0};
68  GLenum formats_[8] = {0};
69  uint8_t dirty_image_binds_ = 0;
70 
71  public:
73 
74  void apply_state(void) override;
75  void force_state(void) override;
76 
77  void issue_barrier(eGPUBarrier barrier_bits) override;
78 
79  void texture_bind(Texture *tex, eGPUSamplerState sampler, int unit) override;
80  void texture_bind_temp(GLTexture *tex);
81  void texture_unbind(Texture *tex) override;
82  void texture_unbind_all(void) override;
83 
84  void image_bind(Texture *tex, int unit) override;
85  void image_unbind(Texture *tex) override;
86  void image_unbind_all(void) override;
87 
88  void texture_unpack_row_length_set(uint len) override;
89 
92 
93  private:
94  static void set_write_mask(const eGPUWriteMask value);
95  static void set_depth_test(const eGPUDepthTest value);
96  static void set_stencil_test(const eGPUStencilTest test, const eGPUStencilOp operation);
97  static void set_stencil_mask(const eGPUStencilTest test, const GPUStateMutable state);
98  static void set_clip_distances(const int new_dist_len, const int old_dist_len);
99  static void set_logic_op(const bool enable);
100  static void set_facing(const bool invert);
101  static void set_backface_culling(const eGPUFaceCullTest test);
102  static void set_provoking_vert(const eGPUProvokingVertex vert);
103  static void set_shadow_bias(const bool enable);
104  static void set_blend(const eGPUBlend value);
105 
106  void set_state(const GPUState &state);
107  void set_mutable_state(const GPUStateMutable &state);
108 
109  void texture_bind_apply(void);
110  void image_bind_apply(void);
111 
112  MEM_CXX_CLASS_ALLOC_FUNCS("GLStateManager")
113 };
114 
115 static inline GLbitfield to_gl(eGPUBarrier barrier_bits)
116 {
117  GLbitfield barrier = 0;
118  if (barrier_bits & GPU_BARRIER_SHADER_IMAGE_ACCESS) {
119  barrier |= GL_SHADER_IMAGE_ACCESS_BARRIER_BIT;
120  }
121  if (barrier_bits & GPU_BARRIER_TEXTURE_FETCH) {
122  barrier |= GL_TEXTURE_FETCH_BARRIER_BIT;
123  }
124  return barrier;
125 }
126 
127 } // namespace gpu
128 } // namespace blender
unsigned int uint
Definition: BLI_sys_types.h:83
eGPUBlend
Definition: GPU_state.h:54
eGPUWriteMask
Definition: GPU_state.h:25
eGPUProvokingVertex
Definition: GPU_state.h:108
eGPUFaceCullTest
Definition: GPU_state.h:102
eGPUBarrier
Definition: GPU_state.h:38
@ GPU_BARRIER_TEXTURE_FETCH
Definition: GPU_state.h:41
@ GPU_BARRIER_SHADER_IMAGE_ACCESS
Definition: GPU_state.h:40
eGPUStencilOp
Definition: GPU_state.h:94
eGPUDepthTest
Definition: GPU_state.h:77
eGPUStencilTest
Definition: GPU_state.h:87
eGPUSamplerState
Definition: GPU_texture.h:40
Read Guarded memory(de)allocation.
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Texture
void texture_bind_temp(GLTexture *tex)
Definition: gl_state.cc:485
GLFrameBuffer * active_fb
Definition: gl_state.hh:46
void image_unbind(Texture *tex) override
Definition: gl_state.cc:589
uint8_t bound_image_slots(void)
Definition: gl_state.cc:641
void image_bind(Texture *tex, int unit) override
Definition: gl_state.cc:575
uint64_t bound_texture_slots(void)
Definition: gl_state.cc:558
void texture_unpack_row_length_set(uint len) override
Definition: gl_state.cc:553
void apply_state(void) override
Definition: gl_state.cc:74
void force_state(void) override
Definition: gl_state.cc:87
void issue_barrier(eGPUBarrier barrier_bits) override
Definition: gl_state.cc:658
void texture_bind(Texture *tex, eGPUSamplerState sampler, int unit) override
Definition: gl_state.cc:465
void texture_unbind_all(void) override
Definition: gl_state.cc:514
void image_unbind_all(void) override
Definition: gl_state.cc:606
void texture_unbind(Texture *tex) override
Definition: gl_state.cc:496
static GLenum to_gl(const GPUAttachmentType type)
unsigned char uint8_t
Definition: stdint.h:81
unsigned __int64 uint64_t
Definition: stdint.h:93
CCL_NAMESPACE_BEGIN ccl_device float invert(float color, float factor)
Definition: svm_invert.h:19
uint len