Blender  V2.93
gl_shader.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  * The Original Code is Copyright (C) 2020 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #pragma once
25 
26 #include "MEM_guardedalloc.h"
27 
28 #include "glew-mx.h"
29 
30 #include "gpu_shader_private.hh"
31 
32 namespace blender {
33 namespace gpu {
34 
38 class GLShader : public Shader {
39  private:
41  GLuint shader_program_ = 0;
43  GLuint vert_shader_ = 0;
44  GLuint geom_shader_ = 0;
45  GLuint frag_shader_ = 0;
47  bool compilation_failed_ = false;
48 
49  eGPUShaderTFBType transform_feedback_type_ = GPU_SHADER_TFB_NONE;
50 
51  public:
52  GLShader(const char *name);
53  ~GLShader();
54 
55  /* Return true on success. */
59  bool finalize(void) override;
60 
62  const eGPUShaderTFBType geom_type) override;
63  bool transform_feedback_enable(GPUVertBuf *buf) override;
64  void transform_feedback_disable(void) override;
65 
66  void bind(void) override;
67  void unbind(void) override;
68 
69  void uniform_float(int location, int comp_len, int array_size, const float *data) override;
70  void uniform_int(int location, int comp_len, int array_size, const int *data) override;
71 
72  void vertformat_from_shader(GPUVertFormat *format) const override;
73 
74  /* DEPRECATED: Kept only because of BGL API. */
75  int program_handle_get(void) const override;
76 
77  private:
78  char *glsl_patch_get(void);
79 
80  GLuint create_shader_stage(GLenum gl_stage, MutableSpan<const char *> sources);
81 
82  MEM_CXX_CLASS_ALLOC_FUNCS("GLShader");
83 };
84 
85 } // namespace gpu
86 } // namespace blender
eGPUShaderTFBType
Definition: GPU_shader.h:35
@ GPU_SHADER_TFB_NONE
Definition: GPU_shader.h:36
struct GPUVertBuf GPUVertBuf
Read Guarded memory(de)allocation.
void bind(void) override
Definition: gl_shader.cc:204
void transform_feedback_disable(void) override
Definition: gl_shader.cc:262
bool finalize(void) override
Definition: gl_shader.cc:175
void unbind(void) override
Definition: gl_shader.cc:210
void fragment_shader_from_glsl(MutableSpan< const char * > sources) override
Definition: gl_shader.cc:170
void uniform_float(int location, int comp_len, int array_size, const float *data) override
Definition: gl_shader.cc:273
bool transform_feedback_enable(GPUVertBuf *buf) override
Definition: gl_shader.cc:234
GLShader(const char *name)
Definition: gl_shader.cc:45
int program_handle_get(void) const override
Definition: gl_shader.cc:429
void transform_feedback_names_set(Span< const char * > name_list, const eGPUShaderTFBType geom_type) override
Definition: gl_shader.cc:226
void vertformat_from_shader(GPUVertFormat *format) const override
Definition: gl_shader.cc:401
void uniform_int(int location, int comp_len, int array_size, const int *data) override
Definition: gl_shader.cc:300
void geometry_shader_from_glsl(MutableSpan< const char * > sources) override
Definition: gl_shader.cc:165
void vertex_shader_from_glsl(MutableSpan< const char * > sources) override
Definition: gl_shader.cc:160
format
Definition: logImageCore.h:47