Added DX11 renderer stub.

This commit is contained in:
bkaradzic 2012-07-08 19:10:07 -07:00
parent 60d2993808
commit 98ebe1f076
8 changed files with 3094 additions and 2939 deletions

View File

@ -227,7 +227,7 @@ namespace bgfx
charsetFillTexture(vga8x16, &rgba[8*pitch], 16, pitch, bpp); charsetFillTexture(vga8x16, &rgba[8*pitch], 16, pitch, bpp);
m_texture = s_ctx.createTexture(mem, BGFX_TEXTURE_MIN_POINT|BGFX_TEXTURE_MAG_POINT|BGFX_TEXTURE_MIP_POINT, NULL, NULL); m_texture = s_ctx.createTexture(mem, BGFX_TEXTURE_MIN_POINT|BGFX_TEXTURE_MAG_POINT|BGFX_TEXTURE_MIP_POINT, NULL, NULL);
#if BGFX_CONFIG_RENDERER_DIRECT3D #if BGFX_CONFIG_RENDERER_DIRECT3D9
mem = bgfx::alloc(sizeof(vs_debugfont_hlsl)+1); mem = bgfx::alloc(sizeof(vs_debugfont_hlsl)+1);
memcpy(mem->data, vs_debugfont_hlsl, mem->size-1); memcpy(mem->data, vs_debugfont_hlsl, mem->size-1);
#else #else
@ -237,7 +237,7 @@ namespace bgfx
mem->data[mem->size-1] = '\0'; mem->data[mem->size-1] = '\0';
bgfx::VertexShaderHandle vsh = bgfx::createVertexShader(mem); bgfx::VertexShaderHandle vsh = bgfx::createVertexShader(mem);
#if BGFX_CONFIG_RENDERER_DIRECT3D #if BGFX_CONFIG_RENDERER_DIRECT3D9
mem = bgfx::alloc(sizeof(fs_debugfont_hlsl)+1); mem = bgfx::alloc(sizeof(fs_debugfont_hlsl)+1);
memcpy(mem->data, fs_debugfont_hlsl, mem->size-1); memcpy(mem->data, fs_debugfont_hlsl, mem->size-1);
#else #else
@ -458,11 +458,11 @@ namespace bgfx
RendererType::Enum getRendererType() RendererType::Enum getRendererType()
{ {
#if BGFX_CONFIG_RENDERER_DIRECT3D #if BGFX_CONFIG_RENDERER_DIRECT3D9
return RendererType::Direct3D9; return RendererType::Direct3D9;
#elif BGFX_CONFIG_RENDERER_OPENGL #elif BGFX_CONFIG_RENDERER_OPENGL
return RendererType::OpenGL; return RendererType::OpenGL;
#elif BGFX_CONFIG_RENDERER_OPENGLES #elif BGFX_CONFIG_RENDERER_OPENGLES2
return RendererType::OpenGLES; return RendererType::OpenGLES;
#else #else
return RendererType::Null; return RendererType::Null;

View File

@ -132,6 +132,14 @@ namespace stl = std;
#define BGFX_SAMPLER_RENDERTARGET_DEPTH UINT16_C(0x0002) #define BGFX_SAMPLER_RENDERTARGET_DEPTH UINT16_C(0x0002)
#define BGFX_SAMPLER_TYPE_MASK UINT16_C(0x0003) #define BGFX_SAMPLER_TYPE_MASK UINT16_C(0x0003)
#if BGFX_CONFIG_RENDERER_DIRECT3D9
# define BGFX_RENDERER_NAME "Direct3D 9"
#elif BGFX_CONFIG_RENDERER_OPENGL
# define BGFX_RENDERER_NAME "OpenGL"
#elif BGFX_CONFIG_RENDERER_OPENGLES2
# define BGFX_RENDERER_NAME "OpenGL ES 2"
#endif // BGFX_CONFIG_RENDERER_
namespace bgfx namespace bgfx
{ {
extern const uint32_t g_constantTypeSize[ConstantType::Count]; extern const uint32_t g_constantTypeSize[ConstantType::Count];
@ -1088,7 +1096,7 @@ namespace bgfx
void setInstanceDataBuffer(const InstanceDataBuffer* _idb) void setInstanceDataBuffer(const InstanceDataBuffer* _idb)
{ {
#if BGFX_CONFIG_RENDERER_OPENGLES #if BGFX_CONFIG_RENDERER_OPENGLES2
#else #else
m_state.m_instanceDataOffset = _idb->offset; m_state.m_instanceDataOffset = _idb->offset;
m_state.m_instanceDataStride = _idb->stride; m_state.m_instanceDataStride = _idb->stride;
@ -1878,7 +1886,7 @@ namespace bgfx
const InstanceDataBuffer* allocInstanceDataBuffer(uint16_t _num, uint16_t _stride) const InstanceDataBuffer* allocInstanceDataBuffer(uint16_t _num, uint16_t _stride)
{ {
#if BGFX_CONFIG_RENDERER_OPENGLES #if BGFX_CONFIG_RENDERER_OPENGLES2
return NULL; return NULL;
#else #else
uint16_t stride = BX_ALIGN_16(_stride); uint16_t stride = BX_ALIGN_16(_stride);

View File

@ -6,21 +6,25 @@
#ifndef __CONFIG_H__ #ifndef __CONFIG_H__
#define __CONFIG_H__ #define __CONFIG_H__
#if !defined(BGFX_CONFIG_RENDERER_DIRECT3D) && !defined(BGFX_CONFIG_RENDERER_OPENGL) && !defined(BGFX_CONFIG_RENDERER_OPENGLES) && !defined(BGFX_CONFIG_RENDERER_NULL) #if !defined(BGFX_CONFIG_RENDERER_DIRECT3D9) && !defined(BGFX_CONFIG_RENDERER_DIRECT3D11) && !defined(BGFX_CONFIG_RENDERER_OPENGL) && !defined(BGFX_CONFIG_RENDERER_OPENGLES2) && !defined(BGFX_CONFIG_RENDERER_NULL)
# ifndef BGFX_CONFIG_RENDERER_DIRECT3D # ifndef BGFX_CONFIG_RENDERER_DIRECT3D9
# define BGFX_CONFIG_RENDERER_DIRECT3D (BX_PLATFORM_WINDOWS|BX_PLATFORM_XBOX360) # define BGFX_CONFIG_RENDERER_DIRECT3D9 (BX_PLATFORM_WINDOWS|BX_PLATFORM_XBOX360)
# endif // BGFX_CONFIG_RENDERER_DIRECT3D # endif // BGFX_CONFIG_RENDERER_DIRECT3D9
# ifndef BGFX_CONFIG_RENDERER_DIRECT3D11
# define BGFX_CONFIG_RENDERER_DIRECT3D11 0
# endif // BGFX_CONFIG_RENDERER_DIRECT3D11
# ifndef BGFX_CONFIG_RENDERER_OPENGL # ifndef BGFX_CONFIG_RENDERER_OPENGL
# define BGFX_CONFIG_RENDERER_OPENGL (BX_PLATFORM_LINUX|BX_PLATFORM_OSX) # define BGFX_CONFIG_RENDERER_OPENGL (BX_PLATFORM_LINUX|BX_PLATFORM_OSX)
# endif // BGFX_CONFIG_RENDERER_OPENGL # endif // BGFX_CONFIG_RENDERER_OPENGL
# ifndef BGFX_CONFIG_RENDERER_OPENGLES # ifndef BGFX_CONFIG_RENDERER_OPENGLES2
# define BGFX_CONFIG_RENDERER_OPENGLES (BX_PLATFORM_NACL|BX_PLATFORM_ANDROID|BX_PLATFORM_IOS) # define BGFX_CONFIG_RENDERER_OPENGLES2 (BX_PLATFORM_NACL|BX_PLATFORM_ANDROID|BX_PLATFORM_IOS)
# endif // BGFX_CONFIG_RENDERER_OPENGLES # endif // BGFX_CONFIG_RENDERER_OPENGLES
# ifndef BGFX_CONFIG_RENDERER_NULL # ifndef BGFX_CONFIG_RENDERER_NULL
# define BGFX_CONFIG_RENDERER_NULL (!(BGFX_CONFIG_RENDERER_DIRECT3D|BGFX_CONFIG_RENDERER_OPENGL|BGFX_CONFIG_RENDERER_OPENGLES) ) # define BGFX_CONFIG_RENDERER_NULL (!(BGFX_CONFIG_RENDERER_DIRECT3D9|BGFX_CONFIG_RENDERER_OPENGL|BGFX_CONFIG_RENDERER_OPENGLES2) )
# endif // BGFX_CONFIG_RENDERER_NULL # endif // BGFX_CONFIG_RENDERER_NULL
#endif // !defined... #endif // !defined...

141
src/renderer_d3d11.cpp Normal file
View File

@ -0,0 +1,141 @@
/*
* Copyright 2011-2012 Branimir Karadzic. All rights reserved.
* License: http://www.opensource.org/licenses/BSD-2-Clause
*/
#include "bgfx_p.h"
#if BGFX_CONFIG_RENDERER_DIRECT3D11
namespace bgfx
{
void ConstantBuffer::commit()
{
}
void TextVideoMemBlitter::setup()
{
}
void TextVideoMemBlitter::render(uint32_t /*_numIndices*/)
{
}
void Context::flip()
{
}
void Context::rendererInit()
{
}
void Context::rendererShutdown()
{
}
void Context::rendererCreateIndexBuffer(IndexBufferHandle /*_handle*/, Memory* /*_mem*/)
{
}
void Context::rendererDestroyIndexBuffer(IndexBufferHandle /*_handle*/)
{
}
void Context::rendererCreateVertexDecl(VertexDeclHandle /*_handle*/, const VertexDecl& /*_decl*/)
{
}
void Context::rendererDestroyVertexDecl(VertexDeclHandle /*_handle*/)
{
}
void Context::rendererCreateVertexBuffer(VertexBufferHandle /*_handle*/, Memory* /*_mem*/, VertexDeclHandle /*_declHandle*/)
{
}
void Context::rendererDestroyVertexBuffer(VertexBufferHandle /*_handle*/)
{
}
void Context::rendererCreateDynamicIndexBuffer(IndexBufferHandle /*_handle*/, uint32_t /*_size*/)
{
}
void Context::rendererUpdateDynamicIndexBuffer(IndexBufferHandle /*_handle*/, uint32_t /*_offset*/, uint32_t /*_size*/, Memory* /*_mem*/)
{
}
void Context::rendererDestroyDynamicIndexBuffer(IndexBufferHandle /*_handle*/)
{
}
void Context::rendererCreateDynamicVertexBuffer(VertexBufferHandle /*_handle*/, uint32_t /*_size*/)
{
}
void Context::rendererUpdateDynamicVertexBuffer(VertexBufferHandle /*_handle*/, uint32_t /*_offset*/, uint32_t /*_size*/, Memory* /*_mem*/)
{
}
void Context::rendererDestroyDynamicVertexBuffer(VertexBufferHandle /*_handle*/)
{
}
void Context::rendererCreateVertexShader(VertexShaderHandle /*_handle*/, Memory* /*_mem*/)
{
}
void Context::rendererDestroyVertexShader(VertexShaderHandle /*_handle*/)
{
}
void Context::rendererCreateFragmentShader(FragmentShaderHandle /*_handle*/, Memory* /*_mem*/)
{
}
void Context::rendererDestroyFragmentShader(FragmentShaderHandle /*_handle*/)
{
}
void Context::rendererCreateMaterial(MaterialHandle /*_handle*/, VertexShaderHandle /*_vsh*/, FragmentShaderHandle /*_fsh*/)
{
}
void Context::rendererDestroyMaterial(FragmentShaderHandle /*_handle*/)
{
}
void Context::rendererCreateTexture(TextureHandle /*_handle*/, Memory* /*_mem*/, uint32_t /*_flags*/)
{
}
void Context::rendererDestroyTexture(TextureHandle /*_handle*/)
{
}
void Context::rendererCreateRenderTarget(RenderTargetHandle /*_handle*/, uint16_t /*_width*/, uint16_t /*_height*/, uint32_t /*_flags*/, uint32_t /*_textureFlags*/)
{
}
void Context::rendererDestroyRenderTarget(RenderTargetHandle /*_handle*/)
{
}
void Context::rendererCreateUniform(UniformHandle /*_handle*/, ConstantType::Enum /*_type*/, uint16_t /*_num*/, const char* /*_name*/)
{
}
void Context::rendererDestroyUniform(UniformHandle /*_handle*/)
{
}
void Context::rendererSaveScreenShot(Memory* /*_mem*/)
{
}
void Context::rendererSubmit()
{
}
}
#endif // BGFX_CONFIG_RENDERER_DIRECT3D11

View File

@ -5,7 +5,7 @@
#include "bgfx_p.h" #include "bgfx_p.h"
#if BGFX_CONFIG_RENDERER_DIRECT3D #if BGFX_CONFIG_RENDERER_DIRECT3D9
# include "renderer_d3d9.h" # include "renderer_d3d9.h"
namespace bgfx namespace bgfx
@ -192,7 +192,7 @@ namespace bgfx
m_D3DPERF_BeginEvent = (D3DPERF_BeginEventFunc)GetProcAddress(m_d3d9dll, "D3DPERF_BeginEvent"); m_D3DPERF_BeginEvent = (D3DPERF_BeginEventFunc)GetProcAddress(m_d3d9dll, "D3DPERF_BeginEvent");
m_D3DPERF_EndEvent = (D3DPERF_EndEventFunc)GetProcAddress(m_d3d9dll, "D3DPERF_EndEvent"); m_D3DPERF_EndEvent = (D3DPERF_EndEventFunc)GetProcAddress(m_d3d9dll, "D3DPERF_EndEvent");
#if BGFX_CONFIG_RENDERER_DIRECT3D_EX #if BGFX_CONFIG_RENDERER_DIRECT3D9EX
Direct3DCreate9ExFunc direct3DCreate9Ex = (Direct3DCreate9ExFunc)GetProcAddress(m_d3d9dll, "Direct3DCreate9Ex"); Direct3DCreate9ExFunc direct3DCreate9Ex = (Direct3DCreate9ExFunc)GetProcAddress(m_d3d9dll, "Direct3DCreate9Ex");
BGFX_FATAL(NULL != direct3DCreate9Ex, bgfx::Fatal::D3D9_UnableToCreateInterface, "Function Direct3DCreate9Ex not found."); BGFX_FATAL(NULL != direct3DCreate9Ex, bgfx::Fatal::D3D9_UnableToCreateInterface, "Function Direct3DCreate9Ex not found.");
direct3DCreate9Ex(D3D_SDK_VERSION, &m_d3d9); direct3DCreate9Ex(D3D_SDK_VERSION, &m_d3d9);
@ -247,7 +247,7 @@ namespace bgfx
for (uint32_t ii = 0; ii < countof(behaviorFlags) && NULL == m_device; ++ii) for (uint32_t ii = 0; ii < countof(behaviorFlags) && NULL == m_device; ++ii)
{ {
#if BGFX_CONFIG_RENDERER_DIRECT3D_EX #if BGFX_CONFIG_RENDERER_DIRECT3D9EX
DX_CHECK(m_d3d9->CreateDeviceEx(m_adapter DX_CHECK(m_d3d9->CreateDeviceEx(m_adapter
, m_deviceType , m_deviceType
, g_bgfxHwnd , g_bgfxHwnd
@ -264,7 +264,7 @@ namespace bgfx
, &m_params , &m_params
, &m_device , &m_device
) ); ) );
#endif // BGFX_CONFIG_RENDERER_DIRECT3D_EX #endif // BGFX_CONFIG_RENDERER_DIRECT3D9EX
} }
BGFX_FATAL(m_device, bgfx::Fatal::D3D9_UnableToCreateDevice, "Unable to create Direct3D9 device."); BGFX_FATAL(m_device, bgfx::Fatal::D3D9_UnableToCreateDevice, "Unable to create Direct3D9 device.");
@ -560,9 +560,9 @@ namespace bgfx
{ {
if (NULL != m_device) if (NULL != m_device)
{ {
#if BGFX_CONFIG_RENDERER_DIRECT3D_EX #if BGFX_CONFIG_RENDERER_DIRECT3D9EX
DX_CHECK(m_device->WaitForVBlank(0) ); DX_CHECK(m_device->WaitForVBlank(0) );
#endif // BGFX_CONFIG_RENDERER_DIRECT3D_EX #endif // BGFX_CONFIG_RENDERER_DIRECT3D9EX
HRESULT hr; HRESULT hr;
hr = m_device->Present(NULL, NULL, NULL, NULL); hr = m_device->Present(NULL, NULL, NULL, NULL);
@ -694,13 +694,13 @@ namespace bgfx
D3DPERF_EndEventFunc m_D3DPERF_EndEvent; D3DPERF_EndEventFunc m_D3DPERF_EndEvent;
#endif // BX_PLATFORM_WINDOWS #endif // BX_PLATFORM_WINDOWS
#if BGFX_CONFIG_RENDERER_DIRECT3D_EX #if BGFX_CONFIG_RENDERER_DIRECT3D9EX
IDirect3D9Ex* m_d3d9; IDirect3D9Ex* m_d3d9;
IDirect3DDevice9Ex* m_device; IDirect3DDevice9Ex* m_device;
#else #else
IDirect3D9* m_d3d9; IDirect3D9* m_d3d9;
IDirect3DDevice9* m_device; IDirect3DDevice9* m_device;
#endif // BGFX_CONFIG_RENDERER_DIRECT3D_EX #endif // BGFX_CONFIG_RENDERER_DIRECT3D9EX
IDirect3DSurface9* m_backBufferColor; IDirect3DSurface9* m_backBufferColor;
IDirect3DSurface9* m_backBufferDepthStencil; IDirect3DSurface9* m_backBufferDepthStencil;
@ -2377,6 +2377,7 @@ namespace bgfx
tvm.clear(); tvm.clear();
uint16_t pos = 10; uint16_t pos = 10;
tvm.printf(0, 0, 0x8f, " " BGFX_RENDERER_NAME " ");
tvm.printf(10, pos++, 0x8e, " Frame: %3.4f [ms] / %3.2f", frameTime*toMs, freq/frameTime); tvm.printf(10, pos++, 0x8e, " Frame: %3.4f [ms] / %3.2f", frameTime*toMs, freq/frameTime);
tvm.printf(10, pos++, 0x8e, " Draw calls: %4d / CPU %3.4f [ms]" tvm.printf(10, pos++, 0x8e, " Draw calls: %4d / CPU %3.4f [ms]"
, m_render->m_num , m_render->m_num
@ -2415,4 +2416,4 @@ namespace bgfx
} }
} }
#endif // BGFX_CONFIG_RENDERER_DIRECT3D #endif // BGFX_CONFIG_RENDERER_DIRECT3D9

View File

@ -6,7 +6,7 @@
#ifndef __RENDERER_D3D9_H__ #ifndef __RENDERER_D3D9_H__
#define __RENDERER_D3D9_H__ #define __RENDERER_D3D9_H__
#define BGFX_CONFIG_RENDERER_DIRECT3D_EX (BX_PLATFORM_WINDOWS && 0) #define BGFX_CONFIG_RENDERER_DIRECT3D9EX (BX_PLATFORM_WINDOWS && 0)
#ifndef D3DSTREAMSOURCE_INDEXEDDATA #ifndef D3DSTREAMSOURCE_INDEXEDDATA
# define D3DSTREAMSOURCE_INDEXEDDATA (1<<30) # define D3DSTREAMSOURCE_INDEXEDDATA (1<<30)
@ -17,16 +17,16 @@
#endif // D3DSTREAMSOURCE_INSTANCEDATA #endif // D3DSTREAMSOURCE_INSTANCEDATA
#if BX_PLATFORM_WINDOWS #if BX_PLATFORM_WINDOWS
# if !BGFX_CONFIG_RENDERER_DIRECT3D_EX # if !BGFX_CONFIG_RENDERER_DIRECT3D9EX
# define D3D_DISABLE_9EX # define D3D_DISABLE_9EX
# endif // !BGFX_CONFIG_RENDERER_DIRECT3D_EX # endif // !BGFX_CONFIG_RENDERER_DIRECT3D9EX
# include <d3d9.h> # include <d3d9.h>
# if BGFX_CONFIG_RENDERER_DIRECT3D_EX # if BGFX_CONFIG_RENDERER_DIRECT3D9EX
typedef HRESULT (WINAPI *Direct3DCreate9ExFunc)(UINT SDKVersion, IDirect3D9Ex**); typedef HRESULT (WINAPI *Direct3DCreate9ExFunc)(UINT SDKVersion, IDirect3D9Ex**);
# else # else
typedef IDirect3D9* (WINAPI *Direct3DCreate9Func)(UINT SDKVersion); typedef IDirect3D9* (WINAPI *Direct3DCreate9Func)(UINT SDKVersion);
# endif // BGFX_CONFIG_RENDERER_DIRECT3D_EX # endif // BGFX_CONFIG_RENDERER_DIRECT3D9EX
typedef int (WINAPI *D3DPERF_BeginEventFunc)(D3DCOLOR col, LPCWSTR wszName); typedef int (WINAPI *D3DPERF_BeginEventFunc)(D3DCOLOR col, LPCWSTR wszName);
typedef int (WINAPI *D3DPERF_EndEventFunc)(); typedef int (WINAPI *D3DPERF_EndEventFunc)();

File diff suppressed because it is too large Load Diff

View File

@ -1,403 +1,403 @@
/* /*
* Copyright 2011-2012 Branimir Karadzic. All rights reserved. * Copyright 2011-2012 Branimir Karadzic. All rights reserved.
* License: http://www.opensource.org/licenses/BSD-2-Clause * License: http://www.opensource.org/licenses/BSD-2-Clause
*/ */
#ifndef __RENDERER_GL_H__ #ifndef __RENDERER_GL_H__
#define __RENDERER_GL_H__ #define __RENDERER_GL_H__
#define BGFX_USE_EGL 0 #define BGFX_USE_EGL 0
#define BGFX_USE_WGL 0 #define BGFX_USE_WGL 0
#if BGFX_CONFIG_RENDERER_OPENGL #if BGFX_CONFIG_RENDERER_OPENGL
# if BX_PLATFORM_LINUX # if BX_PLATFORM_LINUX
# define GL_PROTOTYPES # define GL_PROTOTYPES
# define GL_GLEXT_LEGACY # define GL_GLEXT_LEGACY
# include <GL/gl.h> # include <GL/gl.h>
# include <GL/glx.h> # include <GL/glx.h>
# undef GL_PROTOTYPES # undef GL_PROTOTYPES
# elif BX_PLATFORM_OSX # elif BX_PLATFORM_OSX
# define GL_PROTOTYPES # define GL_PROTOTYPES
# define GL_GLEXT_LEGACY # define GL_GLEXT_LEGACY
# define GL_VERSION_1_2 # define GL_VERSION_1_2
# define GL_VERSION_1_3 # define GL_VERSION_1_3
# define GL_VERSION_1_5 # define GL_VERSION_1_5
# define GL_VERSION_2_0 # define GL_VERSION_2_0
# include <OpenGL/gl.h> # include <OpenGL/gl.h>
# undef GL_VERSION_2_0 # undef GL_VERSION_2_0
# undef GL_VERSION_1_5 # undef GL_VERSION_1_5
# undef GL_VERSION_1_3 # undef GL_VERSION_1_3
# undef GL_VERSION_1_2 # undef GL_VERSION_1_2
# undef GL_PROTOTYPES # undef GL_PROTOTYPES
# else # else
# include <GL/gl.h> # include <GL/gl.h>
# endif // BX_PLATFORM_ # endif // BX_PLATFORM_
# if BX_PLATFORM_WINDOWS # if BX_PLATFORM_WINDOWS
# undef BGFX_USE_WGL # undef BGFX_USE_WGL
# define BGFX_USE_WGL 1 # define BGFX_USE_WGL 1
# endif // BX_PLATFORM_ # endif // BX_PLATFORM_
// remove deprecated from glext.h // remove deprecated from glext.h
# define GL_VERSION_1_2_DEPRECATED # define GL_VERSION_1_2_DEPRECATED
# define GL_ARB_imaging_DEPRECATED # define GL_ARB_imaging_DEPRECATED
# define GL_VERSION_1_3_DEPRECATED # define GL_VERSION_1_3_DEPRECATED
# define GL_VERSION_1_4_DEPRECATED # define GL_VERSION_1_4_DEPRECATED
# define GL_VERSION_1_5_DEPRECATED # define GL_VERSION_1_5_DEPRECATED
# define GL_VERSION_2_0_DEPRECATED # define GL_VERSION_2_0_DEPRECATED
# define GL_VERSION_2_1_DEPRECATED # define GL_VERSION_2_1_DEPRECATED
// ignore everything above 2.1 // ignore everything above 2.1
# define GL_VERSION_3_0 # define GL_VERSION_3_0
# define GL_VERSION_3_0_DEPRECATED # define GL_VERSION_3_0_DEPRECATED
# define GL_VERSION_3_1 # define GL_VERSION_3_1
# define GL_VERSION_3_2 # define GL_VERSION_3_2
# define GL_VERSION_3_3 # define GL_VERSION_3_3
# define GL_VERSION_4_0 # define GL_VERSION_4_0
# define GL_VERSION_4_1 # define GL_VERSION_4_1
# define GL_VERSION_4_2 # define GL_VERSION_4_2
# include <gl/glext.h> # include <gl/glext.h>
#elif BGFX_CONFIG_RENDERER_OPENGLES #elif BGFX_CONFIG_RENDERER_OPENGLES2
# include <GLES2/gl2.h> # include <GLES2/gl2.h>
# include <GLES2/gl2ext.h> # include <GLES2/gl2ext.h>
# if BX_PLATFORM_WINDOWS # if BX_PLATFORM_WINDOWS
# include <EGL/egl.h> # include <EGL/egl.h>
# undef BGFX_USE_EGL # undef BGFX_USE_EGL
# define BGFX_USE_EGL 1 # define BGFX_USE_EGL 1
# endif // BX_PLATFORM_ # endif // BX_PLATFORM_
# ifndef GL_COMPRESSED_RGBA_S3TC_DXT3_EXT # ifndef GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
# define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2 # define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2
# endif // GL_COMPRESSED_RGBA_S3TC_DXT3_EXT # endif // GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
# ifndef GL_COMPRESSED_RGBA_S3TC_DXT5_EXT # ifndef GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
# define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3 # define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3
# endif // GL_COMPRESSED_RGBA_S3TC_DXT5_EXT # endif // GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
# ifndef GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE # ifndef GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE
# define GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE 0x93A0 # define GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE 0x93A0
# endif // GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE # endif // GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE
typedef void (*PFNGLGETTRANSLATEDSHADERSOURCEANGLEPROC)(GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *source); typedef void (*PFNGLGETTRANSLATEDSHADERSOURCEANGLEPROC)(GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *source);
#endif // BGFX_CONFIG_RENDERER_OPENGL #endif // BGFX_CONFIG_RENDERER_OPENGL
#if BX_PLATFORM_NACL #if BX_PLATFORM_NACL
# include <ppapi/gles2/gl2ext_ppapi.h> # include <ppapi/gles2/gl2ext_ppapi.h>
# include <ppapi/c/pp_completion_callback.h> # include <ppapi/c/pp_completion_callback.h>
# include <ppapi/c/ppb_instance.h> # include <ppapi/c/ppb_instance.h>
# include <ppapi/c/ppb_graphics_3d.h> # include <ppapi/c/ppb_graphics_3d.h>
#elif BX_PLATFORM_WINDOWS #elif BX_PLATFORM_WINDOWS
# include <windows.h> # include <windows.h>
#elif BX_PLATFORM_LINUX #elif BX_PLATFORM_LINUX
# include <X11/Xlib.h> # include <X11/Xlib.h>
#endif // BX_PLATFORM_ #endif // BX_PLATFORM_
#if BGFX_CONFIG_DEBUG_GREMEDY && (BX_PLATFORM_WINDOWS || BX_PLATFORM_LINUX) #if BGFX_CONFIG_DEBUG_GREMEDY && (BX_PLATFORM_WINDOWS || BX_PLATFORM_LINUX)
# include <gl/GRemedyGLExtensions.h> # include <gl/GRemedyGLExtensions.h>
#endif // BGFX_CONFIG_DEBUG_GREMEDY && (BX_PLATFORM_WINDOWS || BX_PLATFORM_LINUX) #endif // BGFX_CONFIG_DEBUG_GREMEDY && (BX_PLATFORM_WINDOWS || BX_PLATFORM_LINUX)
#if BGFX_USE_WGL #if BGFX_USE_WGL
typedef PROC (APIENTRYP PFNWGLGETPROCADDRESSPROC) (LPCSTR lpszProc); typedef PROC (APIENTRYP PFNWGLGETPROCADDRESSPROC) (LPCSTR lpszProc);
typedef BOOL (APIENTRYP PFNWGLMAKECURRENTPROC) (HDC hdc, HGLRC hglrc); typedef BOOL (APIENTRYP PFNWGLMAKECURRENTPROC) (HDC hdc, HGLRC hglrc);
typedef HGLRC (APIENTRYP PFNWGLCREATECONTEXTPROC) (HDC hdc); typedef HGLRC (APIENTRYP PFNWGLCREATECONTEXTPROC) (HDC hdc);
typedef BOOL (APIENTRYP PFNWGLDELETECONTEXTPROC) (HGLRC hglrc); typedef BOOL (APIENTRYP PFNWGLDELETECONTEXTPROC) (HGLRC hglrc);
// //
typedef GLenum (APIENTRYP PFNGLGETERRORPROC) (void); typedef GLenum (APIENTRYP PFNGLGETERRORPROC) (void);
typedef void (APIENTRYP PFNGLREADPIXELSPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels); typedef void (APIENTRYP PFNGLREADPIXELSPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels);
typedef void (APIENTRYP PFNGLTEXIMAGE2DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); typedef void (APIENTRYP PFNGLTEXIMAGE2DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
typedef void (APIENTRYP PFNGLTEXPARAMETERIPROC) (GLenum target, GLenum pname, GLint param); typedef void (APIENTRYP PFNGLTEXPARAMETERIPROC) (GLenum target, GLenum pname, GLint param);
typedef void (APIENTRYP PFNGLBINDTEXTUREPROC) (GLenum target, GLuint texture); typedef void (APIENTRYP PFNGLBINDTEXTUREPROC) (GLenum target, GLuint texture);
typedef void (APIENTRYP PFNGLGENTEXTURESPROC) (GLsizei n, GLuint *textures); typedef void (APIENTRYP PFNGLGENTEXTURESPROC) (GLsizei n, GLuint *textures);
typedef void (APIENTRYP PFNGLDELETETEXTURESPROC) (GLsizei n, const GLuint *textures); typedef void (APIENTRYP PFNGLDELETETEXTURESPROC) (GLsizei n, const GLuint *textures);
typedef void (APIENTRYP PFNGLCOLORMASKPROC) (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); typedef void (APIENTRYP PFNGLCOLORMASKPROC) (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
typedef void (APIENTRYP PFNGLDEPTHFUNCPROC) (GLenum func); typedef void (APIENTRYP PFNGLDEPTHFUNCPROC) (GLenum func);
typedef void (APIENTRYP PFNGLDISABLEPROC) (GLenum cap); typedef void (APIENTRYP PFNGLDISABLEPROC) (GLenum cap);
typedef void (APIENTRYP PFNGLVIEWPORTPROC) (GLint x, GLint y, GLsizei width, GLsizei height); typedef void (APIENTRYP PFNGLVIEWPORTPROC) (GLint x, GLint y, GLsizei width, GLsizei height);
typedef void (APIENTRYP PFNGLDRAWELEMENTSPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices); typedef void (APIENTRYP PFNGLDRAWELEMENTSPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
typedef void (APIENTRYP PFNGLGETINTEGERVPROC) (GLenum pname, GLint *params); typedef void (APIENTRYP PFNGLGETINTEGERVPROC) (GLenum pname, GLint *params);
typedef const GLubyte * (APIENTRYP PFNGLGETSTRINGPROC) (GLenum name); typedef const GLubyte * (APIENTRYP PFNGLGETSTRINGPROC) (GLenum name);
typedef void (APIENTRYP PFNGLDRAWARRAYSPROC) (GLenum mode, GLint first, GLsizei count); typedef void (APIENTRYP PFNGLDRAWARRAYSPROC) (GLenum mode, GLint first, GLsizei count);
typedef void (APIENTRYP PFNGLBLENDFUNCPROC) (GLenum sfactor, GLenum dfactor); typedef void (APIENTRYP PFNGLBLENDFUNCPROC) (GLenum sfactor, GLenum dfactor);
typedef void (APIENTRYP PFNGLPOINTSIZEPROC) (GLfloat size); typedef void (APIENTRYP PFNGLPOINTSIZEPROC) (GLfloat size);
typedef void (APIENTRYP PFNGLCULLFACEPROC) (GLenum mode); typedef void (APIENTRYP PFNGLCULLFACEPROC) (GLenum mode);
typedef void (APIENTRYP PFNGLCLEARPROC) (GLbitfield mask); typedef void (APIENTRYP PFNGLCLEARPROC) (GLbitfield mask);
typedef void (APIENTRYP PFNGLSCISSORPROC) (GLint x, GLint y, GLsizei width, GLsizei height); typedef void (APIENTRYP PFNGLSCISSORPROC) (GLint x, GLint y, GLsizei width, GLsizei height);
typedef void (APIENTRYP PFNGLENABLEPROC) (GLenum cap); typedef void (APIENTRYP PFNGLENABLEPROC) (GLenum cap);
typedef void (APIENTRYP PFNGLCLEARSTENCILPROC) (GLint s); typedef void (APIENTRYP PFNGLCLEARSTENCILPROC) (GLint s);
typedef void (APIENTRYP PFNGLDEPTHMASKPROC) (GLboolean flag); typedef void (APIENTRYP PFNGLDEPTHMASKPROC) (GLboolean flag);
typedef void (APIENTRYP PFNGLCLEARDEPTHPROC) (GLdouble depth); typedef void (APIENTRYP PFNGLCLEARDEPTHPROC) (GLdouble depth);
typedef void (APIENTRYP PFNGLCLEARCOLORPROC) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); typedef void (APIENTRYP PFNGLCLEARCOLORPROC) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
#endif // BGFX_USE_WGL #endif // BGFX_USE_WGL
#ifndef GL_APIENTRY #ifndef GL_APIENTRY
# define GL_APIENTRY APIENTRY # define GL_APIENTRY APIENTRY
#endif // GL_APIENTRY #endif // GL_APIENTRY
#ifndef GL_APIENTRYP #ifndef GL_APIENTRYP
# define GL_APIENTRYP APIENTRYP # define GL_APIENTRYP APIENTRYP
#endif // GL_APIENTRYP #endif // GL_APIENTRYP
namespace bgfx namespace bgfx
{ {
typedef void (GL_APIENTRYP PFNGLVERTEXATTRIBDIVISORBGFXPROC)(GLuint _index, GLuint _divisor); typedef void (GL_APIENTRYP PFNGLVERTEXATTRIBDIVISORBGFXPROC)(GLuint _index, GLuint _divisor);
typedef void (GL_APIENTRYP PFNGLDRAWARRAYSINSTANCEDBGFXPROC)(GLenum _mode, GLint _first, GLsizei _count, GLsizei _primcount); typedef void (GL_APIENTRYP PFNGLDRAWARRAYSINSTANCEDBGFXPROC)(GLenum _mode, GLint _first, GLsizei _count, GLsizei _primcount);
typedef void (GL_APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBGFXPROC)(GLenum _mode, GLsizei _count, GLenum _type, const GLvoid* _indices, GLsizei _primcount); typedef void (GL_APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBGFXPROC)(GLenum _mode, GLsizei _count, GLenum _type, const GLvoid* _indices, GLsizei _primcount);
# define _GL_CHECK(_call) \ # define _GL_CHECK(_call) \
do { \ do { \
/*BX_TRACE(#_call);*/ \ /*BX_TRACE(#_call);*/ \
_call; \ _call; \
GLenum err = glGetError(); \ GLenum err = glGetError(); \
BX_CHECK(0 == err, #_call "; glError 0x%x %d", err, err); \ BX_CHECK(0 == err, #_call "; glError 0x%x %d", err, err); \
} while (0) } while (0)
#if BGFX_CONFIG_DEBUG #if BGFX_CONFIG_DEBUG
# define GL_CHECK(_call) _GL_CHECK(_call) # define GL_CHECK(_call) _GL_CHECK(_call)
#else #else
# define GL_CHECK(_call) _call # define GL_CHECK(_call) _call
#endif // BGFX_CONFIG_DEBUG #endif // BGFX_CONFIG_DEBUG
#if BGFX_CONFIG_DEBUG_GREMEDY #if BGFX_CONFIG_DEBUG_GREMEDY
# define _GREMEDY_SETMARKER(_string) \ # define _GREMEDY_SETMARKER(_string) \
do \ do \
{ \ { \
if (NULL != glStringMarkerGREMEDY) \ if (NULL != glStringMarkerGREMEDY) \
{ \ { \
glStringMarkerGREMEDY( (GLsizei)strlen(_string), _string); \ glStringMarkerGREMEDY( (GLsizei)strlen(_string), _string); \
} \ } \
} while(0) } while(0)
# define _GREMEDY_FRAMETERMINATOR() \ # define _GREMEDY_FRAMETERMINATOR() \
do \ do \
{ \ { \
if (NULL != glStringMarkerGREMEDY) \ if (NULL != glStringMarkerGREMEDY) \
{ \ { \
glFrameTerminatorGREMEDY(); \ glFrameTerminatorGREMEDY(); \
} \ } \
} while(0) } while(0)
#else #else
# define _GREMEDY_SETMARKER(_string) do {} while(0) # define _GREMEDY_SETMARKER(_string) do {} while(0)
# define _GREMEDY_FRAMETERMINATOR() do {} while(0) # define _GREMEDY_FRAMETERMINATOR() do {} while(0)
#endif // BGFX_CONFIG_DEBUG_GREMEDY #endif // BGFX_CONFIG_DEBUG_GREMEDY
#define GREMEDY_SETMARKER(_string) _GREMEDY_SETMARKER(_string) #define GREMEDY_SETMARKER(_string) _GREMEDY_SETMARKER(_string)
#define GREMEDY_FRAMETERMINATOR() _GREMEDY_FRAMETERMINATOR() #define GREMEDY_FRAMETERMINATOR() _GREMEDY_FRAMETERMINATOR()
#if BGFX_USE_WGL #if BGFX_USE_WGL
extern PFNWGLGETPROCADDRESSPROC wglGetProcAddress; extern PFNWGLGETPROCADDRESSPROC wglGetProcAddress;
extern PFNWGLMAKECURRENTPROC wglMakeCurrent; extern PFNWGLMAKECURRENTPROC wglMakeCurrent;
extern PFNWGLCREATECONTEXTPROC wglCreateContext; extern PFNWGLCREATECONTEXTPROC wglCreateContext;
#endif // BGFX_USE_WGL #endif // BGFX_USE_WGL
#define GL_IMPORT(_optional, _proto, _func) extern _proto _func #define GL_IMPORT(_optional, _proto, _func) extern _proto _func
#include "glimports.h" #include "glimports.h"
#undef GL_IMPORT #undef GL_IMPORT
class ConstantBuffer; class ConstantBuffer;
struct IndexBuffer struct IndexBuffer
{ {
void create(uint32_t _size, void* _data) void create(uint32_t _size, void* _data)
{ {
m_size = _size; m_size = _size;
GL_CHECK(glGenBuffers(1, &m_id) ); GL_CHECK(glGenBuffers(1, &m_id) );
BX_CHECK(0 != m_id, "Failed to generate buffer id."); BX_CHECK(0 != m_id, "Failed to generate buffer id.");
GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_id) ); GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_id) );
GL_CHECK(glBufferData(GL_ELEMENT_ARRAY_BUFFER GL_CHECK(glBufferData(GL_ELEMENT_ARRAY_BUFFER
, _size , _size
, _data , _data
, (NULL==_data)?GL_DYNAMIC_DRAW:GL_STATIC_DRAW , (NULL==_data)?GL_DYNAMIC_DRAW:GL_STATIC_DRAW
) ); ) );
GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) ); GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) );
} }
void update(uint32_t _offset, uint32_t _size, void* _data) void update(uint32_t _offset, uint32_t _size, void* _data)
{ {
GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_id) ); GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_id) );
GL_CHECK(glBufferSubData(GL_ELEMENT_ARRAY_BUFFER GL_CHECK(glBufferSubData(GL_ELEMENT_ARRAY_BUFFER
, _offset , _offset
, _size , _size
, _data , _data
) ); ) );
GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) ); GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) );
} }
void destroy() void destroy()
{ {
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glDeleteBuffers(1, &m_id); glDeleteBuffers(1, &m_id);
} }
GLuint m_id; GLuint m_id;
uint32_t m_size; uint32_t m_size;
}; };
struct VertexBuffer struct VertexBuffer
{ {
void create(uint32_t _size, void* _data, VertexDeclHandle _declHandle) void create(uint32_t _size, void* _data, VertexDeclHandle _declHandle)
{ {
m_size = _size; m_size = _size;
m_decl = _declHandle; m_decl = _declHandle;
GL_CHECK(glGenBuffers(1, &m_id) ); GL_CHECK(glGenBuffers(1, &m_id) );
BX_CHECK(0 != m_id, "Failed to generate buffer id."); BX_CHECK(0 != m_id, "Failed to generate buffer id.");
GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, m_id) ); GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, m_id) );
GL_CHECK(glBufferData(GL_ARRAY_BUFFER GL_CHECK(glBufferData(GL_ARRAY_BUFFER
, _size , _size
, _data , _data
, (NULL==_data)?GL_DYNAMIC_DRAW:GL_STATIC_DRAW , (NULL==_data)?GL_DYNAMIC_DRAW:GL_STATIC_DRAW
) ); ) );
GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, 0) ); GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, 0) );
} }
void update(uint32_t _offset, uint32_t _size, void* _data) void update(uint32_t _offset, uint32_t _size, void* _data)
{ {
GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, m_id) ); GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, m_id) );
GL_CHECK(glBufferSubData(GL_ARRAY_BUFFER GL_CHECK(glBufferSubData(GL_ARRAY_BUFFER
, _offset , _offset
, _size , _size
, _data , _data
) ); ) );
GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, 0) ); GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, 0) );
} }
void destroy() void destroy()
{ {
GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, 0) ); GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, 0) );
GL_CHECK(glDeleteBuffers(1, &m_id) ); GL_CHECK(glDeleteBuffers(1, &m_id) );
} }
GLuint m_id; GLuint m_id;
uint32_t m_size; uint32_t m_size;
VertexDeclHandle m_decl; VertexDeclHandle m_decl;
}; };
struct Texture struct Texture
{ {
Texture() Texture()
: m_id(0) : m_id(0)
, m_target(GL_TEXTURE_2D) , m_target(GL_TEXTURE_2D)
{ {
} }
void create(const Memory* _mem, uint32_t _flags); void create(const Memory* _mem, uint32_t _flags);
void createColor(uint32_t _width, uint32_t _height, GLenum _min, GLenum _mag); void createColor(uint32_t _width, uint32_t _height, GLenum _min, GLenum _mag);
void createDepth(uint32_t _width, uint32_t _height); void createDepth(uint32_t _width, uint32_t _height);
void destroy(); void destroy();
GLuint m_id; GLuint m_id;
GLenum m_target; GLenum m_target;
}; };
struct Shader struct Shader
{ {
void create(GLenum _type, const uint8_t* _code) void create(GLenum _type, const uint8_t* _code)
{ {
m_id = glCreateShader(_type); m_id = glCreateShader(_type);
m_type = _type; m_type = _type;
if (0 != m_id) if (0 != m_id)
{ {
m_hash = hash(_code, (uint32_t)strlen( (const char*)_code) ); m_hash = hash(_code, (uint32_t)strlen( (const char*)_code) );
GL_CHECK(glShaderSource(m_id, 1, (const GLchar**)&_code, NULL) ); GL_CHECK(glShaderSource(m_id, 1, (const GLchar**)&_code, NULL) );
GL_CHECK(glCompileShader(m_id) ); GL_CHECK(glCompileShader(m_id) );
GLint compiled = 0; GLint compiled = 0;
GL_CHECK(glGetShaderiv(m_id, GL_COMPILE_STATUS, &compiled) ); GL_CHECK(glGetShaderiv(m_id, GL_COMPILE_STATUS, &compiled) );
if (0 == compiled) if (0 == compiled)
{ {
char log[1024]; char log[1024];
GL_CHECK(glGetShaderInfoLog(m_id, sizeof(log), NULL, log) ); GL_CHECK(glGetShaderInfoLog(m_id, sizeof(log), NULL, log) );
BX_TRACE("Failed to compile shader. %d: %s", compiled, log); BX_TRACE("Failed to compile shader. %d: %s", compiled, log);
BX_TRACE("\n####\n%s\n####", _code); BX_TRACE("\n####\n%s\n####", _code);
GL_CHECK(glDeleteShader(m_id) ); GL_CHECK(glDeleteShader(m_id) );
} }
} }
} }
void destroy() void destroy()
{ {
GL_CHECK(glDeleteShader(m_id) ); GL_CHECK(glDeleteShader(m_id) );
} }
GLuint m_id; GLuint m_id;
GLenum m_type; GLenum m_type;
uint32_t m_hash; uint32_t m_hash;
}; };
struct RenderTarget struct RenderTarget
{ {
void create(uint16_t _width, uint16_t _height, uint32_t _flags, uint32_t _textureFlags); void create(uint16_t _width, uint16_t _height, uint32_t _flags, uint32_t _textureFlags);
void destroy(); void destroy();
GLsizei m_width; GLsizei m_width;
GLsizei m_height; GLsizei m_height;
Texture m_color; Texture m_color;
Texture m_depth; Texture m_depth;
GLuint m_fbo; GLuint m_fbo;
GLuint m_rbo; GLuint m_rbo;
}; };
struct Material struct Material
{ {
void create(const Shader& _vsh, const Shader& _fsh); void create(const Shader& _vsh, const Shader& _fsh);
void destroy(); void destroy();
void init(); void init();
void bindAttributes(const VertexDecl& _vertexDecl, uint32_t _baseVertex = 0) const; void bindAttributes(const VertexDecl& _vertexDecl, uint32_t _baseVertex = 0) const;
void bindInstanceData(uint32_t _stride, uint32_t _baseVertex = 0) const; void bindInstanceData(uint32_t _stride, uint32_t _baseVertex = 0) const;
GLuint m_id; GLuint m_id;
uint8_t m_used[Attrib::Count+1]; // dense uint8_t m_used[Attrib::Count+1]; // dense
uint16_t m_attributes[Attrib::Count]; // sparse uint16_t m_attributes[Attrib::Count]; // sparse
uint16_t m_instanceData[BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT]; uint16_t m_instanceData[BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT];
uint32_t m_enabled; uint32_t m_enabled;
GLuint m_sampler[BGFX_CONFIG_MAX_TEXTURES]; GLuint m_sampler[BGFX_CONFIG_MAX_TEXTURES];
uint8_t m_numSamplers; uint8_t m_numSamplers;
ConstantBuffer* m_constantBuffer; ConstantBuffer* m_constantBuffer;
PredefinedUniform m_predefined[PredefinedUniform::Count]; PredefinedUniform m_predefined[PredefinedUniform::Count];
uint8_t m_numPredefined; uint8_t m_numPredefined;
}; };
#if BGFX_CONFIG_RENDERER_OPENGL #if BGFX_CONFIG_RENDERER_OPENGL
struct Queries struct Queries
{ {
void create() void create()
{ {
glGenQueries(countof(m_queries), m_queries); glGenQueries(countof(m_queries), m_queries);
} }
void destroy() void destroy()
{ {
glDeleteQueries(countof(m_queries), m_queries); glDeleteQueries(countof(m_queries), m_queries);
} }
void begin(uint16_t _id, GLenum _target) const void begin(uint16_t _id, GLenum _target) const
{ {
glBeginQuery(_target, m_queries[_id]); glBeginQuery(_target, m_queries[_id]);
} }
void end(GLenum _target) const void end(GLenum _target) const
{ {
glEndQuery(_target); glEndQuery(_target);
} }
uint64_t getResult(uint16_t _id) const uint64_t getResult(uint16_t _id) const
{ {
uint64_t result; uint64_t result;
glGetQueryObjectui64v(m_queries[_id], GL_QUERY_RESULT, &result); glGetQueryObjectui64v(m_queries[_id], GL_QUERY_RESULT, &result);
return result; return result;
} }
GLuint m_queries[64]; GLuint m_queries[64];
}; };
#endif // BGFX_CONFIG_RENDERER_OPENGL #endif // BGFX_CONFIG_RENDERER_OPENGL
} // namespace bgfx } // namespace bgfx
#endif // __RENDERER_GL_H__ #endif // __RENDERER_GL_H__