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..affea3cc25c0dee4d5035ccee64c68a07875f7b1 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 CreateRectangleARBProgramOnce(); |
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); |
+ CreateRectangleARBProgramOnce(); |
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::CreateRectangleARBProgramOnce() { |
+ 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); |
} |