GL is stateful -- when you set a state (i.e., when you bind an FBO),
_everything_ from that point on will execute with that state (so if
you leave the FBO bound, for example, everything that renders
afterwards goes to your FBO, not to the screen -- not what you want).
conceptually it's like leaking, except that you alter behavior and
likely get wrong results.
Similarly, QC might be using an FBO behind your back, so if you change
it for your own operation, you _must_ put it back the way it was, or
else when your function returns QC will believe it's still using its
own FBO and not what you set (so you can't just bind to zero and
expect it to be correct) -- you must _get_ what the current GL state
is (via glGet*), change what you need, and then restore the state to
what it was before you change it so that from everyone else's point of
view nothing happened (things will continue to behave as expected).
This is just how GL stuff works - if that wasn't the case, then any
time anyone called any function at all they'd have to expect that it
could have modified the GL state, and they'd have a ton of restoration
code to deal with it, which would be annoying.
Ok, so sorry for being a bit thick, but I can't figure it out by my own.
I got my openGl code enclosed by these glPushAttrib and glPopAttrib, yet
this is still failing for me at the line before the last one, when I try
to unbind the textureRepresentation from the Image I am using.
There is no other openGl code in my patch - this is all there is, i am
not modyfing anything else (note that for simplicities sake, I am just
acquiring the pixeldata in a buffer and releasing it right away without
reading it for the moment):
... code from hereon:
// open gl
CGLContextObj cgl_ctx = [context CGLContextObj];
GLenum error;
glPushAttrib(GL_ALL_ATTRIB_BITS);
if (![imageToUse lockTextureRepresentationWithColorSpace:colorSpace
forBounds:[imageToUse imageBounds]])
{
NSLog(@"Locking of texture failed.");
return NO;
}
[imageToUse bindTextureRepresentationToCGLContext:cgl_ctx
textureUnit:GL_TEXTURE0 normalizeCoordinates:YES];
// scaling in opengl comes here...
const GLuint scaledTexture;
const GLuint myFBO;
int width = self.inputWidthLEDWall;
int height = self.inputHeightLEDWall;
glGenTextures(1, &scaledTexture); // make the destination
scaled texture
// TODO: set up texture dimensions via glTexImage2D
glGenFramebuffers(1, &myFBO); // make the drawing FBO to
perform the scaling
glBindFramebuffer(GL_FRAMEBUFFER_EXT, myFBO);
glFramebufferTexture2D(GL_FRAMEBUFFER_EXT,
GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, scaledTexture, 0);
glDrawBuffer(GL_COLOR_ATTACHMENT0);
// bind source texture -- you might just use the bindTextureRep
call here?
//glBindTexture(GL_TEXTURE_2D (or rect?), GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, GL_TEXTURE0);
// set up projection -- pixel-for-pixel orthographic
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,width,height,0,0,1);
// draw the source to the destination
// TODO: if better-than-bilinear-scaling is desired, add a shader
here to do bicubic or something
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex2f(0,0);
glTexCoord2f(1,0);
glVertex2f(width,0);
glTexCoord2f(1,1);
glVertex2f(width,height);
glTexCoord2f(0,1);
glVertex2f(0, height);
glEnd();
// done! scaledTexture now has the scaled contents using bilinear
scaling in hardware
// make sure to delete fbos and texture when done.
GLvoid* pixelData = malloc(width * height *3);
glReadPixels(0,0,width, height, GL_RGB, GL_UNSIGNED_INT_8_8_8_8,
&pixelData);
free(pixelData);
glDeleteTextures(1, &scaledTexture);
glDeleteBuffers(1, &myFBO);
glPopAttrib();
[imageToUse unbindTextureRepresentationFromCGLContext:cgl_ctx
textureUnit:GL_TEXTURE0];
// THIS FAILS WITH *** OpenGL error 0x0502 (invalid operation) in
function "-[QCPlugInInputImage
unbindTextureRepresentationFromCGLContext:textureUnit:]"
[imageToUse unlockTextureRepresentation];
--
Christophe Leske
multimedial.de
----------------------------------------
www.multimedial.de - [email protected]
Hohler Strasse 17 - 51645 Gummersbach
+49(0)2261-99824540 // +49(0)177-2497031
----------------------------------------
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Quartzcomposer-dev mailing list ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/quartzcomposer-dev/archive%40mail-archive.com
This email sent to [email protected]