mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-25 00:58:30 -05:00
Merge branch 'master' of github.com:bkaradzic/bgfx
This commit is contained in:
commit
6b9cc431fd
9 changed files with 169 additions and 125 deletions
|
@ -22,8 +22,8 @@ struct PosNormalTangentTexcoordVertex
|
||||||
float m_z;
|
float m_z;
|
||||||
uint32_t m_normal;
|
uint32_t m_normal;
|
||||||
uint32_t m_tangent;
|
uint32_t m_tangent;
|
||||||
float m_u;
|
int16_t m_u;
|
||||||
float m_v;
|
int16_t m_v;
|
||||||
};
|
};
|
||||||
|
|
||||||
static bgfx::VertexDecl s_PosNormalTangentTexcoordDecl;
|
static bgfx::VertexDecl s_PosNormalTangentTexcoordDecl;
|
||||||
|
@ -55,30 +55,30 @@ uint32_t packF4u(float _x, float _y = 0.0f, float _z = 0.0f, float _w = 0.0f)
|
||||||
|
|
||||||
static PosNormalTangentTexcoordVertex s_cubeVertices[24] =
|
static PosNormalTangentTexcoordVertex s_cubeVertices[24] =
|
||||||
{
|
{
|
||||||
{-1.0f, 1.0f, 1.0f, packF4u( 0.0f, 0.0f, 1.0f), 0, 0.0f, 0.0f },
|
{-1.0f, 1.0f, 1.0f, packF4u( 0.0f, 0.0f, 1.0f), 0, 0, 0 },
|
||||||
{ 1.0f, 1.0f, 1.0f, packF4u( 0.0f, 0.0f, 1.0f), 0, 1.0f, 0.0f },
|
{ 1.0f, 1.0f, 1.0f, packF4u( 0.0f, 0.0f, 1.0f), 0, 0x7fff, 0 },
|
||||||
{-1.0f, -1.0f, 1.0f, packF4u( 0.0f, 0.0f, 1.0f), 0, 0.0f, 1.0f },
|
{-1.0f, -1.0f, 1.0f, packF4u( 0.0f, 0.0f, 1.0f), 0, 0, 0x7fff },
|
||||||
{ 1.0f, -1.0f, 1.0f, packF4u( 0.0f, 0.0f, 1.0f), 0, 1.0f, 1.0f },
|
{ 1.0f, -1.0f, 1.0f, packF4u( 0.0f, 0.0f, 1.0f), 0, 0x7fff, 0x7fff },
|
||||||
{-1.0f, 1.0f, -1.0f, packF4u( 0.0f, 0.0f, -1.0f), 0, 0.0f, 0.0f },
|
{-1.0f, 1.0f, -1.0f, packF4u( 0.0f, 0.0f, -1.0f), 0, 0, 0 },
|
||||||
{ 1.0f, 1.0f, -1.0f, packF4u( 0.0f, 0.0f, -1.0f), 0, 1.0f, 0.0f },
|
{ 1.0f, 1.0f, -1.0f, packF4u( 0.0f, 0.0f, -1.0f), 0, 0x7fff, 0 },
|
||||||
{-1.0f, -1.0f, -1.0f, packF4u( 0.0f, 0.0f, -1.0f), 0, 0.0f, 1.0f },
|
{-1.0f, -1.0f, -1.0f, packF4u( 0.0f, 0.0f, -1.0f), 0, 0, 0x7fff },
|
||||||
{ 1.0f, -1.0f, -1.0f, packF4u( 0.0f, 0.0f, -1.0f), 0, 1.0f, 1.0f },
|
{ 1.0f, -1.0f, -1.0f, packF4u( 0.0f, 0.0f, -1.0f), 0, 0x7fff, 0x7fff },
|
||||||
{-1.0f, 1.0f, 1.0f, packF4u( 0.0f, 1.0f, 0.0f), 0, 0.0f, 0.0f },
|
{-1.0f, 1.0f, 1.0f, packF4u( 0.0f, 1.0f, 0.0f), 0, 0, 0 },
|
||||||
{ 1.0f, 1.0f, 1.0f, packF4u( 0.0f, 1.0f, 0.0f), 0, 1.0f, 0.0f },
|
{ 1.0f, 1.0f, 1.0f, packF4u( 0.0f, 1.0f, 0.0f), 0, 0x7fff, 0 },
|
||||||
{-1.0f, 1.0f, -1.0f, packF4u( 0.0f, 1.0f, 0.0f), 0, 0.0f, 1.0f },
|
{-1.0f, 1.0f, -1.0f, packF4u( 0.0f, 1.0f, 0.0f), 0, 0, 0x7fff },
|
||||||
{ 1.0f, 1.0f, -1.0f, packF4u( 0.0f, 1.0f, 0.0f), 0, 1.0f, 1.0f },
|
{ 1.0f, 1.0f, -1.0f, packF4u( 0.0f, 1.0f, 0.0f), 0, 0x7fff, 0x7fff },
|
||||||
{-1.0f, -1.0f, 1.0f, packF4u( 0.0f, -1.0f, 0.0f), 0, 0.0f, 0.0f },
|
{-1.0f, -1.0f, 1.0f, packF4u( 0.0f, -1.0f, 0.0f), 0, 0, 0 },
|
||||||
{ 1.0f, -1.0f, 1.0f, packF4u( 0.0f, -1.0f, 0.0f), 0, 1.0f, 0.0f },
|
{ 1.0f, -1.0f, 1.0f, packF4u( 0.0f, -1.0f, 0.0f), 0, 0x7fff, 0 },
|
||||||
{-1.0f, -1.0f, -1.0f, packF4u( 0.0f, -1.0f, 0.0f), 0, 0.0f, 1.0f },
|
{-1.0f, -1.0f, -1.0f, packF4u( 0.0f, -1.0f, 0.0f), 0, 0, 0x7fff },
|
||||||
{ 1.0f, -1.0f, -1.0f, packF4u( 0.0f, -1.0f, 0.0f), 0, 1.0f, 1.0f },
|
{ 1.0f, -1.0f, -1.0f, packF4u( 0.0f, -1.0f, 0.0f), 0, 0x7fff, 0x7fff },
|
||||||
{ 1.0f, -1.0f, 1.0f, packF4u( 1.0f, 0.0f, 0.0f), 0, 0.0f, 0.0f },
|
{ 1.0f, -1.0f, 1.0f, packF4u( 1.0f, 0.0f, 0.0f), 0, 0, 0 },
|
||||||
{ 1.0f, 1.0f, 1.0f, packF4u( 1.0f, 0.0f, 0.0f), 0, 1.0f, 0.0f },
|
{ 1.0f, 1.0f, 1.0f, packF4u( 1.0f, 0.0f, 0.0f), 0, 0x7fff, 0 },
|
||||||
{ 1.0f, -1.0f, -1.0f, packF4u( 1.0f, 0.0f, 0.0f), 0, 0.0f, 1.0f },
|
{ 1.0f, -1.0f, -1.0f, packF4u( 1.0f, 0.0f, 0.0f), 0, 0, 0x7fff },
|
||||||
{ 1.0f, 1.0f, -1.0f, packF4u( 1.0f, 0.0f, 0.0f), 0, 1.0f, 1.0f },
|
{ 1.0f, 1.0f, -1.0f, packF4u( 1.0f, 0.0f, 0.0f), 0, 0x7fff, 0x7fff },
|
||||||
{-1.0f, -1.0f, 1.0f, packF4u(-1.0f, 0.0f, 0.0f), 0, 0.0f, 0.0f },
|
{-1.0f, -1.0f, 1.0f, packF4u(-1.0f, 0.0f, 0.0f), 0, 0, 0 },
|
||||||
{-1.0f, 1.0f, 1.0f, packF4u(-1.0f, 0.0f, 0.0f), 0, 1.0f, 0.0f },
|
{-1.0f, 1.0f, 1.0f, packF4u(-1.0f, 0.0f, 0.0f), 0, 0x7fff, 0 },
|
||||||
{-1.0f, -1.0f, -1.0f, packF4u(-1.0f, 0.0f, 0.0f), 0, 0.0f, 1.0f },
|
{-1.0f, -1.0f, -1.0f, packF4u(-1.0f, 0.0f, 0.0f), 0, 0, 0x7fff },
|
||||||
{-1.0f, 1.0f, -1.0f, packF4u(-1.0f, 0.0f, 0.0f), 0, 1.0f, 1.0f },
|
{-1.0f, 1.0f, -1.0f, packF4u(-1.0f, 0.0f, 0.0f), 0, 0x7fff, 0x7fff },
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint16_t s_cubeIndices[36] =
|
static const uint16_t s_cubeIndices[36] =
|
||||||
|
@ -299,7 +299,7 @@ int _main_(int _argc, char** _argv)
|
||||||
s_PosNormalTangentTexcoordDecl.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float);
|
s_PosNormalTangentTexcoordDecl.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float);
|
||||||
s_PosNormalTangentTexcoordDecl.add(bgfx::Attrib::Normal, 4, bgfx::AttribType::Uint8, true, true);
|
s_PosNormalTangentTexcoordDecl.add(bgfx::Attrib::Normal, 4, bgfx::AttribType::Uint8, true, true);
|
||||||
s_PosNormalTangentTexcoordDecl.add(bgfx::Attrib::Tangent, 4, bgfx::AttribType::Uint8, true, true);
|
s_PosNormalTangentTexcoordDecl.add(bgfx::Attrib::Tangent, 4, bgfx::AttribType::Uint8, true, true);
|
||||||
s_PosNormalTangentTexcoordDecl.add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Float);
|
s_PosNormalTangentTexcoordDecl.add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Int16, true, true);
|
||||||
s_PosNormalTangentTexcoordDecl.end();
|
s_PosNormalTangentTexcoordDecl.end();
|
||||||
|
|
||||||
const bgfx::Memory* mem;
|
const bgfx::Memory* mem;
|
||||||
|
|
|
@ -284,7 +284,7 @@ namespace bgfx
|
||||||
enum Enum
|
enum Enum
|
||||||
{
|
{
|
||||||
Uint8,
|
Uint8,
|
||||||
Uint16,
|
Int16,
|
||||||
Half,
|
Half,
|
||||||
Float,
|
Float,
|
||||||
|
|
||||||
|
@ -450,6 +450,14 @@ namespace bgfx
|
||||||
|
|
||||||
/// Add attribute to VertexDecl.
|
/// Add attribute to VertexDecl.
|
||||||
///
|
///
|
||||||
|
/// @param _attrib Attribute semantics.
|
||||||
|
/// @param _num Number of elements 1, 2, 3 or 4.
|
||||||
|
/// @param _type Element type.
|
||||||
|
/// @param _normalized Value is normalized for vertex shader.
|
||||||
|
/// @param _asInt Packaging rule for vertexPack, vertexUnpack, and
|
||||||
|
/// vertexConvert for AttribType::Uint8 and AttribType::Int16.
|
||||||
|
/// Unpacking code must be implemented inside vertex shader.
|
||||||
|
///
|
||||||
/// NOTE:
|
/// NOTE:
|
||||||
/// Must be called between begin/end.
|
/// Must be called between begin/end.
|
||||||
void add(Attrib::Enum _attrib, uint8_t _num, AttribType::Enum _type, bool _normalized = false, bool _asInt = false);
|
void add(Attrib::Enum _attrib, uint8_t _num, AttribType::Enum _type, bool _normalized = false, bool _asInt = false);
|
||||||
|
|
|
@ -194,12 +194,12 @@ namespace bgfx
|
||||||
const char* getAttribName(Attrib::Enum _attr);
|
const char* getAttribName(Attrib::Enum _attr);
|
||||||
bool renderFrame();
|
bool renderFrame();
|
||||||
|
|
||||||
inline uint32_t uint16_min(uint16_t _a, uint16_t _b)
|
inline uint16_t uint16_min(uint16_t _a, uint16_t _b)
|
||||||
{
|
{
|
||||||
return _a > _b ? _b : _a;
|
return _a > _b ? _b : _a;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline uint32_t uint16_max(uint16_t _a, uint16_t _b)
|
inline uint16_t uint16_max(uint16_t _a, uint16_t _b)
|
||||||
{
|
{
|
||||||
return _a < _b ? _b : _a;
|
return _a < _b ? _b : _a;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,51 @@ namespace bgfx
|
||||||
# include "glimports.h"
|
# include "glimports.h"
|
||||||
# undef GL_IMPORT
|
# undef GL_IMPORT
|
||||||
|
|
||||||
|
static HGLRC createContext(HDC _hdc)
|
||||||
|
{
|
||||||
|
PIXELFORMATDESCRIPTOR pfd;
|
||||||
|
memset(&pfd, 0, sizeof(pfd) );
|
||||||
|
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
|
||||||
|
pfd.nVersion = 1;
|
||||||
|
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
|
||||||
|
pfd.iPixelType = PFD_TYPE_RGBA;
|
||||||
|
pfd.cColorBits = 32;
|
||||||
|
pfd.cAlphaBits = 8;
|
||||||
|
pfd.cDepthBits = 24;
|
||||||
|
pfd.cStencilBits = 8;
|
||||||
|
pfd.iLayerType = PFD_MAIN_PLANE;
|
||||||
|
|
||||||
|
int pixelFormat = ChoosePixelFormat(_hdc, &pfd);
|
||||||
|
BGFX_FATAL(0 != pixelFormat, Fatal::UnableToInitialize, "ChoosePixelFormat failed!");
|
||||||
|
|
||||||
|
DescribePixelFormat(_hdc, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
|
||||||
|
|
||||||
|
BX_TRACE("Pixel format:\n"
|
||||||
|
"\tiPixelType %d\n"
|
||||||
|
"\tcColorBits %d\n"
|
||||||
|
"\tcAlphaBits %d\n"
|
||||||
|
"\tcDepthBits %d\n"
|
||||||
|
"\tcStencilBits %d\n"
|
||||||
|
, pfd.iPixelType
|
||||||
|
, pfd.cColorBits
|
||||||
|
, pfd.cAlphaBits
|
||||||
|
, pfd.cDepthBits
|
||||||
|
, pfd.cStencilBits
|
||||||
|
);
|
||||||
|
|
||||||
|
int result;
|
||||||
|
result = SetPixelFormat(_hdc, pixelFormat, &pfd);
|
||||||
|
BGFX_FATAL(0 != result, Fatal::UnableToInitialize, "SetPixelFormat failed!");
|
||||||
|
|
||||||
|
HGLRC context = wglCreateContext(_hdc);
|
||||||
|
BGFX_FATAL(NULL != context, Fatal::UnableToInitialize, "wglCreateContext failed!");
|
||||||
|
|
||||||
|
result = wglMakeCurrent(_hdc, context);
|
||||||
|
BGFX_FATAL(0 != result, Fatal::UnableToInitialize, "wglMakeCurrent failed!");
|
||||||
|
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
void GlContext::create(uint32_t _width, uint32_t _height)
|
void GlContext::create(uint32_t _width, uint32_t _height)
|
||||||
{
|
{
|
||||||
m_opengl32dll = LoadLibrary("opengl32.dll");
|
m_opengl32dll = LoadLibrary("opengl32.dll");
|
||||||
|
@ -44,44 +89,28 @@ namespace bgfx
|
||||||
m_hdc = GetDC(g_bgfxHwnd);
|
m_hdc = GetDC(g_bgfxHwnd);
|
||||||
BGFX_FATAL(NULL != m_hdc, Fatal::UnableToInitialize, "GetDC failed!");
|
BGFX_FATAL(NULL != m_hdc, Fatal::UnableToInitialize, "GetDC failed!");
|
||||||
|
|
||||||
PIXELFORMATDESCRIPTOR pfd;
|
// Dummy window to peek into WGL functionality.
|
||||||
memset(&pfd, 0, sizeof(pfd) );
|
//
|
||||||
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
|
// An application can only set the pixel format of a window one time.
|
||||||
pfd.nVersion = 1;
|
// Once a window's pixel format is set, it cannot be changed.
|
||||||
pfd.iPixelType = PFD_TYPE_RGBA;
|
// MSDN: http://msdn.microsoft.com/en-us/library/windows/desktop/dd369049%28v=vs.85%29.aspx
|
||||||
pfd.cColorBits = 32;
|
HWND hwnd = CreateWindowA("STATIC"
|
||||||
pfd.cAlphaBits = 8;
|
, ""
|
||||||
pfd.cDepthBits = 24;
|
, WS_POPUP|WS_DISABLED
|
||||||
pfd.cStencilBits = 8;
|
, -32000
|
||||||
pfd.iLayerType = PFD_MAIN_PLANE;
|
, -32000
|
||||||
|
, 0
|
||||||
int pixelFormat = ChoosePixelFormat(m_hdc, &pfd);
|
, 0
|
||||||
BGFX_FATAL(0 != pixelFormat, Fatal::UnableToInitialize, "ChoosePixelFormat failed!");
|
, NULL
|
||||||
|
, NULL
|
||||||
DescribePixelFormat(m_hdc, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
|
, GetModuleHandle(NULL)
|
||||||
|
, 0
|
||||||
BX_TRACE("Pixel format:\n"
|
|
||||||
"\tiPixelType %d\n"
|
|
||||||
"\tcColorBits %d\n"
|
|
||||||
"\tcAlphaBits %d\n"
|
|
||||||
"\tcDepthBits %d\n"
|
|
||||||
"\tcStencilBits %d\n"
|
|
||||||
, pfd.iPixelType
|
|
||||||
, pfd.cColorBits
|
|
||||||
, pfd.cAlphaBits
|
|
||||||
, pfd.cDepthBits
|
|
||||||
, pfd.cStencilBits
|
|
||||||
);
|
);
|
||||||
|
|
||||||
int result;
|
HDC hdc = GetDC(hwnd);
|
||||||
result = SetPixelFormat(m_hdc, pixelFormat, &pfd);
|
BGFX_FATAL(NULL != hdc, Fatal::UnableToInitialize, "GetDC failed!");
|
||||||
BGFX_FATAL(0 != result, Fatal::UnableToInitialize, "SetPixelFormat failed!");
|
|
||||||
|
|
||||||
m_context = wglCreateContext(m_hdc);
|
HGLRC context = createContext(hdc);
|
||||||
BGFX_FATAL(NULL != m_context, Fatal::UnableToInitialize, "wglCreateContext failed!");
|
|
||||||
|
|
||||||
result = wglMakeCurrent(m_hdc, m_context);
|
|
||||||
BGFX_FATAL(0 != result, Fatal::UnableToInitialize, "wglMakeCurrent failed!");
|
|
||||||
|
|
||||||
wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
|
wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
|
||||||
wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
|
wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
|
||||||
|
@ -90,7 +119,7 @@ namespace bgfx
|
||||||
if (NULL != wglGetExtensionsStringARB)
|
if (NULL != wglGetExtensionsStringARB)
|
||||||
{
|
{
|
||||||
BX_TRACE("WGL extensions:");
|
BX_TRACE("WGL extensions:");
|
||||||
const char* extensions = (const char*)wglGetExtensionsStringARB(m_hdc);
|
const char* extensions = (const char*)wglGetExtensionsStringARB(hdc);
|
||||||
if (NULL != extensions)
|
if (NULL != extensions)
|
||||||
{
|
{
|
||||||
char name[1024];
|
char name[1024];
|
||||||
|
@ -119,10 +148,6 @@ namespace bgfx
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
// An application can only set the pixel format of a window one time.
|
|
||||||
// Once a window's pixel format is set, it cannot be changed.
|
|
||||||
// MSDN: http://msdn.microsoft.com/en-us/library/windows/desktop/dd369049%28v=vs.85%29.aspx
|
|
||||||
if (NULL != wglChoosePixelFormatARB
|
if (NULL != wglChoosePixelFormatARB
|
||||||
&& NULL != wglCreateContextAttribsARB)
|
&& NULL != wglCreateContextAttribsARB)
|
||||||
{
|
{
|
||||||
|
@ -134,15 +159,14 @@ namespace bgfx
|
||||||
WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
|
WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
|
||||||
WGL_DRAW_TO_WINDOW_ARB, true,
|
WGL_DRAW_TO_WINDOW_ARB, true,
|
||||||
WGL_DOUBLE_BUFFER_ARB, true,
|
WGL_DOUBLE_BUFFER_ARB, true,
|
||||||
WGL_RED_BITS_ARB, 8,
|
WGL_COLOR_BITS_ARB, 32,
|
||||||
WGL_BLUE_BITS_ARB, 8,
|
|
||||||
WGL_GREEN_BITS_ARB, 8,
|
|
||||||
WGL_ALPHA_BITS_ARB, 8,
|
|
||||||
WGL_DEPTH_BITS_ARB, 24,
|
WGL_DEPTH_BITS_ARB, 24,
|
||||||
WGL_STENCIL_BITS_ARB, 8,
|
WGL_STENCIL_BITS_ARB, 8,
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int result;
|
||||||
|
int pixelFormat;
|
||||||
uint32_t numFormats = 0;
|
uint32_t numFormats = 0;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
@ -156,6 +180,7 @@ namespace bgfx
|
||||||
|
|
||||||
} while (0 == numFormats);
|
} while (0 == numFormats);
|
||||||
|
|
||||||
|
PIXELFORMATDESCRIPTOR pfd;
|
||||||
DescribePixelFormat(m_hdc, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
|
DescribePixelFormat(m_hdc, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
|
||||||
|
|
||||||
BX_TRACE("Pixel format:\n"
|
BX_TRACE("Pixel format:\n"
|
||||||
|
@ -174,13 +199,16 @@ namespace bgfx
|
||||||
result = SetPixelFormat(m_hdc, pixelFormat, &pfd);
|
result = SetPixelFormat(m_hdc, pixelFormat, &pfd);
|
||||||
BGFX_FATAL(0 != result, Fatal::UnableToInitialize, "SetPixelFormat failed (last err: 0x%08x)!", GetLastError() );
|
BGFX_FATAL(0 != result, Fatal::UnableToInitialize, "SetPixelFormat failed (last err: 0x%08x)!", GetLastError() );
|
||||||
|
|
||||||
wglMakeCurrent(m_hdc, NULL);
|
|
||||||
wglDeleteContext(m_context);
|
|
||||||
|
|
||||||
const int32_t contextAttrs[] =
|
const int32_t contextAttrs[] =
|
||||||
{
|
{
|
||||||
WGL_CONTEXT_MAJOR_VERSION_ARB, 2,
|
#if 1
|
||||||
WGL_CONTEXT_MINOR_VERSION_ARB, 1,
|
WGL_CONTEXT_MAJOR_VERSION_ARB, 2,
|
||||||
|
WGL_CONTEXT_MINOR_VERSION_ARB, 1,
|
||||||
|
#else
|
||||||
|
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
|
||||||
|
WGL_CONTEXT_MINOR_VERSION_ARB, 2,
|
||||||
|
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
|
||||||
|
#endif // 1
|
||||||
#if BGFX_CONFIG_DEBUG
|
#if BGFX_CONFIG_DEBUG
|
||||||
WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB,
|
WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB,
|
||||||
#endif // BGFX_CONFIG_DEBUG
|
#endif // BGFX_CONFIG_DEBUG
|
||||||
|
@ -188,12 +216,19 @@ namespace bgfx
|
||||||
};
|
};
|
||||||
|
|
||||||
m_context = wglCreateContextAttribsARB(m_hdc, 0, contextAttrs);
|
m_context = wglCreateContextAttribsARB(m_hdc, 0, contextAttrs);
|
||||||
|
|
||||||
result = wglMakeCurrent(m_hdc, m_context);
|
|
||||||
BGFX_FATAL(0 != result, Fatal::UnableToInitialize, "wglMakeCurrent failed!");
|
|
||||||
}
|
}
|
||||||
#endif // 0
|
|
||||||
|
|
||||||
|
wglMakeCurrent(NULL, NULL);
|
||||||
|
wglDeleteContext(context);
|
||||||
|
DestroyWindow(hwnd);
|
||||||
|
|
||||||
|
if (NULL == m_context)
|
||||||
|
{
|
||||||
|
m_context = createContext(m_hdc);
|
||||||
|
}
|
||||||
|
|
||||||
|
int result = wglMakeCurrent(m_hdc, m_context);
|
||||||
|
BGFX_FATAL(0 != result, Fatal::UnableToInitialize, "wglMakeCurrent failed!");
|
||||||
import();
|
import();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
#ifndef __RENDERER_D3D_H__
|
#ifndef __RENDERER_D3D_H__
|
||||||
#define __RENDERER_D3D_H__
|
#define __RENDERER_D3D_H__
|
||||||
|
|
||||||
#if BGFX_CONFIG_DEBUG && BX_PLATFORM_WINDOWS && BX_COMPILER_MSVC
|
#if BGFX_CONFIG_RENDERER_DIRECT3D9
|
||||||
# include <dxerr.h>
|
# include <dxerr.h>
|
||||||
# pragma comment(lib, "dxerr.lib")
|
# pragma comment(lib, "dxerr.lib")
|
||||||
# define DX_CHECK_EXTRA_F " (%s): %s"
|
# define DX_CHECK_EXTRA_F " (%s): %s"
|
||||||
|
@ -14,7 +14,7 @@
|
||||||
#else
|
#else
|
||||||
# define DX_CHECK_EXTRA_F ""
|
# define DX_CHECK_EXTRA_F ""
|
||||||
# define DX_CHECK_EXTRA_ARGS
|
# define DX_CHECK_EXTRA_ARGS
|
||||||
#endif // BGFX_CONFIG_DEBUG && BX_PLATFORM_WINDOWS && BX_COMPILER_MSVC
|
#endif // BGFX_CONFIG_RENDERER_DIRECT3D9
|
||||||
|
|
||||||
namespace bgfx
|
namespace bgfx
|
||||||
{
|
{
|
||||||
|
|
|
@ -194,10 +194,10 @@ namespace bgfx
|
||||||
{ DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_UNORM },
|
{ DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_UNORM },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
{ DXGI_FORMAT_R16_UINT, DXGI_FORMAT_R16_UNORM },
|
{ DXGI_FORMAT_R16_SINT, DXGI_FORMAT_R16_SNORM },
|
||||||
{ DXGI_FORMAT_R16G16_UINT, DXGI_FORMAT_R16G16_UNORM },
|
{ DXGI_FORMAT_R16G16_SINT, DXGI_FORMAT_R16G16_SNORM },
|
||||||
{ DXGI_FORMAT_R16G16B16A16_UINT, DXGI_FORMAT_R16G16B16A16_UNORM },
|
{ DXGI_FORMAT_R16G16B16A16_SINT, DXGI_FORMAT_R16G16B16A16_SNORM },
|
||||||
{ DXGI_FORMAT_R16G16B16A16_UINT, DXGI_FORMAT_R16G16B16A16_UNORM },
|
{ DXGI_FORMAT_R16G16B16A16_SINT, DXGI_FORMAT_R16G16B16A16_SNORM },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
{ DXGI_FORMAT_R16_FLOAT, DXGI_FORMAT_R16_FLOAT },
|
{ DXGI_FORMAT_R16_FLOAT, DXGI_FORMAT_R16_FLOAT },
|
||||||
|
@ -2568,7 +2568,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(0, 0, BGFX_CONFIG_DEBUG ? 0x89 : 0x8f, " " BGFX_RENDERER_NAME " ");
|
||||||
tvm.printf(10, pos++, 0x8e, " Frame: %7.3f, % 7.3f \x1f, % 7.3f \x1e [ms] / % 6.2f FPS"
|
tvm.printf(10, pos++, 0x8e, " Frame: %7.3f, % 7.3f \x1f, % 7.3f \x1e [ms] / % 6.2f FPS"
|
||||||
, double(frameTime)*toMs
|
, double(frameTime)*toMs
|
||||||
, double(min)*toMs
|
, double(min)*toMs
|
||||||
|
|
|
@ -2671,7 +2671,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(0, 0, BGFX_CONFIG_DEBUG ? 0x89 : 0x8f, " " BGFX_RENDERER_NAME " ");
|
||||||
tvm.printf(10, pos++, 0x8e, " Frame: %7.3f, % 7.3f \x1f, % 7.3f \x1e [ms] / % 6.2f FPS"
|
tvm.printf(10, pos++, 0x8e, " Frame: %7.3f, % 7.3f \x1f, % 7.3f \x1e [ms] / % 6.2f FPS"
|
||||||
, double(frameTime)*toMs
|
, double(frameTime)*toMs
|
||||||
, double(min)*toMs
|
, double(min)*toMs
|
||||||
|
|
|
@ -117,12 +117,12 @@ namespace bgfx
|
||||||
|
|
||||||
static void GL_APIENTRY stubDrawArraysInstanced(GLenum _mode, GLint _first, GLsizei _count, GLsizei /*_primcount*/)
|
static void GL_APIENTRY stubDrawArraysInstanced(GLenum _mode, GLint _first, GLsizei _count, GLsizei /*_primcount*/)
|
||||||
{
|
{
|
||||||
glDrawArrays(_mode, _first, _count);
|
GL_CHECK(glDrawArrays(_mode, _first, _count) );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void GL_APIENTRY stubDrawElementsInstanced(GLenum _mode, GLsizei _count, GLenum _type, const GLvoid* _indices, GLsizei /*_primcount*/)
|
static void GL_APIENTRY stubDrawElementsInstanced(GLenum _mode, GLsizei _count, GLenum _type, const GLvoid* _indices, GLsizei /*_primcount*/)
|
||||||
{
|
{
|
||||||
glDrawElements(_mode, _count, _type, _indices);
|
GL_CHECK(glDrawElements(_mode, _count, _type, _indices) );
|
||||||
}
|
}
|
||||||
|
|
||||||
#if BGFX_CONFIG_RENDERER_OPENGLES3
|
#if BGFX_CONFIG_RENDERER_OPENGLES3
|
||||||
|
@ -534,7 +534,7 @@ namespace bgfx
|
||||||
static const GLenum s_attribType[AttribType::Count] =
|
static const GLenum s_attribType[AttribType::Count] =
|
||||||
{
|
{
|
||||||
GL_UNSIGNED_BYTE,
|
GL_UNSIGNED_BYTE,
|
||||||
GL_UNSIGNED_SHORT,
|
GL_SHORT,
|
||||||
GL_HALF_FLOAT,
|
GL_HALF_FLOAT,
|
||||||
GL_FLOAT,
|
GL_FLOAT,
|
||||||
};
|
};
|
||||||
|
@ -1404,7 +1404,7 @@ namespace bgfx
|
||||||
if (0 != (_flags & (BGFX_TEXTURE_MIN_ANISOTROPIC|BGFX_TEXTURE_MAG_ANISOTROPIC) )
|
if (0 != (_flags & (BGFX_TEXTURE_MIN_ANISOTROPIC|BGFX_TEXTURE_MAG_ANISOTROPIC) )
|
||||||
&& 0.0f < s_renderCtx.m_maxAnisotropy)
|
&& 0.0f < s_renderCtx.m_maxAnisotropy)
|
||||||
{
|
{
|
||||||
glTexParameterf(m_target, GL_TEXTURE_MAX_ANISOTROPY_EXT, s_renderCtx.m_maxAnisotropy);
|
GL_CHECK(glTexParameterf(m_target, GL_TEXTURE_MAX_ANISOTROPY_EXT, s_renderCtx.m_maxAnisotropy) );
|
||||||
}
|
}
|
||||||
|
|
||||||
GL_CHECK(glBindTexture(m_target, 0) );
|
GL_CHECK(glBindTexture(m_target, 0) );
|
||||||
|
@ -1446,8 +1446,8 @@ namespace bgfx
|
||||||
GL_CHECK(glGenTextures(1, &m_id) );
|
GL_CHECK(glGenTextures(1, &m_id) );
|
||||||
BX_CHECK(0 != m_id, "Failed to generate texture id.");
|
BX_CHECK(0 != m_id, "Failed to generate texture id.");
|
||||||
GL_CHECK(glBindTexture(m_target, m_id) );
|
GL_CHECK(glBindTexture(m_target, m_id) );
|
||||||
// glTexParameteri(m_target, GL_TEXTURE_COMPARE_MODE, GL_NONE);
|
// GL_CHECK(glTexParameteri(m_target, GL_TEXTURE_COMPARE_MODE, GL_NONE) );
|
||||||
// glTexParameteri(m_target, GL_DEPTH_TEXTURE_MODE, GL_NONE);
|
// GL_CHECK(glTexParameteri(m_target, GL_DEPTH_TEXTURE_MODE, GL_NONE) );
|
||||||
GL_CHECK(glTexParameteri(m_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR) );
|
GL_CHECK(glTexParameteri(m_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR) );
|
||||||
GL_CHECK(glTexParameteri(m_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR) );
|
GL_CHECK(glTexParameteri(m_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR) );
|
||||||
GL_CHECK(glTexParameteri(m_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE) );
|
GL_CHECK(glTexParameteri(m_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE) );
|
||||||
|
@ -1941,11 +1941,12 @@ namespace bgfx
|
||||||
GL_GET(GL_MAX_RENDERBUFFER_SIZE, 1);
|
GL_GET(GL_MAX_RENDERBUFFER_SIZE, 1);
|
||||||
|
|
||||||
const char* version = (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION);
|
const char* version = (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION);
|
||||||
GL_CHECK(version = version); // check if error is generated by glGetString.
|
GL_CHECK(;); // check if error is generated by glGetString.
|
||||||
BX_TRACE("GLSL version: %s", version);
|
BX_TRACE("GLSL version: %s", version);
|
||||||
#endif // BGFX_CONFIG_DEBUG
|
#endif // BGFX_CONFIG_DEBUG
|
||||||
|
|
||||||
const char* extensions = (const char*)glGetString(GL_EXTENSIONS);
|
const char* extensions = (const char*)glGetString(GL_EXTENSIONS);
|
||||||
|
GL_CHECK(;); // check if error is generated by glGetString.
|
||||||
if (NULL != extensions)
|
if (NULL != extensions)
|
||||||
{
|
{
|
||||||
char name[1024];
|
char name[1024];
|
||||||
|
@ -2026,13 +2027,13 @@ namespace bgfx
|
||||||
|
|
||||||
if (s_extension[Extension::EXT_texture_filter_anisotropic].m_supported)
|
if (s_extension[Extension::EXT_texture_filter_anisotropic].m_supported)
|
||||||
{
|
{
|
||||||
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &s_renderCtx.m_maxAnisotropy);
|
GL_CHECK(glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &s_renderCtx.m_maxAnisotropy) );
|
||||||
}
|
}
|
||||||
|
|
||||||
#if BGFX_CONFIG_RENDERER_OPENGL|BGFX_CONFIG_RENDERER_OPENGLES3
|
#if BGFX_CONFIG_RENDERER_OPENGL|BGFX_CONFIG_RENDERER_OPENGLES3
|
||||||
if (s_extension[Extension::ARB_texture_multisample].m_supported)
|
if (s_extension[Extension::ARB_texture_multisample].m_supported)
|
||||||
{
|
{
|
||||||
glGetIntegerv(GL_MAX_SAMPLES, &s_renderCtx.m_maxMsaa);
|
GL_CHECK(glGetIntegerv(GL_MAX_SAMPLES, &s_renderCtx.m_maxMsaa) );
|
||||||
}
|
}
|
||||||
#endif // BGFX_CONFIG_RENDERER_OPENGL|BGFX_CONFIG_RENDERER_OPENGLES3
|
#endif // BGFX_CONFIG_RENDERER_OPENGL|BGFX_CONFIG_RENDERER_OPENGLES3
|
||||||
|
|
||||||
|
@ -2991,7 +2992,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(0, 0, BGFX_CONFIG_DEBUG ? 0x89 : 0x8f, " " BGFX_RENDERER_NAME " ");
|
||||||
tvm.printf(10, pos++, 0x8e, " Frame CPU: %7.3f, % 7.3f \x1f, % 7.3f \x1e [ms] / % 6.2f FPS"
|
tvm.printf(10, pos++, 0x8e, " Frame CPU: %7.3f, % 7.3f \x1f, % 7.3f \x1e [ms] / % 6.2f FPS"
|
||||||
, double(frameTime)*toMs
|
, double(frameTime)*toMs
|
||||||
, double(min)*toMs
|
, double(min)*toMs
|
||||||
|
|
|
@ -207,29 +207,29 @@ namespace bgfx
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AttribType::Uint16:
|
case AttribType::Int16:
|
||||||
{
|
{
|
||||||
uint16_t* packed = (uint16_t*)data;
|
int16_t* packed = (int16_t*)data;
|
||||||
if (_inputNormalized)
|
if (_inputNormalized)
|
||||||
{
|
{
|
||||||
if (asInt)
|
if (asInt)
|
||||||
{
|
{
|
||||||
switch (num)
|
switch (num)
|
||||||
{
|
{
|
||||||
default: *packed++ = uint16_t(*_input++ * 32767.0f + 32768.0f);
|
default: *packed++ = int16_t(*_input++ * 32767.0f);
|
||||||
case 3: *packed++ = uint16_t(*_input++ * 32767.0f + 32768.0f);
|
case 3: *packed++ = int16_t(*_input++ * 32767.0f);
|
||||||
case 2: *packed++ = uint16_t(*_input++ * 32767.0f + 32768.0f);
|
case 2: *packed++ = int16_t(*_input++ * 32767.0f);
|
||||||
case 1: *packed++ = uint16_t(*_input++ * 32767.0f + 32768.0f);
|
case 1: *packed++ = int16_t(*_input++ * 32767.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
switch (num)
|
switch (num)
|
||||||
{
|
{
|
||||||
default: *packed++ = uint16_t(*_input++ * 65535.0f);
|
default: *packed++ = int16_t(*_input++ * 65535.0f - 32768.0f);
|
||||||
case 3: *packed++ = uint16_t(*_input++ * 65535.0f);
|
case 3: *packed++ = int16_t(*_input++ * 65535.0f - 32768.0f);
|
||||||
case 2: *packed++ = uint16_t(*_input++ * 65535.0f);
|
case 2: *packed++ = int16_t(*_input++ * 65535.0f - 32768.0f);
|
||||||
case 1: *packed++ = uint16_t(*_input++ * 65535.0f);
|
case 1: *packed++ = int16_t(*_input++ * 65535.0f - 32768.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -237,10 +237,10 @@ namespace bgfx
|
||||||
{
|
{
|
||||||
switch (num)
|
switch (num)
|
||||||
{
|
{
|
||||||
default: *packed++ = uint16_t(*_input++);
|
default: *packed++ = int16_t(*_input++);
|
||||||
case 3: *packed++ = uint16_t(*_input++);
|
case 3: *packed++ = int16_t(*_input++);
|
||||||
case 2: *packed++ = uint16_t(*_input++);
|
case 2: *packed++ = int16_t(*_input++);
|
||||||
case 1: *packed++ = uint16_t(*_input++);
|
case 1: *packed++ = int16_t(*_input++);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -311,27 +311,27 @@ namespace bgfx
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AttribType::Uint16:
|
case AttribType::Int16:
|
||||||
{
|
{
|
||||||
uint16_t* packed = (uint16_t*)data;
|
int16_t* packed = (int16_t*)data;
|
||||||
if (asInt)
|
if (asInt)
|
||||||
{
|
{
|
||||||
switch (num)
|
switch (num)
|
||||||
{
|
{
|
||||||
default: *_output++ = (float(*packed++) - 32768.0f)*1.0f/32767.0f;
|
default: *_output++ = float(*packed++)*1.0f/32767.0f;
|
||||||
case 3: *_output++ = (float(*packed++) - 32768.0f)*1.0f/32767.0f;
|
case 3: *_output++ = float(*packed++)*1.0f/32767.0f;
|
||||||
case 2: *_output++ = (float(*packed++) - 32768.0f)*1.0f/32767.0f;
|
case 2: *_output++ = float(*packed++)*1.0f/32767.0f;
|
||||||
case 1: *_output++ = (float(*packed++) - 32768.0f)*1.0f/32767.0f;
|
case 1: *_output++ = float(*packed++)*1.0f/32767.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
switch (num)
|
switch (num)
|
||||||
{
|
{
|
||||||
default: *_output++ = float(*packed++)*1.0f/65535.0f;
|
default: *_output++ = (float(*packed++) + 32768.0f)*1.0f/65535.0f;
|
||||||
case 3: *_output++ = float(*packed++)*1.0f/65535.0f;
|
case 3: *_output++ = (float(*packed++) + 32768.0f)*1.0f/65535.0f;
|
||||||
case 2: *_output++ = float(*packed++)*1.0f/65535.0f;
|
case 2: *_output++ = (float(*packed++) + 32768.0f)*1.0f/65535.0f;
|
||||||
case 1: *_output++ = float(*packed++)*1.0f/65535.0f;
|
case 1: *_output++ = (float(*packed++) + 32768.0f)*1.0f/65535.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue