Commit 14aa5a42 authored by fischman@chromium.org's avatar fischman@chromium.org

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
parent 71cc6f7a
...@@ -135,6 +135,8 @@ class VideoDecodeDemoInstance : public pp::Instance, ...@@ -135,6 +135,8 @@ class VideoDecodeDemoInstance : public pp::Instance,
void InitGL(); void InitGL();
GLuint CreateTexture(int32_t width, int32_t height, GLenum texture_target); GLuint CreateTexture(int32_t width, int32_t height, GLenum texture_target);
void CreateGLObjects(); void CreateGLObjects();
void Create2DProgramOnce();
void CreateRectangleARBProgramOnce();
Shader CreateProgram(const char* vertex_shader, Shader CreateProgram(const char* vertex_shader,
const char* fragment_shader); const char* fragment_shader);
void CreateShader(GLuint program, GLenum type, const char* source, int size); void CreateShader(GLuint program, GLenum type, const char* source, int size);
...@@ -424,11 +426,13 @@ void VideoDecodeDemoInstance::PictureReady(PP_Resource decoder, ...@@ -424,11 +426,13 @@ void VideoDecodeDemoInstance::PictureReady(PP_Resource decoder,
} }
if (info.texture_target == GL_TEXTURE_2D) { if (info.texture_target == GL_TEXTURE_2D) {
Create2DProgramOnce();
gles2_if_->UseProgram(context_->pp_resource(), shader_2d_.program); gles2_if_->UseProgram(context_->pp_resource(), shader_2d_.program);
gles2_if_->Uniform2f( gles2_if_->Uniform2f(
context_->pp_resource(), shader_2d_.texcoord_scale_location, 1.0, 1.0); context_->pp_resource(), shader_2d_.texcoord_scale_location, 1.0, 1.0);
} else { } else {
assert(info.texture_target == GL_TEXTURE_RECTANGLE_ARB); assert(info.texture_target == GL_TEXTURE_RECTANGLE_ARB);
CreateRectangleARBProgramOnce();
gles2_if_->UseProgram( gles2_if_->UseProgram(
context_->pp_resource(), shader_rectangle_arb_.program); context_->pp_resource(), shader_rectangle_arb_.program);
gles2_if_->Uniform2f(context_->pp_resource(), gles2_if_->Uniform2f(context_->pp_resource(),
...@@ -564,18 +568,36 @@ void VideoDecodeDemoInstance::DeleteTexture(GLuint id) { ...@@ -564,18 +568,36 @@ void VideoDecodeDemoInstance::DeleteTexture(GLuint id) {
} }
void VideoDecodeDemoInstance::CreateGLObjects() { void VideoDecodeDemoInstance::CreateGLObjects() {
// Code and constants for shader. // Assign vertex positions and texture coordinates to buffers for use in
static const char kVertexShader[] = // shader program.
"varying vec2 v_texCoord; \n" static const float kVertices[] = {
"attribute vec4 a_position; \n" -1, 1, -1, -1, 1, 1, 1, -1, // Position coordinates.
"attribute vec2 a_texCoord; \n" 0, 1, 0, 0, 1, 1, 1, 0, // Texture coordinates.
"uniform vec2 v_scale; \n" };
"void main() \n"
"{ \n"
" v_texCoord = v_scale * a_texCoord; \n"
" gl_Position = a_position; \n"
"}";
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[] = static const char kFragmentShader2D[] =
"precision mediump float; \n" "precision mediump float; \n"
"varying vec2 v_texCoord; \n" "varying vec2 v_texCoord; \n"
...@@ -584,7 +606,13 @@ void VideoDecodeDemoInstance::CreateGLObjects() { ...@@ -584,7 +606,13 @@ void VideoDecodeDemoInstance::CreateGLObjects() {
"{" "{"
" gl_FragColor = texture2D(s_texture, v_texCoord); \n" " 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[] = static const char kFragmentShaderRectangle[] =
"#extension GL_ARB_texture_rectangle : require\n" "#extension GL_ARB_texture_rectangle : require\n"
"precision mediump float; \n" "precision mediump float; \n"
...@@ -594,23 +622,6 @@ void VideoDecodeDemoInstance::CreateGLObjects() { ...@@ -594,23 +622,6 @@ void VideoDecodeDemoInstance::CreateGLObjects() {
"{" "{"
" gl_FragColor = texture2DRect(s_texture, v_texCoord).rgba; \n" " 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_ = shader_rectangle_arb_ =
CreateProgram(kVertexShader, kFragmentShaderRectangle); CreateProgram(kVertexShader, kFragmentShaderRectangle);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment