Cifram's picture

Weird encoding issue with transform feedback

This issue (or one that looks very similar) was brought up in a couple posts back in 2009, but none of the solutions mentioned there seem to work for me. I'm attempting to use transform feedback, but when I specify the output varyings with GL.TransformFeedbackVaryings(), I get a link error on my shader, along the lines of "error: Varying (named 4) specified but not present in the program object." Of course, my varying is not called "4". The code that builds the shader is spread over multiple files, but here are the key elements:

The top-level calls that build the shader:

			vertShader = graphics.CreateShader(ShaderType.VertexShader, "data/shaders/MarchingCubes-Pass1.vert");
			shaderPass1 = graphics.CreateShaderProgram(new[] { vertShader });
			GL.TransformFeedbackVaryings(shaderPass1, 1, new string[] { "gl_Position" }, TransformFeedbackMode.InterleavedAttribs);

The implementation of the three functions called on "graphics":

		public int CreateShader(ShaderType type, string shaderFile) {
			string vertShaderSrc = File.ReadAllText(shaderFile);
			int shaderObj = GL.CreateShader(type);
			GL.ShaderSource(shaderObj, vertShaderSrc);
			int success;
			GL.GetShader(shaderObj, ShaderParameter.CompileStatus, out success);
			if (success == 0) {
				Console.WriteLine("### Error compiling shader " + shaderFile + " ###");
			return shaderObj;
		public int CreateShaderProgram(int[] shaders) {
			int program = GL.CreateProgram();
			foreach (int shader in shaders) {
				GL.AttachShader(program, shader);
			return program;
		public void LinkShaderProgram(int program) {
			int success;
			GL.GetProgram(program, ProgramParameter.LinkStatus, out success);
			if (success == 0) {
				Console.WriteLine("### Error linking shader program ###");

And the shader itself (simple as can be, since for now I'm just trying to get TF working at all):

#version 120
void main() {
	gl_Position = gl_Vertex;

And the shader link error:

Link info
error: Varying (named 4) specified but not present in the program object.

If I run this repeatedly, the value it finds is sometimes "4", and sometimes "&". It seems to alternate from one to the other between runs. The inconsistency indicates, to me, that it might be some kind of memory issue, not just a simple encoding problem.

For reference, I'm running Win7 64-bit, a GeForce 8800 GT, nVidia drivers v8.17.12.9610, and OpenTK pulled from SVN head on August 1st.


Comment viewing options

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

Use GL.GetShaderSource to read and print the shader right after you upload it. If there's a memory corruption issue, it will show itself there.

Additionally, try changing the encoding of the shader file to ASCII (you can do that with NotePad, in the "Save As" dialog). It's a wild shot, but I've seen this help before.

Cifram's picture

Changing the encoding didn't make a difference. I tried to output the shader source, but somehow it causes the DEBUGGER to crash! I'm running it in the debugger in Visual Studio 2010 Pro, and a dialog pops up saying vshost.exe crashed and asking if I want to close it or debug it. Of course, debugging it does little good because I don't have the source code for vshost.exe.

However, I wouldn't expect these to reveal anything. The trouble isn't that it's not finding the variable I'm specifying. The trouble is that it's looking for the wrong variable name. I specify the variable name "gl_Position" and it gives me an error message that it can't find a variable called "4" or "&", neither of which are even legal identifiers in GLSL. Further, my shaders work, when not using transform feedback. They compile, link and produce the expected output, so they must be getting transferred to the graphics card properly.

If there's an encoding problem or transmission problem, it's almost certainly in the string that was passed in to GL.TransformFeedbackVaryings.