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-08-21 14:48:34 +0300
committerClément Foucault <foucault.clem@gmail.com>2020-08-21 15:16:42 +0300
commit220fbdf59341f620c06959280e2145132003c5df (patch)
tree32f1d80da91aee1bbe13e69b7f8ac3c93e429ccc /source/blender/gpu/intern
parent1e95a7402c62d2380710a56733e6c4cbe390b3be (diff)
GPUShader: Make GPUShader* an opaque pointer to blender::gpu::Shader
This avoids the misleading inheritance. Also cleanup by setting the blender::gpu::Shader as active shader to avoid some casting.
Diffstat (limited to 'source/blender/gpu/intern')
-rw-r--r--source/blender/gpu/intern/gpu_context_private.hh3
-rw-r--r--source/blender/gpu/intern/gpu_shader.cc41
-rw-r--r--source/blender/gpu/intern/gpu_shader_private.hh6
-rw-r--r--source/blender/gpu/intern/gpu_vertex_format.cc2
4 files changed, 31 insertions, 21 deletions
diff --git a/source/blender/gpu/intern/gpu_context_private.hh b/source/blender/gpu/intern/gpu_context_private.hh
index b774d6b0995..e8c9c976e9a 100644
--- a/source/blender/gpu/intern/gpu_context_private.hh
+++ b/source/blender/gpu/intern/gpu_context_private.hh
@@ -29,6 +29,7 @@
#include "GPU_context.h"
+#include "gpu_shader_private.hh"
#include "gpu_state_private.hh"
#include <mutex>
@@ -43,7 +44,7 @@ struct GPUMatrixState;
struct GPUContext {
public:
/** State managment */
- GPUShader *shader = NULL;
+ blender::gpu::Shader *shader = NULL;
GPUFrameBuffer *current_fbo = NULL;
GPUMatrixState *matrix_state = NULL;
blender::gpu::GPUStateManager *state_manager = NULL;
diff --git a/source/blender/gpu/intern/gpu_shader.cc b/source/blender/gpu/intern/gpu_shader.cc
index a0034a30590..b1772bed6e8 100644
--- a/source/blender/gpu/intern/gpu_shader.cc
+++ b/source/blender/gpu/intern/gpu_shader.cc
@@ -52,6 +52,11 @@ extern "C" char datatoc_gpu_shader_colorspace_lib_glsl[];
using namespace blender;
using namespace blender::gpu;
+/** Opaque type hidding blender::gpu::Shader */
+struct GPUShader {
+ char _pad[1];
+};
+
/* -------------------------------------------------------------------- */
/** \name Debug functions
* \{ */
@@ -302,12 +307,12 @@ GPUShader *GPU_shader_create_ex(const char *vertcode,
return NULL;
};
- return static_cast<GPUShader *>(shader);
+ return reinterpret_cast<GPUShader *>(shader);
}
void GPU_shader_free(GPUShader *shader)
{
- delete static_cast<Shader *>(shader);
+ delete reinterpret_cast<Shader *>(shader);
}
/** \} */
@@ -429,19 +434,19 @@ struct GPUShader *GPU_shader_create_from_arrays_impl(
void GPU_shader_bind(GPUShader *gpu_shader)
{
- Shader *shader = static_cast<Shader *>(gpu_shader);
+ Shader *shader = reinterpret_cast<Shader *>(gpu_shader);
GPUContext *ctx = GPU_context_active_get();
if (ctx->shader != shader) {
ctx->shader = shader;
shader->bind();
- GPU_matrix_bind(shader);
- GPU_shader_set_srgb_uniform(shader);
+ GPU_matrix_bind(gpu_shader);
+ GPU_shader_set_srgb_uniform(gpu_shader);
}
if (GPU_matrix_dirty_get()) {
- GPU_matrix_bind(shader);
+ GPU_matrix_bind(gpu_shader);
}
}
@@ -450,7 +455,7 @@ void GPU_shader_unbind(void)
#ifndef NDEBUG
GPUContext *ctx = GPU_context_active_get();
if (ctx->shader) {
- static_cast<Shader *>(ctx->shader)->unbind();
+ reinterpret_cast<Shader *>(ctx->shader)->unbind();
}
ctx->shader = NULL;
#endif
@@ -466,12 +471,12 @@ void GPU_shader_unbind(void)
bool GPU_shader_transform_feedback_enable(GPUShader *shader, GPUVertBuf *vertbuf)
{
- return static_cast<Shader *>(shader)->transform_feedback_enable(vertbuf);
+ return reinterpret_cast<Shader *>(shader)->transform_feedback_enable(vertbuf);
}
void GPU_shader_transform_feedback_disable(GPUShader *shader)
{
- static_cast<Shader *>(shader)->transform_feedback_disable();
+ reinterpret_cast<Shader *>(shader)->transform_feedback_disable();
}
/** \} */
@@ -482,48 +487,48 @@ void GPU_shader_transform_feedback_disable(GPUShader *shader)
int GPU_shader_get_uniform(GPUShader *shader, const char *name)
{
- ShaderInterface *interface = static_cast<Shader *>(shader)->interface;
+ ShaderInterface *interface = reinterpret_cast<Shader *>(shader)->interface;
const ShaderInput *uniform = interface->uniform_get(name);
return uniform ? uniform->location : -1;
}
int GPU_shader_get_builtin_uniform(GPUShader *shader, int builtin)
{
- ShaderInterface *interface = static_cast<Shader *>(shader)->interface;
+ ShaderInterface *interface = reinterpret_cast<Shader *>(shader)->interface;
return interface->uniform_builtin((GPUUniformBuiltin)builtin);
}
int GPU_shader_get_builtin_block(GPUShader *shader, int builtin)
{
- ShaderInterface *interface = static_cast<Shader *>(shader)->interface;
+ ShaderInterface *interface = reinterpret_cast<Shader *>(shader)->interface;
return interface->ubo_builtin((GPUUniformBlockBuiltin)builtin);
}
/* DEPRECATED. */
int GPU_shader_get_uniform_block(GPUShader *shader, const char *name)
{
- ShaderInterface *interface = static_cast<Shader *>(shader)->interface;
+ ShaderInterface *interface = reinterpret_cast<Shader *>(shader)->interface;
const ShaderInput *ubo = interface->ubo_get(name);
return ubo ? ubo->location : -1;
}
int GPU_shader_get_uniform_block_binding(GPUShader *shader, const char *name)
{
- ShaderInterface *interface = static_cast<Shader *>(shader)->interface;
+ ShaderInterface *interface = reinterpret_cast<Shader *>(shader)->interface;
const ShaderInput *ubo = interface->ubo_get(name);
return ubo ? ubo->binding : -1;
}
int GPU_shader_get_texture_binding(GPUShader *shader, const char *name)
{
- ShaderInterface *interface = static_cast<Shader *>(shader)->interface;
+ ShaderInterface *interface = reinterpret_cast<Shader *>(shader)->interface;
const ShaderInput *tex = interface->uniform_get(name);
return tex ? tex->binding : -1;
}
int GPU_shader_get_attribute(GPUShader *shader, const char *name)
{
- ShaderInterface *interface = static_cast<Shader *>(shader)->interface;
+ ShaderInterface *interface = reinterpret_cast<Shader *>(shader)->interface;
const ShaderInput *attr = interface->attr_get(name);
return attr ? attr->location : -1;
}
@@ -550,13 +555,13 @@ int GPU_shader_get_program(GPUShader *UNUSED(shader))
void GPU_shader_uniform_vector(
GPUShader *shader, int loc, int len, int arraysize, const float *value)
{
- static_cast<Shader *>(shader)->uniform_float(loc, len, arraysize, value);
+ reinterpret_cast<Shader *>(shader)->uniform_float(loc, len, arraysize, value);
}
void GPU_shader_uniform_vector_int(
GPUShader *shader, int loc, int len, int arraysize, const int *value)
{
- static_cast<Shader *>(shader)->uniform_int(loc, len, arraysize, value);
+ reinterpret_cast<Shader *>(shader)->uniform_int(loc, len, arraysize, value);
}
void GPU_shader_uniform_int(GPUShader *shader, int location, int value)
diff --git a/source/blender/gpu/intern/gpu_shader_private.hh b/source/blender/gpu/intern/gpu_shader_private.hh
index d51c3b03ecb..e5af22cae92 100644
--- a/source/blender/gpu/intern/gpu_shader_private.hh
+++ b/source/blender/gpu/intern/gpu_shader_private.hh
@@ -29,11 +29,15 @@
namespace blender {
namespace gpu {
-class Shader : public GPUShader {
+class Shader {
public:
/** Uniform & attribute locations for shader. */
ShaderInterface *interface;
+ protected:
+ /** For debugging purpose. */
+ char name[64];
+
public:
Shader(const char *name);
virtual ~Shader();
diff --git a/source/blender/gpu/intern/gpu_vertex_format.cc b/source/blender/gpu/intern/gpu_vertex_format.cc
index 2b16f4482b4..ed317b3a0df 100644
--- a/source/blender/gpu/intern/gpu_vertex_format.cc
+++ b/source/blender/gpu/intern/gpu_vertex_format.cc
@@ -407,6 +407,6 @@ void VertexFormat_pack(GPUVertFormat *format)
void GPU_vertformat_from_shader(GPUVertFormat *format, const struct GPUShader *gpushader)
{
- const Shader *shader = static_cast<const Shader *>(gpushader);
+ const Shader *shader = reinterpret_cast<const Shader *>(gpushader);
shader->vertformat_from_shader(format);
}