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

Unified Diff: ppapi/examples/video_decode/video_decode.cc

Issue 10855105: Unbreak ppapi_example_video_decode for platforms that don't have ARB extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/examples/video_decode/video_decode.cc
diff --git a/ppapi/examples/video_decode/video_decode.cc b/ppapi/examples/video_decode/video_decode.cc
index 4e3354ae2bd9986472c2e99a3fadf1c5c3e01c66..3fed6faba10db6b4db5beb7233777d0dd1cc4f7a 100644
--- a/ppapi/examples/video_decode/video_decode.cc
+++ b/ppapi/examples/video_decode/video_decode.cc
@@ -135,6 +135,8 @@ class VideoDecodeDemoInstance : public pp::Instance,
void InitGL();
GLuint CreateTexture(int32_t width, int32_t height, GLenum texture_target);
void CreateGLObjects();
+ void Create2DProgramOnce();
+ void CreateARBProgramOnce();
sail 2012/08/10 17:45:45 I think ARB isn't specific enough. Maybe Create2DR
Ami GONE FROM CHROMIUM 2012/08/10 17:56:19 Changed to CreateRectangleARBProgramOnce to parall
Shader CreateProgram(const char* vertex_shader,
const char* fragment_shader);
void CreateShader(GLuint program, GLenum type, const char* source, int size);
@@ -424,11 +426,13 @@ void VideoDecodeDemoInstance::PictureReady(PP_Resource decoder,
}
if (info.texture_target == GL_TEXTURE_2D) {
+ Create2DProgramOnce();
gles2_if_->UseProgram(context_->pp_resource(), shader_2d_.program);
gles2_if_->Uniform2f(
context_->pp_resource(), shader_2d_.texcoord_scale_location, 1.0, 1.0);
} else {
assert(info.texture_target == GL_TEXTURE_RECTANGLE_ARB);
+ CreateARBProgramOnce();
gles2_if_->UseProgram(
context_->pp_resource(), shader_rectangle_arb_.program);
gles2_if_->Uniform2f(context_->pp_resource(),
@@ -564,18 +568,36 @@ void VideoDecodeDemoInstance::DeleteTexture(GLuint id) {
}
void VideoDecodeDemoInstance::CreateGLObjects() {
- // Code and constants for shader.
- static const char kVertexShader[] =
- "varying vec2 v_texCoord; \n"
- "attribute vec4 a_position; \n"
- "attribute vec2 a_texCoord; \n"
- "uniform vec2 v_scale; \n"
- "void main() \n"
- "{ \n"
- " v_texCoord = v_scale * a_texCoord; \n"
- " gl_Position = a_position; \n"
- "}";
+ // Assign vertex positions and texture coordinates to buffers for use in
+ // shader program.
+ static const float kVertices[] = {
+ -1, 1, -1, -1, 1, 1, 1, -1, // Position coordinates.
+ 0, 1, 0, 0, 1, 1, 1, 0, // Texture coordinates.
+ };
+ GLuint buffer;
+ gles2_if_->GenBuffers(context_->pp_resource(), 1, &buffer);
+ gles2_if_->BindBuffer(context_->pp_resource(), GL_ARRAY_BUFFER, buffer);
+
+ gles2_if_->BufferData(context_->pp_resource(), GL_ARRAY_BUFFER,
+ sizeof(kVertices), kVertices, GL_STATIC_DRAW);
+ assertNoGLError();
+}
+
+static const char kVertexShader[] =
+ "varying vec2 v_texCoord; \n"
+ "attribute vec4 a_position; \n"
+ "attribute vec2 a_texCoord; \n"
+ "uniform vec2 v_scale; \n"
+ "void main() \n"
+ "{ \n"
+ " v_texCoord = v_scale * a_texCoord; \n"
+ " gl_Position = a_position; \n"
+ "}";
+
+void VideoDecodeDemoInstance::Create2DProgramOnce() {
+ if (shader_2d_.program)
+ return;
static const char kFragmentShader2D[] =
"precision mediump float; \n"
"varying vec2 v_texCoord; \n"
@@ -584,7 +606,13 @@ void VideoDecodeDemoInstance::CreateGLObjects() {
"{"
" gl_FragColor = texture2D(s_texture, v_texCoord); \n"
"}";
+ shader_2d_ = CreateProgram(kVertexShader, kFragmentShader2D);
+ assertNoGLError();
+}
+void VideoDecodeDemoInstance::CreateARBProgramOnce() {
+ if (shader_rectangle_arb_.program)
+ return;
static const char kFragmentShaderRectangle[] =
"#extension GL_ARB_texture_rectangle : require\n"
"precision mediump float; \n"
@@ -594,23 +622,6 @@ void VideoDecodeDemoInstance::CreateGLObjects() {
"{"
" gl_FragColor = texture2DRect(s_texture, v_texCoord).rgba; \n"
"}";
-
- // Assign vertex positions and texture coordinates to buffers for use in
- // shader program.
- static const float kVertices[] = {
- -1, 1, -1, -1, 1, 1, 1, -1, // Position coordinates.
- 0, 1, 0, 0, 1, 1, 1, 0, // Texture coordinates.
- };
-
- GLuint buffer;
- gles2_if_->GenBuffers(context_->pp_resource(), 1, &buffer);
- gles2_if_->BindBuffer(context_->pp_resource(), GL_ARRAY_BUFFER, buffer);
-
- gles2_if_->BufferData(context_->pp_resource(), GL_ARRAY_BUFFER,
- sizeof(kVertices), kVertices, GL_STATIC_DRAW);
- assertNoGLError();
-
- shader_2d_ = CreateProgram(kVertexShader, kFragmentShader2D);
shader_rectangle_arb_ =
CreateProgram(kVertexShader, kFragmentShaderRectangle);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698