mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
Add support for uniform int osg_FrameNumber in GLSL
This commit is contained in:
parent
5d7bc2c05e
commit
5e219f6438
@ -266,6 +266,8 @@ CLP(ShaderContext)(CLP(GraphicsStateGuardian) *glgsg, Shader *s) : ShaderContext
|
|||||||
_color_attrib_index = -1;
|
_color_attrib_index = -1;
|
||||||
_transform_table_index = -1;
|
_transform_table_index = -1;
|
||||||
_slider_table_index = -1;
|
_slider_table_index = -1;
|
||||||
|
_frame_number_loc = -1;
|
||||||
|
_frame_number = -1;
|
||||||
_validated = !gl_validate_shaders;
|
_validated = !gl_validate_shaders;
|
||||||
|
|
||||||
nassertv(s->get_language() == Shader::SL_GLSL);
|
nassertv(s->get_language() == Shader::SL_GLSL);
|
||||||
@ -941,7 +943,7 @@ reflect_uniform(int i, char *name_buffer, GLsizei name_buflen) {
|
|||||||
if (noprefix == "TransformTable") {
|
if (noprefix == "TransformTable") {
|
||||||
if (param_type != GL_FLOAT_MAT4) {
|
if (param_type != GL_FLOAT_MAT4) {
|
||||||
GLCAT.error()
|
GLCAT.error()
|
||||||
<< "p3d_TransformTable should be uniform mat4\n";
|
<< "p3d_TransformTable should be uniform mat4[]\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_transform_table_index = p;
|
_transform_table_index = p;
|
||||||
@ -951,7 +953,7 @@ reflect_uniform(int i, char *name_buffer, GLsizei name_buflen) {
|
|||||||
if (noprefix == "SliderTable") {
|
if (noprefix == "SliderTable") {
|
||||||
if (param_type != GL_FLOAT) {
|
if (param_type != GL_FLOAT) {
|
||||||
GLCAT.error()
|
GLCAT.error()
|
||||||
<< "p3d_SliderTable should be uniform float\n";
|
<< "p3d_SliderTable should be uniform float[]\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_slider_table_index = p;
|
_slider_table_index = p;
|
||||||
@ -965,8 +967,6 @@ reflect_uniform(int i, char *name_buffer, GLsizei name_buflen) {
|
|||||||
string noprefix(name_buffer + 4);
|
string noprefix(name_buffer + 4);
|
||||||
// These inputs are supported by OpenSceneGraph. We can support
|
// These inputs are supported by OpenSceneGraph. We can support
|
||||||
// them as well, to increase compatibility.
|
// them as well, to increase compatibility.
|
||||||
// Other inputs we may support in the future:
|
|
||||||
// int osg_FrameNumber
|
|
||||||
|
|
||||||
Shader::ShaderMatSpec bind;
|
Shader::ShaderMatSpec bind;
|
||||||
bind._id = arg_id;
|
bind._id = arg_id;
|
||||||
@ -983,7 +983,7 @@ reflect_uniform(int i, char *name_buffer, GLsizei name_buflen) {
|
|||||||
_shader->_mat_spec.push_back(bind);
|
_shader->_mat_spec.push_back(bind);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
} else if (noprefix == "InverseViewMatrix") {
|
} else if (noprefix == "InverseViewMatrix" || noprefix == "ViewMatrixInverse") {
|
||||||
bind._piece = Shader::SMP_whole;
|
bind._piece = Shader::SMP_whole;
|
||||||
bind._func = Shader::SMF_compose;
|
bind._func = Shader::SMF_compose;
|
||||||
bind._part[0] = Shader::SMO_apiview_to_view;
|
bind._part[0] = Shader::SMO_apiview_to_view;
|
||||||
@ -1012,6 +1012,16 @@ reflect_uniform(int i, char *name_buffer, GLsizei name_buflen) {
|
|||||||
bind._dep[1] = Shader::SSD_NONE;
|
bind._dep[1] = Shader::SSD_NONE;
|
||||||
_shader->_mat_spec.push_back(bind);
|
_shader->_mat_spec.push_back(bind);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
} else if (noprefix == "FrameNumber") {
|
||||||
|
// We don't currently support ints with this mechanism,
|
||||||
|
// so we special-case this one.
|
||||||
|
if (param_type != GL_INT) {
|
||||||
|
GLCAT.error() << "osg_FrameNumber should be uniform int\n";
|
||||||
|
} else {
|
||||||
|
_frame_number_loc = p;
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -1514,6 +1524,14 @@ issue_parameters(int altered) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_frame_number_loc != -1) {
|
||||||
|
int current_frame = ClockObject::get_global_clock()->get_frame_count();
|
||||||
|
if (current_frame != _frame_number) {
|
||||||
|
_glgsg->_glUniform1i(_frame_number_loc, current_frame);
|
||||||
|
_frame_number = current_frame;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Iterate through _ptr parameters
|
// Iterate through _ptr parameters
|
||||||
for (int i = 0; i < (int)_shader->_ptr_spec.size(); ++i) {
|
for (int i = 0; i < (int)_shader->_ptr_spec.size(); ++i) {
|
||||||
Shader::ShaderPtrSpec &spec = _shader->_ptr_spec[i];
|
Shader::ShaderPtrSpec &spec = _shader->_ptr_spec[i];
|
||||||
|
@ -80,6 +80,8 @@ private:
|
|||||||
GLint _slider_table_index;
|
GLint _slider_table_index;
|
||||||
GLsizei _transform_table_size;
|
GLsizei _transform_table_size;
|
||||||
GLsizei _slider_table_size;
|
GLsizei _slider_table_size;
|
||||||
|
GLint _frame_number_loc;
|
||||||
|
GLint _frame_number;
|
||||||
pmap<GLint, GLuint64> _glsl_uniform_handles;
|
pmap<GLint, GLuint64> _glsl_uniform_handles;
|
||||||
|
|
||||||
struct ImageInput {
|
struct ImageInput {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user