Home | History | Annotate | Download | only in iOS
      1 
      2 /*
      3  * Copyright 2011 Google Inc.
      4  *
      5  * Use of this source code is governed by a BSD-style license that can be
      6  * found in the LICENSE file.
      7  */
      8 
      9 
     10 #include "gl/GrGLInterface.h"
     11 
     12 #import <OpenGLES/ES2/gl.h>
     13 #import <OpenGLES/ES2/glext.h>
     14 
     15 const GrGLInterface* GrGLCreateNativeInterface() {
     16     static SkAutoTUnref<GrGLInterface> glInterface;
     17     if (!glInterface.get()) {
     18         GrGLInterface* interface = SkNEW(GrGLInterface);
     19         glInterface.reset(interface);
     20 
     21         interface->fActiveTexture = glActiveTexture;
     22         interface->fAttachShader = glAttachShader;
     23         interface->fBindAttribLocation = glBindAttribLocation;
     24         interface->fBindBuffer = glBindBuffer;
     25         interface->fBindTexture = glBindTexture;
     26         interface->fBlendColor = glBlendColor;
     27         interface->fBlendFunc = glBlendFunc;
     28         interface->fBufferData = (GrGLBufferDataProc)glBufferData;
     29         interface->fBufferSubData = (GrGLBufferSubDataProc)glBufferSubData;
     30         interface->fClear = glClear;
     31         interface->fClearColor = glClearColor;
     32         interface->fClearStencil = glClearStencil;
     33         interface->fColorMask = glColorMask;
     34         interface->fCompileShader = glCompileShader;
     35         interface->fCompressedTexImage2D = glCompressedTexImage2D;
     36         interface->fCopyTexSubImage2D = glCopyTexSubImage2D;
     37         interface->fCreateProgram = glCreateProgram;
     38         interface->fCreateShader = glCreateShader;
     39         interface->fCullFace = glCullFace;
     40         interface->fDeleteBuffers = glDeleteBuffers;
     41         interface->fDeleteProgram = glDeleteProgram;
     42         interface->fDeleteShader = glDeleteShader;
     43         interface->fDeleteTextures = glDeleteTextures;
     44         interface->fDepthMask = glDepthMask;
     45         interface->fDisable = glDisable;
     46         interface->fDisableVertexAttribArray = glDisableVertexAttribArray;
     47         interface->fDrawArrays = glDrawArrays;
     48         interface->fDrawBuffer = NULL;
     49         interface->fDrawBuffers = NULL;
     50         interface->fDrawElements = glDrawElements;
     51         interface->fEnable = glEnable;
     52         interface->fEnableVertexAttribArray = glEnableVertexAttribArray;
     53         interface->fFinish = glFinish;
     54         interface->fFlush = glFlush;
     55         interface->fFrontFace = glFrontFace;
     56         interface->fGenBuffers = glGenBuffers;
     57         interface->fGenerateMipmap = glGenerateMipmap;
     58         interface->fGetBufferParameteriv = glGetBufferParameteriv;
     59         interface->fGetError = glGetError;
     60         interface->fGetIntegerv = glGetIntegerv;
     61         interface->fGetProgramInfoLog = glGetProgramInfoLog;
     62         interface->fGetProgramiv = glGetProgramiv;
     63         interface->fGetShaderInfoLog = glGetShaderInfoLog;
     64         interface->fGetShaderiv = glGetShaderiv;
     65         interface->fGetString = glGetString;
     66         interface->fGenTextures = glGenTextures;
     67         interface->fGetUniformLocation = glGetUniformLocation;
     68         interface->fLineWidth = glLineWidth;
     69         interface->fLinkProgram = glLinkProgram;
     70         interface->fPixelStorei = glPixelStorei;
     71         interface->fReadBuffer = NULL;
     72         interface->fReadPixels = glReadPixels;
     73         interface->fScissor = glScissor;
     74         interface->fShaderSource = glShaderSource;
     75         interface->fStencilFunc = glStencilFunc;
     76         interface->fStencilFuncSeparate = glStencilFuncSeparate;
     77         interface->fStencilMask = glStencilMask;
     78         interface->fStencilMaskSeparate = glStencilMaskSeparate;
     79         interface->fStencilOp = glStencilOp;
     80         interface->fStencilOpSeparate = glStencilOpSeparate;
     81         // mac uses GLenum for internalFormat param (non-standard)
     82         // amounts to int vs. uint.
     83         interface->fTexImage2D = (GrGLTexImage2DProc)glTexImage2D;
     84 #if GL_ARB_texture_storage
     85         interface->fTexStorage2D = glTexStorage2D;
     86 #elif GL_EXT_texture_storage
     87         interface->fTexStorage2D = glTexStorage2DEXT;
     88 #endif
     89 #if GL_EXT_discard_framebuffer
     90         interface->fDiscardFramebuffer = glDiscardFramebufferEXT;
     91 #endif
     92         interface->fTexParameteri = glTexParameteri;
     93         interface->fTexParameteriv = glTexParameteriv;
     94         interface->fTexSubImage2D = glTexSubImage2D;
     95         interface->fUniform1f = glUniform1f;
     96         interface->fUniform1i = glUniform1i;
     97         interface->fUniform1fv = glUniform1fv;
     98         interface->fUniform1iv = glUniform1iv;
     99         interface->fUniform2f = glUniform2f;
    100         interface->fUniform2i = glUniform2i;
    101         interface->fUniform2fv = glUniform2fv;
    102         interface->fUniform2iv = glUniform2iv;
    103         interface->fUniform3f = glUniform3f;
    104         interface->fUniform3i = glUniform3i;
    105         interface->fUniform3fv = glUniform3fv;
    106         interface->fUniform3iv = glUniform3iv;
    107         interface->fUniform4f = glUniform4f;
    108         interface->fUniform4i = glUniform4i;
    109         interface->fUniform4fv = glUniform4fv;
    110         interface->fUniform4iv = glUniform4iv;
    111         interface->fUniform4fv = glUniform4fv;
    112         interface->fUniformMatrix2fv = glUniformMatrix2fv;
    113         interface->fUniformMatrix3fv = glUniformMatrix3fv;
    114         interface->fUniformMatrix4fv = glUniformMatrix4fv;
    115         interface->fUseProgram = glUseProgram;
    116         interface->fVertexAttrib4fv = glVertexAttrib4fv;
    117         interface->fVertexAttribPointer = glVertexAttribPointer;
    118         interface->fViewport = glViewport;
    119         interface->fGenFramebuffers = glGenFramebuffers;
    120         interface->fGetFramebufferAttachmentParameteriv = glGetFramebufferAttachmentParameteriv;
    121         interface->fGetRenderbufferParameteriv = glGetRenderbufferParameteriv;
    122         interface->fBindFramebuffer = glBindFramebuffer;
    123         interface->fFramebufferTexture2D = glFramebufferTexture2D;
    124         interface->fCheckFramebufferStatus = glCheckFramebufferStatus;
    125         interface->fDeleteFramebuffers = glDeleteFramebuffers;
    126         interface->fRenderbufferStorage = glRenderbufferStorage;
    127         interface->fGenRenderbuffers = glGenRenderbuffers;
    128         interface->fDeleteRenderbuffers = glDeleteRenderbuffers;
    129         interface->fFramebufferRenderbuffer = glFramebufferRenderbuffer;
    130         interface->fBindRenderbuffer = glBindRenderbuffer;
    131 
    132 #if GL_OES_mapbuffer
    133         interface->fMapBuffer = glMapBufferOES;
    134         interface->fUnmapBuffer = glUnmapBufferOES;
    135 #endif
    136 
    137 #if GL_APPLE_framebuffer_multisample
    138         interface->fRenderbufferStorageMultisample = glRenderbufferStorageMultisampleAPPLE;
    139         interface->fResolveMultisampleFramebuffer = glResolveMultisampleFramebufferAPPLE;
    140 #endif
    141 
    142 #if GL_OES_vertex_array_object
    143         interface->fBindVertexArray = glBindVertexArrayOES;
    144         interface->fDeleteVertexArrays = glDeleteVertexArraysOES;
    145         interface->fGenVertexArrays = glGenVertexArraysOES;
    146 #endif
    147 
    148         interface->fBindingsExported = kES_GrGLBinding;
    149     }
    150     glInterface.get()->ref();
    151     return glInterface.get();
    152 }
    153