22 #include <type_traits> 27 "attribute vec4 a_Position;\n" 28 "attribute vec2 a_TexCoord;\n" 30 "varying vec2 v_TexCoord;\n" 33 " gl_Position = a_Position;\n" 34 " v_TexCoord = a_TexCoord;\n" 37 const std::string kFragmentShaderOES =
38 "#extension GL_OES_EGL_image_external : require\n" 39 "precision mediump float;\n" 40 "varying vec2 v_TexCoord;\n" 41 "uniform samplerExternalOES sTexture;\n" 42 "uniform bool uRedUnknown;\n" 44 " vec4 sample = texture2D(sTexture, v_TexCoord);\n" 45 " float grey = 0.21 * sample.r + 0.71 * sample.g + 0.07 * sample.b;\n" 46 " gl_FragColor = vec4(grey, uRedUnknown?0.0:grey, uRedUnknown?0.0:grey, 0.5);\n" 49 const std::string kFragmentShaderBlendingOES =
50 "#extension GL_OES_EGL_image_external : require\n" 51 "precision mediump float;\n" 52 "varying vec2 v_TexCoord;\n" 53 "uniform samplerExternalOES sTexture;\n" 54 "uniform sampler2D uDepthTexture;\n" 55 "uniform vec2 uScreenScale;\n" 56 "uniform bool uRedUnknown;\n" 58 " vec4 sample = texture2D(sTexture, v_TexCoord);\n" 59 " vec2 coord = uScreenScale * gl_FragCoord.xy;\n;" 60 " vec4 depthPacked = texture2D(uDepthTexture, coord);\n" 61 " float depth = dot(depthPacked, 1./vec4(1.,255.,65025.,16581375.));\n" 63 " gl_FragColor = vec4(sample.r, sample.g, sample.b, 0.5);\n" 65 " float grey = 0.21 * sample.r + 0.71 * sample.g + 0.07 * sample.b;\n" 66 " gl_FragColor = vec4(grey, uRedUnknown?0.0:grey, uRedUnknown?0.0:grey, 0.5);\n" 71 "precision mediump float;\n" 72 "varying vec2 v_TexCoord;\n" 73 "uniform sampler2D sTexture;\n" 74 "uniform bool uRedUnknown;\n" 76 " vec4 sample = texture2D(sTexture, v_TexCoord);\n" 77 " float grey = 0.21 * sample.r + 0.71 * sample.g + 0.07 * sample.b;\n" 78 " gl_FragColor = vec4(grey, uRedUnknown?0.0:grey, uRedUnknown?0.0:grey, 0.5);\n" 81 const std::string kFragmentShaderBlending =
82 "precision mediump float;\n" 83 "varying vec2 v_TexCoord;\n" 84 "uniform sampler2D sTexture;\n" 85 "uniform sampler2D uDepthTexture;\n" 86 "uniform vec2 uScreenScale;\n" 87 "uniform bool uRedUnknown;\n" 89 " vec4 sample = texture2D(sTexture, v_TexCoord);\n" 90 " vec2 coord = uScreenScale * gl_FragCoord.xy;\n;" 91 " vec4 depthPacked = texture2D(uDepthTexture, coord);\n" 92 " float depth = dot(depthPacked, 1./vec4(1.,255.,65025.,16581375.));\n" 94 " gl_FragColor = vec4(sample.r, sample.g, sample.b, 0.5);\n" 96 " float grey = 0.21 * sample.r + 0.71 * sample.g + 0.07 * sample.b;\n" 97 " gl_FragColor = vec4(grey, uRedUnknown?0.0:grey, uRedUnknown?0.0:grey, 0.5);\n" 136 LOGI(
"textureId=%d", textureId);
152 oes_?kFragmentShaderBlendingOES.c_str():kFragmentShaderBlending.c_str());
162 glUseProgram(program);
166 glActiveTexture(GL_TEXTURE0);
169 glBindTexture(GL_TEXTURE_EXTERNAL_OES,
texture_id_);
177 glActiveTexture(GL_TEXTURE1);
179 glBindTexture(GL_TEXTURE_2D, depthTexture);
181 GLuint depth_texture_handle = glGetUniformLocation(program,
"uDepthTexture");
182 glUniform1i(depth_texture_handle, 1);
184 GLuint screenScale_handle = glGetUniformLocation(program,
"uScreenScale");
185 glUniform2f(screenScale_handle, 1.0
f/(
float)screenWidth, 1.0
f/(
float)screenHeight);
188 GLuint screenScale_handle = glGetUniformLocation(program,
"uRedUnknown");
189 glUniform1i(screenScale_handle, redUnknown);
191 GLuint attributeVertices = glGetAttribLocation(program,
"a_Position");
192 GLuint attributeUvs = glGetAttribLocation(program,
"a_TexCoord");
197 glEnableVertexAttribArray(attributeVertices);
198 glEnableVertexAttribArray(attributeUvs);
200 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
202 glDisableVertexAttribArray(attributeVertices);
203 glDisableVertexAttribArray(attributeUvs);
206 glDepthMask(GL_TRUE);
207 glDisable (GL_BLEND);
static std::vector< GLuint > shaderPrograms_
void Draw(const float *transformed_uvs, const GLuint &depthTexture, int screenWidth, int screenHeight, bool redUnknown)
static const char kFragmentShader[]
GLuint CreateProgram(const char *vertex_source, const char *fragment_source)
static constexpr int kNumVertices
static const GLfloat BackgroundRenderer_kVertices[]
#define UASSERT(condition)
void InitializeGlContent(GLuint textureId, bool oes)
static const GLfloat BackgroundRenderer_kTexCoord[]
void CheckGlError(const char *operation)
static const char kVertexShader[]