Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: glTexSubImage3D & GL_INVALID_OPERATION; voxelization

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2012
    Posts
    6

    glTexSubImage3D & GL_INVALID_OPERATION; voxelization

    I have been failing to render to a 3D texture for voxelization so I decided to go a slightly different route. I am able to create a FBO, and given a SINGLE clip plane, can render slices into the 3D texture traversing from front to back. This creates a solid voxelization, as instead of rendering slices (like slices of bread), it simply shears off everything in nearest the viewer. So to get a hollow voxelization, I want 'bread slices', so I added a second clipping plane.... but then I was no longer able render into a 3D texture, for whatever reason.

    So my hope is to use glReadPixels to get the FBO data, then use glTexSubImage3D to write the data directly into the 3D texture.

    Thus far, glTexSubImage3D has been throwing glError with GL_INVALID_OPERATION:
    http://www.opengl.org/sdk/docs/man/x...SubImage3D.xml

    I believe I have narrowed down the issue to the GL_PIXEL_UNPACK_BUFFER, as it doesn't seems like the other causes of this error apply to my program. Thing is, I'm not really sure what the GL_PIXEL_UNPACK_BUFFER is or how it relates.

    Any thoughts?

    Texture setup:
    Code :
    //Set texture dimensions
    	texX = texY = texZ = size;
     
    	glGenTextures(1, &texture);
    	glBindTexture(GL_TEXTURE_3D, texture);
     
    	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP);
    	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
     
    	glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, texX, texY, texZ, 0, GL_RGBA,      GL_UNSIGNED_BYTE, NULL);

    Render to texture
    Code :
    void renderToTex(){
     
    	glGenFramebuffers(1,&framebufferObject);
     
    	glBindTexture(GL_TEXTURE_3D, texture);
     
    	image = new GLubyte[texX * texY * 4];
     
    	glBindFramebuffer(GL_FRAMEBUFFER, framebufferObject);
    	glActiveTexture(GL_TEXTURE0);
     
    	for(int z = 0; z < texZ; z++){
     
    		glFramebufferTextureLayer(GL_FRAMEBUFFER,
    								  GL_COLOR_ATTACHMENT0,
    								  texture,
    								  0,
    								  z);
     
    		//Check frame buffer status
    		cout << endl << "FRAMEBUFFER STATUS: ";
    		checkFramebufferStatus();
    		printFramebufferInfo();
     
    		//Render into texture
    		renderIntoSlice(z);
     
    		//Fill FBO image data
    		glReadPixels(0,0, texX, texY, GL_RGBA, GL_UNSIGNED_BYTE, image);
     
    		//Copy FBO image data into texture
    		glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, z, texX, texY, 1, GL_RGBA, GL_UNSIGNED_BYTE, image);
     
    		//Print texel values by slice; prints contents of 'image' array
    		printPixelsInSlice(z);
     
    	}
     
    	glBindFramebuffer(GL_FRAMEBUFFER, 0);
    }

    Render a single slice:
    Code :
    void renderIntoSlice(int z){
     
    	GLclampf foreColor[3] = {1.0, 1.0, 1.0f};
    	GLclampf backColor[3] = {0, 0, 0};
    	double equation0[4]; // near slice; not the same clipping plane used for the viewing box
    	double equation1[4]; // far slice; not the same clipping plane used for the viewing box
    	double zDis = sigFloor(ply.zMin) + ortho - (ortho / texZ * z);
     
    	//Background color should have alpha == 0?
    	glClearColor(backColor[0], backColor[1], backColor[2], 0);
     
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
    	glEnable(GL_DEPTH_TEST);
     
    	//Get equation of 'near slice' clipping plane
    	equationPlane(0, 0, -1, //Normal
    				  0, 0, zDis,
    				  equation0);	
    	glClipPlane(GL_CLIP_PLANE0, equation0); 
    	glEnable(GL_CLIP_PLANE0);
     
    	//Get equation of 'far slice' clipping plane
    	equationPlane(0, 0, 1, //Normal
    				  0, 0, sigFloor(ply.zMin) + ortho - (ortho / texZ * (z + 1)),
    				  equation1);	
    	glClipPlane(GL_CLIP_PLANE1, equation1); 
    	glEnable(GL_CLIP_PLANE1);
     
    	glColor3fv(foreColor);
    	drawMesh();
     
    	glDisable(GL_CULL_FACE);
    }

  2. #2
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,256
    Are you sure it is glTexSubImage3D that is generating that error? Did you call glGetError before it to make sure it returns GL_NO_ERROR?
    I tested the similar code (no rendering) on a 16x16x16 RGBA8 and I'm not getting any errors. Can you write a minimal program?
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •