Hi,
help anyone?
I think that I should be pretty close to nailing it so far.
Am I storing all the necessary states?
Is the order of calls correct?
I got this setup for now, still failing at the end when unbinding the
texturelocking from the image itself - if anyone wants to get the whole
project for further inspection, I am also ready to mail it or to put it
up somewhere.
I am stuck right now as the error message provided by QC doesn't say
what specifically is still not working - it doesn't give me any clue
whatsoever:
If this is something obvious I could read up, please let me know - for
the moment, I just simply don't know where to start.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
// -- image data procession from hereon /////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
// get the image to use
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
id<QCPlugInInputImageSource> imageToUse = self.inputImage;
CGColorSpaceRef colorSpace = (CGColorSpaceGetModel([imageToUse
imageColorSpace]) == kCGColorSpaceModelRGB ? [imageToUse
imageColorSpace] : [context colorSpace]);
// open gl
CGLContextObj cgl_ctx = [context CGLContextObj];
GLenum error;
glPushAttrib(GL_ALL_ATTRIB_BITS);
GLint previousFBO, previousReadFBO,previousDrawFBO;
glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &previousFBO);
glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING_EXT, &previousReadFBO);
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING_EXT, &previousDrawFBO);
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...
GLuint scaledTexture;
GLuint myFBO;
NSUInteger width = self.inputWidthLEDWall;
NSUInteger 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);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, previousFBO);
glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, previousReadFBO);
glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, previousDrawFBO);
glPopAttrib();
[imageToUse unbindTextureRepresentationFromCGLContext:cgl_ctx
textureUnit:GL_TEXTURE0];
[imageToUse unlockTextureRepresentation];
glDeleteBuffers(1, &myFBO);
glDeleteTextures(1, &scaledTexture);
--
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]