Ignore:
Timestamp:
Sep 22, 2014 7:03:25 AM (10 years ago)
Author:
ming
Message:

Re #1790: Use OpenGL textures instead of platform dependent textures.

This revision contains:

  • remove the generation of iOS texture (instead directly use OpenGL textures)
  • add iOS and Android window type
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/src/pjmedia-videodev/opengl_dev.c

    r4821 r4925  
    2727#include <pjmedia-videodev/opengl_dev.h> 
    2828#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 
    3137#else 
    3238#   include <GL/gl.h> 
     
    4046#define DEFAULT_FPS             15 
    4147 
    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 
    4353 
    4454enum { 
     
    7080/* OpenGL buffers structure. */ 
    7181struct 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; 
    7890}; 
    7991 
     
    201213} 
    202214 
    203 void pjmedia_vid_dev_opengl_create_buffers(pj_pool_t *pool, gl_buffers **glb) 
     215void pjmedia_vid_dev_opengl_create_buffers(pj_pool_t *pool, pj_bool_t direct, 
     216                                           gl_buffers **glb) 
    204217{ 
    205218    gl_buffers *glbuf = PJ_POOL_ZALLOC_T(pool, gl_buffers); 
     
    208221    glDisable(GL_DEPTH_TEST); 
    209222     
    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); 
    215232} 
    216233 
     
    222239    GLchar *attribName[NUM_ATTRIBUTES] = { "position", "texCoord" }; 
    223240     
    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        } 
    234253    } 
    235254     
     
    246265} 
    247266 
    248 pj_status_t pjmedia_vid_dev_opengl_draw(gl_buffers *glb, unsigned int texture, 
    249                                         unsigned int name) 
     267pj_status_t pjmedia_vid_dev_opengl_draw(gl_buffers *glb, unsigned int width, 
     268                                        unsigned int height, void *pixels) 
    250269{ 
    251270    static const GLfloat squareVertices[] = { 
     
    258277        0, 1, 1, 1, 0, 0, 1, 0 
    259278    }; 
    260     GLenum tex = (GLenum) texture; 
    261     GLuint nam = (GLuint) name; 
    262  
    263     glBindTexture(tex, nam); 
     279 
     280    glBindTexture(GL_TEXTURE_2D, glb->rendTex); 
    264281     
    265282    /* Set texture parameters */ 
     
    269286    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 
    270287     
    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)); 
    272295     
    273296    /* 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)); 
    275299     
    276300    /* Draw the texture on the screen with OpenGL ES 2 */ 
     
    289313     
    290314    /* Present */ 
    291     glBindRenderbuffer(GL_RENDERBUFFER, glb->rendBuf); 
     315    if (!glb->direct) 
     316        glBindRenderbuffer(GL_RENDERBUFFER, glb->rendBuf); 
    292317     
    293318    return PJ_SUCCESS; 
     
    304329        glDeleteRenderbuffers(1, &glb->rendBuf); 
    305330        glb->rendBuf = 0; 
     331    } 
     332     
     333    if (glb->rendTex) { 
     334        glDeleteTextures(1, &glb->rendTex); 
     335        glb->rendTex = 0; 
    306336    } 
    307337     
Note: See TracChangeset for help on using the changeset viewer.