diff --git a/Classes/Retronator/Xni/Framework/Graphics/GraphicsDevice.m b/Classes/Retronator/Xni/Framework/Graphics/GraphicsDevice.m index c9737e5..776ee4a 100644 --- a/Classes/Retronator/Xni/Framework/Graphics/GraphicsDevice.m +++ b/Classes/Retronator/Xni/Framework/Graphics/GraphicsDevice.m @@ -549,17 +549,18 @@ } - (void) setRenderTarget:(RenderTarget2D*)renderTarget{ + GLenum format, type; + if (renderTarget == nil) { if (rrt) { //We had render target before now we have to flip it vertically rrt = NO; + glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebuffer); } - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRenderbuffer); + }else{ GLuint rtFramebuffer = [renderTarget colorFramebuffer]; - GLuint rtRenderbuffer = [renderTarget colorRenderbuffer]; - GLenum format, type; [GraphicsDevice getFormat:&format AndType:&type ForSurfaceFormat:renderTarget.format]; // RENDER TO TEXTURE BUFFER @@ -567,12 +568,6 @@ // on out screen plane glBindFramebufferOES(GL_FRAMEBUFFER_OES, rtFramebuffer); -// glBindRenderbufferOES(GL_RENDERBUFFER_OES, rtRenderbuffer); -// -// glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer); -// glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, renderTarget.width, renderTarget.height); -// glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer); - // create the texture object glBindTexture(GL_TEXTURE_2D, renderTarget.textureId); @@ -581,7 +576,6 @@ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR); - // fill the texture data (the max texture size needs to be power of 2) glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, renderTarget.width, renderTarget.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); @@ -591,18 +585,11 @@ //glOrthof(0, renderTarget.width, renderTarget.height, 0, -1, 1); // CHECK FRAME BUFFER STATUS HERE - - -// GLenum status = glCheckFramebufferStatusOES(GL_FRAMEBUFFER); -// if(status == GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT){ -// NSLog(@"GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT"); -// }else if(status == GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT){ -// NSLog(@"GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT"); -// }else if(status == GL_FRAMEBUFFER_UNSUPPORTED){ -// NSLog(@"GL_FRAMEBUFFER_UNSUPPORTED"); -// }else if(status == GL_FRAMEBUFFER_COMPLETE){ -// NSLog(@"GL_FRAMEBUFFER_COMPLETE"); -// } + GLenum status = glCheckFramebufferStatusOES(GL_FRAMEBUFFER); + if(status != GL_FRAMEBUFFER_COMPLETE){ + NSLog(@"Error binding renderTarget"); + } + rrt = YES; } } diff --git a/Classes/Retronator/Xni/Framework/Graphics/RenderTarget2D.m b/Classes/Retronator/Xni/Framework/Graphics/RenderTarget2D.m index 0c04a4a..26d855b 100644 --- a/Classes/Retronator/Xni/Framework/Graphics/RenderTarget2D.m +++ b/Classes/Retronator/Xni/Framework/Graphics/RenderTarget2D.m @@ -17,13 +17,27 @@ @interface RenderTarget2D (){ GLuint framebuffer; - GLuint renderBuffer; } @end @implementation RenderTarget2D +- (id)initWithGraphicsDevice:(GraphicsDevice *)theGraphicsDevice width:(int)theWidth height:(int)theHeight{ + + return [self initWithGraphicsDevice:theGraphicsDevice width:theWidth height:theHeight mipmap:NO surfaceFormat:SurfaceFormatAlpha8 depthFormat:DepthFormatNone multiSampleCount:0 usage:RenderTargetUsageDiscardContents]; +} + +- (id)initWithGraphicsDevice:(GraphicsDevice *)theGraphicsDevice + width:(int)theWidth + height:(int)theHeight + mipmap:(BOOL)theMipmap + surfaceFormat:(SurfaceFormat)theSurfaceFormat + depthFormat:(DepthFormat)theDepthFormat{ + + return [self initWithGraphicsDevice:theGraphicsDevice width:theWidth height:theHeight mipmap:NO surfaceFormat:theSurfaceFormat depthFormat:theDepthFormat multiSampleCount:0 usage:RenderTargetUsageDiscardContents]; +} + - (id)initWithGraphicsDevice:(GraphicsDevice *)theGraphicsDevice width:(int)theWidth height:(int)theHeight @@ -38,9 +52,6 @@ //Texture is already created by super object. //Here we only create a framebuffer. glGenFramebuffersOES(1, &framebuffer); - - glGenRenderbuffersOES(1, &renderBuffer); - } return self; } @@ -51,17 +62,13 @@ return framebuffer; } --(GLuint) colorRenderbuffer{ - return renderBuffer; -} - - (void)dealloc{ glDeleteFramebuffers(1, &framebuffer); [super dealloc]; } -- (void) saveAsPng:(NSData*)textureData width:(int)width height:(int)height{ - -} +//- (void) saveAsPng:(NSData*)textureData width:(int)width height:(int)height{ +// +//} @end diff --git a/Classes/System/Delegate.m b/Classes/System/Delegate.m index 2b8d867..2de5e55 100644 --- a/Classes/System/Delegate.m +++ b/Classes/System/Delegate.m @@ -61,6 +61,10 @@ return NO; } +-(NSString *)description{ + return [NSString stringWithFormat:@"%@: [%@, %@]",[super description],target, NSStringFromSelector(method)]; +} + - (NSUInteger) hash { return [target hash] ^ [NSStringFromSelector(method) hash]; }