Soren's picture

[Solved] OpenGL, creating tessellation shaders through GL.CreateShader()

Hi,

Been struggling with this problem for some time now, whenever i attach my tessellation shaders, nothing shows up on screen.
From debugging in glslDevil, it tells me that the values of the enums ShaderType.TessEvaluationShader and ShaderType.TessControlShader are unknown to OpenGL in the GL.CreateShader calls.

My creation code looks like this:

var tessControlSource = new StreamReader("shaders/chap3-tcs.glsl").ReadToEnd();
var tessEvalSource = new StreamReader("shaders/chap3-tes.glsl").ReadToEnd();
 
var tessControlShader = GL.CreateShader(ShaderType.TessControlShader);
GL.ShaderSource(tessControlShader, tessControlSource);
GL.CompileShader(tessControlShader);
 
var tessEvalShader = GL.CreateShader(ShaderType.TessEvaluationShader);
GL.ShaderSource(tessEvalShader, tessEvalSource);
GL.CompileShader(tessEvalShader);
 
var renderProgram = GL.CreateProgram();
GL.AttachShader(renderProgram, vertexShader); // Snip
GL.AttachShader(renderProgram, fragmentShader); // Snip
GL.AttachShader(renderProgram, tessControlShader);
GL.AttachShader(renderProgram, tessEvalShader);
GL.AttachShader(renderProgram, geometryShader); // Snip
GL.LinkProgram(renderProgram);

TCS:

#version 430 core
 
layout (vertices = 3) out;
 
void main(void)
{
	if (gl_InvocationID == 0)
	{
		gl_TessLevelInner[0] = 5.0;
		gl_TessLevelOuter[0] = 5.0;
		gl_TessLevelOuter[1] = 5.0;
		gl_TessLevelOuter[2] = 5.0;
	}
	gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;
}

TES:

#version 430 core
 
layout (triangles, equal_spacing, cw) in;
 
void main(void)
{
	gl_Position = (gl_TessCord.x * gl_in[0].gl_Position +
				   gl_TessCord.y * gl_in[1].gl_Position +
				   gl_TessCord.z * gl_in[2].gl_Position);
}

I'm running on a GTX 670 with the newest drivers, and I've tested the capabilities of it through GPU Caps Viewer to make sure sure it supported tessellation.
Furthermore my CPU is i7 930 and I'm on Windows 7 64-bit.

The project is using .net 4.5 and I'm using the Nuget package and the OpenGL4 API.

I am new to tessellation, so at the moment I'm just trying to get this to work and move on from there.

Any chances anyone have stomped on this before or have any ideas on how it can be fixed?
I'd appreciate every bit of help i can get.


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

AFAIK glslDevil does not support tesselation shaders. I do not know if this has been fixed in the more recent open source version - take a look into apitrace instead.

ShaderType.TessEvaluationShader and TessControlShader match the values in glext.h (just checked), so there is no reason why they would not work. Try using a debug OpenGL context (pass GraphicsContextFlags.Debug to the constructor) and hook the ARB_debug_info callbacks to gather additional debugging information. Apitrace should also indicate whether there is an OpenGL error happening somewhere in the pipeline.

Soren's picture

Apitrace worked wonders, thanks for the tip, without it I'd still be sitting there staring at the code.

I found out I misspelled gl_TessCoord in the tessellation evaluation shader.
Those pesky O's, didn't catch it on my triple checking of the shaders.
Apitrace kindly showed me the attribute that was wrong and so on.

GL.GetError() returned NoError all the way though.

Thanks for the help, really enjoy using this library!
That apitrace really is an invaluable tool.

kkc0923's picture

Hi. I think you read OpenGL superbible 6th edition, chapter 3, right?

I have same problem and I solved simply by chaning

GL.DrawArrays(PrimitiveType.Triangles, 0, 3);

to

GL.DrawArrays(PrimitiveType.Patches, 0, 3);

It should be works :)

Soren's picture

Yeah, that's exactly it!

I managed to get it to work by correcting the shader typo and changing just that.