Jump to content
  • Advertisement
Sign in to follow this  
Tyler Camp

OpenGL OpenGL - Render to 3D framebuffer

This topic is 709 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I'm rendering 2D shadow geometry to a separate framebuffer for each light source, for later use in a shader. The number of light sources vary so I can't have a strict set of textures to reference.
I want to render to a 3D framebuffer to index into these layers. I've written my code as such, but am getting OpenGL errors:
make_scene_occlusion(Render_SceneOcclusion *output) {
	const int frame_width = 2048;
	const int frame_height = 2048;

	while(glGetError() != GL_NO_ERROR) {}


	output->num_maps = 0;

	u32 framebuffer;
	glGenFramebuffers(1, &framebuffer);
	glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);

	u32 rendertextures[12];
	glGenTextures(12, rendertextures);

	output->buf_id = framebuffer;
	output->num_maps = 12;


	for(int i = 0; i < 12; i++) {
		const auto & map = output->occlusion_maps[i];
		glBindTexture(GL_TEXTURE_2D, rendertextures[i]);
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, frame_width, frame_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);


		glFramebufferTexture3D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_3D, rendertextures[i], 0, i);
		output->occlusion_maps[i].idx = i;
		output->occlusion_maps[i].texid = rendertextures[i];
... I get GL_INVALID_ENUM after the call to glFramebufferTexture3D.
In some references I've found people using TEXTURE_2D_ARRAY, but I'm rendering with immediate mode so I don't know if the GL context will support it. Thoughts?
Edited by tylercamp

Share this post

Link to post
Share on other sites
I don't think you can do this.

You can use the gs to decide where you want to write data ("layered rendering"), or you can look into compute shaders and store ops. Some of the restrictions are relaxed there.

For your specific problem, it could be probably better to use one, high res texture instead of multiple smaller ones. That way you don't have to change bindings each draw.

Share this post

Link to post
Share on other sites

There is no such thing as a 3D framebuffer, you can attach slices/layer of a 3-D texture ( 3-D texture/texture array ) as a framebuffer attachment. A framebuffer is 2D conceptually. It seems from the code you posted you are creating 12 2D texture and then attaching the said texture as a layer of a '3-D' texture. Also you need to specify your tex params prior to creating the texture with glTexImage2D.

Edited by cgrant

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!