bgfx/src/renderer_gl.h

831 lines
20 KiB
C
Raw Normal View History

2012-07-08 22:10:07 -04:00
/*
2014-02-11 01:07:04 -05:00
* Copyright 2011-2014 Branimir Karadzic. All rights reserved.
2012-07-08 22:10:07 -04:00
* License: http://www.opensource.org/licenses/BSD-2-Clause
*/
#ifndef BGFX_RENDERER_GL_H_HEADER_GUARD
#define BGFX_RENDERER_GL_H_HEADER_GUARD
2012-07-08 22:10:07 -04:00
#define BGFX_USE_EGL (BGFX_CONFIG_RENDERER_OPENGLES && (BX_PLATFORM_ANDROID || BX_PLATFORM_EMSCRIPTEN || BX_PLATFORM_QNX || BX_PLATFORM_WINDOWS) )
#define BGFX_USE_WGL (BGFX_CONFIG_RENDERER_OPENGL && BX_PLATFORM_WINDOWS)
2014-02-19 23:08:22 -05:00
#define BGFX_USE_GL_DYNAMIC_LIB (BX_PLATFORM_LINUX || BX_PLATFORM_OSX || BX_PLATFORM_WINDOWS)
2012-07-08 22:10:07 -04:00
#if BGFX_CONFIG_RENDERER_OPENGL
2013-03-06 00:37:31 -05:00
# if BGFX_CONFIG_RENDERER_OPENGL >= 31
# include <gl/glcorearb.h>
2013-12-21 00:43:07 -05:00
# if BX_PLATFORM_OSX
# define GL_ARB_shader_objects // OSX collsion with GLhandleARB in gltypes.h
# endif // BX_PLATFORM_OSX
2012-07-08 22:10:07 -04:00
# else
2013-03-06 00:37:31 -05:00
# if BX_PLATFORM_LINUX
# define GL_PROTOTYPES
# define GL_GLEXT_LEGACY
# include <GL/gl.h>
# undef GL_PROTOTYPES
# elif BX_PLATFORM_OSX
# define GL_GLEXT_LEGACY
# define long ptrdiff_t
# include <OpenGL/gl.h>
# undef long
# undef GL_VERSION_1_2
# undef GL_VERSION_1_3
# undef GL_VERSION_1_4
# undef GL_VERSION_1_5
# undef GL_VERSION_2_0
# else
# include <GL/gl.h>
# endif // BX_PLATFORM_
2012-07-08 22:10:07 -04:00
2013-03-06 00:37:31 -05:00
# include <gl/glext.h>
# endif // BGFX_CONFIG_RENDERER_OPENGL >= 31
#elif BGFX_CONFIG_RENDERER_OPENGLES
2014-02-20 00:22:22 -05:00
typedef double GLdouble;
# if BGFX_CONFIG_RENDERER_OPENGLES < 30
2013-07-21 17:44:53 -04:00
# if BX_PLATFORM_IOS
# include <OpenGLES/ES2/gl.h>
# include <OpenGLES/ES2/glext.h>
//#define GL_UNSIGNED_INT_10_10_10_2_OES 0x8DF6
#define GL_UNSIGNED_INT_2_10_10_10_REV_EXT 0x8368
#define GL_TEXTURE_3D_OES 0x806F
2013-07-21 17:44:53 -04:00
#define GL_SAMPLER_3D_OES 0x8B5F
#define GL_TEXTURE_WRAP_R_OES 0x8072
2013-07-21 17:44:53 -04:00
#define GL_PROGRAM_BINARY_LENGTH_OES 0x8741
# else
# include <GLES2/gl2platform.h>
# include <GLES2/gl2.h>
# include <GLES2/gl2ext.h>
# endif // BX_PLATFORM_
2014-02-19 23:08:22 -05:00
typedef int64_t GLint64;
typedef uint64_t GLuint64;
2013-01-13 21:39:25 -05:00
# define GL_PROGRAM_BINARY_LENGTH GL_PROGRAM_BINARY_LENGTH_OES
# define GL_HALF_FLOAT GL_HALF_FLOAT_OES
2014-02-20 02:49:28 -05:00
# define GL_RGBA8 GL_RGBA8_OES
2013-01-13 21:39:25 -05:00
# define GL_UNSIGNED_INT_2_10_10_10_REV GL_UNSIGNED_INT_2_10_10_10_REV_EXT
# define GL_TEXTURE_3D GL_TEXTURE_3D_OES
2013-01-13 21:39:25 -05:00
# define GL_SAMPLER_3D GL_SAMPLER_3D_OES
# define GL_TEXTURE_WRAP_R GL_TEXTURE_WRAP_R_OES
2013-06-18 01:11:45 -04:00
# define GL_MIN GL_MIN_EXT
# define GL_MAX GL_MAX_EXT
# define GL_DEPTH_COMPONENT24 GL_DEPTH_COMPONENT24_OES
# define GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8_OES
# define GL_DEPTH_COMPONENT32 GL_DEPTH_COMPONENT32_OES
# define GL_UNSIGNED_INT_24_8 GL_UNSIGNED_INT_24_8_OES
# elif BGFX_CONFIG_RENDERER_OPENGLES >= 30
2012-10-14 01:21:02 -04:00
# include <GLES3/gl3platform.h>
# include <GLES3/gl3.h>
# include <GLES3/gl3ext.h>
# endif // BGFX_CONFIG_RENDERER_
2012-07-08 22:10:07 -04:00
# if BGFX_USE_EGL
2013-01-13 21:39:25 -05:00
# include "glcontext_egl.h"
# endif // BGFX_USE_EGL
2012-07-08 22:10:07 -04:00
2012-10-22 22:39:59 -04:00
# if BX_PLATFORM_EMSCRIPTEN
# include <emscripten/emscripten.h>
# endif // BX_PLATFORM_EMSCRIPTEN
2013-03-06 00:37:31 -05:00
#endif // BGFX_CONFIG_RENDERER_OPENGL
#ifndef GL_LUMINANCE
# define GL_LUMINANCE 0x1909
#endif // GL_LUMINANCE
2013-03-06 00:37:31 -05:00
2014-04-02 01:31:02 -04:00
#ifndef GL_BGRA
# define GL_BGRA 0x80E1
#endif // GL_BGRA
2012-10-14 01:21:02 -04:00
2014-03-29 20:22:24 -04:00
#ifndef GL_R8
# define GL_R8 0x8229
#endif // GL_R8
#ifndef GL_R16
# define GL_R16 0x822A
#endif // GL_R16
2014-04-02 01:31:02 -04:00
#ifndef GL_R16F
# define GL_R16F 0x822D
#endif // GL_R16F
2013-04-16 02:10:32 -04:00
2014-04-02 01:31:02 -04:00
#ifndef GL_R32F
# define GL_R32F 0x822E
#endif // GL_R32F
2014-04-01 01:41:56 -04:00
#ifndef GL_RED
# define GL_RED 0x1903
#endif // GL_RED
2014-04-07 00:31:28 -04:00
#ifndef GL_RED_INTEGER
# define GL_RED_INTEGER 0x8D94
#endif // GL_RED_INTEGER
2014-04-01 01:41:56 -04:00
#ifndef GL_GREEN
# define GL_GREEN 0x1904
#endif // GL_GREEN
#ifndef GL_BLUE
# define GL_BLUE 0x1905
#endif // GL_BLUE
2014-04-07 00:31:28 -04:00
#ifndef GL_RGBA_INTEGER
# define GL_RGBA_INTEGER 0x8D99
#endif // GL_RGBA_INTEGER
2014-04-02 01:31:02 -04:00
#ifndef GL_RGB10_A2
# define GL_RGB10_A2 0x8059
#endif // GL_RGB10_A2
2013-04-16 02:10:32 -04:00
#ifndef GL_RGBA16
# define GL_RGBA16 0x805B
#endif // GL_RGBA16
#ifndef GL_RGBA16F
# define GL_RGBA16F 0x881A
#endif // GL_RGBA16F
2014-04-07 00:31:28 -04:00
#ifndef GL_R16UI
# define GL_R16UI 0x8234
#endif // GL_R16UI
#ifndef GL_RGBA16UI
# define GL_RGBA16UI 0x8D76
#endif // GL_RGBA16UI
2014-01-12 16:51:26 -05:00
#ifndef GL_COMPRESSED_RGB_S3TC_DXT1_EXT
# define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0
#endif // GL_COMPRESSED_RGB_S3TC_DXT1_EXT
#ifndef GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
# define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1
#endif // GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
2012-10-14 01:21:02 -04:00
#ifndef GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
# define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2
#endif // GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
2012-07-08 22:10:07 -04:00
#ifndef GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
# define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3
#endif // GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
2012-07-08 22:10:07 -04:00
#ifndef GL_COMPRESSED_LUMINANCE_LATC1_EXT
# define GL_COMPRESSED_LUMINANCE_LATC1_EXT 0x8C70
#endif // GL_COMPRESSED_LUMINANCE_LATC1_EXT
#ifndef GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
# define GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT 0x8C72
#endif // GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
#ifndef GL_COMPRESSED_RED_RGTC1
# define GL_COMPRESSED_RED_RGTC1 0x8DBB
#endif // GL_COMPRESSED_RED_RGTC1
2013-01-22 23:34:08 -05:00
#ifndef GL_COMPRESSED_RG_RGTC2
# define GL_COMPRESSED_RG_RGTC2 0x8DBD
#endif // GL_COMPRESSED_RG_RGTC2
2013-01-22 23:34:08 -05:00
#ifndef GL_ETC1_RGB8_OES
# define GL_ETC1_RGB8_OES 0x8D64
#endif // GL_ETC1_RGB8_OES
#ifndef GL_COMPRESSED_RGB8_ETC2
# define GL_COMPRESSED_RGB8_ETC2 0x9274
#endif // GL_COMPRESSED_RGB8_ETC2
2013-09-05 00:42:31 -04:00
#ifndef GL_COMPRESSED_RGBA8_ETC2_EAC
# define GL_COMPRESSED_RGBA8_ETC2_EAC 0x9278
#endif // GL_COMPRESSED_RGBA8_ETC2_EAC
2013-09-05 00:42:31 -04:00
#ifndef GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
# define GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x9276
#endif // GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
2013-09-05 00:42:31 -04:00
#ifndef GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG
# define GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG 0x8C01
#endif // GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG
2013-09-03 23:13:07 -04:00
#ifndef GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG
# define GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG 0x8C03
#endif // GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG
2013-09-03 23:13:07 -04:00
#ifndef GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG
# define GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG 0x8C00
#endif // GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG
2013-09-03 23:13:07 -04:00
#ifndef GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG
# define GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG 0x8C02
#endif // GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG
2013-09-03 23:13:07 -04:00
#ifndef GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG
# define GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG 0x9137
#endif // GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG
2013-09-05 00:42:31 -04:00
#ifndef GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG
# define GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG 0x9138
#endif // GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG
2013-09-05 00:42:31 -04:00
#ifndef GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE
# define GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE 0x93A0
#endif // GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE
2012-07-08 22:10:07 -04:00
#ifndef GL_TEXTURE_MAX_ANISOTROPY_EXT
# define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
#endif // GL_TEXTURE_MAX_ANISOTROPY_EXT
2012-12-09 22:20:32 -05:00
#ifndef GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT
# define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
#endif // GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT
2012-12-09 22:20:32 -05:00
2014-04-01 01:41:56 -04:00
#ifndef GL_TEXTURE_SWIZZLE_RGBA
# define GL_TEXTURE_SWIZZLE_RGBA 0x8E46
#endif // GL_TEXTURE_SWIZZLE_RGBA
2014-02-20 02:49:28 -05:00
#ifndef GL_MAX_SAMPLES
# define GL_MAX_SAMPLES 0x8D57
#endif // GL_MAX_SAMPLES
2014-02-21 02:03:31 -05:00
#ifndef GL_MAX_COLOR_ATTACHMENTS
# define GL_MAX_COLOR_ATTACHMENTS 0x8CDF
#endif // GL_MAX_COLOR_ATTACHMENTS
#ifndef GL_QUERY_RESULT
# define GL_QUERY_RESULT 0x8866
#endif // GL_QUERY_RESULT
2014-02-20 02:49:28 -05:00
#ifndef GL_READ_FRAMEBUFFER
# define GL_READ_FRAMEBUFFER 0x8CA8
#endif /// GL_READ_FRAMEBUFFER
#ifndef GL_DRAW_FRAMEBUFFER
# define GL_DRAW_FRAMEBUFFER 0x8CA9
#endif // GL_DRAW_FRAMEBUFFER
2014-02-21 02:03:31 -05:00
#ifndef GL_TIME_ELAPSED
# define GL_TIME_ELAPSED 0x88BF
#endif // GL_TIME_ELAPSED
#ifndef GL_VBO_FREE_MEMORY_ATI
# define GL_VBO_FREE_MEMORY_ATI 0x87FB
#endif // GL_VBO_FREE_MEMORY_ATI
2012-07-08 22:10:07 -04:00
#ifndef GL_TEXTURE_FREE_MEMORY_ATI
# define GL_TEXTURE_FREE_MEMORY_ATI 0x87FC
#endif // GL_TEXTURE_FREE_MEMORY_ATI
2013-03-06 00:37:31 -05:00
#ifndef GL_RENDERBUFFER_FREE_MEMORY_ATI
# define GL_RENDERBUFFER_FREE_MEMORY_ATI 0x87FD
#endif // GL_RENDERBUFFER_FREE_MEMORY_ATI
2013-03-06 00:37:31 -05:00
// http://developer.download.nvidia.com/opengl/specs/GL_NVX_gpu_memory_info.txt
#ifndef GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX
# define GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX 0x9047
#endif // GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX
2013-03-06 00:37:31 -05:00
#ifndef GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX
# define GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX 0x9048
#endif // GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX
2013-03-06 00:37:31 -05:00
#ifndef GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX
# define GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX 0x9049
#endif // GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX
2013-03-06 00:37:31 -05:00
#ifndef GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX
# define GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX 0x904A
#endif // GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX
2013-03-06 00:37:31 -05:00
#ifndef GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX
# define GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX 0x904B
#endif // GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX
#ifndef GL_UNPACK_ROW_LENGTH
# define GL_UNPACK_ROW_LENGTH 0x0CF2
#endif // GL_UNPACK_ROW_LENGTH
2012-07-08 22:10:07 -04:00
2014-01-12 16:51:26 -05:00
#ifndef GL_DEPTH_STENCIL
# define GL_DEPTH_STENCIL 0x84F9
#endif // GL_DEPTH_STENCIL
#ifndef GL_DEPTH_COMPONENT32
# define GL_DEPTH_COMPONENT32 0x81A7
#endif // GL_DEPTH_COMPONENT32
2013-02-03 15:23:48 -05:00
#ifndef GL_DEPTH_COMPONENT32F
# define GL_DEPTH_COMPONENT32F 0x8CAC
#endif // GL_DEPTH_COMPONENT32F
#ifndef GL_DEPTH_STENCIL_ATTACHMENT
# define GL_DEPTH_STENCIL_ATTACHMENT 0x821A
#endif // GL_DEPTH_STENCIL_ATTACHMENT
2013-02-03 15:23:48 -05:00
#ifndef GL_TEXTURE_COMPARE_MODE
# define GL_TEXTURE_COMPARE_MODE 0x884C
#endif // GL_TEXTURE_COMPARE_MODE
#ifndef GL_TEXTURE_COMPARE_FUNC
# define GL_TEXTURE_COMPARE_FUNC 0x884D
#endif // GL_TEXTURE_COMPARE_FUNC
#ifndef GL_COMPARE_REF_TO_TEXTURE
# define GL_COMPARE_REF_TO_TEXTURE 0x884E
#endif // GL_COMPARE_REF_TO_TEXTURE
#ifndef GL_SAMPLER_2D_SHADOW
# define GL_SAMPLER_2D_SHADOW 0x8B62
#endif // GL_SAMPLER_2D_SHADOW
2014-03-10 00:20:34 -04:00
#ifndef GL_TEXTURE_MAX_LEVEL
# define GL_TEXTURE_MAX_LEVEL 0x813D
#endif // GL_TEXTURE_MAX_LEVEL
2014-05-11 15:48:11 -04:00
#ifndef GL_COMPUTE_SHADER
# define GL_COMPUTE_SHADER 0x91B9
#endif // GL_COMPUTE_SHADER
2014-07-20 23:27:13 -04:00
#ifndef GL_READ_ONLY
# define GL_READ_ONLY 0x88B8
#endif // GL_READ_ONLY
#ifndef GL_WRITE_ONLY
# define GL_WRITE_ONLY 0x88B9
#endif // GL_WRITE_ONLY
#ifndef GL_READ_WRITE
# define GL_READ_WRITE 0x88BA
#endif // GL_READ_WRITE
#ifndef GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT
# define GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT 0x00000001
#endif // GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT
#ifndef GL_ELEMENT_ARRAY_BARRIER_BIT
# define GL_ELEMENT_ARRAY_BARRIER_BIT 0x00000002
#endif // GL_ELEMENT_ARRAY_BARRIER_BIT
#ifndef GL_SHADER_IMAGE_ACCESS_BARRIER_BIT
# define GL_SHADER_IMAGE_ACCESS_BARRIER_BIT 0x00000020
#endif // GL_SHADER_IMAGE_ACCESS_BARRIER_BIT
#ifndef GL_SHADER_STORAGE_BARRIER_BIT
# define GL_SHADER_STORAGE_BARRIER_BIT 0x00002000
#endif // GL_SHADER_STORAGE_BARRIER_BIT
#ifndef GL_SHADER_STORAGE_BUFFER
# define GL_SHADER_STORAGE_BUFFER 0x90D2
#endif // GL_SHADER_STORAGE_BUFFER
#ifndef GL_IMAGE_1D
# define GL_IMAGE_1D 0x904C
#endif // GL_IMAGE_1D
#ifndef GL_IMAGE_2D
# define GL_IMAGE_2D 0x904D
#endif // GL_IMAGE_2D
#ifndef GL_IMAGE_3D
# define GL_IMAGE_3D 0x904E
#endif // GL_IMAGE_3D
#ifndef GL_IMAGE_CUBE
# define GL_IMAGE_CUBE 0x9050
#endif // GL_IMAGE_CUBE
#ifndef GL_PROGRAM_INPUT
# define GL_PROGRAM_INPUT 0x92E3
#endif // GL_PROGRAM_INPUT
#ifndef GL_ACTIVE_RESOURCES
# define GL_ACTIVE_RESOURCES 0x92F5
#endif // GL_ACTIVE_RESOURCES
#ifndef GL_UNIFORM
# define GL_UNIFORM 0x92E1
#endif // GL_UNIFORM
#ifndef GL_BUFFER_VARIABLE
# define GL_BUFFER_VARIABLE 0x92E5
#endif // GL_BUFFER_VARIABLE
#ifndef GL_UNSIGNED_INT_VEC2
# define GL_UNSIGNED_INT_VEC2 0x8DC6
#endif // GL_UNSIGNED_INT_VEC2
#ifndef GL_UNSIGNED_INT_VEC3
# define GL_UNSIGNED_INT_VEC3 0x8DC7
#endif // GL_UNSIGNED_INT_VEC3
#ifndef GL_UNSIGNED_INT_VEC4
# define GL_UNSIGNED_INT_VEC4 0x8DC8
#endif // GL_UNSIGNED_INT_VEC4
#ifndef GL_TYPE
# define GL_TYPE 0x92FA
#endif // GL_TYPE
2012-07-08 22:10:07 -04:00
#if BX_PLATFORM_NACL
2013-01-13 21:39:25 -05:00
# include "glcontext_ppapi.h"
2012-07-08 22:10:07 -04:00
#elif BX_PLATFORM_WINDOWS
# include <windows.h>
#elif BX_PLATFORM_LINUX
2013-01-13 21:39:25 -05:00
# include "glcontext_glx.h"
#elif BX_PLATFORM_OSX
# include "glcontext_nsgl.h"
2013-07-13 01:27:46 -04:00
#elif BX_PLATFORM_IOS
2013-07-21 17:44:53 -04:00
# include "glcontext_eagl.h"
2012-07-08 22:10:07 -04:00
#endif // BX_PLATFORM_
#if BGFX_USE_WGL
2013-01-13 21:39:25 -05:00
# include "glcontext_wgl.h"
2012-07-08 22:10:07 -04:00
#endif // BGFX_USE_WGL
#ifndef GL_APIENTRY
2012-10-14 01:21:02 -04:00
# define GL_APIENTRY APIENTRY
2012-07-08 22:10:07 -04:00
#endif // GL_APIENTRY
#ifndef GL_APIENTRYP
2012-10-14 01:21:02 -04:00
# define GL_APIENTRYP GL_APIENTRY*
2012-07-08 22:10:07 -04:00
#endif // GL_APIENTRYP
2013-01-12 22:13:51 -05:00
#if !BGFX_CONFIG_RENDERER_OPENGL
# define glClearDepth glClearDepthf
#endif // !BGFX_CONFIG_RENDERER_OPENGL
namespace bgfx
{
class ConstantBuffer;
void dumpExtensions(const char* _extensions);
2014-04-02 01:31:02 -04:00
const char* glEnumName(GLenum _enum);
#define _GL_CHECK(_check, _call) \
2014-06-08 23:57:39 -04:00
BX_MACRO_BLOCK_BEGIN \
2012-07-08 22:10:07 -04:00
/*BX_TRACE(#_call);*/ \
_call; \
GLenum err = glGetError(); \
2014-04-02 01:31:02 -04:00
_check(0 == err, #_call "; GL error 0x%x: %s", err, glEnumName(err) ); \
BX_UNUSED(err); \
2014-06-08 23:57:39 -04:00
BX_MACRO_BLOCK_END
2012-07-08 22:10:07 -04:00
2014-06-08 23:57:39 -04:00
#define IGNORE_GL_ERROR_CHECK(...) BX_NOOP()
2012-07-08 22:10:07 -04:00
#if BGFX_CONFIG_DEBUG
# define GL_CHECK(_call) _GL_CHECK(BX_CHECK, _call)
2014-03-27 12:55:39 -04:00
# define GL_CHECK_I(_call) _GL_CHECK(IGNORE_GL_ERROR_CHECK, _call)
2012-07-08 22:10:07 -04:00
#else
# define GL_CHECK(_call) _call
# define GL_CHECK_I(_call) _call
2012-07-08 22:10:07 -04:00
#endif // BGFX_CONFIG_DEBUG
#define GL_IMPORT_TYPEDEFS 1
2013-12-08 01:01:32 -05:00
#define GL_IMPORT(_optional, _proto, _func, _import) extern _proto _func
2012-07-08 22:10:07 -04:00
#include "glimports.h"
2013-04-27 02:43:31 -04:00
class VaoStateCache
2013-01-22 02:36:47 -05:00
{
public:
GLuint add(uint32_t _hash)
{
invalidate(_hash);
GLuint arrayId;
GL_CHECK(glGenVertexArrays(1, &arrayId) );
m_hashMap.insert(stl::make_pair(_hash, arrayId) );
return arrayId;
}
GLuint find(uint32_t _hash)
{
HashMap::iterator it = m_hashMap.find(_hash);
if (it != m_hashMap.end() )
{
return it->second;
}
return UINT32_MAX;
}
void invalidate(uint32_t _hash)
{
GL_CHECK(glBindVertexArray(0) );
HashMap::iterator it = m_hashMap.find(_hash);
if (it != m_hashMap.end() )
{
GL_CHECK(glDeleteVertexArrays(1, &it->second) );
m_hashMap.erase(it);
}
}
void invalidate()
{
GL_CHECK(glBindVertexArray(0) );
for (HashMap::iterator it = m_hashMap.begin(), itEnd = m_hashMap.end(); it != itEnd; ++it)
{
GL_CHECK(glDeleteVertexArrays(1, &it->second) );
}
m_hashMap.clear();
}
private:
typedef stl::unordered_map<uint32_t, GLuint> HashMap;
HashMap m_hashMap;
};
class VaoCacheRef
{
public:
void add(uint32_t _hash)
{
m_vaoSet.insert(_hash);
}
void invalidate(VaoStateCache& _vaoCache)
2013-01-22 02:36:47 -05:00
{
for (VaoSet::iterator it = m_vaoSet.begin(), itEnd = m_vaoSet.end(); it != itEnd; ++it)
{
_vaoCache.invalidate(*it);
}
m_vaoSet.clear();
}
2013-01-22 22:56:40 -05:00
typedef stl::unordered_set<uint32_t> VaoSet;
2013-01-22 02:36:47 -05:00
VaoSet m_vaoSet;
};
class SamplerStateCache
{
public:
GLuint add(uint32_t _hash)
{
invalidate(_hash);
GLuint samplerId;
GL_CHECK(glGenSamplers(1, &samplerId) );
m_hashMap.insert(stl::make_pair(_hash, samplerId) );
return samplerId;
}
GLuint find(uint32_t _hash)
{
HashMap::iterator it = m_hashMap.find(_hash);
if (it != m_hashMap.end() )
{
return it->second;
}
return UINT32_MAX;
}
void invalidate(uint32_t _hash)
{
HashMap::iterator it = m_hashMap.find(_hash);
if (it != m_hashMap.end() )
{
GL_CHECK(glDeleteSamplers(1, &it->second) );
m_hashMap.erase(it);
}
}
void invalidate()
{
for (HashMap::iterator it = m_hashMap.begin(), itEnd = m_hashMap.end(); it != itEnd; ++it)
{
GL_CHECK(glDeleteSamplers(1, &it->second) );
}
m_hashMap.clear();
}
private:
typedef stl::unordered_map<uint32_t, GLuint> HashMap;
HashMap m_hashMap;
};
struct IndexBufferGL
2012-07-08 22:10:07 -04:00
{
void create(uint32_t _size, void* _data)
{
m_size = _size;
GL_CHECK(glGenBuffers(1, &m_id) );
BX_CHECK(0 != m_id, "Failed to generate buffer id.");
GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_id) );
GL_CHECK(glBufferData(GL_ELEMENT_ARRAY_BUFFER
, _size
, _data
, (NULL==_data)?GL_DYNAMIC_DRAW:GL_STATIC_DRAW
) );
GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) );
}
void update(uint32_t _offset, uint32_t _size, void* _data)
{
2013-09-01 17:02:12 -04:00
BX_CHECK(0 != m_id, "Updating invalid index buffer.");
2012-07-08 22:10:07 -04:00
GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_id) );
GL_CHECK(glBufferSubData(GL_ELEMENT_ARRAY_BUFFER
, _offset
, _size
, _data
) );
GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) );
}
2013-01-22 02:36:47 -05:00
void destroy();
void add(uint32_t _hash)
2012-07-08 22:10:07 -04:00
{
2013-01-22 02:36:47 -05:00
m_vcref.add(_hash);
2012-07-08 22:10:07 -04:00
}
GLuint m_id;
uint32_t m_size;
2013-01-22 02:36:47 -05:00
VaoCacheRef m_vcref;
2012-07-08 22:10:07 -04:00
};
2014-01-09 01:08:37 -05:00
struct VertexBufferGL
2012-07-08 22:10:07 -04:00
{
void create(uint32_t _size, void* _data, VertexDeclHandle _declHandle)
{
m_size = _size;
m_decl = _declHandle;
GL_CHECK(glGenBuffers(1, &m_id) );
BX_CHECK(0 != m_id, "Failed to generate buffer id.");
GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, m_id) );
GL_CHECK(glBufferData(GL_ARRAY_BUFFER
, _size
, _data
, (NULL==_data)?GL_DYNAMIC_DRAW:GL_STATIC_DRAW
) );
GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, 0) );
}
void update(uint32_t _offset, uint32_t _size, void* _data)
{
2013-09-01 17:02:12 -04:00
BX_CHECK(0 != m_id, "Updating invalid vertex buffer.");
2012-07-08 22:10:07 -04:00
GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, m_id) );
GL_CHECK(glBufferSubData(GL_ARRAY_BUFFER
, _offset
, _size
, _data
) );
GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, 0) );
}
2013-01-22 02:36:47 -05:00
void destroy();
void add(uint32_t _hash)
2012-07-08 22:10:07 -04:00
{
2013-01-22 02:36:47 -05:00
m_vcref.add(_hash);
2012-07-08 22:10:07 -04:00
}
GLuint m_id;
uint32_t m_size;
VertexDeclHandle m_decl;
2013-01-22 02:36:47 -05:00
VaoCacheRef m_vcref;
2013-01-12 22:13:51 -05:00
};
struct TextureGL
2012-07-08 22:10:07 -04:00
{
TextureGL()
2012-07-08 22:10:07 -04:00
: m_id(0)
2014-02-06 02:07:11 -05:00
, m_rbo(0)
2012-07-08 22:10:07 -04:00
, m_target(GL_TEXTURE_2D)
, m_fmt(GL_ZERO)
, m_type(GL_ZERO)
, m_flags(0)
, m_currentFlags(UINT32_MAX)
, m_numMips(0)
2012-07-08 22:10:07 -04:00
{
}
2014-02-06 02:07:11 -05:00
bool init(GLenum _target, uint32_t _width, uint32_t _height, uint8_t _format, uint8_t _numMips, uint32_t _flags);
void create(const Memory* _mem, uint32_t _flags, uint8_t _skip);
2012-07-08 22:10:07 -04:00
void destroy();
void update(uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem);
void setSamplerState(uint32_t _flags);
void commit(uint32_t _stage, uint32_t _flags);
2012-07-08 22:10:07 -04:00
GLuint m_id;
2014-02-06 02:07:11 -05:00
GLuint m_rbo;
2012-07-08 22:10:07 -04:00
GLenum m_target;
2012-08-13 00:02:11 -04:00
GLenum m_fmt;
GLenum m_type;
uint32_t m_flags;
uint32_t m_currentFlags;
2014-02-06 02:07:11 -05:00
uint32_t m_width;
uint32_t m_height;
uint8_t m_numMips;
uint8_t m_requestedFormat;
uint8_t m_textureFormat;
2012-07-08 22:10:07 -04:00
};
struct ShaderGL
2012-07-08 22:10:07 -04:00
{
ShaderGL()
2013-10-03 23:39:55 -04:00
: m_id(0)
, m_type(0)
, m_hash(0)
2013-10-03 23:39:55 -04:00
{
}
void create(Memory* _mem);
void destroy();
2012-07-08 22:10:07 -04:00
GLuint m_id;
GLenum m_type;
uint32_t m_hash;
};
struct FrameBufferGL
2012-07-08 22:10:07 -04:00
{
FrameBufferGL()
2014-02-06 02:07:11 -05:00
: m_num(0)
2013-02-17 23:42:33 -05:00
{
memset(m_fbo, 0, sizeof(m_fbo) );
}
2014-02-06 02:07:11 -05:00
void create(uint8_t _num, const TextureHandle* _handles);
2012-07-08 22:10:07 -04:00
void destroy();
2013-02-17 23:42:33 -05:00
void resolve();
2012-07-08 22:10:07 -04:00
2014-02-06 02:07:11 -05:00
uint8_t m_num;
2013-02-17 23:42:33 -05:00
GLuint m_fbo[2];
2014-02-06 02:07:11 -05:00
uint32_t m_width;
uint32_t m_height;
2012-07-08 22:10:07 -04:00
};
struct ProgramGL
2012-07-08 22:10:07 -04:00
{
ProgramGL()
2013-10-03 23:39:55 -04:00
: m_id(0)
, m_constantBuffer(NULL)
2013-09-21 02:07:14 -04:00
, m_numPredefined(0)
{
}
void create(const ShaderGL& _vsh, const ShaderGL& _fsh);
2012-07-08 22:10:07 -04:00
void destroy();
void init();
void bindAttributes(const VertexDecl& _vertexDecl, uint32_t _baseVertex = 0) const;
void bindInstanceData(uint32_t _stride, uint32_t _baseVertex = 0) const;
2013-01-22 02:36:47 -05:00
void add(uint32_t _hash)
{
m_vcref.add(_hash);
}
2012-07-08 22:10:07 -04:00
GLuint m_id;
uint8_t m_used[Attrib::Count+1]; // dense
GLint m_attributes[Attrib::Count]; // sparse
GLint m_instanceData[BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT];
2012-07-08 22:10:07 -04:00
GLint m_sampler[BGFX_CONFIG_MAX_TEXTURES];
2012-07-08 22:10:07 -04:00
uint8_t m_numSamplers;
ConstantBuffer* m_constantBuffer;
PredefinedUniform m_predefined[PredefinedUniform::Count];
uint8_t m_numPredefined;
2013-01-22 02:36:47 -05:00
VaoCacheRef m_vcref;
2012-07-08 22:10:07 -04:00
};
struct QueriesGL
2012-07-08 22:10:07 -04:00
{
void create()
{
2013-08-07 00:04:28 -04:00
glGenQueries(BX_COUNTOF(m_queries), m_queries);
2012-07-08 22:10:07 -04:00
}
void destroy()
{
2013-08-07 00:04:28 -04:00
glDeleteQueries(BX_COUNTOF(m_queries), m_queries);
2012-07-08 22:10:07 -04:00
}
void begin(uint16_t _id, GLenum _target) const
{
glBeginQuery(_target, m_queries[_id]);
}
void end(GLenum _target) const
{
glEndQuery(_target);
}
uint64_t getResult(uint16_t _id) const
{
uint64_t result;
glGetQueryObjectui64v(m_queries[_id], GL_QUERY_RESULT, &result);
return result;
}
GLuint m_queries[64];
};
} // namespace bgfx
#endif // BGFX_RENDERER_GL_H_HEADER_GUARD