updaed for iOS6

This commit is contained in:
Michael Nguyen
2013-10-28 15:20:35 -07:00
parent 4eb1fd35e0
commit 84ca7457b5
86 changed files with 304 additions and 14535 deletions
+37 -28
View File
@@ -33,7 +33,7 @@ bool checkFramebufferStatus();
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
if ( context == nil)
context = [[EAGLContext alloc] initWithAPI: kEAGLRenderingAPIOpenGLES1];
if (!context || ![EAGLContext setCurrentContext:context])
{
[self release];
@@ -46,20 +46,29 @@ bool checkFramebufferStatus();
- (void)render
{
// NSLog(@"Renderer - render");
struct timeval tv;
uint dt;
// This application only creates a single context which is already set current at this point.
// This call is redundant, but needed if dealing with multiple contexts.
[EAGLContext setCurrentContext:context];
// This application only creates a single default framebuffer which is already bound at this point.
// This call is redundant, but needed if dealing with multiple framebuffers.
glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebuffer);
GLfloat currentRatio = (GLfloat) backingWidth / (GLfloat) backingHeight;
if ((GLfloat)backingWidth / (GLfloat)backingHeight < ACTUAL_RATIO)
// for retina devices. because of the 568 px, the ratio between height-width skews the
// frame a bit
if ( backingHeight == 568 || backingWidth == 568) {
viewPort.left = 0;
viewPort.top = -((backingWidth/ACTUAL_RATIO)-backingHeight)/2 + 22; // account for status bar
viewPort.right = backingWidth;
viewPort.bottom = -((backingWidth/ACTUAL_RATIO)-backingHeight)/2 + backingWidth / ACTUAL_RATIO - 22;
}
else if (currentRatio < ACTUAL_RATIO)
{
viewPort.left = 0;
viewPort.top = -((backingWidth/ACTUAL_RATIO)-backingHeight)/2;
@@ -73,21 +82,21 @@ bool checkFramebufferStatus();
viewPort.right = backingHeight * ACTUAL_RATIO;
viewPort.bottom = -((backingWidth/ACTUAL_RATIO)-backingHeight)/2 + backingWidth / ACTUAL_RATIO + backingHeight;
}
glViewport(viewPort.left, viewPort.top, viewPort.right-viewPort.left, viewPort.bottom-viewPort.top);
JRenderer::GetInstance()->SetActualWidth(viewPort.right-viewPort.left);
JRenderer::GetInstance()->SetActualHeight(viewPort.bottom-viewPort.top);
gettimeofday(&tv, NULL);
uint64_t tickCount = tv.tv_sec * 1000 + tv.tv_usec / 1000;
dt = (tickCount - lastTickCount);
lastTickCount = tickCount;
g_engine->SetDelta((float)dt / 1000.0f);
g_engine->Update((float)dt / 1000.0f);
g_engine->Render();
// This application only creates a single color renderbuffer which is already bound at this point.
@@ -103,18 +112,18 @@ bool checkFramebufferStatus();
glDeleteFramebuffers(1, &defaultFramebuffer);
defaultFramebuffer = 0;
}
if(colorRenderbuffer) {
glDeleteRenderbuffers(1, &colorRenderbuffer);
colorRenderbuffer = 0;
}
glGenFramebuffers(1, &defaultFramebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebuffer);
glGenRenderbuffers(1, &colorRenderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer);
// Allocate color buffer backing based on the current layer size
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRenderbuffer);
[context renderbufferStorage:GL_RENDERBUFFER fromDrawable:layer];
@@ -127,41 +136,41 @@ bool checkFramebufferStatus();
glEnable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE); // do not calculate inside of poly's
glFrontFace(GL_CCW);
glFrontFace(GL_CCW);
glEnable (GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// glEnable(GL_SCISSOR_TEST); // Enable Clipping
// glEnable(GL_SCISSOR_TEST); // Enable Clipping
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background (yes that's the way fuckers)
glClearDepthf(1.0f); // Depth Buffer Setup
return YES;
}
bool checkFramebufferStatus() {
GLenum status = (GLenum)glCheckFramebufferStatus(GL_FRAMEBUFFER);
switch(status) {
case GL_FRAMEBUFFER_COMPLETE:
return true;
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
printf("Framebuffer incomplete,incomplete attachment\n");
return false;
case GL_FRAMEBUFFER_UNSUPPORTED:
printf("Unsupported framebuffer format\n");
return false;
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
printf("Framebuffer incomplete,missing attachment\n");
return false;
}
return false;
}
@@ -187,7 +196,7 @@ bool checkFramebufferStatus() {
[context release];
context = nil;
[super dealloc];
}