Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Unified Diff: webrtc/sdk/objc/Framework/Classes/Video/RTCShader.mm

Issue 2869143002: iOS: Add interface for injecting custom shaders (Closed)
Patch Set: Rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/sdk/objc/Framework/Classes/Video/RTCShader.mm
diff --git a/webrtc/sdk/objc/Framework/Classes/Video/RTCShader.mm b/webrtc/sdk/objc/Framework/Classes/Video/RTCShader.mm
index 155a0165a13a2ca8b3ef0eaf7dff3f4abb49de46..3c3e6abb275fd13c8590a185091a351cb13da849 100644
--- a/webrtc/sdk/objc/Framework/Classes/Video/RTCShader.mm
+++ b/webrtc/sdk/objc/Framework/Classes/Video/RTCShader.mm
@@ -10,11 +10,17 @@
#import "RTCShader.h"
+#if TARGET_OS_IPHONE
+#import <OpenGLES/ES3/gl.h>
+#else
+#import <OpenGL/gl3.h>
+#endif
+
#include <algorithm>
#include <array>
#include <memory>
-#import "RTCShader+Private.h"
+#import "RTCOpenGLDefines.h"
#include "webrtc/base/checks.h"
#include "webrtc/base/logging.h"
@@ -95,17 +101,30 @@ GLuint RTCCreateProgramFromFragmentSource(const char fragmentShaderSource[]) {
if (fragmentShader) {
glDeleteShader(fragmentShader);
}
- return program;
-}
-// Set vertex shader variables 'position' and 'texcoord' in |program| to use
-// |vertexBuffer| and |vertexArray| to store the vertex data.
-BOOL RTCSetupVerticesForProgram(GLuint program, GLuint* vertexBuffer, GLuint* vertexArray) {
+ // Set vertex shader variables 'position' and 'texcoord' in program.
GLint position = glGetAttribLocation(program, "position");
GLint texcoord = glGetAttribLocation(program, "texcoord");
if (position < 0 || texcoord < 0) {
- return NO;
+ glDeleteProgram(program);
+ return 0;
}
+
+ // Read position attribute with size of 2 and stride of 4 beginning at the start of the array. The
+ // last argument indicates offset of data within the vertex buffer.
+ glVertexAttribPointer(position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), (void *)0);
+ glEnableVertexAttribArray(position);
+
+ // Read texcoord attribute with size of 2 and stride of 4 beginning at the first texcoord in the
+ // array. The last argument indicates offset of data within the vertex buffer.
+ glVertexAttribPointer(
+ texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), (void *)(2 * sizeof(GLfloat)));
+ glEnableVertexAttribArray(texcoord);
+
+ return program;
+}
+
+BOOL RTCCreateVertexBuffer(GLuint *vertexBuffer, GLuint *vertexArray) {
#if !TARGET_OS_IPHONE
glGenVertexArrays(1, vertexArray);
if (*vertexArray == 0) {
@@ -115,25 +134,11 @@ BOOL RTCSetupVerticesForProgram(GLuint program, GLuint* vertexBuffer, GLuint* ve
#endif
glGenBuffers(1, vertexBuffer);
if (*vertexBuffer == 0) {
+ glDeleteVertexArrays(1, vertexArray);
return NO;
}
glBindBuffer(GL_ARRAY_BUFFER, *vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, 4 * 4 * sizeof(GLfloat), NULL, GL_DYNAMIC_DRAW);
-
- // Read position attribute with size of 2 and stride of 4 beginning at the
- // start of the array. The last argument indicates offset of data within the
- // vertex buffer.
- glVertexAttribPointer(position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat),
- (void *)0);
- glEnableVertexAttribArray(position);
-
- // Read texcoord attribute from |gVertices| with size of 2 and stride of 4
- // beginning at the first texcoord in the array. The last argument indicates
- // offset of data within |gVertices| as supplied to the vertex buffer.
- glVertexAttribPointer(texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat),
- (void *)(2 * sizeof(GLfloat)));
- glEnableVertexAttribArray(texcoord);
-
return YES;
}
« no previous file with comments | « webrtc/sdk/objc/Framework/Classes/Video/RTCShader.h ('k') | webrtc/sdk/objc/Framework/Classes/Video/RTCShader+Private.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698