ShadowSyrah's picture

TexImage doesn't send data to gpu


I'm working on a project that translates this techniques (GPU Gems3) into OpenGL. Everything worked just fine until I added the last step of the process (Generating the indices).

Now, none of the textures that I made are actually send to the memory of the gpu. The gpu just says: sorry mate, but you didn't send me anything to fill this up, so you get 0.0 from me if you sample that texture (and I've tested this enough to be absolutely sure).

This is the code for making the texture and sending the data to the gpu:

            NoiseVolTextureID = GL.GenTexture();
            GL.BindTexture(TextureTarget.Texture3D, NoiseVolTextureID);
            GL.TexParameter(TextureTarget.Texture3D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture3D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            GL.TexParameter(TextureTarget.Texture3D, TextureParameterName.TextureWrapR, (int)TextureWrapMode.Repeat);
            GL.TexParameter(TextureTarget.Texture3D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
            GL.TexParameter(TextureTarget.Texture3D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);
            GL.TexImage3D(TextureTarget.Texture3D, 0, PixelInternalFormat.R32f, TerrainGeneratorSettings.NoiseVolumeSize, TerrainGeneratorSettings.NoiseVolumeSize, TerrainGeneratorSettings.NoiseVolumeSize, 0, PixelFormat.Red, PixelType.Float, TerrainGeneratorSettings.NoiseVol);
            NoiseVolTextureLocation = GL.GetUniformLocation(ShaderProgram, "noiseVol");

With NoiseVolTextureID a private int, and TerrainGeneratorSettings.NoiseVol a static float[,,] filled with numbers between -1.0f and 1.0f, and ShaderProgram an int that contains a linked and compiled shader.

The code for drawing:

                GL.BindTexture(TextureTarget.Texture3D, NoiseVolTextureID);
                GL.DrawArrays(BeginMode.Points, 0, Vertices.GetLength(0) * Vertices.GetLength(1) * Vertices.GetLength(2));

With Vertices a Vector3 array of positions. There is a lot more going on in the drawing code than this (like TransformFeedback Buffers etc.), but those work just fine, the problem is in generating and filling the textures.

Knowing me it is probably some stupid thing that I forgot, but I've stared too much at the code to see the problem. If you need anything else, just let me know.


Comment viewing options

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

gDEBugger and BuGLe are the best OpenGL debuggers I am aware of. There are also a few things you can also try yourself:

  • As a quick sanity check, run your application with a debug version of OpenTK.dll (compile OpenTK.sln and copy the debug dll to your application directory). The debug dll calls GL.GetError() after every function call which can be very helpful when debugging non-obvious errors.
  • I assume TerrainGeneratorSettings.NoiseVol is filled with data, correct? Try calling GL.GetTexImage3d() to see if the texture object is being filled correctly. If it is, then the texture code is a red-herring (the problem lies elsewhere).
ShadowSyrah's picture

Thanks for the help!

I've found out that the problem lays in the GL.DrawArrays() code, but what precisely the problem is I don't know yet (GetError says: invalid operation), but the Shaders compile without so much as a warning.

I'm now going to check out one of the debuggers you suggested and see what they say that the problem is.