Cube Mapping Crash/Invalid_Enum

Started by tdc, April 09, 2015, 00:20:25

Previous topic - Next topic

tdc

Hi,
I'm trying to create a Cubemap using textures from other FBOs (environment mapping). Whenever I try to call glTexImage2D depending on the format and InternalFormat parameter I either get an INVALID_ENUM (via glGetError) or a JRE-crash ("A fatal error has been detected by the Java Runtime Environment:  ...")
The line looks like that:
lTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, width, height,
				0, GL_RGBA, GL_UNSIGNED_BYTE, front.getTextureID());

(width = height = 1024)
Overall the code for the Cubemap currently looks something like that:
top.updateTexture();
		bottom.updateTexture();
		front.updateTexture();
		back.updateTexture();
		left.updateTexture();
		right.updateTexture();
		
		glEnable(GL_TEXTURE_CUBE_MAP);
		glBindTexture(GL_TEXTURE_CUBE_MAP, cubemapID);
		
		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S,
				GL_CLAMP_TO_EDGE);
		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T,
				GL_CLAMP_TO_EDGE);
		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R,
				GL_CLAMP_TO_EDGE);
		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL,
				0);
		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL,
				0);
		glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
		
		glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, width, height,
				0, GL_RGBA, GL_UNSIGNED_BYTE, front.getTextureID());
//		...

		glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
		glDisable(GL_TEXTURE_CUBE_MAP);

This problem looks similar but isn't solved yet.
Any ideas how to solve that? How exactly does the InternalFormat work?

Kai

Hi,

what are you trying to do with the glTexImage2D call? That function is used to transfer texel memory to the texture.
So, the issue is likely not with the format or internal format but with your usage of the last argument to glTexImage2D.

You are using the overload of glTexImage2D taking an integer as the last argument that is interpreted on the native OpenGL side as:
- either the host-side/client-side address of pixels of an image that you want to upload to the texture
- or the byte-offset of a server-side buffer bound to PIXEL_UNPACK_BUFFER from which texels should be copied to the texture

Have a look at the documentation of glTexImage2D

Put it another way: You cannot (yet) transfer texture memory from one texture to another directly with a single OpenGL API call, currently. You can only transfer texels from host-memory (your client-side/Java-side ByteBuffer) or from a server-side buffer object.
But I am not sure whether you actually need to do that.

Because, if you already rendered to the texture you only need to bind that rendered-to texture to GL_TEXTURE_CUBE_MAP and you should be good to go to source texels/sample from it when rendering some environment map or cube map. You do not have to copy texels from that texture to another texture.

This means you should create a cube map texture right from the start and render to the individual cube map faces of that texture using the framebuffer object. Then, you can simply use the cube map texture directly for sampling.

quew8

Just to follow up on what @Kai said.

The way you use Framebuffers like this is to create a texture, bind that as a colour attachment of a framebuffer (using the glFramebufferTexture() function). Then when you render anything with that framebuffer bound, it renders into the texture. Then just use that texture as normal.

With cube maps, the "textarget" parameter of glFramebufferTexture() specifies which face of the cube map to bind. Obviously just have 6 framebuffers with a different face bound to each one.