int solid_load(void) { debuggl_check( "pre solid_load check" ); char const * const paths_vs[] = { "mvp.vs.glsl", 0 }; char const * const paths_fs[] = { "solid.fs.glsl", 0 }; shader_program_sources const sources[] = { {GL_VERTEX_SHADER, paths_vs}, {GL_FRAGMENT_SHADER, paths_fs}, {0,0} }; if( solid.program ) { debuggl_check( glDeleteProgram(solid.program) ); solid.program = 0; } solid.program = shader_program_load_from_files(sources); if( !solid.program ) { fprintf(stderr, "%s failed\n", __func__); return -2; } debuggl_check( solid.u_modelview = glGetProgramResourceLocation(solid.program, GL_UNIFORM, "u_modelview") ); debuggl_check( solid.u_projection = glGetProgramResourceLocation(solid.program, GL_UNIFORM, "u_projection") ); debuggl_check( solid.u_color = glGetProgramResourceLocation(solid.program, GL_UNIFORM, "u_color") ); return 0; }
static void validate_location(GLuint prog, GLenum iface, const char *name, GLuint value) { GLuint loc = glGetProgramResourceLocation(prog, iface, name); /* Validate result against old API. */ switch (iface) { case GL_UNIFORM: if (glGetUniformLocation(prog, name) != loc) piglit_report_result(PIGLIT_FAIL); break; case GL_PROGRAM_INPUT: if (glGetAttribLocation(prog, name) != loc) piglit_report_result(PIGLIT_FAIL); break; case GL_PROGRAM_OUTPUT: if (glGetFragDataLocation(prog, name) != loc) piglit_report_result(PIGLIT_FAIL); break; } /* Expected value. */ if (loc != value) { fprintf(stderr, "got value %d for %s, expected %d\n", loc, name, value); piglit_report_result(PIGLIT_FAIL); } /* No errors should have happened. */ if (!piglit_check_gl_error(GL_NO_ERROR)) piglit_report_result(PIGLIT_FAIL); }
/* Test subroutine uniform location query with vs, fs and gs. */ static bool test_subroutine_stages_vs_fs_gs() { GLuint prog, i; if (!piglit_is_extension_supported("GL_ARB_shader_subroutine")) { piglit_report_subtest_result(PIGLIT_SKIP, __func__); return true; } prog = piglit_build_simple_program_multiple_shaders( GL_VERTEX_SHADER, vs_subroutine_text, GL_GEOMETRY_SHADER, gs_subroutine_text, GL_FRAGMENT_SHADER, fs_subroutine_text, 0); glUseProgram(prog); /* Iterate through all valid subroutine enums passing invalid name. */ for (i = 0; i < (sizeof(valid_enums_sub)/sizeof(GLenum)); i++) { glGetProgramResourceLocation(prog, valid_enums_sub[i], "name"); if (!piglit_check_gl_error(GL_NO_ERROR)) piglit_report_result(PIGLIT_FAIL); } CHECK_SUB(VERTEX); CHECK_SUB(FRAGMENT); CHECK_SUB(GEOMETRY); piglit_report_subtest_result(PIGLIT_PASS, __func__); return true; }
/* Test subroutine uniform location query with compute. */ static bool test_subroutine_stages_compute() { GLuint prog, i; if (!piglit_is_extension_supported("GL_ARB_shader_subroutine")) { piglit_report_subtest_result(PIGLIT_SKIP, __func__); return true; } if (!piglit_is_extension_supported("GL_ARB_compute_shader")) { piglit_report_subtest_result(PIGLIT_SKIP, __func__); return true; } prog = piglit_build_simple_program_multiple_shaders( GL_COMPUTE_SHADER, compute_subroutine_text, 0); glUseProgram(prog); /* Iterate through all valid subroutine enums passing invalid name. */ for (i = 0; i < (sizeof(valid_enums_sub_com)/sizeof(GLenum)); i++) { glGetProgramResourceLocation(prog, valid_enums_sub_com[i], "name"); if (!piglit_check_gl_error(GL_NO_ERROR)) piglit_report_result(PIGLIT_FAIL); } CHECK_SUB(COMPUTE); piglit_report_subtest_result(PIGLIT_PASS, __func__); return true; }
int positiongen_load(void) { debuggl_check( "pre positiongen_load check" ); char const * const paths[] = { "positiongen.glsl", 0 }; shader_program_sources const sources[] = { {GL_COMPUTE_SHADER, paths}, {0,0} }; if( positiongen.program ) { debuggl_check( glDeleteProgram(positiongen.program) ); positiongen.program = 0; } positiongen.program = shader_program_load_from_files(sources); if( !positiongen.program ) { fprintf(stderr, "%s failed\n", __func__); return -2; } debuggl_check( positiongen.w_output = glGetProgramResourceIndex(positiongen.program, GL_SHADER_STORAGE_BLOCK, "w_output") ); debuggl_check( positiongen.u_time = glGetProgramResourceLocation(positiongen.program, GL_UNIFORM, "u_time") ); return 0; }
void piglit_init(int argc, char **argv) { GLuint prog, shader; unsigned i; bool pass = true; piglit_require_extension("GL_ARB_program_interface_query"); piglit_require_extension("GL_ARB_explicit_attrib_location"); piglit_require_extension("GL_ARB_explicit_uniform_location"); /* Test invalid program. */ glGetProgramResourceLocation(42, GL_UNIFORM, "name"); if (!piglit_check_gl_error(GL_INVALID_VALUE)) { piglit_report_subtest_result(PIGLIT_FAIL, "invalid program test 1"); pass = false; } /* Test passing a shader, not program. */ shader = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_loc); glGetProgramResourceLocation(shader, GL_UNIFORM, "name"); if (!piglit_check_gl_error(GL_INVALID_OPERATION)) { piglit_report_subtest_result(PIGLIT_FAIL, "invalid program test 2"); pass = false; } prog = piglit_build_simple_program_unlinked(vs_loc, fs_loc); if (!piglit_check_gl_error(GL_NO_ERROR)) piglit_report_result(PIGLIT_FAIL); /* Test unlinked program. */ glGetProgramResourceLocation(prog, GL_UNIFORM, "name"); if (!piglit_check_gl_error(GL_INVALID_OPERATION)) { piglit_report_subtest_result(PIGLIT_FAIL, "invalid program test 3"); pass = false; } if (pass) piglit_report_subtest_result(PIGLIT_PASS, "invalid program tests"); if (!piglit_check_gl_error(GL_NO_ERROR)) piglit_report_result(PIGLIT_FAIL); /* Test a linked program. */ glLinkProgram(prog); glUseProgram(prog); /* Iterate through all valid enums passing invalid name. */ for (i = 0; i < (sizeof(valid_enums)/sizeof(GLenum)); i++) { glGetProgramResourceLocation(prog, valid_enums[i], "name"); if (!piglit_check_gl_error(GL_NO_ERROR)) piglit_report_result(PIGLIT_FAIL); } /* Test invalid enum, there is no defined error by the spec. */ glGetProgramResourceLocation(prog, GL_ATOMIC_COUNTER_BUFFER, "name"); if (glGetError() == GL_NO_ERROR) { piglit_report_subtest_result(PIGLIT_FAIL, "invalid enum test"); pass = false; } else { piglit_report_subtest_result(PIGLIT_PASS, "invalid enum test"); } /* Test 3 illegal array cases referenced in the spec as 'bug 9254'. */ if (glGetProgramResourceLocation(prog, GL_UNIFORM, "array[+1]") != -1) { piglit_report_subtest_result(PIGLIT_FAIL, "array case 1"); pass = false; } if (glGetProgramResourceLocation(prog, GL_UNIFORM, "array[01]") != -1) { piglit_report_subtest_result(PIGLIT_FAIL, "array case 2"); pass = false; } if (glGetProgramResourceLocation(prog, GL_UNIFORM, "array[ 0]") != -1) { piglit_report_subtest_result(PIGLIT_FAIL, "array case 3"); pass = false; } if (pass) piglit_report_subtest_result(PIGLIT_PASS, "invalid array input"); /* Valid inputs. */ validate_location(prog, GL_UNIFORM, "color", 9); validate_location(prog, GL_PROGRAM_INPUT, "input0", 3); validate_location(prog, GL_PROGRAM_INPUT, "input1", 6); validate_location(prog, GL_PROGRAM_OUTPUT, "output0", 1); validate_location(prog, GL_PROGRAM_OUTPUT, "output1", 0); /* Array indexing cases. */ validate_location(prog, GL_UNIFORM, "array", 1); validate_location(prog, GL_UNIFORM, "array[0]", 1); validate_location(prog, GL_UNIFORM, "array[1]", 2); /* All valid inputs succeeded if we got this far. */ piglit_report_subtest_result(PIGLIT_PASS, "valid inputs"); if (!piglit_check_gl_error(GL_NO_ERROR)) piglit_report_result(PIGLIT_FAIL); /* Tests that require GL_ARB_shader_subroutine. */ pass = test_subroutine_stages_vs_fs_gs() && pass; pass = test_subroutine_stages_tcs_tes() && pass; pass = test_subroutine_stages_compute() && pass; piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL); }
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_ARBProgramInterfaceQuery_nglGetProgramResourceLocation(JNIEnv *__env, jclass clazz, jint program, jint programInterface, jlong nameAddress) { glGetProgramResourceLocationPROC glGetProgramResourceLocation = (glGetProgramResourceLocationPROC)tlsGetFunction(900); intptr_t name = (intptr_t)nameAddress; UNUSED_PARAM(clazz) return (jint)glGetProgramResourceLocation(program, programInterface, name); }
static void check_prop(GLuint prog, GLenum programInterface, int index, const char *name, void *inputs, struct check_t c, bool *pass) { int values[10], parent_idx, i; char subsubtest[150]; GLsizei length, tmp = -1; char buf[21]; GLenum pif; GLuint loc; /* skip the test if it is not supported */ if(!check_extensions_prop(c.prop)) { return; } /* generate the name of the subsubtest for error-reporting purposes */ snprintf(subsubtest, sizeof(subsubtest), "%s: %s on %s", name, piglit_get_gl_enum_name(c.prop), piglit_get_gl_enum_name(programInterface)); /* retrieve the property */ glGetProgramResourceiv(prog, programInterface, index, 1, &c.prop, 10, &length, values); if (!piglit_check_gl_error(GL_NO_ERROR)) { printf(" Latest error generated while running '%s'\n", subsubtest); *pass = false; return; } /* check the return value */ switch (c.prop) { case GL_OFFSET: case GL_ARRAY_STRIDE: case GL_ATOMIC_COUNTER_BUFFER_INDEX: basic_check(subsubtest, values[0], c.values[0], pass); break; case GL_BLOCK_INDEX: /* check that the index of the parent matches the name * of the parent */ switch (programInterface) { case GL_UNIFORM: pif = GL_UNIFORM_BLOCK; break; case GL_BUFFER_VARIABLE: pif = GL_SHADER_STORAGE_BLOCK; break; default: assert(!"unexpected programInterface value"); pif = GL_NONE; } parent_idx = glGetProgramResourceIndex(prog, pif, (char*)inputs); piglit_check_gl_error(GL_NO_ERROR); if (parent_idx != values[0]) { glGetProgramResourceName(prog, programInterface, values[0], sizeof(buf), NULL, buf); fprintf(stderr, "'%s' expected parent name to be %s" "(idx = %i) but got parent name %s(idx = %i)\n", subsubtest, (char*)inputs, parent_idx, buf, values[0]); *pass = false; } break; case GL_BUFFER_BINDING: if (values[0] < 0) { fprintf(stderr, "'%s' invalid buffer binding point\n", subsubtest); *pass = false; } /* Binding index is necessary for ATOMIC_COUNTER_BUFFER */ if (programInterface == GL_ATOMIC_COUNTER_BUFFER) { if (values[0] != c.values[0]) { fprintf(stderr, "'%s' expected binding point %i" " but got %i\n", subsubtest, c.values[0], values[0]); *pass = false; } break; } /* check against another API call */ if (programInterface != GL_UNIFORM_BLOCK) { break; } glGetActiveUniformBlockiv(prog, index, GL_UNIFORM_BLOCK_BINDING, &tmp); piglit_check_gl_error(GL_NO_ERROR); if (tmp != values[0]) { fprintf(stderr, "'%s' inconsistent buffer binding point" "(%i) with glGetActiveUniformBlockiv" "(%i)\n", subsubtest, values[0], tmp); *pass = false; } break; case GL_ACTIVE_VARIABLES: case GL_COMPATIBLE_SUBROUTINES: switch (programInterface) { case GL_UNIFORM_BLOCK: pif = GL_UNIFORM; break; case GL_SHADER_STORAGE_BLOCK: pif = GL_BUFFER_VARIABLE; break; case GL_VERTEX_SUBROUTINE_UNIFORM: pif = GL_VERTEX_SUBROUTINE; break; case GL_TESS_CONTROL_SUBROUTINE_UNIFORM: pif = GL_TESS_CONTROL_SUBROUTINE; break; case GL_COMPUTE_SUBROUTINE_UNIFORM: pif = GL_COMPUTE_SUBROUTINE; break; case GL_ATOMIC_COUNTER_BUFFER: /* do nothing */ break; default: assert(!"unexpected programInterface value"); pif = GL_NONE; } /* check that the return count is as expected */ if (c.count != length) { fprintf(stderr, "'%s' expected %zu entries but got %i" "\n", subsubtest, c.count, length); length = 1; *pass = false; break; } /* harcode the index test for GL_ATOMIC_COUNTER_BUFFER */ if (programInterface == GL_ATOMIC_COUNTER_BUFFER) { if (values[0] != 0) { fprintf(stderr, "'%s' expected index 0 but got " "%i", subsubtest, values[0]); *pass = false; } break; } for (i = 0; i < length; i++) { buf[0] = '\0'; glGetProgramResourceName(prog, pif, values[i], sizeof(buf), NULL, buf); piglit_check_gl_error(GL_NO_ERROR); if (!is_resource_in_list(inputs, buf, i, false)) { fprintf(stderr, "'%s' could not find active " "resource '%s' (idx = %i) in the active" " list\n", subsubtest, buf, values[i]); *pass = false; } } break; case GL_BUFFER_DATA_SIZE: /* Nothing we can check here... */ break; case GL_LOCATION: loc = glGetProgramResourceLocation(prog, programInterface, name); piglit_check_gl_error(GL_NO_ERROR); if (loc != values[0]) { fprintf(stderr, "'%s' inconsistent value between " "glGetProgramResourceiv(%i) and " "glGetProgramResourceLocation(%i).\n", subsubtest, values[0], loc); *pass = false; break; } if (prog == prog_loc && values[0] != c.values[0]) { fprintf(stderr, "'%s' expected location %i but got " "%i\n", subsubtest, c.values[0], values[0]); *pass = false; break; } /* continue by testing the (in)validity of the index */ basic_check(subsubtest, values[0], c.values[0], pass); break; case GL_LOCATION_INDEX: loc = glGetProgramResourceLocationIndex(prog, programInterface, name); piglit_check_gl_error(GL_NO_ERROR); if (loc != values[0]) { fprintf(stderr, "'%s' inconsistent value between " "glGetProgramResourceiv(%i) and " "glGetProgramResourceLocationIndex(%i)." "\n", subsubtest, values[0], loc); *pass = false; break; } /* continue by testing the (in)validity of the index */ basic_check(subsubtest, values[0], c.values[0], pass); break; default: /* check that the return count is as expected */ if (c.count != length) { fprintf(stderr, "'%s' expected %zu entries but got %i" "\n", subsubtest, c.count, length); length = 1; *pass = false; break; } /* go through all the values returned */ for (i = 0; i < length; i++) { if (values[i] != c.values[i]) { fprintf(stderr, "'%s' expected %i but got %i at" " index %i\n", subsubtest, c.values[i], values[i], i); *pass = false; } } break; } }
gl::GLint Program::getResourceLocation(gl::GLenum programInterface, const std::string & name) const { checkDirty(); return glGetProgramResourceLocation(id(), programInterface, name.c_str()); }
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_GL43_nglGetProgramResourceLocation(JNIEnv *__env, jclass clazz, jint program, jint programInterface, jlong nameAddress, jlong __functionAddress) { const GLchar *name = (const GLchar *)(intptr_t)nameAddress; glGetProgramResourceLocationPROC glGetProgramResourceLocation = (glGetProgramResourceLocationPROC)(intptr_t)__functionAddress; UNUSED_PARAMS(__env, clazz) return (jint)glGetProgramResourceLocation(program, programInterface, name); }
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_GL43_nglGetProgramResourceLocation(JNIEnv *env, jclass clazz, jint program, jint programInterface, jlong name, jlong function_pointer) { const GLchar *name_address = (const GLchar *)(intptr_t)name; glGetProgramResourceLocationPROC glGetProgramResourceLocation = (glGetProgramResourceLocationPROC)((intptr_t)function_pointer); GLint __result = glGetProgramResourceLocation(program, programInterface, name_address); return __result; }