Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

879744 Posts in 33002 Topics- by 24376 Members - Latest Member: xnothegame1

May 24, 2013, 08:00:50 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)GL_INVALID_OPERATION at glFramebufferTexture2DEXT
Pages: [1]
Print
Author Topic: GL_INVALID_OPERATION at glFramebufferTexture2DEXT  (Read 355 times)
Christian Knudsen
Level 10
*****



View Profile WWW Email
« on: June 26, 2012, 10:49:41 AM »

I'm trying to get a basic FBO up and running, but I'm getting a GL_INVALID_OPERATION error when trying to assign a texture to the FBO. I'm on WindowsXP and am programming in Freepascal with SDL as the context wrapper. Here's a code snippet:

Code:
   glEnable(GL_TEXTURE_2D);
   glClearColor(0.0, 0.0, 0.0, 0.0);
   glViewport(0, 0, 800, 600);
   glClear(GL_COLOR_BUFFER_BIT);
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glOrtho(0.0, 800, 600, 0.0, -1.0, 1.0);
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
   glEnable(GL_BLEND);
   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   glDisable(GL_LIGHTING);
   glShadeModel(GL_SMOOTH);

[...]

   TempSurface := IMG_Load('gfx/logo.png');
   glGenTextures(1, @TexID);
   glBindTexture(GL_TEXTURE_2D, TexID);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   glTexImage2D(GL_TEXTURE_2D, 0, 4, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, TempSurface^.pixels);
   SDL_FreeSurface(TempSurface);

[...]

   IF glext_LoadExtension('GL_EXT_framebuffer_object') THEN BEGIN
      glGenFramebuffersEXT(1, @FBO);
      glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FBO);
// NO ERROR HERE
      glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, TexID, 0);
// GL_INVALID_OPERATION RETURNED HERE!
      glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
   END;

I can't figure out what I'm doing wrong here...
Logged

Laserbrain Studios
Currently working on Hostile Takeover (TIGSource DevLog)
ThemsAllTook
Moderator
Level 8
******


Alex Diener


View Profile WWW
« Reply #1 on: June 26, 2012, 11:19:00 AM »

Strange, looks correct as far as I can see. Have you tried printing out FBO and TexID to ensure that they're nonzero?
Logged
Christian Knudsen
Level 10
*****



View Profile WWW Email
« Reply #2 on: June 26, 2012, 11:29:19 AM »

Yeah, they're both 1.
Logged

Laserbrain Studios
Currently working on Hostile Takeover (TIGSource DevLog)
Christian Knudsen
Level 10
*****



View Profile WWW Email
« Reply #3 on: June 26, 2012, 11:37:55 AM »

My textures are 16-bit and that seems to be causing the invalid operation error, because if I try to assign a 32-bit texture to the FBO instead, I don't get that error. So does the texture assigned to the FBO have to be the same bit depth as the desktop or something?

Also, I'm now instead getting GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT when I check the status of the FBO.


I was looking at the wrong output. I'm still getting the error.
Logged

Laserbrain Studios
Currently working on Hostile Takeover (TIGSource DevLog)
ThemsAllTook
Moderator
Level 8
******


Alex Diener


View Profile WWW
« Reply #4 on: June 26, 2012, 12:03:10 PM »

Weird! Well, from the API reference:

Quote
GL_INVALID_OPERATION​ is generated if zero is bound to target​.
GL_INVALID_OPERATION​ is generated if textarget​ and texture​ are not compatible.

I'd assume it's the second one, and you may have been on the right track with the crossed-out part of your post. I'm not entirely sure what all is entailed in compatibility between textarget and texture, though...it'll probably just take some experimentation to figure it out.

Before you edited your post, I found this. I'll leave it here in case you have an NVidia GPU and it becomes relevant: http://www.opengl.org/wiki/Common_Mistakes#Render_To_Texture
Logged
Christian Knudsen
Level 10
*****



View Profile WWW Email
« Reply #5 on: June 26, 2012, 01:03:52 PM »

You're right. It's definitely a texture issue, 'cause when I assign zero instead of a texture, I no longer get an error.
Logged

Laserbrain Studios
Currently working on Hostile Takeover (TIGSource DevLog)
Christian Knudsen
Level 10
*****



View Profile WWW Email
« Reply #6 on: June 26, 2012, 02:53:43 PM »

It was the texture's internal format. I had to change it to GL_RGBA instead of 4.
Logged

Laserbrain Studios
Currently working on Hostile Takeover (TIGSource DevLog)
ThemsAllTook
Moderator
Level 8
******


Alex Diener


View Profile WWW
« Reply #7 on: June 26, 2012, 03:21:14 PM »

Very interesting! I would have assumed those would behave the same way. Glad you solved it!
Logged
Christian Knudsen
Level 10
*****



View Profile WWW Email
« Reply #8 on: June 26, 2012, 03:58:26 PM »

Apparently the FBO doesn't accept the same internal formats as the texture itself. Paragraph "4.4.4 Framebuffer Completeness" of http://www.opengl.org/registry/specs/EXT/framebuffer_object.txt lists the formats that are color-renderable:

Quote
The following base internal formats from table 3.15 are "color-renderable": RGB, RGBA, FLOAT_R_NV, FLOAT_RG_NV, FLOAT_RGB_NV, and FLOAT_RGBA_NV.  The sized internal formats from table 3.16 that have a color-renderable base internal format are also color-renderable.  No other formats, including compressed internal formats, are color-renderable.
Logged

Laserbrain Studios
Currently working on Hostile Takeover (TIGSource DevLog)
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic