1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com 2bd3e3202ad5111a8a259e976594d7e6864e3b6d2yangsu@google.com/* 3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2011 Google Inc. 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 7bd3e3202ad5111a8a259e976594d7e6864e3b6d2yangsu@google.com */ 8bd3e3202ad5111a8a259e976594d7e6864e3b6d2yangsu@google.com 96c8c34e65ff8248ec7374e0d662d7f5684d800fatomhudson@google.com#include "gl/GrGLInterface.h" 10bd3e3202ad5111a8a259e976594d7e6864e3b6d2yangsu@google.com 11bd3e3202ad5111a8a259e976594d7e6864e3b6d2yangsu@google.com#import <OpenGLES/ES2/gl.h> 12bd3e3202ad5111a8a259e976594d7e6864e3b6d2yangsu@google.com#import <OpenGLES/ES2/glext.h> 13bd3e3202ad5111a8a259e976594d7e6864e3b6d2yangsu@google.com 14cca3c8f21b80f515a236a4b0d1e1f0b6418fcc97bsalomon@google.comconst GrGLInterface* GrGLCreateNativeInterface() { 15a3b15ed0373b873d4c497b51384b8c07d751753acommit-bot@chromium.org GrGLInterface* interface = SkNEW(GrGLInterface); 160b77d6892b067ad402c9678b0226bff70599fbe2bsalomon@google.com 17bfadab42c6302a4e1060b875ac510599160c9df5bsalomon@google.com GrGLInterface::Functions* functions = &interface->fFunctions; 18304eb1c3ef88145ef3e2d37adafa35e708a792ebbsalomon@google.com 19c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fActiveTexture = glActiveTexture; 20c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fAttachShader = glAttachShader; 21c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fBindAttribLocation = glBindAttribLocation; 22c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fBindBuffer = glBindBuffer; 23c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fBindTexture = glBindTexture; 24c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fBlendColor = glBlendColor; 25c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fBlendFunc = glBlendFunc; 26c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fBufferData = (GrGLBufferDataProc)glBufferData; 27c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fBufferSubData = (GrGLBufferSubDataProc)glBufferSubData; 28c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fClear = glClear; 29c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fClearColor = glClearColor; 30c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fClearStencil = glClearStencil; 31c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fColorMask = glColorMask; 32c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fCompileShader = glCompileShader; 33c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fCompressedTexImage2D = glCompressedTexImage2D; 3437d20f75320e8182f4cdbce5f3d59a339f915e05krajcevski functions->fCompressedTexSubImage2D = glCompressedTexSubImage2D; 35c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fCopyTexSubImage2D = glCopyTexSubImage2D; 36c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fCreateProgram = glCreateProgram; 37c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fCreateShader = glCreateShader; 38c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fCullFace = glCullFace; 39c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fDeleteBuffers = glDeleteBuffers; 40c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fDeleteProgram = glDeleteProgram; 41c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fDeleteShader = glDeleteShader; 42c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fDeleteTextures = glDeleteTextures; 43c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fDepthMask = glDepthMask; 44c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fDisable = glDisable; 45c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fDisableVertexAttribArray = glDisableVertexAttribArray; 46c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fDrawArrays = glDrawArrays; 47c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fDrawBuffer = NULL; 48c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fDrawBuffers = NULL; 49c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fDrawElements = glDrawElements; 50c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fEnable = glEnable; 51c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fEnableVertexAttribArray = glEnableVertexAttribArray; 52c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fFinish = glFinish; 53c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fFlush = glFlush; 54c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fFrontFace = glFrontFace; 55c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fGenBuffers = glGenBuffers; 56c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fGenerateMipmap = glGenerateMipmap; 57c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fGetBufferParameteriv = glGetBufferParameteriv; 58c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fGetError = glGetError; 59c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fGetIntegerv = glGetIntegerv; 60c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fGetProgramInfoLog = glGetProgramInfoLog; 61c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fGetProgramiv = glGetProgramiv; 62c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fGetShaderInfoLog = glGetShaderInfoLog; 63c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fGetShaderiv = glGetShaderiv; 64c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fGetString = glGetString; 65c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fGenTextures = glGenTextures; 66c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fGetUniformLocation = glGetUniformLocation; 67c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fLineWidth = glLineWidth; 68c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fLinkProgram = glLinkProgram; 69c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fPixelStorei = glPixelStorei; 70c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fReadBuffer = NULL; 71c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fReadPixels = glReadPixels; 72c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fScissor = glScissor; 73ae0054e48ac65caf0e808e254dfdff6ac945fa2ecommit-bot@chromium.org functions->fShaderSource = (GrGLShaderSourceProc) glShaderSource; 74c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fStencilFunc = glStencilFunc; 75c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fStencilFuncSeparate = glStencilFuncSeparate; 76c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fStencilMask = glStencilMask; 77c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fStencilMaskSeparate = glStencilMaskSeparate; 78c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fStencilOp = glStencilOp; 79c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fStencilOpSeparate = glStencilOpSeparate; 80a3b15ed0373b873d4c497b51384b8c07d751753acommit-bot@chromium.org // mac uses GLenum for internalFormat param (non-standard) 81a3b15ed0373b873d4c497b51384b8c07d751753acommit-bot@chromium.org // amounts to int vs. uint. 82c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fTexImage2D = (GrGLTexImage2DProc)glTexImage2D; 83ecd84842b3f65918eb040c53391172b6413fd7adbsalomon@google.com#if GL_ARB_texture_storage 84c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fTexStorage2D = glTexStorage2D; 85ecd84842b3f65918eb040c53391172b6413fd7adbsalomon@google.com#elif GL_EXT_texture_storage 86c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fTexStorage2D = glTexStorage2DEXT; 87ecd84842b3f65918eb040c53391172b6413fd7adbsalomon@google.com#endif 88a6ffb58b109f71512bde4e14d06a655914578c8drobertphillips@google.com#if GL_EXT_discard_framebuffer 89c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fDiscardFramebuffer = glDiscardFramebufferEXT; 90a6ffb58b109f71512bde4e14d06a655914578c8drobertphillips@google.com#endif 91c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fTexParameteri = glTexParameteri; 92c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fTexParameteriv = glTexParameteriv; 93c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fTexSubImage2D = glTexSubImage2D; 94c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fUniform1f = glUniform1f; 95c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fUniform1i = glUniform1i; 96c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fUniform1fv = glUniform1fv; 97c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fUniform1iv = glUniform1iv; 98c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fUniform2f = glUniform2f; 99c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fUniform2i = glUniform2i; 100c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fUniform2fv = glUniform2fv; 101c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fUniform2iv = glUniform2iv; 102c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fUniform3f = glUniform3f; 103c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fUniform3i = glUniform3i; 104c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fUniform3fv = glUniform3fv; 105c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fUniform3iv = glUniform3iv; 106c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fUniform4f = glUniform4f; 107c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fUniform4i = glUniform4i; 108c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fUniform4fv = glUniform4fv; 109c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fUniform4iv = glUniform4iv; 110c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fUniform4fv = glUniform4fv; 111c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fUniformMatrix2fv = glUniformMatrix2fv; 112c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fUniformMatrix3fv = glUniformMatrix3fv; 113c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fUniformMatrix4fv = glUniformMatrix4fv; 114c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fUseProgram = glUseProgram; 115c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fVertexAttrib4fv = glVertexAttrib4fv; 116c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fVertexAttribPointer = glVertexAttribPointer; 117c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fViewport = glViewport; 118c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fGenFramebuffers = glGenFramebuffers; 119c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fGetFramebufferAttachmentParameteriv = glGetFramebufferAttachmentParameteriv; 120c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fGetRenderbufferParameteriv = glGetRenderbufferParameteriv; 121c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fBindFramebuffer = glBindFramebuffer; 122c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fFramebufferTexture2D = glFramebufferTexture2D; 123c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fCheckFramebufferStatus = glCheckFramebufferStatus; 124c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fDeleteFramebuffers = glDeleteFramebuffers; 125c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fRenderbufferStorage = glRenderbufferStorage; 126c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fGenRenderbuffers = glGenRenderbuffers; 127c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fDeleteRenderbuffers = glDeleteRenderbuffers; 128c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fFramebufferRenderbuffer = glFramebufferRenderbuffer; 129c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fBindRenderbuffer = glBindRenderbuffer; 130d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 131ecd84842b3f65918eb040c53391172b6413fd7adbsalomon@google.com#if GL_OES_mapbuffer 132c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fMapBuffer = glMapBufferOES; 133c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fUnmapBuffer = glUnmapBufferOES; 134ecd84842b3f65918eb040c53391172b6413fd7adbsalomon@google.com#endif 135d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 136160b478eed1dd4924a86a87fd60c91139e08ff71commit-bot@chromium.org#if GL_EXT_map_buffer_range || GL_ES_VERSION_3_0 137160b478eed1dd4924a86a87fd60c91139e08ff71commit-bot@chromium.org functions->fMapBufferRange = glMapBufferRangeEXT; 138160b478eed1dd4924a86a87fd60c91139e08ff71commit-bot@chromium.org functions->fFlushMappedBufferRange = glFlushMappedBufferRangeEXT; 139160b478eed1dd4924a86a87fd60c91139e08ff71commit-bot@chromium.org#endif 140160b478eed1dd4924a86a87fd60c91139e08ff71commit-bot@chromium.org 141ecd84842b3f65918eb040c53391172b6413fd7adbsalomon@google.com#if GL_APPLE_framebuffer_multisample 14266c9582d1bed717d72c9d3f789f761cb08e28264jvanverth functions->fRenderbufferStorageMultisampleES2APPLE = glRenderbufferStorageMultisampleAPPLE; 143c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fResolveMultisampleFramebuffer = glResolveMultisampleFramebufferAPPLE; 144ecd84842b3f65918eb040c53391172b6413fd7adbsalomon@google.com#endif 145ecd84842b3f65918eb040c53391172b6413fd7adbsalomon@google.com 146ecd84842b3f65918eb040c53391172b6413fd7adbsalomon@google.com#if GL_OES_vertex_array_object 147c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fBindVertexArray = glBindVertexArrayOES; 148c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fDeleteVertexArrays = glDeleteVertexArraysOES; 149c72425ae368bfcb47de7d2532eb90d305ec0d1cfcommit-bot@chromium.org functions->fGenVertexArrays = glGenVertexArraysOES; 150ecd84842b3f65918eb040c53391172b6413fd7adbsalomon@google.com#endif 151d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 152a3baf3be0e2a3128fb73bd41d40d130f75a4dc86commit-bot@chromium.org#if GL_EXT_debug_marker 153a3baf3be0e2a3128fb73bd41d40d130f75a4dc86commit-bot@chromium.org functions->fInsertEventMarker = glInsertEventMarkerEXT; 154a3baf3be0e2a3128fb73bd41d40d130f75a4dc86commit-bot@chromium.org functions->fPushGroupMarker = glPushGroupMarkerEXT; 155283ce52572d1d9b4ee800e4f354000d89bcac47fcommit-bot@chromium.org functions->fPopGroupMarker = glPopGroupMarkerEXT; 156a3baf3be0e2a3128fb73bd41d40d130f75a4dc86commit-bot@chromium.org#endif 157a3baf3be0e2a3128fb73bd41d40d130f75a4dc86commit-bot@chromium.org 158a34bb60c4e319f2289106d519544fe09d43eabd5bsalomon@google.com#if GL_ES_VERSION_3_0 || GL_ARB_invalidate_subdata 159a34bb60c4e319f2289106d519544fe09d43eabd5bsalomon@google.com functions->fInvalidateFramebuffer = glInvalidateFramebuffer; 160a34bb60c4e319f2289106d519544fe09d43eabd5bsalomon@google.com functions->fInvalidateSubFramebuffer = glInvalidateSubFramebuffer; 161a34bb60c4e319f2289106d519544fe09d43eabd5bsalomon@google.com#endif 162a34bb60c4e319f2289106d519544fe09d43eabd5bsalomon@google.com 163a34bb60c4e319f2289106d519544fe09d43eabd5bsalomon@google.com#if GL_ARB_invalidate_subdata 164a34bb60c4e319f2289106d519544fe09d43eabd5bsalomon@google.com functions->fInvalidateBufferData = glInvalidateBufferData; 165a34bb60c4e319f2289106d519544fe09d43eabd5bsalomon@google.com functions->fInvalidateBufferSubData = glInvalidateBufferSubData; 166a34bb60c4e319f2289106d519544fe09d43eabd5bsalomon@google.com functions->fInvalidateTexImage = glInvalidateTexImage; 167a34bb60c4e319f2289106d519544fe09d43eabd5bsalomon@google.com functions->fInvalidateTexSubImage = glInvalidateTexSubImage; 168a34bb60c4e319f2289106d519544fe09d43eabd5bsalomon@google.com#endif 169a34bb60c4e319f2289106d519544fe09d43eabd5bsalomon@google.com 1709e90aed5de82732cc9921f01388d3063a41a053bcommit-bot@chromium.org interface->fStandard = kGLES_GrGLStandard; 17190313cc36a6f43a3e9d3818aca536cd6631c222bcommit-bot@chromium.org interface->fExtensions.init(kGLES_GrGLStandard, glGetString, NULL, glGetIntegerv); 172304eb1c3ef88145ef3e2d37adafa35e708a792ebbsalomon@google.com 173a3b15ed0373b873d4c497b51384b8c07d751753acommit-bot@chromium.org return interface; 1746fb736fc2ea5f3f7ac44494211cc6755180ca192bsalomon@google.com} 175