--- C:\DOCUME~1\xxx\LOCALS~1\Temp\GeometryShader.cs-revBASE.svn000.tmp.cs zo aug 23 17:01:54 2009 +++ N:\opentk\Source\Examples\OpenGL\EXT\GeometryShader.cs zo aug 23 17:02:57 2009 @@ -57,9 +57,9 @@ Exit(); } - // create a shader object. + // Create a program object. shaderProgram = GL.CreateProgram(); - // create shader objects for all three types. + // Create shader objects for all three types. int vert = GL.CreateShader(ShaderType.VertexShader); int frag = GL.CreateShader(ShaderType.FragmentShader); int geom = GL.CreateShader(ShaderType.GeometryShaderExt); @@ -122,31 +122,33 @@ compileShader(vert, vertSource); compileShader(geom, geomSource); - // attach shaders and link the program. + // The next three program parameters must be set before the program is linked. + + // Set the input type of the primitives we are going to feed the geometry shader, this should be the same as + // the primitive type given to GL.Begin. If the types do not match a GL error will occur (todo: verify GL_INVALID_ENUM, on glBegin) + GL.Ext.ProgramParameter(shaderProgram, ExtGeometryShader4.GeometryInputTypeExt, (int)All.Lines); + // Set the output type of the geometry shader. Becasue we input Lines we will output LineStrip(s). + GL.Ext.ProgramParameter(shaderProgram, ExtGeometryShader4.GeometryOutputTypeExt, (int)All.LineStrip); + + // We must tell the shader program how much vertices the geometry shader will output (at most). + // The simple way is to query the maximum and use that. + int tmp; + // Get the maximum amount of vertices into tmp. + GL.GetInteger((GetPName)ExtGeometryShader4.MaxGeometryOutputVerticesExt, out tmp); + // And feed amount that to the shader program. (0x0400 on a HD3850, with catalyst 9.8) + GL.Ext.ProgramParameter(shaderProgram, ExtGeometryShader4.GeometryVerticesOutExt, tmp); + + // Attach shaders and link the program. GL.AttachShader(shaderProgram, frag); GL.AttachShader(shaderProgram, vert); GL.AttachShader(shaderProgram, geom); GL.LinkProgram(shaderProgram); - // output link info log. + // Output link info log. string info; GL.GetProgramInfoLog(shaderProgram, out info); Debug.WriteLine(info); - // Set the input type of the primitives we are going to feed the geometry shader, this should be the same as - // the primitive type given to GL.Begin. If the types do not match a GL error will occur (todo: verify GL_INVALID_ENUM, on glBegin) - GL.Ext.ProgramParameter(shaderProgram, ExtGeometryShader4.GeometryInputTypeExt, (int)All.Lines); - // Set the output type of the geometry shader. Becasue we input Lines we will output LineStrip(s). - GL.Ext.ProgramParameter(shaderProgram, ExtGeometryShader4.GeometryOutputTypeExt, (int)All.LineStrip); - - // We must tell the shader program how much vertices the geometry shader will output (at most). - // The simple way is to query the maximum and use that. - int tmp; - // Get the maximum amount of vertices into tmp. - GL.GetInteger((GetPName)ExtGeometryShader4.MaxGeometryOutputVerticesExt, out tmp); - // And feed amount that to the shader program. (0x0400 on a HD3850, with catalyst 9.8) - GL.Ext.ProgramParameter(shaderProgram, ExtGeometryShader4.GeometryVerticesOutExt, tmp); - // Set clearcolor and bind the shader program. GL.ClearColor(0.1f, 0.1f, 0.1f, 0.1f); GL.UseProgram(shaderProgram); @@ -207,7 +209,7 @@ OpenTK.Matrix4 ortho = OpenTK.Matrix4.CreateOrthographicOffCenter(-1, 1, -1, 1, 1, -1); GL.LoadMatrix(ref ortho); - // Set selector state back to matrix mode + // Set selector state back to modelview matrix mode GL.MatrixMode(MatrixMode.Modelview); base.OnResize(e);