Home | History | Annotate | Download | only in include
      1 /*
      2     Copyright 2011 Google Inc.
      3 
      4     Licensed under the Apache License, Version 2.0 (the "License");
      5     you may not use this file except in compliance with the License.
      6     You may obtain a copy of the License at
      7 
      8          http://www.apache.org/licenses/LICENSE-2.0
      9 
     10     Unless required by applicable law or agreed to in writing, software
     11     distributed under the License is distributed on an "AS IS" BASIS,
     12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13     See the License for the specific language governing permissions and
     14     limitations under the License.
     15  */
     16 
     17 
     18 #ifndef GrGLConfig_DEFINED
     19 #define GrGLConfig_DEFINED
     20 
     21 #include "GrTypes.h"
     22 #include "GrGLDefines.h"
     23 
     24 /**
     25  * Optional GL config file.
     26  */
     27 #ifdef GR_GL_CUSTOM_SETUP_HEADER
     28     #include GR_GL_CUSTOM_SETUP_HEADER
     29 #endif
     30 
     31 #if !defined(GR_GL_FUNCTION_TYPE)
     32     #define GR_GL_FUNCTION_TYPE
     33 #endif
     34 
     35 /**
     36  * The following are optional defines that can be enabled at the compiler
     37  * command line, in a IDE project, in a GrUserConfig.h file, or in a GL custom
     38  * file (if one is in use). If a GR_GL_CUSTOM_SETUP_HEADER is used they can
     39  * also be placed there.
     40  *
     41  * GR_GL_LOG_CALLS: if 1 Gr can print every GL call using GrPrintf. Defaults to
     42  * 0. Logging can be enabled and disabled at runtime using a debugger via to
     43  * global gLogCallsGL. The initial value of gLogCallsGL is controlled by
     44  * GR_GL_LOG_CALLS_START.
     45  *
     46  * GR_GL_LOG_CALLS_START: controls the initial value of gLogCallsGL when
     47  * GR_GL_LOG_CALLS is 1. Defaults to 0.
     48  *
     49  * GR_GL_CHECK_ERROR: if enabled Gr can do a glGetError() after every GL call.
     50  * Defaults to 1 if GR_DEBUG is set, otherwise 0. When GR_GL_CHECK_ERROR is 1
     51  * this can be toggled in a debugger using the gCheckErrorGL global. The initial
     52  * value of gCheckErrorGL is controlled by by GR_GL_CHECK_ERROR_START.
     53  *
     54  * GR_GL_CHECK_ERROR_START: controls the initial value of gCheckErrorGL
     55  * when GR_GL_CHECK_ERROR is 1.  Defaults to 1.
     56  *
     57  * GR_GL_NO_CONSTANT_ATTRIBUTES: if this evaluates to true then the GL backend
     58  * will use uniforms instead of attributes in all cases when there is not
     59  * per-vertex data. This is important when the underlying GL implementation
     60  * doesn't actually support immediate style attribute values (e.g. when
     61  * the GL stream is converted to DX as in ANGLE on Chrome). Defaults to 0.
     62  *
     63  * GR_GL_ATTRIBUTE_MATRICES: If changing uniforms is very expensive it may be
     64  * faster to use vertex attributes for matrices (set via glVertexAttrib3fv).
     65  * Setting this build flag enables this behavior. GR_GL_NO_CONSTANT_ATTRIBUTES
     66  * must not be set since this uses constant attributes for the matrices.
     67  * Defaults to 0.
     68  */
     69 
     70 #if !defined(GR_GL_LOG_CALLS)
     71     #define GR_GL_LOG_CALLS                 0
     72 #endif
     73 
     74 #if !defined(GR_GL_LOG_CALLS_START)
     75     #define GR_GL_LOG_CALLS_START           0
     76 #endif
     77 
     78 #if !defined(GR_GL_CHECK_ERROR)
     79     #define GR_GL_CHECK_ERROR               GR_DEBUG
     80 #endif
     81 
     82 #if !defined(GR_GL_CHECK_ERROR_START)
     83     #define GR_GL_CHECK_ERROR_START         1
     84 #endif
     85 
     86 #if !defined(GR_GL_NO_CONSTANT_ATTRIBUTES)
     87     #define GR_GL_NO_CONSTANT_ATTRIBUTES    0
     88 #endif
     89 
     90 #if !defined(GR_GL_ATTRIBUTE_MATRICES)
     91     #define GR_GL_ATTRIBUTE_MATRICES        0
     92 #endif
     93 
     94 #if(GR_GL_NO_CONSTANT_ATTRIBUTES) && (GR_GL_ATTRIBUTE_MATRICES)
     95     #error "Cannot combine GR_GL_NO_CONSTANT_ATTRIBUTES and GR_GL_ATTRIBUTE_MATRICES"
     96 #endif
     97 
     98 ////////////////////////////////////////////////////////////////////////////////
     99 
    100 /**
    101  * The following macros are used to staticlly configure the default
    102  * GrGLInterface, but should not be used outside of the GrGLInterface
    103  * scaffolding.  Undefine here to prevent accidental use.
    104  */
    105 #undef GR_SUPPORT_GLDESKTOP
    106 #undef GR_SUPPORT_GLES1
    107 #undef GR_SUPPORT_GLES2
    108 #undef GR_SUPPORT_GLES
    109 
    110 ////////////////////////////////////////////////////////////////////////////////
    111 
    112 #if GR_SCALAR_IS_FIXED
    113     #define GrGLType   GL_FIXED
    114 #elif GR_SCALAR_IS_FLOAT
    115     #define GrGLType   GR_GL_FLOAT
    116 #else
    117     #error "unknown GR_SCALAR type"
    118 #endif
    119 
    120 #if GR_TEXT_SCALAR_IS_USHORT
    121     #define GrGLTextType                    GR_GL_UNSIGNED_SHORT
    122     #define GR_GL_TEXT_TEXTURE_NORMALIZED   1
    123 #elif GR_TEXT_SCALAR_IS_FLOAT
    124     #define GrGLTextType                    GR_GL_FLOAT
    125     #define GR_GL_TEXT_TEXTURE_NORMALIZED   0
    126 #elif GR_TEXT_SCALAR_IS_FIXED
    127     #define GrGLTextType                    GR_GL_FIXED
    128     #define GR_GL_TEXT_TEXTURE_NORMALIZED   0
    129 #else
    130     #error "unknown GR_TEXT_SCALAR type"
    131 #endif
    132 
    133 // Pick a pixel config for 32bit bitmaps. Our default is GL_RGBA (except on
    134 // Windows where we match GDI's order).
    135 #ifndef GR_GL_32BPP_COLOR_FORMAT
    136     #if GR_WIN32_BUILD || GR_LINUX_BUILD
    137         #define GR_GL_32BPP_COLOR_FORMAT    GR_GL_BGRA
    138     #else
    139         #define GR_GL_32BPP_COLOR_FORMAT    GR_GL_RGBA
    140     #endif
    141 #endif
    142 
    143 ////////////////////////////////////////////////////////////////////////////////
    144 
    145 extern void GrGLCheckErr(const char* location, const char* call);
    146 
    147 extern void GrGLClearErr();
    148 
    149 #if GR_GL_CHECK_ERROR
    150     extern bool gCheckErrorGL;
    151     #define GR_GL_CHECK_ERROR_IMPL(X) if (gCheckErrorGL) GrGLCheckErr(GR_FILE_AND_LINE_STR, #X)
    152 #else
    153     #define GR_GL_CHECK_ERROR_IMPL(X)
    154 #endif
    155 
    156 #if GR_GL_LOG_CALLS
    157     extern bool gLogCallsGL;
    158     #define GR_GL_LOG_CALLS_IMPL(X) if (gLogCallsGL) GrPrintf(GR_FILE_AND_LINE_STR "GL: " #X "\n")
    159 #else
    160     #define GR_GL_LOG_CALLS_IMPL(X)
    161 #endif
    162 
    163 #define GR_GL(X)                 GrGLGetGLInterface()->f##X;; GR_GL_LOG_CALLS_IMPL(X); GR_GL_CHECK_ERROR_IMPL(X);
    164 #define GR_GL_NO_ERR(X)          GrGLGetGLInterface()->f##X;; GR_GL_LOG_CALLS_IMPL(X);
    165 
    166 #define GR_GL_SUPPORT_DESKTOP   (kDesktop_GrGLBinding == GrGLGetGLInterface()->fBindingsExported)
    167 #define GR_GL_SUPPORT_ES1       (kES1_GrGLBinding == GrGLGetGLInterface()->fBindingsExported)
    168 #define GR_GL_SUPPORT_ES2       (kES2_GrGLBinding == GrGLGetGLInterface()->fBindingsExported)
    169 #define GR_GL_SUPPORT_ES        (GR_GL_SUPPORT_ES1 || GR_GL_SUPPORT_ES2)
    170 
    171 ////////////////////////////////////////////////////////////////////////////////
    172 
    173 /**
    174  *  GrGLRestoreResetRowLength() will reset GL_UNPACK_ROW_LENGTH to 0. We write
    175  *  this wrapper, since GL_UNPACK_ROW_LENGTH is not available on all GL versions
    176  */
    177 extern void GrGLRestoreResetRowLength();
    178 
    179 ////////////////////////////////////////////////////////////////////////////////
    180 
    181 /**
    182  *  Some drivers want the var-int arg to be zero-initialized on input.
    183  */
    184 #define GR_GL_INIT_ZERO     0
    185 #define GR_GL_GetIntegerv(e, p)     \
    186     do {                            \
    187         *(p) = GR_GL_INIT_ZERO;     \
    188         GR_GL(GetIntegerv(e, p));   \
    189     } while (0)
    190 
    191 ////////////////////////////////////////////////////////////////////////////////
    192 
    193 #endif
    194