- Timestamp:
- Sep 22, 2014 7:03:25 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia-videodev/opengl_dev.c
r4821 r4925 27 27 #include <pjmedia-videodev/opengl_dev.h> 28 28 #ifdef PJMEDIA_VIDEO_DEV_HAS_OPENGL_ES 29 # include <OpenGLES/ES2/gl.h> 30 # include <OpenGLES/ES2/glext.h> 29 # if PJ_ANDROID 30 # include <GLES2/gl2.h> 31 # include <GLES2/gl2ext.h> 32 # define GL_BGRA GL_RGBA 33 # else 34 # include <OpenGLES/ES2/gl.h> 35 # include <OpenGLES/ES2/glext.h> 36 # endif 31 37 #else 32 38 # include <GL/gl.h> … … 40 46 #define DEFAULT_FPS 15 41 47 42 #define LOG(a) 48 #if PJ_ANDROID 49 # define LOG(a) PJ_LOG(3, (THIS_FILE, a)) 50 #else 51 # define LOG(a) 52 #endif 43 53 44 54 enum { … … 70 80 /* OpenGL buffers structure. */ 71 81 struct gl_buffers { 72 GLuint frameBuf; 73 GLuint rendBuf; 74 GLuint directProg; 75 76 int rendBufW; 77 int rendBufH; 82 GLuint frameBuf; 83 GLuint rendBuf; 84 GLuint rendTex; 85 GLuint directProg; 86 87 int rendBufW; 88 int rendBufH; 89 pj_bool_t direct; 78 90 }; 79 91 … … 201 213 } 202 214 203 void pjmedia_vid_dev_opengl_create_buffers(pj_pool_t *pool, gl_buffers **glb) 215 void pjmedia_vid_dev_opengl_create_buffers(pj_pool_t *pool, pj_bool_t direct, 216 gl_buffers **glb) 204 217 { 205 218 gl_buffers *glbuf = PJ_POOL_ZALLOC_T(pool, gl_buffers); … … 208 221 glDisable(GL_DEPTH_TEST); 209 222 210 glGenFramebuffers(1, &glbuf->frameBuf); 211 glBindFramebuffer(GL_FRAMEBUFFER, glbuf->frameBuf); 212 213 glGenRenderbuffers(1, &glbuf->rendBuf); 214 glBindRenderbuffer(GL_RENDERBUFFER, glbuf->rendBuf); 223 if (!(glbuf->direct = direct)) { 224 glGenFramebuffers(1, &glbuf->frameBuf); 225 glBindFramebuffer(GL_FRAMEBUFFER, glbuf->frameBuf); 226 227 glGenRenderbuffers(1, &glbuf->rendBuf); 228 glBindRenderbuffer(GL_RENDERBUFFER, glbuf->rendBuf); 229 } 230 231 glGenTextures(1, &glbuf->rendTex); 215 232 } 216 233 … … 222 239 GLchar *attribName[NUM_ATTRIBUTES] = { "position", "texCoord" }; 223 240 224 glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, 225 &glb->rendBufW); 226 glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, 227 &glb->rendBufH); 228 229 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 230 GL_RENDERBUFFER, glb->rendBuf); 231 if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { 232 LOG("Unable to create frame buffer"); 233 return -1; 241 if (!glb->direct ) { 242 glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, 243 &glb->rendBufW); 244 glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, 245 &glb->rendBufH); 246 247 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 248 GL_RENDERBUFFER, glb->rendBuf); 249 if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { 250 LOG("Unable to create frame buffer"); 251 return -1; 252 } 234 253 } 235 254 … … 246 265 } 247 266 248 pj_status_t pjmedia_vid_dev_opengl_draw(gl_buffers *glb, unsigned int texture,249 unsigned int name)267 pj_status_t pjmedia_vid_dev_opengl_draw(gl_buffers *glb, unsigned int width, 268 unsigned int height, void *pixels) 250 269 { 251 270 static const GLfloat squareVertices[] = { … … 258 277 0, 1, 1, 1, 0, 0, 1, 0 259 278 }; 260 GLenum tex = (GLenum) texture; 261 GLuint nam = (GLuint) name; 262 263 glBindTexture(tex, nam); 279 280 glBindTexture(GL_TEXTURE_2D, glb->rendTex); 264 281 265 282 /* Set texture parameters */ … … 269 286 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 270 287 271 glBindFramebuffer(GL_FRAMEBUFFER, glb->frameBuf); 288 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)width, (GLsizei)height, 289 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid *)pixels); 290 291 glFlush(); 292 293 /* Do we render directly to the screen? */ 294 glBindFramebuffer(GL_FRAMEBUFFER, (glb->direct? 0: glb->frameBuf)); 272 295 273 296 /* Set the view port to the entire view */ 274 glViewport(0, 0, glb->rendBufW, glb->rendBufH); 297 glViewport(0, 0, (glb->direct? width: glb->rendBufW), 298 (glb->direct? height: glb->rendBufH)); 275 299 276 300 /* Draw the texture on the screen with OpenGL ES 2 */ … … 289 313 290 314 /* Present */ 291 glBindRenderbuffer(GL_RENDERBUFFER, glb->rendBuf); 315 if (!glb->direct) 316 glBindRenderbuffer(GL_RENDERBUFFER, glb->rendBuf); 292 317 293 318 return PJ_SUCCESS; … … 304 329 glDeleteRenderbuffers(1, &glb->rendBuf); 305 330 glb->rendBuf = 0; 331 } 332 333 if (glb->rendTex) { 334 glDeleteTextures(1, &glb->rendTex); 335 glb->rendTex = 0; 306 336 } 307 337
Note: See TracChangeset
for help on using the changeset viewer.