Removed extraneous glBind calls, added FPS debugging info

--HG--
extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%4040
This commit is contained in:
kearwood
2012-04-12 08:49:47 +00:00
parent 3ff648a08f
commit 1c3ffa4d67
4 changed files with 22 additions and 28 deletions

View File

@@ -95,6 +95,7 @@ typedef enum KREngineParameterType {KRENGINE_PARAMETER_INT, KRENGINE_PARAMETER_F
NSString *debug_text;
}
- (id)initForWidth: (GLuint)width Height: (GLuint)height;
- (BOOL)loadVertexShader:(NSString *)vertexShaderName fragmentShader:(NSString *)fragmentShaderName forProgram:(GLuint *)programPointer withOptions:(NSString *)options;

View File

@@ -57,7 +57,7 @@ double const PI = 3.141592653589793f;
- (id)initForWidth: (GLuint)width Height: (GLuint)height
{
debug_text = @"";
debug_text = [[NSString alloc] init];
sun_yaw = 4.333;
sun_pitch = 0.55;
m_iFrame = 0;
@@ -587,6 +587,8 @@ double const PI = 3.141592653589793f;
[self invalidatePostShader];
[self destroyBuffers];
[debug_text release];
debug_text = nil;
[super dealloc];
}
@@ -753,15 +755,6 @@ double const PI = 3.141592653589793f;
-1.0 + dScale, dScale * iPos + dScale - 1.0,
};
/*
GLfloat charTexCoords[] = {
dTexScale * iCol, dTexScale * iRow,
dTexScale * iCol + dTexScale, dTexScale * iRow,
dTexScale * iCol, dTexScale * iRow + dTexScale,
dTexScale * iCol + dTexScale, dTexScale * iRow + dTexScale
};
*/
GLfloat charTexCoords[] = {
dTexScale * iCol, dTexScale * iRow + dTexScale,
dTexScale * iCol, dTexScale * iRow,
@@ -1150,7 +1143,8 @@ double const PI = 3.141592653589793f;
- (void)setDebugText: (NSString *)text
{
debug_text = text;
[debug_text release];
debug_text = [text retain];
}

View File

@@ -209,14 +209,9 @@
[self createFramebuffers];
}
glBindFramebuffer(GL_FRAMEBUFFER, viewFramebuffer);
//glBindFramebuffer(GL_FRAMEBUFFER, viewFramebuffer);
glViewport(0, 0, backingWidth, backingHeight);
/*
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
*/
}
}
@@ -226,7 +221,7 @@
if (context)
{
glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);
//glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);
success = [context presentRenderbuffer:GL_RENDERBUFFER];
}

View File

@@ -165,7 +165,7 @@
camera_position = KRVector3(-850, -10, -700);
displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(drawView:)];
[displayLink setFrameInterval:1]; // Maximum 60fps
[displayLink setFrameInterval:2]; // Maximum 30fps
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
_lastTime= [displayLink timestamp];
@@ -181,6 +181,9 @@
- (void)drawView:(id)sender
{
CFTimeInterval frame_start_time = CACurrentMediaTime();
NSAutoreleasePool *framePool = [[NSAutoreleasePool alloc] init];
CFTimeInterval time = [displayLink timestamp];
float deltaTime = (time - _lastTime);
_lastTime = time;
@@ -195,6 +198,8 @@
iParam = [engine getParameterCount];
}
if(cParamDisplayFrames && iParam < [engine getParameterCount]) {
cParamDisplayFrames--;
char szText[256];
@@ -238,14 +243,7 @@
}
}
[glView setDisplayFramebuffer];
//double dScaleFactor = [engine getModelManager]->getFirstModel()->getMaxDimension() / 100.0f;
double dScaleFactor = 1000.0f * deltaTime;
camera_position.z += (-cos(camera_pitch) * cos(camera_yaw) * leftStickDeltaX + -cos(camera_pitch) * cos(camera_yaw - 90.0f * d2r) * -leftStickDeltaY) * dScaleFactor;
@@ -254,10 +252,16 @@
camera_yaw += rightStickDeltaY * 180.0 * d2r * deltaTime;
camera_pitch += rightStickDeltaX * 180.0 * d2r * deltaTime;
[glView setDisplayFramebuffer];
[engine renderScene: [glView getScene] WithPosition:camera_position Yaw: camera_yaw Pitch: camera_pitch Roll:0.0f];
[glView presentFramebuffer];
[framePool release];
double frameTime = CACurrentMediaTime() - frame_start_time;
NSLog(@"frameTime = %.1f ms (%.2f fps / %.2f fps) - %.2f%%", frameTime * 1000.0f, 1.0f / frameTime, 1.0f / deltaTime, frameTime / deltaTime * 100.0f);
}
@end