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{
|
- (void) setRenderTarget:(RenderTarget2D*)renderTarget{
|
||||||
|
GLenum format, type;
|
||||||
|
|
||||||
if (renderTarget == nil) {
|
if (renderTarget == nil) {
|
||||||
if (rrt) {
|
if (rrt) {
|
||||||
//We had render target before now we have to flip it vertically
|
//We had render target before now we have to flip it vertically
|
||||||
rrt = NO;
|
rrt = NO;
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebuffer);
|
||||||
}
|
}
|
||||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRenderbuffer);
|
|
||||||
}else{
|
}else{
|
||||||
GLuint rtFramebuffer = [renderTarget colorFramebuffer];
|
GLuint rtFramebuffer = [renderTarget colorFramebuffer];
|
||||||
GLuint rtRenderbuffer = [renderTarget colorRenderbuffer];
|
|
||||||
|
|
||||||
GLenum format, type;
|
|
||||||
[GraphicsDevice getFormat:&format AndType:&type ForSurfaceFormat:renderTarget.format];
|
[GraphicsDevice getFormat:&format AndType:&type ForSurfaceFormat:renderTarget.format];
|
||||||
|
|
||||||
// RENDER TO TEXTURE BUFFER
|
// RENDER TO TEXTURE BUFFER
|
||||||
@ -567,12 +568,6 @@
|
|||||||
// on out screen plane
|
// on out screen plane
|
||||||
glBindFramebufferOES(GL_FRAMEBUFFER_OES, rtFramebuffer);
|
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
|
// create the texture object
|
||||||
glBindTexture(GL_TEXTURE_2D, renderTarget.textureId);
|
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_MIN_FILTER,GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_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)
|
// 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);
|
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);
|
//glOrthof(0, renderTarget.width, renderTarget.height, 0, -1, 1);
|
||||||
|
|
||||||
// CHECK FRAME BUFFER STATUS HERE
|
// CHECK FRAME BUFFER STATUS HERE
|
||||||
|
GLenum status = glCheckFramebufferStatusOES(GL_FRAMEBUFFER);
|
||||||
|
if(status != GL_FRAMEBUFFER_COMPLETE){
|
||||||
// GLenum status = glCheckFramebufferStatusOES(GL_FRAMEBUFFER);
|
NSLog(@"Error binding renderTarget");
|
||||||
// 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");
|
|
||||||
// }
|
|
||||||
rrt = YES;
|
rrt = YES;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,13 +17,27 @@
|
|||||||
|
|
||||||
@interface RenderTarget2D (){
|
@interface RenderTarget2D (){
|
||||||
GLuint framebuffer;
|
GLuint framebuffer;
|
||||||
GLuint renderBuffer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation RenderTarget2D
|
@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
|
- (id)initWithGraphicsDevice:(GraphicsDevice *)theGraphicsDevice
|
||||||
width:(int)theWidth
|
width:(int)theWidth
|
||||||
height:(int)theHeight
|
height:(int)theHeight
|
||||||
@ -38,9 +52,6 @@
|
|||||||
//Texture is already created by super object.
|
//Texture is already created by super object.
|
||||||
//Here we only create a framebuffer.
|
//Here we only create a framebuffer.
|
||||||
glGenFramebuffersOES(1, &framebuffer);
|
glGenFramebuffersOES(1, &framebuffer);
|
||||||
|
|
||||||
glGenRenderbuffersOES(1, &renderBuffer);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@ -51,17 +62,13 @@
|
|||||||
return framebuffer;
|
return framebuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(GLuint) colorRenderbuffer{
|
|
||||||
return renderBuffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)dealloc{
|
- (void)dealloc{
|
||||||
glDeleteFramebuffers(1, &framebuffer);
|
glDeleteFramebuffers(1, &framebuffer);
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) saveAsPng:(NSData*)textureData width:(int)width height:(int)height{
|
//- (void) saveAsPng:(NSData*)textureData width:(int)width height:(int)height{
|
||||||
|
//
|
||||||
}
|
//}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -61,6 +61,10 @@
|
|||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-(NSString *)description{
|
||||||
|
return [NSString stringWithFormat:@"%@: [%@, %@]",[super description],target, NSStringFromSelector(method)];
|
||||||
|
}
|
||||||
|
|
||||||
- (NSUInteger) hash {
|
- (NSUInteger) hash {
|
||||||
return [target hash] ^ [NSStringFromSelector(method) hash];
|
return [target hash] ^ [NSStringFromSelector(method) hash];
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user