glgsg: Fix sharing shaders between GSGs

Fixes #1728
This commit is contained in:
rdb 2025-09-14 11:00:13 +02:00
parent b275a72d0f
commit e661d02815
6 changed files with 19 additions and 11 deletions

View File

@ -388,14 +388,17 @@ valid() {
* all of the shader's input parameters.
*/
void CLP(CgShaderContext)::
bind() {
bind(GraphicsStateGuardian *gsg) {
CLP(GraphicsStateGuardian) *glgsg = (CLP(GraphicsStateGuardian) *)gsg;
_glgsg = glgsg;
if (_cg_program != 0) {
// Bind the shaders.
cgGLEnableProgramProfiles(_cg_program);
cgGLBindProgram(_cg_program);
cg_report_errors();
_glgsg->report_my_gl_errors();
glgsg->report_my_gl_errors();
}
}

View File

@ -34,7 +34,7 @@ public:
ALLOC_DELETED_CHAIN(CLP(CgShaderContext));
bool valid(void) override;
void bind() override;
void bind(GraphicsStateGuardian *gsg) override;
void unbind() override;
void set_state_and_transform(const RenderState *state,

View File

@ -8717,7 +8717,7 @@ do_issue_shader() {
// If it's a different type of shader, make sure to unbind the old.
_current_shader_context->unbind();
}
context->bind();
context->bind(this);
_current_shader = shader;
}

View File

@ -416,7 +416,7 @@ CLP(ShaderContext)(CLP(GraphicsStateGuardian) *glgsg, Shader *s) : ShaderContext
if (_glgsg->_current_shader_context == nullptr) {
_glgsg->_glUseProgram(0);
} else {
_glgsg->_current_shader_context->bind();
_glgsg->_current_shader_context->bind(_glgsg);
}
_mat_part_cache = new LVecBase4f[_shader->cp_get_mat_cache_size()];
@ -2192,15 +2192,18 @@ valid() {
* all of the shader's input parameters.
*/
void CLP(ShaderContext)::
bind() {
bind(GraphicsStateGuardian *gsg) {
CLP(GraphicsStateGuardian) *glgsg = (CLP(GraphicsStateGuardian) *)gsg;
_glgsg = glgsg;
if (!_validated) {
_glgsg->_glValidateProgram(_glsl_program);
glgsg->_glValidateProgram(_glsl_program);
glsl_report_program_errors(_glsl_program, false);
_validated = true;
}
if (!_shader->get_error_flag()) {
_glgsg->_glUseProgram(_glsl_program);
glgsg->_glUseProgram(_glsl_program);
}
if (GLCAT.is_spam()) {
@ -2208,7 +2211,7 @@ bind() {
<< _shader->get_filename() << "\n";
}
_glgsg->report_my_gl_errors();
glgsg->report_my_gl_errors();
}
/**

View File

@ -42,7 +42,7 @@ public:
bool get_sampler_texture_type(int &out, GLenum param_type);
bool valid(void) override;
void bind() override;
void bind(GraphicsStateGuardian *gsg) override;
void unbind() override;
void set_state_and_transform(const RenderState *state,

View File

@ -19,6 +19,8 @@
#include "savedContext.h"
#include "shader.h"
class GraphicsStateGuardian;
/**
* The ShaderContext is meant to contain the compiled version of a shader
* string. ShaderContext is an abstract base class, there will be a subclass
@ -38,7 +40,7 @@ public:
const TransformState *) {};
INLINE virtual bool valid() { return false; }
INLINE virtual void bind() {};
INLINE virtual void bind(GraphicsStateGuardian *gsg) {};
INLINE virtual void unbind() {};
INLINE virtual void issue_parameters(int altered) {};
INLINE virtual void disable_shader_vertex_arrays() {};