annotate Classes/MySampleProjectViewController.m @ 6:7a0e6eeedd92

Style fixes
author Eric Wing <ewing . public |-at-| gmail . com>
date Mon, 08 Aug 2011 19:32:30 -0700
parents 5ec52341f221
children
rev   line source
0
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
1 //
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
2 // MySampleProjectViewController.m
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
3 // MySampleProject
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
4 //
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
5 // Created by Eric Wing on 7/29/11.
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
6 // Copyright 2011 __MyCompanyName__. All rights reserved.
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
7 //
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
8
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
9 #import <QuartzCore/QuartzCore.h>
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
10
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
11 #import "MySampleProjectViewController.h"
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
12 #import "EAGLView.h"
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
13
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
14 // Uniform index.
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
15 enum {
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
16 UNIFORM_TRANSLATE,
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
17 NUM_UNIFORMS
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
18 };
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
19 GLint uniforms[NUM_UNIFORMS];
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
20
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
21 // Attribute index.
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
22 enum {
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
23 ATTRIB_VERTEX,
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
24 ATTRIB_COLOR,
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
25 NUM_ATTRIBUTES
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
26 };
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
27
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
28 @interface MySampleProjectViewController ()
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
29 @property (nonatomic, retain) EAGLContext *context;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
30 @property (nonatomic, assign) CADisplayLink *displayLink;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
31 - (BOOL)loadShaders;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
32 - (BOOL)compileShader:(GLuint *)shader type:(GLenum)type file:(NSString *)file;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
33 - (BOOL)linkProgram:(GLuint)prog;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
34 - (BOOL)validateProgram:(GLuint)prog;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
35 @end
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
36
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
37 @implementation MySampleProjectViewController
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
38
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
39 @synthesize animating, context, displayLink;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
40
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
41 - (void)awakeFromNib
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
42 {
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
43 #if USE_OPENGLES2
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
44 EAGLContext* aContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
45 #else
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
46 EAGLContext* aContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
47 #endif
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
48
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
49 if (!aContext)
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
50 NSLog(@"Failed to create ES context");
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
51 else if (![EAGLContext setCurrentContext:aContext])
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
52 NSLog(@"Failed to set ES context current");
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
53
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
54 self.context = aContext;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
55 [aContext release];
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
56
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
57 [(EAGLView *)self.view setContext:context];
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
58 [(EAGLView *)self.view setFramebuffer];
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
59
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
60 #if USE_OPENGLES2
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
61 if ([context API] == kEAGLRenderingAPIOpenGLES2)
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
62 [self loadShaders];
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
63 #endif
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
64
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
65 animating = FALSE;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
66 animationFrameInterval = 1;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
67 self.displayLink = nil;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
68 }
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
69
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
70 - (void)dealloc
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
71 {
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
72 if (program)
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
73 {
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
74 glDeleteProgram(program);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
75 program = 0;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
76 }
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
77
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
78 // Tear down context.
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
79 if ([EAGLContext currentContext] == context)
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
80 [EAGLContext setCurrentContext:nil];
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
81
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
82 [context release];
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
83
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
84 [super dealloc];
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
85 }
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
86
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
87 - (void)viewWillAppear:(BOOL)animated
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
88 {
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
89 [self startAnimation];
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
90
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
91 [super viewWillAppear:animated];
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
92 }
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
93
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
94 - (void)viewWillDisappear:(BOOL)animated
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
95 {
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
96 [self stopAnimation];
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
97
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
98 [super viewWillDisappear:animated];
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
99 }
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
100
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
101 - (void)viewDidUnload
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
102 {
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
103 [super viewDidUnload];
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
104
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
105 if (program)
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
106 {
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
107 glDeleteProgram(program);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
108 program = 0;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
109 }
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
110
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
111 // Tear down context.
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
112 if ([EAGLContext currentContext] == context)
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
113 [EAGLContext setCurrentContext:nil];
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
114 self.context = nil;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
115 }
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
116
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
117 - (NSInteger)animationFrameInterval
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
118 {
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
119 return animationFrameInterval;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
120 }
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
121
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
122 - (void)setAnimationFrameInterval:(NSInteger)frameInterval
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
123 {
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
124 /*
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
125 Frame interval defines how many display frames must pass between each time the display link fires.
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
126 The display link will only fire 30 times a second when the frame internal is two on a display that refreshes 60 times a second. The default frame interval setting of one will fire 60 times a second when the display refreshes at 60 times a second. A frame interval setting of less than one results in undefined behavior.
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
127 */
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
128 if (frameInterval >= 1)
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
129 {
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
130 animationFrameInterval = frameInterval;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
131
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
132 if (animating)
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
133 {
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
134 [self stopAnimation];
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
135 [self startAnimation];
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
136 }
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
137 }
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
138 }
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
139
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
140 - (void)startAnimation
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
141 {
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
142 if (!animating)
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
143 {
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
144 CADisplayLink *aDisplayLink = [[UIScreen mainScreen] displayLinkWithTarget:self selector:@selector(drawFrame)];
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
145 [aDisplayLink setFrameInterval:animationFrameInterval];
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
146 [aDisplayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
147 self.displayLink = aDisplayLink;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
148
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
149 animating = TRUE;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
150 }
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
151 }
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
152
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
153 - (void)stopAnimation
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
154 {
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
155 if (animating)
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
156 {
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
157 [self.displayLink invalidate];
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
158 self.displayLink = nil;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
159 animating = FALSE;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
160 }
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
161 }
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
162
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
163 - (void)drawFrame
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
164 {
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
165 [(EAGLView *)self.view setFramebuffer];
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
166
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
167 // Replace the implementation of this method to do your own custom drawing.
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
168 static const GLfloat squareVertices[] = {
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
169 -0.5f, -0.33f,
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
170 0.5f, -0.33f,
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
171 -0.5f, 0.33f,
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
172 0.5f, 0.33f,
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
173 };
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
174
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
175 static const GLubyte squareColors[] = {
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
176 255, 255, 0, 255,
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
177 0, 255, 255, 255,
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
178 0, 0, 0, 0,
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
179 255, 0, 255, 255,
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
180 };
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
181
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
182 static float transY = 0.0f;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
183
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
184 glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
185 glClear(GL_COLOR_BUFFER_BIT);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
186
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
187 #if USE_OPENGLES2
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
188 // Use shader program.
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
189 glUseProgram(program);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
190
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
191 // Update uniform value.
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
192 glUniform1f(uniforms[UNIFORM_TRANSLATE], (GLfloat)transY);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
193 transY += 0.075f;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
194
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
195 // Update attribute values.
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
196 glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, squareVertices);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
197 glEnableVertexAttribArray(ATTRIB_VERTEX);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
198 glVertexAttribPointer(ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, 1, 0, squareColors);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
199 glEnableVertexAttribArray(ATTRIB_COLOR);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
200
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
201 // Validate program before drawing. This is a good check, but only really necessary in a debug build.
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
202 // DEBUG macro must be defined in your debug configurations if that's not already the case.
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
203 #if defined(DEBUG)
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
204 if (![self validateProgram:program])
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
205 {
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
206 NSLog(@"Failed to validate program: %d", program);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
207 return;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
208 }
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
209 #endif
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
210 #else
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
211 glMatrixMode(GL_PROJECTION);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
212 glLoadIdentity();
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
213 glMatrixMode(GL_MODELVIEW);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
214 glLoadIdentity();
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
215 glTranslatef(0.0f, (GLfloat)(sinf(transY)/2.0f), 0.0f);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
216 transY += 0.075f;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
217
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
218 glVertexPointer(2, GL_FLOAT, 0, squareVertices);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
219 glEnableClientState(GL_VERTEX_ARRAY);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
220 glColorPointer(4, GL_UNSIGNED_BYTE, 0, squareColors);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
221 glEnableClientState(GL_COLOR_ARRAY);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
222 #endif
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
223
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
224 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
225
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
226 [(EAGLView *)self.view presentFramebuffer];
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
227 }
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
228
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
229 - (void)didReceiveMemoryWarning
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
230 {
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
231 // Releases the view if it doesn't have a superview.
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
232 [super didReceiveMemoryWarning];
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
233
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
234 // Release any cached data, images, etc. that aren't in use.
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
235 }
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
236
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
237 - (BOOL)compileShader:(GLuint *)shader type:(GLenum)type file:(NSString *)file
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
238 {
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
239 GLint status;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
240 const GLchar *source;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
241
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
242 source = (GLchar *)[[NSString stringWithContentsOfFile:file encoding:NSUTF8StringEncoding error:nil] UTF8String];
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
243 if (!source)
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
244 {
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
245 NSLog(@"Failed to load vertex shader");
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
246 return FALSE;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
247 }
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
248
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
249 *shader = glCreateShader(type);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
250 glShaderSource(*shader, 1, &source, NULL);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
251 glCompileShader(*shader);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
252
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
253 #if defined(DEBUG)
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
254 GLint logLength;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
255 glGetShaderiv(*shader, GL_INFO_LOG_LENGTH, &logLength);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
256 if (logLength > 0)
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
257 {
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
258 GLchar *log = (GLchar *)malloc(logLength);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
259 glGetShaderInfoLog(*shader, logLength, &logLength, log);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
260 NSLog(@"Shader compile log:\n%s", log);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
261 free(log);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
262 }
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
263 #endif
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
264
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
265 glGetShaderiv(*shader, GL_COMPILE_STATUS, &status);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
266 if (status == 0)
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
267 {
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
268 glDeleteShader(*shader);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
269 return FALSE;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
270 }
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
271
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
272 return TRUE;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
273 }
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
274
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
275 - (BOOL)linkProgram:(GLuint)prog
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
276 {
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
277 GLint status;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
278
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
279 glLinkProgram(prog);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
280
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
281 #if defined(DEBUG)
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
282 GLint logLength;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
283 glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &logLength);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
284 if (logLength > 0)
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
285 {
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
286 GLchar *log = (GLchar *)malloc(logLength);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
287 glGetProgramInfoLog(prog, logLength, &logLength, log);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
288 NSLog(@"Program link log:\n%s", log);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
289 free(log);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
290 }
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
291 #endif
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
292
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
293 glGetProgramiv(prog, GL_LINK_STATUS, &status);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
294 if (status == 0)
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
295 return FALSE;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
296
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
297 return TRUE;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
298 }
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
299
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
300 - (BOOL)validateProgram:(GLuint)prog
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
301 {
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
302 GLint logLength, status;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
303
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
304 glValidateProgram(prog);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
305 glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &logLength);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
306 if (logLength > 0)
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
307 {
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
308 GLchar *log = (GLchar *)malloc(logLength);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
309 glGetProgramInfoLog(prog, logLength, &logLength, log);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
310 NSLog(@"Program validate log:\n%s", log);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
311 free(log);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
312 }
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
313
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
314 glGetProgramiv(prog, GL_VALIDATE_STATUS, &status);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
315 if (status == 0)
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
316 return FALSE;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
317
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
318 return TRUE;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
319 }
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
320
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
321 - (BOOL)loadShaders
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
322 {
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
323 GLuint vertShader, fragShader;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
324 NSString *vertShaderPathname, *fragShaderPathname;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
325
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
326 // Create shader program.
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
327 program = glCreateProgram();
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
328
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
329 // Create and compile vertex shader.
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
330 vertShaderPathname = [[NSBundle mainBundle] pathForResource:@"Shader" ofType:@"vsh"];
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
331 if (![self compileShader:&vertShader type:GL_VERTEX_SHADER file:vertShaderPathname])
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
332 {
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
333 NSLog(@"Failed to compile vertex shader");
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
334 return FALSE;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
335 }
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
336
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
337 // Create and compile fragment shader.
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
338 fragShaderPathname = [[NSBundle mainBundle] pathForResource:@"Shader" ofType:@"fsh"];
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
339 if (![self compileShader:&fragShader type:GL_FRAGMENT_SHADER file:fragShaderPathname])
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
340 {
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
341 NSLog(@"Failed to compile fragment shader");
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
342 return FALSE;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
343 }
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
344
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
345 // Attach vertex shader to program.
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
346 glAttachShader(program, vertShader);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
347
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
348 // Attach fragment shader to program.
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
349 glAttachShader(program, fragShader);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
350
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
351 // Bind attribute locations.
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
352 // This needs to be done prior to linking.
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
353 glBindAttribLocation(program, ATTRIB_VERTEX, "position");
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
354 glBindAttribLocation(program, ATTRIB_COLOR, "color");
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
355
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
356 // Link program.
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
357 if (![self linkProgram:program])
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
358 {
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
359 NSLog(@"Failed to link program: %d", program);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
360
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
361 if (vertShader)
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
362 {
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
363 glDeleteShader(vertShader);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
364 vertShader = 0;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
365 }
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
366 if (fragShader)
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
367 {
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
368 glDeleteShader(fragShader);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
369 fragShader = 0;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
370 }
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
371 if (program)
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
372 {
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
373 glDeleteProgram(program);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
374 program = 0;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
375 }
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
376
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
377 return FALSE;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
378 }
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
379
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
380 // Get uniform locations.
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
381 uniforms[UNIFORM_TRANSLATE] = glGetUniformLocation(program, "translate");
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
382
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
383 // Release vertex and fragment shaders.
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
384 if (vertShader)
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
385 glDeleteShader(vertShader);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
386 if (fragShader)
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
387 glDeleteShader(fragShader);
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
388
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
389 return TRUE;
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
390 }
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
391
5ec52341f221 Initial commit
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
392 @end