我目前在 OpenGL 中遇到一个问题,无法成功将统一数组传递给 GLSL。不幸的是,我一直遇到“GetUniformLocation 失败”错误。
如果您能提供任何见解或建议来帮助我解决此问题,我将非常感激。预先感谢您的协助!
下面是我的代码片段: GLSL:
precision highp float;
uniform float params[3];
void main(void) {
float value = params[0] + params[1] + params[2];
if (value > 5) {
// Additional shader logic...
}
}
CPP:
void function() {
float params[3];
glUseProgram(programHandle1[0]);
GLint uniformLocation = glGetUniformLocation(programHandle1[0], "params");
if (uniformLocation == -1) {
printf("GetUniformLocation failed.\n");
} else {
glUniform1fv(uniformLocation, 3, params);
}
}
OpenGL信息: penGL ES版本:OpenGL ES 3.1 V6.4.11.499680 GLSL 版本:OpenGL ES GLSL ES 3.10 支持的扩展: GL_OES_vertex_type_10_10_10_2 GL_OES_vertex_half_float GL_OES_element_index_uint GL_OES_mapbuffer GL_OES_vertex_array_object GL_OES_compressed_ETC1_RGB8_texture GL_OES_compressed_paletted_texture GL_OES_texture_npot GL_OES_r gb8_rgba8 GL_OES_深度_纹理 GL_OES_深度_纹理_立方体_映射 GL_OES_深度24 GL_OES_深度32 GL_OES_打包_深度_模板 GL_OES_fbo_render_mipmap GL_OES_get_program_binary GL_OES_片段_精度_高 GL_OES_标准_导数 GL_OES_EGL _image GL_OES_EGL_image_external GL_OES_EGL_image_external_essl3 GL_OES_EGL_sync GL_OES_texture_stencil8 GL_OES_shader_image_atomic GL_OES_texture_storage_multisample_2d_array GL_OES_required_internalformat GL_OES_surfaceless_context GL_OES_copy_image GL_O ES_draw_buffers_indexed GL_OES_texture_border_clamp GL_OES_texture_buffer GL_OES_texture_cube_map_array GL_OES_draw_elements_base_vertex GL_OES_texture_half_float GL_OES_texture_float GL_KHR_blend_equation_advanced GL_KHR_debug GL_KHR_robustness GL_ KHR_robust_buffer_access_behavior GL_EXT_texture_type_2_10_10_10_REV GL_EXT_texture_filter_anisotropic GL_EXT_texture_compression_dxt1 GL_EXT_texture_format_BGRA8888 GL_EXT_texture_compression_s3tc GL_EXT_read_format_bgra GL_EXT_multi_draw_arrays GL_EXT_碎片深度GL_EXT_discard_framebuffer GL_EXT_blend_minmax GL_EXT_multisampled_render_to_texture GL_EXT_color_buffer_half_float GL_EXT_color_buffer_float GL_EXT_鲁棒性 GL_EXT_texture_sRGB_decode GL_EXT_draw_buffers_indexed GL_EXT_texture_border_clamp GL_EXT_texture_buffer GL_ EXT_copy_image GL_EXT_texture_cube_map_array GL_EXT_multi_draw_indirect GL_EXT_draw_elements_base_vertex GL_EXT_texture_rg GL_EXT_protected_textures GL_EXT_sRGB GL_EXT_draw_buffers GL_EXT_unpack_subimage GL_EXT_timer_query GL_VIV_direct_texture
返回 -1 的属性或统一位置查询并不是错误,它只是意味着该着色器程序中未使用该属性或统一。
如果它存在于源代码中并返回-1,则仅意味着它已被编译器删除,因为它是多余的。