On Tuesday 03 August 2010 12:56:41 Chia-I Wu wrote: > I see your point. There are more than one way to interpret the > diagram. Now I am curious if the diagram is all the D3D documents have > for triangle strip with adjacency?
As far as the public docs go I think that's it. > > and so on. If you have a testcase that shows which way it is, great, > > lets change it (aka fix it). Otherwise I'm just not too excited about > > changing code that was working with the (corny) testcases it had for > > something without any. > > Sure. Where can I find the test cases, if they are public? I've tested with a few proprietary demos/apps, but since I've implemented gs in Mesa as well we can use that. You can put the attached files in demos/src/glsl and compile it there. I never tested triangle strips with adjacency in mesa but it seems to be at least rendering something (the adjacency vertices are definitely flipped). Try glDrawArrays with different values, e.g. 1) glDrawArrays(GL_TRIANGLE_STRIP_ADJACENCY_ARB, 0, 6); 2) glDrawArrays(GL_TRIANGLE_STRIP_ADJACENCY_ARB, 2, 6); 3) glDrawArrays(GL_TRIANGLE_STRIP_ADJACENCY_ARB, 4, 6); 4) glDrawArrays(GL_TRIANGLE_STRIP_ADJACENCY_ARB, 0, 8); 5) glDrawArrays(GL_TRIANGLE_STRIP_ADJACENCY_ARB, 2, 8); 6) glDrawArrays(GL_TRIANGLE_STRIP_ADJACENCY_ARB, 0, 10); It'd be awesome if we had a piglit test for it, but right now anything that with some manual testing looks like whatever proprietary NVIDIA/AMD drivers do would be fine. z
#include <assert.h> #include <string.h> #include <stdio.h> #include <stdlib.h> #include <math.h> #define GL_GLEXT_PROTOTYPES #include <GL/glew.h> #include <GL/glut.h> #include <GL/glext.h> #include "shaderutil.h" static const char *filename = "tri-adj.geom"; static GLuint fragShader; static GLuint vertShader; static GLuint geoShader; static GLuint program; #define QUIT 9999 struct Vertex { float position[4]; float color[4]; }; const struct Vertex vTri[10] = { { { -1.0f, -0.33f, 0.5f, 1.0f },//0 { 1.0f, 0.0f, 0.0f, 1.0f } }, { { -1.0f, 0.33f, 0.5f, 1.0f },//1 { 0.0f, 1.0f, 0.0f, 1.0f } }, { { -0.5f, 0.33f, 0.5f, 1.0f },//2 { 0.0f, 0.0f, 1.0f, 1.0f } }, { { -0.5f, -1.0f, 0.5f, 1.0f },//3 { 1.0f, 1.0f, 0.0f, 1.0f } }, { { 0.0f, -0.33f, 0.5f, 1.0f },//4 { 0.0f, 0.0f, 0.0f, 1.0f } }, { { 0.0f, 1.0f, 0.5f, 1.0f },//5 { 0.5f, 0.5f, 0.0f, 1.0f } }, { { 0.5f, 0.33f, 0.5f, 1.0f },//6 { 0.0f, 1.0f, 0.0f, 1.0f } }, { { 0.5f, -1.0f, 0.5f, 1.0f },//7 { 1.0f, 0.0f, 1.0f, 1.0f } }, { { 1.0f, -0.33f, 0.5f, 1.0f },//8 { 1.0f, 1.0f, 0.0f, 1.0f } }, { { 1.0f, 0.33f, 0.5f, 1.0f },//9 { 1.0f, 0.0f, 1.0f, 1.0f } } }; static void usage( char *name ) { fprintf(stderr, "usage: %s\n", name); fprintf(stderr, "\n" ); } static void load_and_compile_shader(GLuint shader, const char *text) { GLint stat; glShaderSource(shader, 1, (const GLchar **) &text, NULL); glCompileShader(shader); glGetShaderiv(shader, GL_COMPILE_STATUS, &stat); if (!stat) { GLchar log[1000]; GLsizei len; glGetShaderInfoLog(shader, 1000, &len, log); fprintf(stderr, "tri-adj: problem compiling shader:\n%s\n", log); exit(1); } } static void read_shader(GLuint shader, const char *filename) { const int max = 100*1000; int n; char *buffer = (char*) malloc(max); FILE *f = fopen(filename, "r"); if (!f) { fprintf(stderr, "tri-adj: Unable to open shader file %s\n", filename); exit(1); } n = fread(buffer, 1, max, f); printf("tri-adj: read %d bytes from shader file %s\n", n, filename); if (n > 0) { buffer[n] = 0; load_and_compile_shader(shader, buffer); } fclose(f); free(buffer); } static void check_link(GLuint prog) { GLint stat; glGetProgramiv(prog, GL_LINK_STATUS, &stat); if (!stat) { GLchar log[1000]; GLsizei len; glGetProgramInfoLog(prog, 1000, &len, log); fprintf(stderr, "Linker error:\n%s\n", log); } } static void init(void) { static const char *fragShaderText = "void main() {\n" " gl_FragColor = gl_Color;\n" "}\n"; static const char *vertShaderText = "void main() {\n" " gl_FrontColor = gl_Color;\n" " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" "}\n"; static const char *geoShaderText = "#version 120\n" "#extension GL_ARB_geometry_shader4 : enable\n" "void main()\n" "{\n" " for(int i = 0; i < gl_VerticesIn; ++i)\n" " {\n" " gl_FrontColor = gl_FrontColorIn[i];\n" " gl_Position = gl_PositionIn[i];\n" " EmitVertex();\n" " }\n" "}\n"; if (!ShadersSupported()) exit(1); fragShader = glCreateShader(GL_FRAGMENT_SHADER); load_and_compile_shader(fragShader, fragShaderText); vertShader = glCreateShader(GL_VERTEX_SHADER); load_and_compile_shader(vertShader, vertShaderText); geoShader = glCreateShader(GL_GEOMETRY_SHADER_ARB); if (filename) read_shader(geoShader, filename); else load_and_compile_shader(geoShader, geoShaderText); program = glCreateProgram(); glAttachShader(program, vertShader); glAttachShader(program, geoShader); glAttachShader(program, fragShader); glProgramParameteriARB(program, GL_GEOMETRY_INPUT_TYPE_ARB, GL_TRIANGLES_ADJACENCY_ARB); glProgramParameteriARB(program, GL_GEOMETRY_OUTPUT_TYPE_ARB, GL_TRIANGLE_STRIP); { int temp; glGetIntegerv(GL_MAX_GEOMETRY_OUTPUT_VERTICES_ARB,&temp); glProgramParameteriARB(program,GL_GEOMETRY_VERTICES_OUT_ARB,temp); } glLinkProgram(program); check_link(program); glUseProgram(program); assert(glGetError() == 0); glEnableClientState( GL_VERTEX_ARRAY ); glEnableClientState( GL_COLOR_ARRAY ); glVertexPointer( 4, GL_FLOAT, sizeof(vTri[0]), vTri[0].position ); glColorPointer( 4, GL_FLOAT, sizeof(vTri[0]), vTri[1].color ); } static void args(int argc, char *argv[]) { if (argc != 1) { usage(argv[0]); exit(1); } } static void Display( void ) { glClearColor(0, 0, 0, 1); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glUseProgram(program); glEnable(GL_VERTEX_PROGRAM_ARB); glDrawArrays(GL_TRIANGLE_STRIP_ADJACENCY_ARB, 4, 6); glFlush(); } static void Reshape( int width, int height ) { glViewport( 0, 0, width, height ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); /*glTranslatef( 0.0, 0.0, -15.0 );*/ } static void CleanUp(void) { glDeleteShader(fragShader); glDeleteShader(vertShader); glDeleteProgram(program); } static void Key( unsigned char key, int x, int y ) { (void) x; (void) y; switch (key) { case 27: CleanUp(); exit(0); break; } glutPostRedisplay(); } int main( int argc, char *argv[] ) { glutInit( &argc, argv ); glutInitWindowPosition( 0, 0 ); glutInitWindowSize( 250, 250 ); glutInitDisplayMode( GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH ); glutCreateWindow(argv[0]); glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutDisplayFunc( Display ); args(argc, argv); init(); glutMainLoop(); return 0; }
#version 120 #extension GL_EXT_geometry_shader4: enable void main() { gl_Position = gl_PositionIn[1]; gl_FrontColor = vec4(1, 0, 0, 0.5); EmitVertex(); gl_Position = gl_PositionIn[3]; gl_FrontColor = vec4(0, 1, 0, 0.5); EmitVertex(); gl_Position = gl_PositionIn[5]; gl_FrontColor = vec4(0, 0, 1, 0.5); EmitVertex(); EndPrimitive(); gl_Position = gl_PositionIn[0]; gl_FrontColor = vec4(1, 1, 1, 1); EmitVertex(); gl_Position = gl_PositionIn[2]; gl_FrontColor = vec4(1, 0, 0, 1); EmitVertex(); gl_Position = gl_PositionIn[4]; gl_FrontColor = vec4(0, 0, 1, 1); EmitVertex(); EndPrimitive(); }
_______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev