Corrected shader link status validation
--HG-- extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%40103
This commit is contained in:
@@ -40,12 +40,14 @@
|
||||
/* The pixel dimensions of the backbuffer */
|
||||
GLint backingWidth, backingHeight;
|
||||
|
||||
EAGLContext *context;
|
||||
|
||||
|
||||
/* OpenGL names for the renderbuffer and framebuffers used to render to this view */
|
||||
GLuint viewFramebuffer, viewRenderbuffer;
|
||||
}
|
||||
|
||||
@property (nonatomic, retain) EAGLContext *context;
|
||||
|
||||
// OpenGL drawing
|
||||
- (BOOL)createFramebuffers;
|
||||
- (void)destroyFramebuffer;
|
||||
|
||||
@@ -57,15 +57,15 @@
|
||||
|
||||
eaglLayer.opaque = YES;
|
||||
eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];
|
||||
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
||||
_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
||||
|
||||
if (!context)
|
||||
if (!_context)
|
||||
{
|
||||
[self release];
|
||||
return nil;
|
||||
}
|
||||
|
||||
if (![EAGLContext setCurrentContext:context])
|
||||
if (![EAGLContext setCurrentContext:_context])
|
||||
{
|
||||
[self release];
|
||||
return nil;
|
||||
@@ -86,6 +86,7 @@
|
||||
|
||||
- (void)dealloc {
|
||||
[_engine release]; _engine = nil;
|
||||
[_context release]; _context = nil;
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
@@ -123,7 +124,7 @@
|
||||
// ----- Create color buffer for viewFramebuffer -----
|
||||
GLDEBUG(glGenRenderbuffers(1, &viewRenderbuffer));
|
||||
GLDEBUG(glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer));
|
||||
[context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer*)self.layer];
|
||||
[_context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer*)self.layer];
|
||||
GLDEBUG(glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &backingWidth));
|
||||
GLDEBUG(glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &backingHeight));
|
||||
NSLog(@"Backing width: %d, height: %d", backingWidth, backingHeight);
|
||||
@@ -166,7 +167,7 @@
|
||||
|
||||
- (void)setDisplayFramebuffer;
|
||||
{
|
||||
if (context)
|
||||
if (_context)
|
||||
{
|
||||
if (!viewFramebuffer)
|
||||
{
|
||||
@@ -183,11 +184,11 @@
|
||||
{
|
||||
BOOL success = FALSE;
|
||||
|
||||
if (context)
|
||||
if (_context)
|
||||
{
|
||||
//GLDEBUG(glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer));
|
||||
|
||||
success = [context presentRenderbuffer:GL_RENDERBUFFER];
|
||||
success = [_context presentRenderbuffer:GL_RENDERBUFFER];
|
||||
}
|
||||
|
||||
return success;
|
||||
|
||||
@@ -163,11 +163,13 @@
|
||||
cParamDisplayFrames = 0;
|
||||
|
||||
camera_position = KRVector3(-85, -1, -70);
|
||||
|
||||
}
|
||||
|
||||
- (void)viewDidAppear:(BOOL)animated
|
||||
{
|
||||
displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(drawView:)];
|
||||
[displayLink setFrameInterval:2]; // Maximum 30fps
|
||||
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
|
||||
|
||||
_lastTime= [displayLink timestamp];
|
||||
}
|
||||
|
||||
@@ -181,93 +183,97 @@
|
||||
|
||||
- (void)drawView:(id)sender
|
||||
{
|
||||
glGetError(); // Clear any prior errors...
|
||||
|
||||
|
||||
CFTimeInterval frame_start_time = CACurrentMediaTime();
|
||||
|
||||
NSAutoreleasePool *framePool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
|
||||
CFTimeInterval time = [displayLink timestamp];
|
||||
float deltaTime = (time - _lastTime);
|
||||
_lastTime = time;
|
||||
|
||||
const GLfloat PI = 3.14159265;
|
||||
const GLfloat d2r = PI * 2 / 360;
|
||||
|
||||
|
||||
KREngine *engine = glView.engine;
|
||||
int iParam = int(dLeftSlider * ([engine getParameterCount] + 1));
|
||||
if(iParam > [engine getParameterCount]) {
|
||||
iParam = [engine getParameterCount];
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(cParamDisplayFrames && iParam < [engine getParameterCount]) {
|
||||
cParamDisplayFrames--;
|
||||
char szText[256];
|
||||
const char *szName = [[engine getParameterLabelWithIndex: iParam] UTF8String];
|
||||
double dValue = [engine getParameterValueWithIndex: iParam];
|
||||
switch([engine getParameterTypeWithIndex: iParam]) {
|
||||
case KRENGINE_PARAMETER_INT:
|
||||
sprintf(szText, "%s: %i", szName, (int)dValue);
|
||||
break;
|
||||
case KRENGINE_PARAMETER_BOOL:
|
||||
sprintf(szText, "%s: %s", szName, dValue == 0.0 ? "false" : "true");
|
||||
break;
|
||||
case KRENGINE_PARAMETER_FLOAT:
|
||||
sprintf(szText, "%s: %f", szName, dValue);
|
||||
break;
|
||||
}
|
||||
NSString *debug_text = [[NSString alloc] initWithUTF8String:szText];
|
||||
engine.debug_text = debug_text;
|
||||
[debug_text release];
|
||||
} else {
|
||||
engine.debug_text = @"";
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(bUpdateParam) {
|
||||
bUpdateParam = false;
|
||||
if(glView.context && glView.engine) {
|
||||
//glGetError(); // Clear any prior errors...
|
||||
|
||||
double dValue = dRightSlider * ([engine getParameterMaxWithIndex: iParam] - [engine getParameterMinWithIndex: iParam]) + [engine getParameterMinWithIndex: iParam];
|
||||
switch([engine getParameterTypeWithIndex: iParam]) {
|
||||
case KRENGINE_PARAMETER_INT:
|
||||
dValue = dRightSlider * ([engine getParameterMaxWithIndex: iParam] + 0.5 - [engine getParameterMinWithIndex: iParam]) + [engine getParameterMinWithIndex: iParam];
|
||||
[engine setParameterValueWithIndex: iParam Value: dValue];
|
||||
break;
|
||||
case KRENGINE_PARAMETER_BOOL:
|
||||
[engine setParameterValueWithIndex: iParam Value: 1.0 - dValue];
|
||||
break;
|
||||
case KRENGINE_PARAMETER_FLOAT:
|
||||
[engine setParameterValueWithIndex: iParam Value: dValue];
|
||||
break;
|
||||
|
||||
CFTimeInterval frame_start_time = CACurrentMediaTime();
|
||||
|
||||
//NSAutoreleasePool *framePool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
|
||||
CFTimeInterval time = [displayLink timestamp];
|
||||
float deltaTime = (time - _lastTime);
|
||||
_lastTime = time;
|
||||
|
||||
const GLfloat PI = 3.14159265;
|
||||
const GLfloat d2r = PI * 2 / 360;
|
||||
|
||||
|
||||
KREngine *engine = glView.engine;
|
||||
int iParam = int(dLeftSlider * ([engine getParameterCount] + 1));
|
||||
if(iParam > [engine getParameterCount]) {
|
||||
iParam = [engine getParameterCount];
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(cParamDisplayFrames && iParam < [engine getParameterCount]) {
|
||||
cParamDisplayFrames--;
|
||||
char szText[256];
|
||||
const char *szName = [[engine getParameterLabelWithIndex: iParam] UTF8String];
|
||||
double dValue = [engine getParameterValueWithIndex: iParam];
|
||||
switch([engine getParameterTypeWithIndex: iParam]) {
|
||||
case KRENGINE_PARAMETER_INT:
|
||||
sprintf(szText, "%s: %i", szName, (int)dValue);
|
||||
break;
|
||||
case KRENGINE_PARAMETER_BOOL:
|
||||
sprintf(szText, "%s: %s", szName, dValue == 0.0 ? "false" : "true");
|
||||
break;
|
||||
case KRENGINE_PARAMETER_FLOAT:
|
||||
sprintf(szText, "%s: %f", szName, dValue);
|
||||
break;
|
||||
}
|
||||
NSString *debug_text = [[NSString alloc] initWithUTF8String:szText];
|
||||
engine.debug_text = debug_text;
|
||||
[debug_text release];
|
||||
} else {
|
||||
engine.debug_text = @"";
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(bUpdateParam) {
|
||||
bUpdateParam = false;
|
||||
|
||||
double dValue = dRightSlider * ([engine getParameterMaxWithIndex: iParam] - [engine getParameterMinWithIndex: iParam]) + [engine getParameterMinWithIndex: iParam];
|
||||
switch([engine getParameterTypeWithIndex: iParam]) {
|
||||
case KRENGINE_PARAMETER_INT:
|
||||
dValue = dRightSlider * ([engine getParameterMaxWithIndex: iParam] + 0.5 - [engine getParameterMinWithIndex: iParam]) + [engine getParameterMinWithIndex: iParam];
|
||||
[engine setParameterValueWithIndex: iParam Value: dValue];
|
||||
break;
|
||||
case KRENGINE_PARAMETER_BOOL:
|
||||
[engine setParameterValueWithIndex: iParam Value: 1.0 - dValue];
|
||||
break;
|
||||
case KRENGINE_PARAMETER_FLOAT:
|
||||
[engine setParameterValueWithIndex: iParam Value: dValue];
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
double dScaleFactor = 200.0f * deltaTime;
|
||||
|
||||
camera_position.z += (-cos(camera_pitch) * cos(camera_yaw) * leftStickDeltaX + -cos(camera_pitch) * cos(camera_yaw - 90.0f * d2r) * -leftStickDeltaY) * dScaleFactor;
|
||||
camera_position.x += (cos(camera_pitch) * sin(camera_yaw) * leftStickDeltaX + cos(camera_pitch) * sin(camera_yaw - 90.0f * d2r) * -leftStickDeltaY) * dScaleFactor;
|
||||
camera_position.y += sin(camera_pitch) * leftStickDeltaX * dScaleFactor;
|
||||
camera_yaw += rightStickDeltaY * 180.0 * d2r * deltaTime;
|
||||
camera_pitch += rightStickDeltaX * 180.0 * d2r * deltaTime;
|
||||
|
||||
|
||||
|
||||
assert([EAGLContext setCurrentContext:glView.context]);
|
||||
[glView setDisplayFramebuffer];
|
||||
KRScene *scene = [glView getScene];
|
||||
[engine renderScene: scene 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);
|
||||
}
|
||||
|
||||
double dScaleFactor = 200.0f * deltaTime;
|
||||
|
||||
camera_position.z += (-cos(camera_pitch) * cos(camera_yaw) * leftStickDeltaX + -cos(camera_pitch) * cos(camera_yaw - 90.0f * d2r) * -leftStickDeltaY) * dScaleFactor;
|
||||
camera_position.x += (cos(camera_pitch) * sin(camera_yaw) * leftStickDeltaX + cos(camera_pitch) * sin(camera_yaw - 90.0f * d2r) * -leftStickDeltaY) * dScaleFactor;
|
||||
camera_position.y += sin(camera_pitch) * leftStickDeltaX * dScaleFactor;
|
||||
camera_yaw += rightStickDeltaY * 180.0 * d2r * deltaTime;
|
||||
camera_pitch += rightStickDeltaX * 180.0 * d2r * deltaTime;
|
||||
|
||||
|
||||
[glView setDisplayFramebuffer];
|
||||
KRScene *scene = [glView getScene];
|
||||
[engine renderScene: scene 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
|
||||
|
||||
Reference in New Issue
Block a user