gfxGLEnumTranslate.cpp
Engine/source/gfx/gl/gfxGLEnumTranslate.cpp
Public Variables
GFXGLBlend [GFXBlend_COUNT]
GFXGLBlendOp [GFXBlendOp_COUNT]
GFXGLBufferType [GFXBufferType_COUNT]
GFXGLCmpFunc [GFXCmp_COUNT]
GFXGLCullMode [GFXCull_COUNT]
GFXGLFaceType [6]
GFXGLFillMode [GFXFill_COUNT]
GFXGLPrimType [GFXPT_COUNT]
GFXGLStencilOp [GFXStencilOp_COUNT]
GFXGLTextureAddress [GFXAddress_COUNT]
GFXGLTextureFilter [GFXTextureFilter_COUNT]
GFXGLTextureFormat [GFXFormat_COUNT]
GFXGLTextureInternalFormat [GFXFormat_COUNT]
GLint *
GFXGLTextureSwizzle [GFXFormat_COUNT]
GFXGLTextureType [GFXFormat_COUNT]
Detailed Description
Public Variables
GLenum GFXGLBlend [GFXBlend_COUNT]
GLenum GFXGLBlendOp [GFXBlendOp_COUNT]
GLenum GFXGLBufferType [GFXBufferType_COUNT]
GLenum GFXGLCmpFunc [GFXCmp_COUNT]
GLenum GFXGLCullMode [GFXCull_COUNT]
GLenum GFXGLFaceType [6]
GLenum GFXGLFillMode [GFXFill_COUNT]
GLenum GFXGLPrimType [GFXPT_COUNT]
GLenum GFXGLStencilOp [GFXStencilOp_COUNT]
GLenum GFXGLTextureAddress [GFXAddress_COUNT]
GLenum GFXGLTextureFilter [GFXTextureFilter_COUNT]
GLenum GFXGLTextureFormat [GFXFormat_COUNT]
GLenum GFXGLTextureInternalFormat [GFXFormat_COUNT]
GLint * GFXGLTextureSwizzle [GFXFormat_COUNT]
GLenum GFXGLTextureType [GFXFormat_COUNT]
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#include "platform/platform.h" 25#include "gfx/gl/gfxGLEnumTranslate.h" 26 27GLenum GFXGLPrimType[GFXPT_COUNT]; 28GLenum GFXGLBlend[GFXBlend_COUNT]; 29GLenum GFXGLBlendOp[GFXBlendOp_COUNT]; 30GLenum GFXGLTextureFilter[GFXTextureFilter_COUNT]; 31GLenum GFXGLTextureAddress[GFXAddress_COUNT]; 32GLenum GFXGLCmpFunc[GFXCmp_COUNT]; 33GLenum GFXGLStencilOp[GFXStencilOp_COUNT]; 34GLenum GFXGLTextureInternalFormat[GFXFormat_COUNT]; 35GLenum GFXGLTextureFormat[GFXFormat_COUNT]; 36GLenum GFXGLTextureType[GFXFormat_COUNT]; 37GLint* GFXGLTextureSwizzle[GFXFormat_COUNT]; 38GLenum GFXGLBufferType[GFXBufferType_COUNT]; 39GLenum GFXGLCullMode[GFXCull_COUNT]; 40GLenum GFXGLFillMode[GFXFill_COUNT]; 41GLenum GFXGLFaceType[6]; 42 43void GFXGLEnumTranslate::init() 44{ 45 // Buffer types 46 GFXGLBufferType[GFXBufferTypeStatic] = GL_STATIC_DRAW; 47 GFXGLBufferType[GFXBufferTypeDynamic] = GL_DYNAMIC_DRAW; 48 GFXGLBufferType[GFXBufferTypeVolatile] = GL_STREAM_DRAW; 49 GFXGLBufferType[GFXBufferTypeImmutable] = GL_STATIC_DRAW; 50 51 // Primitives 52 GFXGLPrimType[GFXPointList] = GL_POINTS; 53 GFXGLPrimType[GFXLineList] = GL_LINES; 54 GFXGLPrimType[GFXLineStrip] = GL_LINE_STRIP; 55 GFXGLPrimType[GFXTriangleList] = GL_TRIANGLES; 56 GFXGLPrimType[GFXTriangleStrip] = GL_TRIANGLE_STRIP; 57 58 // Blend 59 GFXGLBlend[GFXBlendZero] = GL_ZERO; 60 GFXGLBlend[GFXBlendOne] = GL_ONE; 61 GFXGLBlend[GFXBlendSrcColor] = GL_SRC_COLOR; 62 GFXGLBlend[GFXBlendInvSrcColor] = GL_ONE_MINUS_SRC_COLOR; 63 GFXGLBlend[GFXBlendSrcAlpha] = GL_SRC_ALPHA; 64 GFXGLBlend[GFXBlendInvSrcAlpha] = GL_ONE_MINUS_SRC_ALPHA; 65 GFXGLBlend[GFXBlendDestAlpha] = GL_DST_ALPHA; 66 GFXGLBlend[GFXBlendInvDestAlpha] = GL_ONE_MINUS_DST_ALPHA; 67 GFXGLBlend[GFXBlendDestColor] = GL_DST_COLOR; 68 GFXGLBlend[GFXBlendInvDestColor] = GL_ONE_MINUS_DST_COLOR; 69 GFXGLBlend[GFXBlendSrcAlphaSat] = GL_SRC_ALPHA_SATURATE; 70 71 // Blend op 72 GFXGLBlendOp[GFXBlendOpAdd] = GL_FUNC_ADD; 73 GFXGLBlendOp[GFXBlendOpSubtract] = GL_FUNC_SUBTRACT; 74 GFXGLBlendOp[GFXBlendOpRevSubtract] = GL_FUNC_REVERSE_SUBTRACT; 75 GFXGLBlendOp[GFXBlendOpMin] = GL_MIN; 76 GFXGLBlendOp[GFXBlendOpMax] = GL_MAX; 77 78 79 // Comparison 80 GFXGLCmpFunc[GFXCmpNever] = GL_NEVER; 81 GFXGLCmpFunc[GFXCmpLess] = GL_LESS; 82 GFXGLCmpFunc[GFXCmpEqual] = GL_EQUAL; 83 GFXGLCmpFunc[GFXCmpLessEqual] = GL_LEQUAL; 84 GFXGLCmpFunc[GFXCmpGreater] = GL_GREATER; 85 GFXGLCmpFunc[GFXCmpNotEqual] = GL_NOTEQUAL; 86 GFXGLCmpFunc[GFXCmpGreaterEqual] = GL_GEQUAL; 87 GFXGLCmpFunc[GFXCmpAlways] = GL_ALWAYS; 88 89 GFXGLTextureFilter[GFXTextureFilterNone] = GL_NEAREST; 90 GFXGLTextureFilter[GFXTextureFilterPoint] = GL_NEAREST; 91 GFXGLTextureFilter[GFXTextureFilterLinear] = GL_LINEAR; 92 GFXGLTextureFilter[GFXTextureFilterAnisotropic] = GL_LINEAR; 93 94 GFXGLTextureAddress[GFXAddressWrap] = GL_REPEAT; 95 GFXGLTextureAddress[GFXAddressMirror] = GL_REPEAT; 96 GFXGLTextureAddress[GFXAddressClamp] = GL_CLAMP_TO_EDGE; 97 GFXGLTextureAddress[GFXAddressBorder] = GL_REPEAT; 98 GFXGLTextureAddress[GFXAddressMirrorOnce] = GL_REPEAT; 99 100 // Stencil ops 101 GFXGLStencilOp[GFXStencilOpKeep] = GL_KEEP; 102 GFXGLStencilOp[GFXStencilOpZero] = GL_ZERO; 103 GFXGLStencilOp[GFXStencilOpReplace] = GL_REPLACE; 104 GFXGLStencilOp[GFXStencilOpIncrSat] = GL_INCR; 105 GFXGLStencilOp[GFXStencilOpDecrSat] = GL_DECR; 106 GFXGLStencilOp[GFXStencilOpInvert] = GL_INVERT; 107 108 GFXGLStencilOp[GFXStencilOpIncr] = GL_INCR_WRAP; 109 GFXGLStencilOp[GFXStencilOpDecr] = GL_DECR_WRAP; 110 111 // Texture formats 112 for(int i = 0; i < GFXFormat_COUNT; ++i) 113 { 114 GFXGLTextureInternalFormat[i] = GL_NONE; 115 GFXGLTextureFormat[i] = GL_NONE; 116 GFXGLTextureType[i] = GL_NONE; 117 GFXGLTextureSwizzle[i] = NULL; 118 } 119 120 GFXGLTextureInternalFormat[GFXFormatA8] = GL_R8; 121 GFXGLTextureInternalFormat[GFXFormatL8] = GL_R8; 122 GFXGLTextureInternalFormat[GFXFormatR5G5B5A1] = GL_RGB5_A1; 123 GFXGLTextureInternalFormat[GFXFormatR5G5B5X1] = GL_RGB5_A1; 124 GFXGLTextureInternalFormat[GFXFormatL16] = GL_R16; 125 GFXGLTextureInternalFormat[GFXFormatD16] = GL_DEPTH_COMPONENT16; 126 GFXGLTextureInternalFormat[GFXFormatR8G8B8] = GL_RGB8; 127 GFXGLTextureInternalFormat[GFXFormatR8G8B8A8] = GL_RGBA8; 128 GFXGLTextureInternalFormat[GFXFormatR8G8B8X8] = GL_RGBA8; 129 GFXGLTextureInternalFormat[GFXFormatB8G8R8A8] = GL_RGBA8; 130 GFXGLTextureInternalFormat[GFXFormatR10G10B10A2] = GL_RGB10_A2; 131 GFXGLTextureInternalFormat[GFXFormatR11G11B10] = GL_R11F_G11F_B10F; 132 GFXGLTextureInternalFormat[GFXFormatD32] = GL_DEPTH_COMPONENT32; 133 GFXGLTextureInternalFormat[GFXFormatD24X8] = GL_DEPTH24_STENCIL8; 134 GFXGLTextureInternalFormat[GFXFormatD24S8] = GL_DEPTH24_STENCIL8; 135 GFXGLTextureInternalFormat[GFXFormatR16G16B16A16] = GL_RGBA16; 136 GFXGLTextureInternalFormat[GFXFormatBC1] = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; 137 GFXGLTextureInternalFormat[GFXFormatBC2] = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; 138 GFXGLTextureInternalFormat[GFXFormatBC3] = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; 139 GFXGLTextureInternalFormat[GFXFormatBC4] = GL_COMPRESSED_RED_RGTC1; 140 GFXGLTextureInternalFormat[GFXFormatBC5] = GL_COMPRESSED_RG_RGTC2; 141 //sRGB 142 GFXGLTextureInternalFormat[GFXFormatR8G8B8_SRGB] = GL_SRGB8; 143 GFXGLTextureInternalFormat[GFXFormatR8G8B8A8_SRGB] = GL_SRGB8_ALPHA8; 144 GFXGLTextureInternalFormat[GFXFormatBC1_SRGB] = GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT; 145 GFXGLTextureInternalFormat[GFXFormatBC2_SRGB] = GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT; 146 GFXGLTextureInternalFormat[GFXFormatBC3_SRGB] = GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT; 147 148 GFXGLTextureFormat[GFXFormatA8] = GL_RED; 149 GFXGLTextureFormat[GFXFormatL8] = GL_RED; 150 GFXGLTextureFormat[GFXFormatR5G5B5A1] = GL_RGBA; 151 GFXGLTextureFormat[GFXFormatR5G5B5X1] = GL_RGBA; 152 GFXGLTextureFormat[GFXFormatL16] = GL_RED; 153 GFXGLTextureFormat[GFXFormatD16] = GL_DEPTH_COMPONENT; 154 GFXGLTextureFormat[GFXFormatR8G8B8] = GL_RGB; 155 GFXGLTextureFormat[GFXFormatR8G8B8A8] = GL_RGBA; 156 GFXGLTextureFormat[GFXFormatR8G8B8X8] = GL_RGBA; 157 GFXGLTextureFormat[GFXFormatB8G8R8A8] = GL_BGRA; 158 GFXGLTextureFormat[GFXFormatR10G10B10A2] = GL_RGBA; 159 GFXGLTextureFormat[GFXFormatR11G11B10] = GL_RGB; 160 GFXGLTextureFormat[GFXFormatD32] = GL_DEPTH_COMPONENT; 161 GFXGLTextureFormat[GFXFormatD24X8] = GL_DEPTH_STENCIL; 162 GFXGLTextureFormat[GFXFormatD24S8] = GL_DEPTH_STENCIL; 163 GFXGLTextureFormat[GFXFormatR16G16B16A16] = GL_RGBA; 164 GFXGLTextureFormat[GFXFormatBC1] = GL_RGBA; 165 GFXGLTextureFormat[GFXFormatBC2] = GL_RGBA; 166 GFXGLTextureFormat[GFXFormatBC3] = GL_RGBA; 167 GFXGLTextureFormat[GFXFormatBC4] = GL_RED; 168 GFXGLTextureFormat[GFXFormatBC5] = GL_RG; 169 //sRGB 170 GFXGLTextureFormat[GFXFormatR8G8B8_SRGB] = GL_RGB; 171 GFXGLTextureFormat[GFXFormatR8G8B8A8_SRGB] = GL_RGBA; 172 GFXGLTextureFormat[GFXFormatBC1_SRGB] = GL_RGBA; 173 GFXGLTextureFormat[GFXFormatBC2_SRGB] = GL_RGBA; 174 GFXGLTextureFormat[GFXFormatBC3_SRGB] = GL_RGBA; 175 176 GFXGLTextureType[GFXFormatA8] = GL_UNSIGNED_BYTE; 177 GFXGLTextureType[GFXFormatL8] = GL_UNSIGNED_BYTE; 178 GFXGLTextureType[GFXFormatR5G5B5A1] = GL_UNSIGNED_SHORT_5_5_5_1; 179 GFXGLTextureType[GFXFormatR5G5B5X1] = GL_UNSIGNED_SHORT_5_5_5_1; 180 GFXGLTextureType[GFXFormatL16] = GL_UNSIGNED_SHORT; 181 GFXGLTextureType[GFXFormatD16] = GL_UNSIGNED_SHORT; 182 GFXGLTextureType[GFXFormatR8G8B8] = GL_UNSIGNED_BYTE; 183 GFXGLTextureType[GFXFormatR8G8B8A8] = GL_UNSIGNED_BYTE; 184 GFXGLTextureType[GFXFormatR8G8B8X8] = GL_UNSIGNED_BYTE; 185 GFXGLTextureType[GFXFormatB8G8R8A8] = GL_UNSIGNED_BYTE;; 186 GFXGLTextureType[GFXFormatR10G10B10A2] = GL_UNSIGNED_INT_10_10_10_2; 187 GFXGLTextureType[GFXFormatR11G11B10] = GL_UNSIGNED_INT_10F_11F_11F_REV; 188 GFXGLTextureType[GFXFormatD32] = GL_UNSIGNED_INT; 189 GFXGLTextureType[GFXFormatD24X8] = GL_UNSIGNED_INT_24_8; 190 GFXGLTextureType[GFXFormatD24S8] = GL_UNSIGNED_INT_24_8; 191 GFXGLTextureType[GFXFormatR16G16B16A16] = GL_UNSIGNED_SHORT; 192 GFXGLTextureType[GFXFormatBC1] = GL_UNSIGNED_BYTE; 193 GFXGLTextureType[GFXFormatBC2] = GL_UNSIGNED_BYTE; 194 GFXGLTextureType[GFXFormatBC3] = GL_UNSIGNED_BYTE; 195 GFXGLTextureType[GFXFormatBC4] = GL_UNSIGNED_BYTE; 196 GFXGLTextureType[GFXFormatBC5] = GL_UNSIGNED_BYTE; 197 // sRGB 198 GFXGLTextureType[GFXFormatR8G8B8_SRGB] = GL_UNSIGNED_BYTE; 199 GFXGLTextureType[GFXFormatR8G8B8A8_SRGB] = GL_UNSIGNED_BYTE; 200 GFXGLTextureType[GFXFormatBC1_SRGB] = GL_UNSIGNED_BYTE; 201 GFXGLTextureType[GFXFormatBC2_SRGB] = GL_UNSIGNED_BYTE; 202 GFXGLTextureType[GFXFormatBC3_SRGB] = GL_UNSIGNED_BYTE; 203 204 205 static GLint Swizzle_GFXFormatA8[] = { GL_NONE, GL_NONE, GL_NONE, GL_RED }; 206 static GLint Swizzle_GFXFormatL[] = { GL_RED, GL_RED, GL_RED, GL_ALPHA }; 207 GFXGLTextureSwizzle[GFXFormatA8] = Swizzle_GFXFormatA8; // old GL_ALPHA8 208 GFXGLTextureSwizzle[GFXFormatL8] = Swizzle_GFXFormatL; // old GL_LUMINANCE8 209 GFXGLTextureSwizzle[GFXFormatL16] = Swizzle_GFXFormatL; // old GL_LUMINANCE16 210 211 GFXGLTextureInternalFormat[GFXFormatR32F] = GL_R32F; 212 GFXGLTextureFormat[GFXFormatR32F] = GL_RED; 213 GFXGLTextureType[GFXFormatR32F] = GL_FLOAT; 214 215 GFXGLTextureInternalFormat[GFXFormatR32G32B32A32F] = GL_RGBA32F_ARB; 216 GFXGLTextureFormat[GFXFormatR32G32B32A32F] = GL_RGBA; 217 GFXGLTextureType[GFXFormatR32G32B32A32F] = GL_FLOAT; 218 219 GFXGLTextureInternalFormat[GFXFormatR16F] = GL_R16F; 220 GFXGLTextureFormat[GFXFormatR16F] = GL_RED; 221 GFXGLTextureType[GFXFormatR16F] = GL_HALF_FLOAT_ARB; 222 223 GFXGLTextureInternalFormat[GFXFormatR16G16F] = GL_RG16F; 224 GFXGLTextureFormat[GFXFormatR16G16F] = GL_RG; 225 GFXGLTextureType[GFXFormatR16G16F] = GL_HALF_FLOAT_ARB; 226 227 GFXGLTextureInternalFormat[GFXFormatR16G16B16A16F] = GL_RGBA16F_ARB; 228 GFXGLTextureFormat[GFXFormatR16G16B16A16F] = GL_RGBA; 229 GFXGLTextureType[GFXFormatR16G16B16A16F] = GL_HALF_FLOAT_ARB; 230 231 if( gglHasExtension(ARB_ES2_compatibility) ) 232 { 233 GFXGLTextureInternalFormat[GFXFormatR5G6B5] = GL_RGB5_A1; 234 GFXGLTextureFormat[GFXFormatR5G6B5] = GL_RGBA; 235 GFXGLTextureType[GFXFormatR5G6B5] = GL_UNSIGNED_SHORT_5_5_5_1; 236 } 237 else 238 { 239 GFXGLTextureInternalFormat[GFXFormatR5G6B5] = GL_RGB565; 240 GFXGLTextureFormat[GFXFormatR5G6B5] = GL_RGB; 241 GFXGLTextureType[GFXFormatR5G6B5] = GL_UNSIGNED_SHORT_5_6_5; 242 } 243 244 if( gglHasExtension(ARB_texture_rg) ) 245 { 246 GFXGLTextureInternalFormat[GFXFormatR16G16] = GL_RG16; 247 GFXGLTextureFormat[GFXFormatR16G16] = GL_RG; 248 GFXGLTextureType[GFXFormatR16G16] = GL_UNSIGNED_SHORT; 249 } 250 else 251 { 252 GFXGLTextureInternalFormat[GFXFormatR16G16] = GL_RGBA16; 253 GFXGLTextureFormat[GFXFormatR16G16] = GL_RGBA; 254 GFXGLTextureType[GFXFormatR16G16] = GL_UNSIGNED_SHORT; 255 } 256 257 // Cull - Opengl render upside down need to invert cull 258 GFXGLCullMode[GFXCullNone] = GL_FRONT; 259 GFXGLCullMode[GFXCullCW] = GL_FRONT; 260 GFXGLCullMode[GFXCullCCW] = GL_BACK; 261 262 // Fill 263 GFXGLFillMode[GFXFillPoint] = GL_POINT; 264 GFXGLFillMode[GFXFillWireframe] = GL_LINE; 265 GFXGLFillMode[GFXFillSolid] = GL_FILL; 266 267 //cubemap face type 268 GFXGLFaceType[0] = GL_TEXTURE_CUBE_MAP_POSITIVE_X; 269 GFXGLFaceType[1] = GL_TEXTURE_CUBE_MAP_NEGATIVE_X; 270 GFXGLFaceType[2] = GL_TEXTURE_CUBE_MAP_POSITIVE_Y; 271 GFXGLFaceType[3] = GL_TEXTURE_CUBE_MAP_NEGATIVE_Y; 272 GFXGLFaceType[4] = GL_TEXTURE_CUBE_MAP_POSITIVE_Z; 273 GFXGLFaceType[5] = GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; 274} 275