Search code examples
opengl-esglslopengl-shader-builder

OpenGL-glGetUniformLocation failed


I'm currently encountering an issue in OpenGL where I'm unable to successfully pass a uniform array to GLSL.Unfortunately, I'm consistently encountering the 'GetUniformLocation failed' error.

I would be immensely grateful for any insights or suggestions to help me resolve this issue. Thank you in advance for your assistance!

Below is a snippet of my code: 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 information: penGL ES Version: OpenGL ES 3.1 V6.4.11.499680 GLSL Version: OpenGL ES GLSL ES 3.10 Supported Extensions: 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_rgb8_rgba8 GL_OES_depth_texture GL_OES_depth_texture_cube_map GL_OES_depth24 GL_OES_depth32 GL_OES_packed_depth_stencil GL_OES_fbo_render_mipmap GL_OES_get_program_binary GL_OES_fragment_precision_high GL_OES_standard_derivatives 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_OES_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_frag_depth 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_robustness 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


Solution

  • An attribute or uniform location query returning -1 isn't an error, it just means that the attribute or uniform isn't used in that shader program.

    If it existed in the source and returns -1, it just means it's been stripped by the compiler because it was redundant.