-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathKxMovieGLView.m
executable file
·705 lines (555 loc) · 19.6 KB
/
KxMovieGLView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
//
// KxMovieGLView.m
// kxmovie
//
// Created by Kolyvan on 22.10.12.
// Copyright (c) 2012 Konstantin Boukreev . All rights reserved.
//
// https://github.com/kolyvan/kxmovie
// this file is part of KxMovie
// KxMovie is licenced under the LGPL v3, see lgpl-3.0.txt
#import "KxMovieGLView.h"
#import <QuartzCore/QuartzCore.h>
#import <OpenGLES/EAGLDrawable.h>
#import <OpenGLES/EAGL.h>
#import <OpenGLES/ES2/gl.h>
#import <OpenGLES/ES2/glext.h>
#import "KxMovieDecoder.h"
#import "KxLogger.h"
//////////////////////////////////////////////////////////
#pragma mark - shaders
#define STRINGIZE(x) #x
#define STRINGIZE2(x) STRINGIZE(x)
#define SHADER_STRING(text) @ STRINGIZE2(text)
NSString *const vertexShaderString = SHADER_STRING
(
attribute vec4 position;
attribute vec2 texcoord;
uniform mat4 modelViewProjectionMatrix;
varying vec2 v_texcoord;
void main()
{
gl_Position = modelViewProjectionMatrix * position;
v_texcoord = texcoord.xy;
}
);
NSString *const rgbFragmentShaderString = SHADER_STRING
(
varying highp vec2 v_texcoord;
uniform sampler2D s_texture;
void main()
{
gl_FragColor = texture2D(s_texture, v_texcoord);
}
);
NSString *const yuvFragmentShaderString = SHADER_STRING
(
varying highp vec2 v_texcoord;
uniform sampler2D s_texture_y;
uniform sampler2D s_texture_u;
uniform sampler2D s_texture_v;
void main()
{
highp float y = texture2D(s_texture_y, v_texcoord).r;
highp float u = texture2D(s_texture_u, v_texcoord).r - 0.5;
highp float v = texture2D(s_texture_v, v_texcoord).r - 0.5;
highp float r = y + 1.402 * v;
highp float g = y - 0.344 * u - 0.714 * v;
highp float b = y + 1.772 * u;
gl_FragColor = vec4(r,g,b,1.0);
}
);
static BOOL validateProgram(GLuint prog)
{
GLint status;
glValidateProgram(prog);
#ifdef DEBUG
GLint logLength;
glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &logLength);
if (logLength > 0)
{
GLchar *log = (GLchar *)malloc(logLength);
glGetProgramInfoLog(prog, logLength, &logLength, log);
LoggerVideo(1, @"Program validate log:\n%s", log);
free(log);
}
#endif
glGetProgramiv(prog, GL_VALIDATE_STATUS, &status);
if (status == GL_FALSE) {
LoggerVideo(0, @"Failed to validate program %d", prog);
return NO;
}
return YES;
}
static GLuint compileShader(GLenum type, NSString *shaderString)
{
GLint status;
const GLchar *sources = (GLchar *)shaderString.UTF8String;
GLuint shader = glCreateShader(type);
if (shader == 0 || shader == GL_INVALID_ENUM) {
LoggerVideo(0, @"Failed to create shader %d", type);
return 0;
}
glShaderSource(shader, 1, &sources, NULL);
glCompileShader(shader);
#ifdef DEBUG
GLint logLength;
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength);
if (logLength > 0)
{
GLchar *log = (GLchar *)malloc(logLength);
glGetShaderInfoLog(shader, logLength, &logLength, log);
LoggerVideo(1, @"Shader compile log:\n%s", log);
free(log);
}
#endif
glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
if (status == GL_FALSE) {
glDeleteShader(shader);
LoggerVideo(0, @"Failed to compile shader:\n");
return 0;
}
return shader;
}
static void mat4f_LoadOrtho(float left, float right, float bottom, float top, float near, float far, float* mout)
{
float r_l = right - left;
float t_b = top - bottom;
float f_n = far - near;
float tx = - (right + left) / (right - left);
float ty = - (top + bottom) / (top - bottom);
float tz = - (far + near) / (far - near);
mout[0] = 2.0f / r_l;
mout[1] = 0.0f;
mout[2] = 0.0f;
mout[3] = 0.0f;
mout[4] = 0.0f;
mout[5] = 2.0f / t_b;
mout[6] = 0.0f;
mout[7] = 0.0f;
mout[8] = 0.0f;
mout[9] = 0.0f;
mout[10] = -2.0f / f_n;
mout[11] = 0.0f;
mout[12] = tx;
mout[13] = ty;
mout[14] = tz;
mout[15] = 1.0f;
}
//////////////////////////////////////////////////////////
#pragma mark - frame renderers
@protocol KxMovieGLRenderer
- (BOOL) isValid;
- (NSString *) fragmentShader;
- (void) resolveUniforms: (GLuint) program;
- (void) setFrame: (KxVideoFrame *) frame;
- (BOOL) prepareRender;
@end
@interface KxMovieGLRenderer_RGB : NSObject<KxMovieGLRenderer> {
GLint _uniformSampler;
GLuint _texture;
}
@end
@implementation KxMovieGLRenderer_RGB
- (BOOL) isValid
{
return (_texture != 0);
}
- (NSString *) fragmentShader
{
return rgbFragmentShaderString;
}
- (void) resolveUniforms: (GLuint) program
{
_uniformSampler = glGetUniformLocation(program, "s_texture");
}
- (void) setFrame: (KxVideoFrame *) frame
{
KxVideoFrameRGB *rgbFrame = (KxVideoFrameRGB *)frame;
assert(rgbFrame.rgb.length == rgbFrame.width * rgbFrame.height * 3);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
if (0 == _texture)
glGenTextures(1, &_texture);
glBindTexture(GL_TEXTURE_2D, _texture);
glTexImage2D(GL_TEXTURE_2D,
0,
GL_RGB,
frame.width,
frame.height,
0,
GL_RGB,
GL_UNSIGNED_BYTE,
rgbFrame.rgb.bytes);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
- (BOOL) prepareRender
{
if (_texture == 0)
return NO;
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, _texture);
glUniform1i(_uniformSampler, 0);
return YES;
}
- (void) dealloc
{
if (_texture) {
glDeleteTextures(1, &_texture);
_texture = 0;
}
}
@end
@interface KxMovieGLRenderer_YUV : NSObject<KxMovieGLRenderer> {
GLint _uniformSamplers[3];
GLuint _textures[3];
}
@end
@implementation KxMovieGLRenderer_YUV
- (BOOL) isValid
{
return (_textures[0] != 0);
}
- (NSString *) fragmentShader
{
return yuvFragmentShaderString;
}
- (void) resolveUniforms: (GLuint) program
{
_uniformSamplers[0] = glGetUniformLocation(program, "s_texture_y");
_uniformSamplers[1] = glGetUniformLocation(program, "s_texture_u");
_uniformSamplers[2] = glGetUniformLocation(program, "s_texture_v");
}
- (void) setFrame: (KxVideoFrame *) frame
{
KxVideoFrameYUV *yuvFrame = (KxVideoFrameYUV *)frame;
assert(yuvFrame.luma.length == yuvFrame.width * yuvFrame.height);
assert(yuvFrame.chromaB.length == (yuvFrame.width * yuvFrame.height) / 4);
assert(yuvFrame.chromaR.length == (yuvFrame.width * yuvFrame.height) / 4);
const NSUInteger frameWidth = frame.width;
const NSUInteger frameHeight = frame.height;
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
if (0 == _textures[0])
glGenTextures(3, _textures);
const UInt8 *pixels[3] = { yuvFrame.luma.bytes, yuvFrame.chromaB.bytes, yuvFrame.chromaR.bytes };
const NSUInteger widths[3] = { frameWidth, frameWidth / 2, frameWidth / 2 };
const NSUInteger heights[3] = { frameHeight, frameHeight / 2, frameHeight / 2 };
for (int i = 0; i < 3; ++i) {
glBindTexture(GL_TEXTURE_2D, _textures[i]);
glTexImage2D(GL_TEXTURE_2D,
0,
GL_LUMINANCE,
widths[i],
heights[i],
0,
GL_LUMINANCE,
GL_UNSIGNED_BYTE,
pixels[i]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
}
- (BOOL) prepareRender
{
if (_textures[0] == 0)
return NO;
for (int i = 0; i < 3; ++i) {
glActiveTexture(GL_TEXTURE0 + i);
glBindTexture(GL_TEXTURE_2D, _textures[i]);
glUniform1i(_uniformSamplers[i], i);
}
return YES;
}
- (void) dealloc
{
if (_textures[0])
glDeleteTextures(3, _textures);
}
@end
//////////////////////////////////////////////////////////
#pragma mark - gl view
enum {
ATTRIBUTE_VERTEX,
ATTRIBUTE_TEXCOORD,
};
@implementation KxMovieGLView {
KxMovieDecoder *_decoder;
EAGLContext *_context;
GLuint _framebuffer;
GLuint _renderbuffer;
GLint _backingWidth;
GLint _backingHeight;
GLuint _program;
GLint _uniformMatrix;
GLfloat _vertices[8];
id<KxMovieGLRenderer> _renderer;
}
+ (Class) layerClass
{
return [CAEAGLLayer class];
}
- (id) initWithFrame:(CGRect)frame
decoder: (KxMovieDecoder *) decoder
{
self = [super initWithFrame:frame];
if (self) {
_decoder = decoder;
if ([decoder setupVideoFrameFormat:KxVideoFrameFormatYUV]) {
_renderer = [[KxMovieGLRenderer_YUV alloc] init];
LoggerVideo(1, @"OK use YUV GL renderer");
} else {
_renderer = [[KxMovieGLRenderer_RGB alloc] init];
LoggerVideo(1, @"OK use RGB GL renderer");
}
CAEAGLLayer *eaglLayer = (CAEAGLLayer*) self.layer;
self.layer.frame = CGRectMake(0, 0, self.frame.size.width*2, self.frame.size.height*2);
self.contentScaleFactor = 2;
CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
const CGFloat myColor[] = {0.0, 0.0, 0.0, 0.0};
eaglLayer.backgroundColor = CGColorCreate(rgb, myColor);
CGColorSpaceRelease(rgb);
eaglLayer.opaque = NO;
self.opaque = NO;
self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0];
eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:FALSE], kEAGLDrawablePropertyRetainedBacking,
kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat,
nil];
_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
if (!_context ||
![EAGLContext setCurrentContext:_context]) {
LoggerVideo(0, @"failed to setup EAGLContext");
self = nil;
return nil;
}
glGenFramebuffers(1, &_framebuffer);
glGenRenderbuffers(1, &_renderbuffer);
glBindFramebuffer(GL_FRAMEBUFFER, _framebuffer);
glBindRenderbuffer(GL_RENDERBUFFER, _renderbuffer);
[_context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer*)self.layer];
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &_backingWidth);
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &_backingHeight);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, _renderbuffer);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (status != GL_FRAMEBUFFER_COMPLETE) {
LoggerVideo(0, @"failed to make complete framebuffer object %x", status);
self = nil;
return nil;
}
GLenum glError = glGetError();
if (GL_NO_ERROR != glError) {
LoggerVideo(0, @"failed to setup GL %x", glError);
self = nil;
return nil;
}
if (![self loadShaders]) {
self = nil;
return nil;
}
_vertices[0] = -1.0f; // x0
_vertices[1] = -1.0f; // y0
_vertices[2] = 1.0f; // ..
_vertices[3] = -1.0f;
_vertices[4] = -1.0f;
_vertices[5] = 1.0f;
_vertices[6] = 1.0f; // x3
_vertices[7] = 1.0f; // y3
LoggerVideo(1, @"OK setup GL");
}
return self;
}
- (void)dealloc
{
_renderer = nil;
if (_framebuffer) {
glDeleteFramebuffers(1, &_framebuffer);
_framebuffer = 0;
}
if (_renderbuffer) {
glDeleteRenderbuffers(1, &_renderbuffer);
_renderbuffer = 0;
}
if (_program) {
glDeleteProgram(_program);
_program = 0;
}
if ([EAGLContext currentContext] == _context) {
[EAGLContext setCurrentContext:nil];
}
_context = nil;
}
- (void)layoutSubviews
{
glBindRenderbuffer(GL_RENDERBUFFER, _renderbuffer);
[_context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer*)self.layer];
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &_backingWidth);
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &_backingHeight);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (status != GL_FRAMEBUFFER_COMPLETE) {
LoggerVideo(0, @"failed to make complete framebuffer object %x", status);
} else {
LoggerVideo(1, @"OK setup GL framebuffer %d:%d", _backingWidth, _backingHeight);
}
[self updateVertices];
[self render: nil];
}
- (UIImage*)snapshot
{
// Get the size of the backing CAEAGLLayer
//glBindRenderbufferOES(GL_RENDERBUFFER_OES, _colorRenderbuffer);
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &_backingWidth);
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &_backingHeight);
NSInteger x = 0, y = 0, width = _backingWidth, height = _backingHeight;
NSInteger dataLength = width * height * 4;
GLubyte *data = (GLubyte*)malloc(dataLength * sizeof(GLubyte));
// Read pixel data from the framebuffer
glPixelStorei(GL_PACK_ALIGNMENT, 4);
glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);
// Create a CGImage with the pixel data
// If your OpenGL ES content is opaque, use kCGImageAlphaNoneSkipLast to ignore the alpha channel
// otherwise, use kCGImageAlphaPremultipliedLast
CGDataProviderRef ref = CGDataProviderCreateWithData(NULL, data, dataLength, NULL);
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
CGImageRef iref = CGImageCreate(width, height, 8, 32, width * 4, colorspace, kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast,
ref, NULL, true, kCGRenderingIntentDefault);
// OpenGL ES measures data in PIXELS
// Create a graphics context with the target size measured in POINTS
NSInteger widthInPoints, heightInPoints;
/* if (NULL != UIGraphicsBeginImageContextWithOptions) { // TODO put this in when we figure out why this check doesnt work!
// On iOS 4 and later, use UIGraphicsBeginImageContextWithOptions to take the scale into consideration
// Set the scale parameter to your OpenGL ES view's contentScaleFactor
// so that you get a high-resolution snapshot when its value is greater than 1.0
CGFloat scale = self.contentScaleFactor;
widthInPoints = width / scale;
heightInPoints = height / scale;
UIGraphicsBeginImageContextWithOptions(CGSizeMake(widthInPoints, heightInPoints), NO, scale);
}
else {*/
// On iOS prior to 4, fall back to use UIGraphicsBeginImageContext
widthInPoints = width;
heightInPoints = height;
UIGraphicsBeginImageContext(CGSizeMake(widthInPoints, heightInPoints));
//}
CGContextRef cgcontext = UIGraphicsGetCurrentContext();
// UIKit coordinate system is upside down to GL/Quartz coordinate system
// Flip the CGImage by rendering it to the flipped bitmap context
// The size of the destination area is measured in POINTS
CGContextSetBlendMode(cgcontext, kCGBlendModeCopy);
CGContextDrawImage(cgcontext, CGRectMake(0.0, 0.0, widthInPoints, heightInPoints), iref);
// Retrieve the UIImage from the current context
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// Clean up
free(data);
CFRelease(ref);
CFRelease(colorspace);
CGImageRelease(iref);
return image;
}
- (void)setContentMode:(UIViewContentMode)contentMode
{
[super setContentMode:contentMode];
[self updateVertices];
if (_renderer.isValid)
[self render:nil];
}
- (BOOL)loadShaders
{
BOOL result = NO;
GLuint vertShader = 0, fragShader = 0;
_program = glCreateProgram();
vertShader = compileShader(GL_VERTEX_SHADER, vertexShaderString);
if (!vertShader)
goto exit;
fragShader = compileShader(GL_FRAGMENT_SHADER, _renderer.fragmentShader);
if (!fragShader)
goto exit;
glAttachShader(_program, vertShader);
glAttachShader(_program, fragShader);
glBindAttribLocation(_program, ATTRIBUTE_VERTEX, "position");
glBindAttribLocation(_program, ATTRIBUTE_TEXCOORD, "texcoord");
glLinkProgram(_program);
GLint status;
glGetProgramiv(_program, GL_LINK_STATUS, &status);
if (status == GL_FALSE) {
LoggerVideo(0, @"Failed to link program %d", _program);
goto exit;
}
result = validateProgram(_program);
_uniformMatrix = glGetUniformLocation(_program, "modelViewProjectionMatrix");
[_renderer resolveUniforms:_program];
exit:
if (vertShader)
glDeleteShader(vertShader);
if (fragShader)
glDeleteShader(fragShader);
if (result) {
LoggerVideo(1, @"OK setup GL programm");
} else {
glDeleteProgram(_program);
_program = 0;
}
return result;
}
- (void)updateVertices
{
const BOOL fit = (self.contentMode == UIViewContentModeScaleAspectFit);
const float width = _decoder.frameWidth;
const float height = _decoder.frameHeight;
const float dH = (float)_backingHeight / height;
const float dW = (float)_backingWidth / width;
const float dd = fit ? MIN(dH, dW) : MAX(dH, dW);
const float h = (height * dd / (float)_backingHeight);
const float w = (width * dd / (float)_backingWidth );
_vertices[0] = - w;
_vertices[1] = - h;
_vertices[2] = w;
_vertices[3] = - h;
_vertices[4] = - w;
_vertices[5] = h;
_vertices[6] = w;
_vertices[7] = h;
}
- (void)render: (KxVideoFrame *) frame
{
static const GLfloat texCoords[] = {
0.0f, 1.0f,
1.0f, 1.0f,
0.0f, 0.0f,
1.0f, 0.0f,
};
[EAGLContext setCurrentContext:_context];
glBindFramebuffer(GL_FRAMEBUFFER, _framebuffer);
glViewport(0, 0, _backingWidth, _backingHeight);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(_program);
if (frame) {
[_renderer setFrame:frame];
}
if ([_renderer prepareRender]) {
GLfloat modelviewProj[16];
mat4f_LoadOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, modelviewProj);
glUniformMatrix4fv(_uniformMatrix, 1, GL_FALSE, modelviewProj);
glVertexAttribPointer(ATTRIBUTE_VERTEX, 2, GL_FLOAT, 0, 0, _vertices);
glEnableVertexAttribArray(ATTRIBUTE_VERTEX);
glVertexAttribPointer(ATTRIBUTE_TEXCOORD, 2, GL_FLOAT, 0, 0, texCoords);
glEnableVertexAttribArray(ATTRIBUTE_TEXCOORD);
#if 0
if (!validateProgram(_program))
{
LoggerVideo(0, @"Failed to validate program");
return;
}
#endif
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
glBindRenderbuffer(GL_RENDERBUFFER, _renderbuffer);
[_context presentRenderbuffer:GL_RENDERBUFFER];
}
@end