mirror of
https://github.com/thes3m/XNI
synced 2024-12-26 13:26:06 +01:00
Changes:
- cleaned RenderTarget2D code. - fixed graphics device bug when switching from rendertarget to backbuffer. git-svn-id: http://xni.googlecode.com/svn/XNI@129 ac433895-eea3-a490-d80a-17149a75e588
This commit is contained in:
parent
4409443ae0
commit
8819987253
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -61,6 +61,10 @@
|
||||
return NO;
|
||||
}
|
||||
|
||||
-(NSString *)description{
|
||||
return [NSString stringWithFormat:@"%@: [%@, %@]",[super description],target, NSStringFromSelector(method)];
|
||||
}
|
||||
|
||||
- (NSUInteger) hash {
|
||||
return [target hash] ^ [NSStringFromSelector(method) hash];
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user