summaryrefslogtreecommitdiffstats
path: root/ppapi/examples/video_decode
diff options
context:
space:
mode:
authorfischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-10 19:34:42 +0000
committerfischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-10 19:34:42 +0000
commit14aa5a42a37ba3508f915eb11cec14a20bb6bc29 (patch)
tree476b8db014e0100a960e9bd615144105941b95f3 /ppapi/examples/video_decode
parent71cc6f7a9a8b35b6eb457e4b1d824a1a5612480d (diff)
downloadchromium_src-14aa5a42a37ba3508f915eb11cec14a20bb6bc29.zip
chromium_src-14aa5a42a37ba3508f915eb11cec14a20bb6bc29.tar.gz
chromium_src-14aa5a42a37ba3508f915eb11cec14a20bb6bc29.tar.bz2
Unbreak ppapi_example_video_decode for platforms that don't have ARB extensions.
(originally broken by r141977) Review URL: https://chromiumcodereview.appspot.com/10855105 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151109 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/examples/video_decode')
-rw-r--r--ppapi/examples/video_decode/video_decode.cc67
1 files changed, 39 insertions, 28 deletions
diff --git a/ppapi/examples/video_decode/video_decode.cc b/ppapi/examples/video_decode/video_decode.cc
index 4e3354a..affea3c 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);
}