On 09/04/2013 02:25 PM, Ian Romanick wrote:
> On 09/04/2013 11:08 AM, Jacob Penner wrote:
>> Add piglit_link_simple_program_with_gs()
>> Add piglit_build_simple_program_with_gs()
>> Add piglit_build_simple_program_unlinked_with_gs()
>> ---
>>  tests/util/piglit-shader.c | 102 
>> +++++++++++++++++++++++++++++++++++++++++++++
>>  tests/util/piglit-shader.h |   7 ++++
>>  2 files changed, 109 insertions(+)
>>
>> diff --git a/tests/util/piglit-shader.c b/tests/util/piglit-shader.c
>> index f7bd06f..227f80c 100644
>> --- a/tests/util/piglit-shader.c
>> +++ b/tests/util/piglit-shader.c
>> @@ -322,3 +322,105 @@ piglit_build_simple_program(const char *vs_source, 
>> const char *fs_source)
>>  
>>      return prog;
>>  }
>> +
>> +GLint piglit_link_simple_program_with_gs(GLint vs, GLint gs, GLint fs)
> 
> Yuck.  What's going to happen when we have tesselation shaders?  In
> computers, there at most 4 numbers: zero, one, two, and N.  Some will
> argue whether or not two should be in that list.
> piglit_link_simple_program already handles one and two, and there's no
> need for zero.  I'd suggest making a new function:
> 
> GLint piglit_link_program_mulitple_shaders(GLint sh1, ...)
> {
>       va_list ap;
>         GLint prog;
> 
>         piglit_require_GLSL();
> 
>         prog = glCreateProgram();
> 
>       va_start(ap, sh1);
> 
>         sh = sh1;
>       do {
>               glAttachShader(prog, sh);
>               sh = va_arg(ap, GLint);
>       } while (sh != 0);
> 
>       va_end(ap);
> 
>         /* If the shaders reference piglit_vertex or piglit_tex, bind
>          * them to some fixed attribute locations so they can be used
>          * with piglit_draw_rect_tex() in GLES.
>          */
>         glBindAttribLocation(prog, PIGLIT_ATTRIB_POS, "piglit_vertex");
>         glBindAttribLocation(prog, PIGLIT_ATTRIB_TEX, "piglit_texcoord");
> 
>         glLinkProgram(prog);
> 
>         if (!piglit_link_check_status(prog)) {
>                 glDeleteProgram(prog);
>                 prog = 0;
>         }
> 
>         return prog;
> }
> 
> Use 0 to terminate the list, and use varargs macros to iterate the list.
> 
> Do the same thing for the other variations.
> 
>> +{
>> +    GLint prog;
>> +
>> +    piglit_require_GLSL();
>> +
>> +    prog = glCreateProgram();
>> +    if (vs)
>> +            glAttachShader(prog, vs);
>> +    if (gs)
>> +            glAttachShader(prog, gs);
>> +    if (fs)
>> +            glAttachShader(prog, fs);
>> +
>> +    /* If the shaders reference piglit_vertex or piglit_tex, bind
>> +     * them to some fixed attribute locations so they can be used
>> +     * with piglit_draw_rect_tex() in GLES.
>> +     */
>> +    glBindAttribLocation(prog, PIGLIT_ATTRIB_POS, "piglit_vertex");
>> +    glBindAttribLocation(prog, PIGLIT_ATTRIB_TEX, "piglit_texcoord");
>> +
>> +    glLinkProgram(prog);
>> +
>> +    if (!piglit_link_check_status(prog)) {
>> +            glDeleteProgram(prog);
>> +            prog = 0;
>> +    }
>> +
>> +    return prog;
>> +}
>> +
>> +/**
>> + * Builds a program from optional VS, GS and FS sources, but does not link
>> + * it. If there is a compile failure, the test is terminated.
>> + */
>> +GLint
>> +piglit_build_simple_program_unlinked_with_gs(const char *vs_source,
>> +                                         const char *gs_source,
>> +                                         const char *fs_source)

I should have pointed out the signature for this version is more
complicated, but the idea is the same:

GLint
piglit_build_simple_program_unlinked_with_gs(const char *source1,
                                                GLenum target1,
                                                ...);


>> +{
>> +    GLuint prog;
>> +
>> +    piglit_require_GLSL();
>> +    prog = glCreateProgram();
>> +    if (vs_source) {
>> +            GLuint vs = piglit_compile_shader_text(GL_VERTEX_SHADER,
>> +                                                   vs_source);
>> +            glAttachShader(prog, vs);
>> +            glDeleteShader(vs);
>> +    }
>> +    if (gs_source) {
>> +            GLuint gs = piglit_compile_shader_text(GL_GEOMETRY_SHADER,
>> +                                                   gs_source);
>> +            glAttachShader(prog, gs);
>> +            glDeleteShader(gs);
>> +    }
>> +    if (fs_source) {
>> +            GLuint fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER,
>> +                                                   fs_source);
>> +            glAttachShader(prog, fs);
>> +            glDeleteShader(fs);
>> +    }
>> +    return prog;
>> +}
>> +
>> +/**
>> + * Builds and links a program from optional VS, GS and FS sources,
>> + * throwing PIGLIT_FAIL on error.
>> + */
>> +GLint
>> +piglit_build_simple_program_with_gs(const char *vs_source,
>> +                                const char *gs_source,
>> +                                const char *fs_source)
>> +{
>> +    GLuint vs = 0, gs = 0, fs = 0, prog;
>> +
>> +    if (vs_source) {
>> +            vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_source);
>> +    }
>> +
>> +    if (gs_source) {
>> +            gs = piglit_compile_shader_text(GL_GEOMETRY_SHADER, gs_source);
>> +    }
>> +
>> +    if (fs_source) {
>> +            fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_source);
>> +    }
>> +
>> +    prog = piglit_link_simple_program_with_gs(vs, gs, fs);
>> +    if (!prog)
>> +            piglit_report_result(PIGLIT_FAIL);
>> +
>> +    if (fs)
>> +            glDeleteShader(fs);
>> +    if (gs)
>> +            glDeleteShader(gs);
>> +    if (vs)
>> +            glDeleteShader(vs);
>> +
>> +    return prog;
>> +}
>> diff --git a/tests/util/piglit-shader.h b/tests/util/piglit-shader.h
>> index 8f18f0a..91acbe8 100644
>> --- a/tests/util/piglit-shader.h
>> +++ b/tests/util/piglit-shader.h
>> @@ -38,6 +38,13 @@ GLint piglit_link_simple_program(GLint vs, GLint fs);
>>  GLint piglit_build_simple_program(const char *vs_source, const char 
>> *fs_source);
>>  GLuint piglit_build_simple_program_unlinked(const char *vs_source,
>>                                          const char *fs_source);
>> +GLint piglit_link_simple_program_with_gs(GLint vs, GLint gs, GLint fs);
>> +GLint piglit_build_simple_program_with_gs(const char *vs_source,
>> +                                      const char *gs_source,
>> +                                      const char *fs_source);
>> +GLint piglit_build_simple_program_unlinked_with_gs(const char *vs_source,
>> +                                               const char *gs_source,
>> +                                               const char *fs_source);
>>  
>>  #if defined(PIGLIT_USE_OPENGL_ES1)
>>  #define glAttachShader assert(!"glAttachShader does not exist in ES1")
>>

_______________________________________________
Piglit mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/piglit

Reply via email to