mirror of https://github.com/bkaradzic/bgfx
Separated GL context code.
This commit is contained in:
parent
174524dde4
commit
b77df356c1
|
@ -94,7 +94,7 @@ namespace entry
|
|||
, 0
|
||||
);
|
||||
|
||||
bgfx::setHwnd(m_hwnd);
|
||||
bgfx::winSetHwnd(m_hwnd);
|
||||
|
||||
adjust(DEFAULT_WIDTH, DEFAULT_HEIGHT, true);
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace bgfx
|
|||
|
||||
namespace bgfx
|
||||
{
|
||||
void setHwnd(::HWND _hwnd);
|
||||
void winSetHwnd(::HWND _hwnd);
|
||||
} // namespace bgfx
|
||||
|
||||
#endif // BX_PLATFORM_
|
||||
|
|
|
@ -5,10 +5,6 @@
|
|||
|
||||
#include "bgfx_p.h"
|
||||
|
||||
#if BX_PLATFORM_WINDOWS
|
||||
HWND g_bgfxHwnd = NULL;
|
||||
#endif // BX_PLATFORM_WINDOWS
|
||||
|
||||
#if BGFX_CONFIG_USE_TINYSTL
|
||||
namespace tinystl
|
||||
{
|
||||
|
@ -38,7 +34,9 @@ namespace bgfx
|
|||
#endif // BGFX_CONFIG_MULTITHREADED
|
||||
|
||||
#if BX_PLATFORM_WINDOWS
|
||||
void setHwnd(::HWND _hwnd)
|
||||
HWND g_bgfxHwnd = NULL;
|
||||
|
||||
void winSetHwnd(::HWND _hwnd)
|
||||
{
|
||||
g_bgfxHwnd = _hwnd;
|
||||
}
|
||||
|
|
|
@ -68,7 +68,6 @@ extern void dbgPrintfData(const void* _data, uint32_t _size, const char* _format
|
|||
|
||||
#if BX_PLATFORM_WINDOWS
|
||||
# include <windows.h>
|
||||
extern HWND g_bgfxHwnd;
|
||||
#elif BX_PLATFORM_XBOX360
|
||||
# include <malloc.h>
|
||||
# include <xtl.h>
|
||||
|
@ -144,6 +143,10 @@ namespace stl = std;
|
|||
|
||||
namespace bgfx
|
||||
{
|
||||
#if BX_PLATFORM_WINDOWS
|
||||
extern HWND g_bgfxHwnd;
|
||||
#endif // BX_PLATFORM_WINDOWS
|
||||
|
||||
struct Clear
|
||||
{
|
||||
uint32_t m_rgba;
|
||||
|
|
|
@ -0,0 +1,116 @@
|
|||
/*
|
||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "bgfx_p.h"
|
||||
|
||||
#if (BGFX_CONFIG_RENDERER_OPENGLES2|BGFX_CONFIG_RENDERER_OPENGLES3|BGFX_CONFIG_RENDERER_OPENGL)
|
||||
# include "renderer_gl.h"
|
||||
|
||||
# if BGFX_USE_EGL
|
||||
|
||||
namespace bgfx
|
||||
{
|
||||
# define GL_IMPORT(_optional, _proto, _func) _proto _func
|
||||
# include "glimports.h"
|
||||
# undef GL_IMPORT
|
||||
|
||||
void GlContext::create(uint32_t _width, uint32_t _height)
|
||||
{
|
||||
EGLNativeDisplayType ndt = EGL_DEFAULT_DISPLAY;
|
||||
EGLNativeWindowType nwt = (EGLNativeWindowType)NULL;
|
||||
# if BX_PLATFORM_WINDOWS
|
||||
ndt = GetDC(g_bgfxHwnd);
|
||||
nwt = g_bgfxHwnd;
|
||||
# endif // BX_PLATFORM_
|
||||
m_display = eglGetDisplay(ndt);
|
||||
BGFX_FATAL(m_display != EGL_NO_DISPLAY, Fatal::UnableToInitialize, "Failed to create display 0x%08x", m_display);
|
||||
|
||||
EGLint major = 0;
|
||||
EGLint minor = 0;
|
||||
EGLBoolean success = eglInitialize(m_display, &major, &minor);
|
||||
BGFX_FATAL(success && major >= 1 && minor >= 3, Fatal::UnableToInitialize, "Failed to initialize %d.%d", major, minor);
|
||||
|
||||
EGLint attrs[] =
|
||||
{
|
||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
||||
|
||||
# if BX_PLATFORM_ANDROID
|
||||
EGL_DEPTH_SIZE, 16,
|
||||
# else
|
||||
EGL_DEPTH_SIZE, 24,
|
||||
# endif // BX_PLATFORM_
|
||||
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
EGLint contextAttrs[] =
|
||||
{
|
||||
# if BGFX_CONFIG_RENDERER_OPENGLES2
|
||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
||||
# elif BGFX_CONFIG_RENDERER_OPENGLES3
|
||||
EGL_CONTEXT_CLIENT_VERSION, 3,
|
||||
# endif // BGFX_CONFIG_RENDERER_
|
||||
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
EGLint numConfig = 0;
|
||||
EGLConfig config = 0;
|
||||
success = eglChooseConfig(m_display, attrs, &config, 1, &numConfig);
|
||||
BGFX_FATAL(success, Fatal::UnableToInitialize, "eglChooseConfig");
|
||||
|
||||
m_surface = eglCreateWindowSurface(m_display, config, nwt, NULL);
|
||||
BGFX_FATAL(m_surface != EGL_NO_SURFACE, Fatal::UnableToInitialize, "Failed to create surface.");
|
||||
|
||||
m_context = eglCreateContext(m_display, config, EGL_NO_CONTEXT, contextAttrs);
|
||||
BGFX_FATAL(m_context != EGL_NO_CONTEXT, Fatal::UnableToInitialize, "Failed to create context.");
|
||||
|
||||
success = eglMakeCurrent(m_display, m_surface, m_surface, m_context);
|
||||
BGFX_FATAL(success, Fatal::UnableToInitialize, "Failed to set context.");
|
||||
|
||||
# if BX_PLATFORM_EMSCRIPTEN
|
||||
emscripten_set_canvas_size(_width, _height);
|
||||
# endif // BX_PLATFORM_EMSCRIPTEN
|
||||
|
||||
import();
|
||||
}
|
||||
|
||||
void GlContext::destroy()
|
||||
{
|
||||
eglMakeCurrent(EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
||||
eglDestroyContext(m_display, m_context);
|
||||
eglDestroySurface(m_display, m_surface);
|
||||
eglTerminate(m_display);
|
||||
m_context = NULL;
|
||||
}
|
||||
|
||||
void GlContext::resize(uint32_t _width, uint32_t _height)
|
||||
{
|
||||
}
|
||||
|
||||
void GlContext::swap()
|
||||
{
|
||||
eglMakeCurrent(m_display, m_surface, m_surface, m_context);
|
||||
eglSwapBuffers(m_display, m_surface);
|
||||
}
|
||||
|
||||
void GlContext::import()
|
||||
{
|
||||
# if !BX_PLATFORM_EMSCRIPTEN
|
||||
# define GL_IMPORT(_optional, _proto, _func) \
|
||||
{ \
|
||||
_func = (_proto)eglGetProcAddress(#_func); \
|
||||
BX_TRACE(#_func " 0x%08x", _func); \
|
||||
BGFX_FATAL(_optional || NULL != _func, Fatal::UnableToInitialize, "Failed to create OpenGLES context. eglGetProcAddress(\"%s\")", #_func); \
|
||||
}
|
||||
# include "glimports.h"
|
||||
# undef GL_IMPORT
|
||||
# endif // !BX_PLATFORM_EMSCRIPTEN
|
||||
}
|
||||
|
||||
} // namespace bgfx
|
||||
|
||||
# endif // BGFX_USE_EGL
|
||||
#endif // (BGFX_CONFIG_RENDERER_OPENGLES2|BGFX_CONFIG_RENDERER_OPENGLES3|BGFX_CONFIG_RENDERER_OPENGL)
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#ifndef __GLCONTEXT_EGL_H__
|
||||
#define __GLCONTEXT_EGL_H__
|
||||
|
||||
#if BGFX_USE_EGL
|
||||
|
||||
#include <EGL/egl.h>
|
||||
|
||||
namespace bgfx
|
||||
{
|
||||
struct GlContext
|
||||
{
|
||||
GlContext()
|
||||
: m_context(NULL)
|
||||
, m_display(NULL)
|
||||
, m_surface(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
void create(uint32_t _width, uint32_t _height);
|
||||
void destroy();
|
||||
void resize(uint32_t _width, uint32_t _height);
|
||||
void swap();
|
||||
void import();
|
||||
|
||||
bool isValid() const
|
||||
{
|
||||
return NULL != m_context;
|
||||
}
|
||||
|
||||
EGLContext m_context;
|
||||
EGLDisplay m_display;
|
||||
EGLSurface m_surface;
|
||||
};
|
||||
} // namespace bgfx
|
||||
|
||||
#endif // BGFX_USE_EGL
|
||||
|
||||
#endif // __GLCONTEXT_EGL_H__
|
|
@ -0,0 +1,175 @@
|
|||
/*
|
||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "bgfx_p.h"
|
||||
|
||||
#if (BGFX_CONFIG_RENDERER_OPENGLES2|BGFX_CONFIG_RENDERER_OPENGLES3|BGFX_CONFIG_RENDERER_OPENGL)
|
||||
# include "renderer_gl.h"
|
||||
|
||||
# if BX_PLATFORM_LINUX
|
||||
|
||||
namespace bgfx
|
||||
{
|
||||
# define GL_IMPORT(_optional, _proto, _func) _proto _func
|
||||
# include "glimports.h"
|
||||
# undef GL_IMPORT
|
||||
|
||||
static ::Display* s_display;
|
||||
static ::Window s_window;
|
||||
|
||||
void x11SetDisplayWindow(::Display* _display, ::Window _window)
|
||||
{
|
||||
s_display = _display;
|
||||
s_window = _window;
|
||||
}
|
||||
|
||||
void GlContext::create(uint32_t _width, uint32_t _height)
|
||||
{
|
||||
XLockDisplay(s_display);
|
||||
|
||||
int major, minor;
|
||||
bool version = glXQueryVersion(s_display, &major, &minor);
|
||||
BGFX_FATAL(version, Fatal::UnableToInitialize, "Failed to query GLX version");
|
||||
BGFX_FATAL( (major == 1 && minor >= 3) || major > 1
|
||||
, Fatal::UnableToInitialize
|
||||
, "GLX version is not >=1.3 (%d.%d)."
|
||||
, major
|
||||
, minor
|
||||
);
|
||||
|
||||
const int attrsGlx[] =
|
||||
{
|
||||
GLX_RENDER_TYPE, GLX_RGBA_BIT,
|
||||
GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
|
||||
GLX_DOUBLEBUFFER, true,
|
||||
GLX_RED_SIZE, 8,
|
||||
GLX_BLUE_SIZE, 8,
|
||||
GLX_GREEN_SIZE, 8,
|
||||
GLX_ALPHA_SIZE, 8,
|
||||
GLX_DEPTH_SIZE, 24,
|
||||
GLX_STENCIL_SIZE, 8,
|
||||
None,
|
||||
};
|
||||
|
||||
// Find suitable config
|
||||
GLXFBConfig bestConfig = NULL;
|
||||
|
||||
int numConfigs;
|
||||
GLXFBConfig* configs = glXChooseFBConfig(s_display, DefaultScreen(s_display), attrsGlx, &numConfigs);
|
||||
|
||||
BX_TRACE("glX num configs %d", numConfigs);
|
||||
|
||||
XVisualInfo* visualInfo = 0;
|
||||
for (int ii = 0; ii < numConfigs; ++ii)
|
||||
{
|
||||
visualInfo = glXGetVisualFromFBConfig(s_display, configs[ii]);
|
||||
if (NULL != visualInfo)
|
||||
{
|
||||
BX_TRACE("---");
|
||||
bool valid = true;
|
||||
for (uint32_t attr = 6; attr < countof(attrsGlx)-1 && attrsGlx[attr] != None; attr += 2)
|
||||
{
|
||||
int value;
|
||||
glXGetFBConfigAttrib(s_display, configs[ii], attrsGlx[attr], &value);
|
||||
BX_TRACE("glX %d/%d %2d: %4x, %8x (%8x%s)"
|
||||
, ii
|
||||
, numConfigs
|
||||
, attr/2
|
||||
, attrsGlx[attr]
|
||||
, value
|
||||
, attrsGlx[attr + 1]
|
||||
, value < attrsGlx[attr + 1] ? " *" : ""
|
||||
);
|
||||
|
||||
if (value < attrsGlx[attr + 1])
|
||||
{
|
||||
valid = false;
|
||||
#if !BGFX_CONFIG_DEBUG
|
||||
break;
|
||||
#endif // BGFX_CONFIG_DEBUG
|
||||
}
|
||||
}
|
||||
|
||||
if (valid)
|
||||
{
|
||||
bestConfig = configs[ii];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
XFree(visualInfo);
|
||||
visualInfo = 0;
|
||||
}
|
||||
|
||||
XFree(configs);
|
||||
BGFX_FATAL(visualInfo, Fatal::UnableToInitialize, "Failed to find a suitable X11 display configuration.");
|
||||
|
||||
BX_TRACE("Create GL 2.1 context.");
|
||||
m_context = glXCreateContext(s_display, visualInfo, 0, GL_TRUE);
|
||||
BGFX_FATAL(NULL != m_context, Fatal::UnableToInitialize, "Failed to create GL 2.1 context.");
|
||||
|
||||
XFree(visualInfo);
|
||||
|
||||
typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
|
||||
glXCreateContextAttribsARBProc glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)glXGetProcAddress((const GLubyte*)"glXCreateContextAttribsARB");
|
||||
if (NULL != glXCreateContextAttribsARB)
|
||||
{
|
||||
BX_TRACE("Create GL 3.0 context.");
|
||||
const int contextAttrs[] =
|
||||
{
|
||||
GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
|
||||
GLX_CONTEXT_MINOR_VERSION_ARB, 0,
|
||||
None,
|
||||
};
|
||||
|
||||
GLXContext context = glXCreateContextAttribsARB(s_display, bestConfig, 0, true, contextAttrs);
|
||||
|
||||
if (NULL != context)
|
||||
{
|
||||
glXDestroyContext(s_display, m_context);
|
||||
m_context = context;
|
||||
}
|
||||
}
|
||||
|
||||
glXMakeCurrent(s_display, s_window, m_context);
|
||||
|
||||
XUnlockDisplay(s_display);
|
||||
|
||||
import();
|
||||
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glXSwapBuffers(s_display, s_window);
|
||||
}
|
||||
|
||||
void GlContext::destroy()
|
||||
{
|
||||
}
|
||||
|
||||
void GlContext::resize(uint32_t _width, uint32_t _height)
|
||||
{
|
||||
}
|
||||
|
||||
void GlContext::swap()
|
||||
{
|
||||
glXSwapBuffers(s_display, s_window);
|
||||
}
|
||||
|
||||
void GlContext::import()
|
||||
{
|
||||
# define GL_IMPORT(_optional, _proto, _func) \
|
||||
{ \
|
||||
_func = (_proto)glXGetProcAddress((const GLubyte*)#_func); \
|
||||
BGFX_FATAL(_optional || NULL != _func, Fatal::UnableToInitialize, "Failed to create OpenGL context. glXGetProcAddress %s", #_func); \
|
||||
}
|
||||
# include "glimports.h"
|
||||
# undef GL_IMPORT
|
||||
}
|
||||
|
||||
} // namespace bgfx
|
||||
|
||||
# endif // BX_PLATFORM_LINUX
|
||||
#endif // (BGFX_CONFIG_RENDERER_OPENGLES2|BGFX_CONFIG_RENDERER_OPENGLES3|BGFX_CONFIG_RENDERER_OPENGL)
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#ifndef __GLCONTEXT_GLX_H__
|
||||
#define __GLCONTEXT_GLX_H__
|
||||
|
||||
#if BX_PLATFORM_LINUX
|
||||
|
||||
# include <X11/Xlib.h>
|
||||
|
||||
namespace bgfx
|
||||
{
|
||||
struct GlContext
|
||||
{
|
||||
GlContext()
|
||||
: m_context(0)
|
||||
{
|
||||
}
|
||||
|
||||
void create(uint32_t _width, uint32_t _height);
|
||||
void destroy();
|
||||
void resize(uint32_t _width, uint32_t _height);
|
||||
void swap();
|
||||
void import();
|
||||
|
||||
bool isValid() const
|
||||
{
|
||||
return 0 != m_context;
|
||||
}
|
||||
|
||||
GLXContext m_context;
|
||||
};
|
||||
} // namespace bgfx
|
||||
|
||||
#endif // BX_PLATFORM_LINUX
|
||||
|
||||
#endif // __GLCONTEXT_GLX_H__
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "bgfx_p.h"
|
||||
|
||||
#if (BGFX_CONFIG_RENDERER_OPENGLES2|BGFX_CONFIG_RENDERER_OPENGLES3|BGFX_CONFIG_RENDERER_OPENGL)
|
||||
# include "renderer_gl.h"
|
||||
|
||||
# if BX_PLATFORM_NACL
|
||||
|
||||
namespace bgfx
|
||||
{
|
||||
# define GL_IMPORT(_optional, _proto, _func) _proto _func
|
||||
# include "glimports.h"
|
||||
# undef GL_IMPORT
|
||||
|
||||
void naclSwapCompleteCb(void* _data, int32_t _result);
|
||||
|
||||
PP_CompletionCallback naclSwapComplete =
|
||||
{
|
||||
naclSwapCompleteCb,
|
||||
NULL,
|
||||
PP_COMPLETIONCALLBACK_FLAG_NONE
|
||||
};
|
||||
|
||||
void GlContext::create(uint32_t _width, uint32_t _height)
|
||||
{
|
||||
int32_t attribs[] =
|
||||
{
|
||||
PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8,
|
||||
PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 24,
|
||||
PP_GRAPHICS3DATTRIB_STENCIL_SIZE, 8,
|
||||
PP_GRAPHICS3DATTRIB_SAMPLES, 0,
|
||||
PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS, 0,
|
||||
PP_GRAPHICS3DATTRIB_WIDTH, int32_t(_width),
|
||||
PP_GRAPHICS3DATTRIB_HEIGHT, int32_t(_height),
|
||||
PP_GRAPHICS3DATTRIB_NONE
|
||||
};
|
||||
|
||||
m_context = m_graphicsInterface->Create(m_instance, 0, attribs);
|
||||
m_instInterface->BindGraphics(m_instance, m_context);
|
||||
glSetCurrentContextPPAPI(m_context);
|
||||
m_graphicsInterface->SwapBuffers(m_context, naclSwapComplete);
|
||||
}
|
||||
|
||||
void GlContext::destroy()
|
||||
{
|
||||
}
|
||||
|
||||
void GlContext::resize(uint32_t _width, uint32_t _height)
|
||||
{
|
||||
m_graphicsInterface->ResizeBuffers(m_context, _width, _height);
|
||||
}
|
||||
|
||||
void GlContext::swap()
|
||||
{
|
||||
glSetCurrentContextPPAPI(m_context);
|
||||
m_graphicsInterface->SwapBuffers(m_context, naclSwapComplete);
|
||||
}
|
||||
|
||||
void GlContext::import()
|
||||
{
|
||||
}
|
||||
} // namespace bgfx
|
||||
|
||||
# endif // BX_PLATFORM_NACL
|
||||
#endif // (BGFX_CONFIG_RENDERER_OPENGLES2|BGFX_CONFIG_RENDERER_OPENGLES3|BGFX_CONFIG_RENDERER_OPENGL)
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#ifndef __GLCONTEXT_PPAPI_H__
|
||||
#define __GLCONTEXT_PPAPI_H__
|
||||
|
||||
#if BX_PLATFORM_NACL
|
||||
|
||||
# include <ppapi/gles2/gl2ext_ppapi.h>
|
||||
# include <ppapi/c/pp_completion_callback.h>
|
||||
# include <ppapi/c/ppb_instance.h>
|
||||
# include <ppapi/c/ppb_graphics_3d.h>
|
||||
|
||||
namespace bgfx
|
||||
{
|
||||
struct GlContext
|
||||
{
|
||||
GlContext()
|
||||
: m_context(0)
|
||||
, m_instance(0)
|
||||
, m_instInterface(NULL)
|
||||
, m_graphicsInterface(NULL)
|
||||
, m_instancedArrays(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
void create(uint32_t _width, uint32_t _height);
|
||||
void destroy();
|
||||
void resize(uint32_t _width, uint32_t _height);
|
||||
void swap();
|
||||
void import();
|
||||
|
||||
bool isValid() const
|
||||
{
|
||||
return 0 != m_context;
|
||||
}
|
||||
|
||||
PP_Resource m_context;
|
||||
PP_Instance m_instance;
|
||||
const PPB_Instance* m_instInterface;
|
||||
const PPB_Graphics3D* m_graphicsInterface;
|
||||
const PPB_OpenGLES2InstancedArrays* m_instancedArrays;
|
||||
};
|
||||
} // namespace bgfx
|
||||
|
||||
#endif // BX_PLATFORM_NACL
|
||||
|
||||
#endif // __GLCONTEXT_PPAPI_H__
|
|
@ -0,0 +1,128 @@
|
|||
/*
|
||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "bgfx_p.h"
|
||||
|
||||
#if (BGFX_CONFIG_RENDERER_OPENGLES2|BGFX_CONFIG_RENDERER_OPENGLES3|BGFX_CONFIG_RENDERER_OPENGL)
|
||||
# include "renderer_gl.h"
|
||||
|
||||
# if BGFX_USE_WGL
|
||||
|
||||
namespace bgfx
|
||||
{
|
||||
PFNWGLGETPROCADDRESSPROC wglGetProcAddress;
|
||||
PFNWGLMAKECURRENTPROC wglMakeCurrent;
|
||||
PFNWGLCREATECONTEXTPROC wglCreateContext;
|
||||
PFNWGLDELETECONTEXTPROC wglDeleteContext;
|
||||
|
||||
# define GL_IMPORT(_optional, _proto, _func) _proto _func
|
||||
# include "glimports.h"
|
||||
# undef GL_IMPORT
|
||||
|
||||
void GlContext::create(uint32_t _width, uint32_t _height)
|
||||
{
|
||||
m_opengl32dll = LoadLibrary("opengl32.dll");
|
||||
BGFX_FATAL(NULL != m_opengl32dll, Fatal::UnableToInitialize, "Failed to load opengl32.dll.");
|
||||
|
||||
wglGetProcAddress = (PFNWGLGETPROCADDRESSPROC)GetProcAddress(m_opengl32dll, "wglGetProcAddress");
|
||||
BGFX_FATAL(NULL != wglGetProcAddress, Fatal::UnableToInitialize, "Failed get wglGetProcAddress.");
|
||||
|
||||
wglMakeCurrent = (PFNWGLMAKECURRENTPROC)GetProcAddress(m_opengl32dll, "wglMakeCurrent");
|
||||
BGFX_FATAL(NULL != wglMakeCurrent, Fatal::UnableToInitialize, "Failed get wglMakeCurrent.");
|
||||
|
||||
wglCreateContext = (PFNWGLCREATECONTEXTPROC)GetProcAddress(m_opengl32dll, "wglCreateContext");
|
||||
BGFX_FATAL(NULL != wglCreateContext, Fatal::UnableToInitialize, "Failed get wglCreateContext.");
|
||||
|
||||
wglDeleteContext = (PFNWGLDELETECONTEXTPROC)GetProcAddress(m_opengl32dll, "wglDeleteContext");
|
||||
BGFX_FATAL(NULL != wglDeleteContext, Fatal::UnableToInitialize, "Failed get wglDeleteContext.");
|
||||
|
||||
m_hdc = GetDC(g_bgfxHwnd);
|
||||
BGFX_FATAL(NULL != m_hdc, Fatal::UnableToInitialize, "GetDC failed!");
|
||||
|
||||
PIXELFORMATDESCRIPTOR pfd;
|
||||
memset(&pfd, 0, sizeof(pfd) );
|
||||
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
|
||||
pfd.nVersion = 1;
|
||||
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(m_hdc, &pfd);
|
||||
BGFX_FATAL(0 != pixelFormat, Fatal::UnableToInitialize, "ChoosePixelFormat failed!");
|
||||
|
||||
DescribePixelFormat(m_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(m_hdc, pixelFormat, &pfd);
|
||||
BGFX_FATAL(0 != result, Fatal::UnableToInitialize, "SetPixelFormat failed!");
|
||||
|
||||
m_context = wglCreateContext(m_hdc);
|
||||
BGFX_FATAL(NULL != m_context, Fatal::UnableToInitialize, "wglCreateContext failed!");
|
||||
|
||||
result = wglMakeCurrent(m_hdc, m_context);
|
||||
BGFX_FATAL(0 != result, Fatal::UnableToInitialize, "wglMakeCurrent failed!");
|
||||
|
||||
import();
|
||||
}
|
||||
|
||||
void GlContext::destroy()
|
||||
{
|
||||
wglMakeCurrent(NULL, NULL);
|
||||
|
||||
wglDeleteContext(m_context);
|
||||
m_context = NULL;
|
||||
|
||||
ReleaseDC(g_bgfxHwnd, m_hdc);
|
||||
m_hdc = NULL;
|
||||
|
||||
FreeLibrary(m_opengl32dll);
|
||||
m_opengl32dll = NULL;
|
||||
}
|
||||
|
||||
void GlContext::resize(uint32_t _width, uint32_t _height)
|
||||
{
|
||||
}
|
||||
|
||||
void GlContext::swap()
|
||||
{
|
||||
wglMakeCurrent(m_hdc, m_context);
|
||||
SwapBuffers(m_hdc);
|
||||
}
|
||||
|
||||
void GlContext::import()
|
||||
{
|
||||
# define GL_IMPORT(_optional, _proto, _func) \
|
||||
{ \
|
||||
_func = (_proto)wglGetProcAddress(#_func); \
|
||||
if (_func == NULL) \
|
||||
{ \
|
||||
_func = (_proto)GetProcAddress(m_opengl32dll, #_func); \
|
||||
} \
|
||||
BGFX_FATAL(_optional || NULL != _func, Fatal::UnableToInitialize, "Failed to create OpenGL context. wglGetProcAddress(\"%s\")", #_func); \
|
||||
}
|
||||
# include "glimports.h"
|
||||
# undef GL_IMPORT
|
||||
}
|
||||
|
||||
} // namespace bgfx
|
||||
|
||||
# endif // BGFX_USE_WGL
|
||||
#endif // (BGFX_CONFIG_RENDERER_OPENGLES2|BGFX_CONFIG_RENDERER_OPENGLES3|BGFX_CONFIG_RENDERER_OPENGL)
|
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#ifndef __GLCONTEXT_WGL_H__
|
||||
#define __GLCONTEXT_WGL_H__
|
||||
|
||||
#if BGFX_USE_WGL
|
||||
|
||||
#include <wgl/wglext.h>
|
||||
typedef PROC (APIENTRYP PFNWGLGETPROCADDRESSPROC) (LPCSTR lpszProc);
|
||||
typedef BOOL (APIENTRYP PFNWGLMAKECURRENTPROC) (HDC hdc, HGLRC hglrc);
|
||||
typedef HGLRC (APIENTRYP PFNWGLCREATECONTEXTPROC) (HDC hdc);
|
||||
typedef BOOL (APIENTRYP PFNWGLDELETECONTEXTPROC) (HGLRC hglrc);
|
||||
//
|
||||
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 PFNGLTEXIMAGE2DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
|
||||
typedef void (APIENTRYP PFNGLTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
|
||||
typedef void (APIENTRYP PFNGLTEXPARAMETERIPROC) (GLenum target, GLenum pname, GLint param);
|
||||
typedef void (APIENTRYP PFNGLTEXPARAMETERIVPROC) (GLenum target, GLenum pname, const GLint *params);
|
||||
typedef void (APIENTRYP PFNGLTEXPARAMETERFPROC) (GLenum target, GLenum pname, GLfloat param);
|
||||
typedef void (APIENTRYP PFNGLPIXELSTOREI) (GLenum pname, GLint param);
|
||||
typedef void (APIENTRYP PFNGLBINDTEXTUREPROC) (GLenum target, GLuint texture);
|
||||
typedef void (APIENTRYP PFNGLGENTEXTURESPROC) (GLsizei n, 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 PFNGLDEPTHFUNCPROC) (GLenum func);
|
||||
typedef void (APIENTRYP PFNGLDISABLEPROC) (GLenum cap);
|
||||
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 PFNGLGETINTEGERVPROC) (GLenum pname, GLint *params);
|
||||
typedef void (APIENTRYP PFNGLGETFLOATVPROC) (GLenum pname, GLfloat *params);
|
||||
typedef const GLubyte * (APIENTRYP PFNGLGETSTRINGPROC) (GLenum name);
|
||||
typedef void (APIENTRYP PFNGLDRAWARRAYSPROC) (GLenum mode, GLint first, GLsizei count);
|
||||
typedef void (APIENTRYP PFNGLBLENDFUNCPROC) (GLenum sfactor, GLenum dfactor);
|
||||
typedef void (APIENTRYP PFNGLPOINTSIZEPROC) (GLfloat size);
|
||||
typedef void (APIENTRYP PFNGLCULLFACEPROC) (GLenum mode);
|
||||
typedef void (APIENTRYP PFNGLCLEARPROC) (GLbitfield mask);
|
||||
typedef void (APIENTRYP PFNGLSCISSORPROC) (GLint x, GLint y, GLsizei width, GLsizei height);
|
||||
typedef void (APIENTRYP PFNGLENABLEPROC) (GLenum cap);
|
||||
typedef void (APIENTRYP PFNGLCLEARSTENCILPROC) (GLint s);
|
||||
typedef void (APIENTRYP PFNGLDEPTHMASKPROC) (GLboolean flag);
|
||||
typedef void (APIENTRYP PFNGLCLEARDEPTHPROC) (GLdouble depth);
|
||||
typedef void (APIENTRYP PFNGLCLEARCOLORPROC) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
|
||||
typedef void (APIENTRYP PFNGLSTENCILFUNCPROC) (GLenum func, GLint ref, GLuint mask);
|
||||
typedef void (APIENTRYP PFNGLSTENCILMASKPROC) (GLuint mask);
|
||||
typedef void (APIENTRYP PFNGLSTENCILOPPROC) (GLenum fail, GLenum zfail, GLenum zpass);
|
||||
|
||||
namespace bgfx
|
||||
{
|
||||
extern PFNWGLGETPROCADDRESSPROC wglGetProcAddress;
|
||||
extern PFNWGLMAKECURRENTPROC wglMakeCurrent;
|
||||
extern PFNWGLCREATECONTEXTPROC wglCreateContext;
|
||||
extern PFNWGLDELETECONTEXTPROC wglDeleteContext;
|
||||
|
||||
struct GlContext
|
||||
{
|
||||
GlContext()
|
||||
: m_opengl32dll(NULL)
|
||||
, m_context(NULL)
|
||||
, m_hdc(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
void create(uint32_t _width, uint32_t _height);
|
||||
void destroy();
|
||||
void resize(uint32_t _width, uint32_t _height);
|
||||
void swap();
|
||||
void import();
|
||||
|
||||
bool isValid() const
|
||||
{
|
||||
return NULL != m_context;
|
||||
}
|
||||
|
||||
HMODULE m_opengl32dll;
|
||||
HGLRC m_context;
|
||||
HDC m_hdc;
|
||||
};
|
||||
} // namespace bgfx
|
||||
|
||||
#endif // BGFX_USE_WGL
|
||||
|
||||
#endif // __GLCONTEXT_WGL_H__
|
334
src/glimports.h
334
src/glimports.h
|
@ -1,167 +1,167 @@
|
|||
/*
|
||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#ifndef GL_IMPORT
|
||||
# error GL_IMPORT(_optional, _proto, _func) must be defined!
|
||||
#endif // GL_IMPORT
|
||||
|
||||
#if BGFX_CONFIG_RENDERER_OPENGL
|
||||
// OpenGL 2.1 Reference Pages
|
||||
// http://www.opengl.org/sdk/docs/man/
|
||||
|
||||
#if BX_PLATFORM_WINDOWS
|
||||
GL_IMPORT(false, PFNGLGETERRORPROC, glGetError);
|
||||
GL_IMPORT(false, PFNGLREADPIXELSPROC, glReadPixels);
|
||||
GL_IMPORT(false, PFNGLTEXIMAGE2DPROC, glTexImage2D);
|
||||
GL_IMPORT(false, PFNGLTEXSUBIMAGE2DPROC, glTexSubImage2D);
|
||||
GL_IMPORT(false, PFNGLPIXELSTOREI, glPixelStorei);
|
||||
GL_IMPORT(false, PFNGLTEXPARAMETERIPROC, glTexParameteri);
|
||||
GL_IMPORT(false, PFNGLTEXPARAMETERIVPROC, glTexParameteriv);
|
||||
GL_IMPORT(false, PFNGLTEXPARAMETERFPROC, glTexParameterf);
|
||||
GL_IMPORT(false, PFNGLBINDTEXTUREPROC, glBindTexture);
|
||||
GL_IMPORT(false, PFNGLGENTEXTURESPROC, glGenTextures);
|
||||
GL_IMPORT(false, PFNGLDELETETEXTURESPROC, glDeleteTextures);
|
||||
GL_IMPORT(false, PFNGLCOLORMASKPROC, glColorMask);
|
||||
GL_IMPORT(false, PFNGLDEPTHFUNCPROC, glDepthFunc);
|
||||
GL_IMPORT(false, PFNGLDISABLEPROC, glDisable);
|
||||
GL_IMPORT(false, PFNGLVIEWPORTPROC, glViewport);
|
||||
GL_IMPORT(false, PFNGLDRAWELEMENTSPROC, glDrawElements);
|
||||
GL_IMPORT(false, PFNGLGETINTEGERVPROC, glGetIntegerv);
|
||||
GL_IMPORT(false, PFNGLGETFLOATVPROC, glGetFloatv);
|
||||
GL_IMPORT(false, PFNGLGETSTRINGPROC, glGetString);
|
||||
GL_IMPORT(false, PFNGLDRAWARRAYSPROC, glDrawArrays);
|
||||
GL_IMPORT(false, PFNGLBLENDFUNCPROC, glBlendFunc);
|
||||
GL_IMPORT(false, PFNGLBLENDEQUATIONPROC, glBlendEquation);
|
||||
GL_IMPORT(false, PFNGLPOINTSIZEPROC, glPointSize);
|
||||
GL_IMPORT(false, PFNGLCULLFACEPROC, glCullFace);
|
||||
GL_IMPORT(false, PFNGLCLEARPROC, glClear);
|
||||
GL_IMPORT(false, PFNGLSCISSORPROC, glScissor);
|
||||
GL_IMPORT(false, PFNGLENABLEPROC, glEnable);
|
||||
GL_IMPORT(false, PFNGLCLEARSTENCILPROC, glClearStencil);
|
||||
GL_IMPORT(false, PFNGLDEPTHMASKPROC, glDepthMask);
|
||||
GL_IMPORT(false, PFNGLCLEARDEPTHPROC, glClearDepth);
|
||||
GL_IMPORT(false, PFNGLCLEARCOLORPROC, glClearColor);
|
||||
GL_IMPORT(false, PFNGLSTENCILFUNCPROC, glStencilFunc);
|
||||
GL_IMPORT(false, PFNGLSTENCILMASKPROC, glStencilMask);
|
||||
GL_IMPORT(false, PFNGLSTENCILOPPROC, glStencilOp);
|
||||
#endif // BX_PLATFORM_WINDOWS
|
||||
|
||||
GL_IMPORT(false, PFNGLACTIVETEXTUREPROC, glActiveTexture);
|
||||
GL_IMPORT(false, PFNGLCOMPRESSEDTEXIMAGE2DPROC, glCompressedTexImage2D);
|
||||
GL_IMPORT(false, PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC, glCompressedTexSubImage2D);
|
||||
GL_IMPORT(false, PFNGLCOMPRESSEDTEXIMAGE3DPROC, glCompressedTexImage3D);
|
||||
GL_IMPORT(false, PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC, glCompressedTexSubImage3D);
|
||||
GL_IMPORT(false, PFNGLBINDBUFFERPROC, glBindBuffer);
|
||||
GL_IMPORT(false, PFNGLDELETEBUFFERSPROC, glDeleteBuffers);
|
||||
GL_IMPORT(false, PFNGLGENBUFFERSPROC, glGenBuffers);
|
||||
GL_IMPORT(false, PFNGLBUFFERDATAPROC, glBufferData);
|
||||
GL_IMPORT(false, PFNGLBUFFERSUBDATAPROC, glBufferSubData);
|
||||
GL_IMPORT(false, PFNGLCREATEPROGRAMPROC, glCreateProgram);
|
||||
GL_IMPORT(false, PFNGLCREATESHADERPROC, glCreateShader);
|
||||
GL_IMPORT(false, PFNGLDELETEPROGRAMPROC, glDeleteProgram);
|
||||
GL_IMPORT(false, PFNGLDELETESHADERPROC, glDeleteShader);
|
||||
GL_IMPORT(false, PFNGLATTACHSHADERPROC, glAttachShader);
|
||||
GL_IMPORT(false, PFNGLCOMPILESHADERPROC, glCompileShader);
|
||||
GL_IMPORT(false, PFNGLSHADERSOURCEPROC, glShaderSource);
|
||||
GL_IMPORT(false, PFNGLGETSHADERIVPROC, glGetShaderiv);
|
||||
GL_IMPORT(false, PFNGLGETSHADERINFOLOGPROC, glGetShaderInfoLog);
|
||||
GL_IMPORT(false, PFNGLLINKPROGRAMPROC, glLinkProgram);
|
||||
GL_IMPORT(false, PFNGLGETPROGRAMIVPROC, glGetProgramiv);
|
||||
GL_IMPORT(false, PFNGLGETPROGRAMINFOLOGPROC, glGetProgramInfoLog);
|
||||
GL_IMPORT(false, PFNGLUSEPROGRAMPROC, glUseProgram);
|
||||
GL_IMPORT(false, PFNGLGETACTIVEATTRIBPROC, glGetActiveAttrib);
|
||||
GL_IMPORT(false, PFNGLGETATTRIBLOCATIONPROC, glGetAttribLocation);
|
||||
GL_IMPORT(false, PFNGLGETACTIVEUNIFORMPROC, glGetActiveUniform);
|
||||
GL_IMPORT(false, PFNGLGETUNIFORMLOCATIONPROC, glGetUniformLocation);
|
||||
GL_IMPORT(false, PFNGLENABLEVERTEXATTRIBARRAYPROC, glEnableVertexAttribArray);
|
||||
GL_IMPORT(false, PFNGLDISABLEVERTEXATTRIBARRAYPROC, glDisableVertexAttribArray);
|
||||
GL_IMPORT(false, PFNGLVERTEXATTRIBPOINTERPROC, glVertexAttribPointer);
|
||||
GL_IMPORT(false, PFNGLVERTEXATTRIB1FPROC, glVertexAttrib1f);
|
||||
GL_IMPORT(false, PFNGLVERTEXATTRIB2FPROC, glVertexAttrib2f);
|
||||
GL_IMPORT(false, PFNGLVERTEXATTRIB3FPROC, glVertexAttrib3f);
|
||||
GL_IMPORT(false, PFNGLVERTEXATTRIB4FPROC, glVertexAttrib4f);
|
||||
GL_IMPORT(false, PFNGLBINDFRAMEBUFFERPROC, glBindFramebuffer);
|
||||
GL_IMPORT(false, PFNGLGENFRAMEBUFFERSPROC, glGenFramebuffers);
|
||||
GL_IMPORT(false, PFNGLDELETEFRAMEBUFFERSPROC, glDeleteFramebuffers);
|
||||
GL_IMPORT(false, PFNGLCHECKFRAMEBUFFERSTATUSPROC, glCheckFramebufferStatus);
|
||||
GL_IMPORT(false, PFNGLFRAMEBUFFERRENDERBUFFERPROC, glFramebufferRenderbuffer);
|
||||
GL_IMPORT(false, PFNGLFRAMEBUFFERTEXTURE2DPROC, glFramebufferTexture2D);
|
||||
GL_IMPORT(false, PFNGLBINDRENDERBUFFERPROC, glBindRenderbuffer);
|
||||
GL_IMPORT(false, PFNGLGENRENDERBUFFERSPROC, glGenRenderbuffers);
|
||||
GL_IMPORT(false, PFNGLDELETERENDERBUFFERSPROC, glDeleteRenderbuffers);
|
||||
GL_IMPORT(false, PFNGLRENDERBUFFERSTORAGEPROC, glRenderbufferStorage);
|
||||
GL_IMPORT(false, PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC, glRenderbufferStorageMultisample);
|
||||
GL_IMPORT(false, PFNGLUNIFORM1IPROC, glUniform1i);
|
||||
GL_IMPORT(false, PFNGLUNIFORM1IVPROC, glUniform1iv);
|
||||
GL_IMPORT(false, PFNGLUNIFORM1FPROC, glUniform1f);
|
||||
GL_IMPORT(false, PFNGLUNIFORM1FVPROC, glUniform1fv);
|
||||
GL_IMPORT(false, PFNGLUNIFORM2FVPROC, glUniform2fv);
|
||||
GL_IMPORT(false, PFNGLUNIFORM3FVPROC, glUniform3fv);
|
||||
GL_IMPORT(false, PFNGLUNIFORM4FVPROC, glUniform4fv);
|
||||
GL_IMPORT(false, PFNGLUNIFORMMATRIX3FVPROC, glUniformMatrix3fv);
|
||||
GL_IMPORT(false, PFNGLUNIFORMMATRIX4FVPROC, glUniformMatrix4fv);
|
||||
GL_IMPORT(false, PFNGLTEXIMAGE3DPROC, glTexImage3D);
|
||||
GL_IMPORT(false, PFNGLTEXSUBIMAGE3DPROC, glTexSubImage3D);
|
||||
GL_IMPORT(false, PFNGLCOPYTEXSUBIMAGE3DPROC, glCopyTexSubImage3D);
|
||||
GL_IMPORT(false, PFNGLTEXIMAGE2DMULTISAMPLEPROC, glTexImage2DMultisample);
|
||||
|
||||
GL_IMPORT(false, PFNGLGENQUERIESPROC, glGenQueries);
|
||||
GL_IMPORT(false, PFNGLDELETEQUERIESPROC, glDeleteQueries);
|
||||
GL_IMPORT(false, PFNGLBEGINQUERYPROC, glBeginQuery);
|
||||
GL_IMPORT(false, PFNGLENDQUERYPROC, glEndQuery);
|
||||
GL_IMPORT(false, PFNGLGETQUERYIVPROC, glGetQueryiv);
|
||||
GL_IMPORT(false, PFNGLGETQUERYOBJECTIVPROC, glGetQueryObjectiv);
|
||||
GL_IMPORT(false, PFNGLGETQUERYOBJECTUIVPROC, glGetQueryObjectuiv);
|
||||
|
||||
GL_IMPORT(true, PFNGLGETPROGRAMBINARYPROC, glGetProgramBinary);
|
||||
GL_IMPORT(true, PFNGLPROGRAMBINARYPROC, glProgramBinary);
|
||||
GL_IMPORT(true, PFNGLPROGRAMPARAMETERIPROC, glProgramParameteri);
|
||||
|
||||
GL_IMPORT(true, PFNGLBLITFRAMEBUFFEREXTPROC, glBlitFramebufferEXT);
|
||||
|
||||
GL_IMPORT(true, PFNGLQUERYCOUNTERPROC, glQueryCounter);
|
||||
GL_IMPORT(true, PFNGLGETQUERYOBJECTI64VPROC, glGetQueryObjecti64v);
|
||||
GL_IMPORT(true, PFNGLGETQUERYOBJECTUI64VPROC, glGetQueryObjectui64v);
|
||||
GL_IMPORT(true, PFNGLGETQUERYOBJECTI64VEXTPROC, glGetQueryObjecti64vEXT);
|
||||
GL_IMPORT(true, PFNGLGETQUERYOBJECTUI64VEXTPROC, glGetQueryObjectui64vEXT);
|
||||
|
||||
GL_IMPORT(true, PFNGLSAMPLECOVERAGEARBPROC, glSampleCoverageARB);
|
||||
|
||||
GL_IMPORT(true, PFNGLBINDVERTEXARRAYPROC, glBindVertexArray);
|
||||
GL_IMPORT(true, PFNGLDELETEVERTEXARRAYSPROC, glDeleteVertexArrays);
|
||||
GL_IMPORT(true, PFNGLGENVERTEXARRAYSPROC, glGenVertexArrays);
|
||||
|
||||
GL_IMPORT(true, PFNGLSTENCILFUNCSEPARATEPROC, glStencilFuncSeparate);
|
||||
GL_IMPORT(true, PFNGLSTENCILMASKSEPARATEPROC, glStencilMaskSeparate);
|
||||
GL_IMPORT(true, PFNGLSTENCILOPSEPARATEPROC, glStencilOpSeparate);
|
||||
|
||||
GL_IMPORT(true, PFNGLBLENDFUNCSEPARATEPROC, glBlendFuncSeparate);
|
||||
GL_IMPORT(true, PFNGLBLENDEQUATIONSEPARATEPROC, glBlendEquationSeparate);
|
||||
|
||||
#if BGFX_CONFIG_DEBUG_GREMEDY
|
||||
GL_IMPORT(true, PFNGLSTRINGMARKERGREMEDYPROC, glStringMarkerGREMEDY);
|
||||
GL_IMPORT(true, PFNGLFRAMETERMINATORGREMEDYPROC, glFrameTerminatorGREMEDY);
|
||||
#endif // BGFX_CONFIG_DEBUG_GREMEDY
|
||||
|
||||
#elif BGFX_CONFIG_RENDERER_OPENGLES2
|
||||
|
||||
// OpenGL ES 2.0 Reference Pages
|
||||
// http://www.khronos.org/opengles/sdk/docs/man/
|
||||
|
||||
GL_IMPORT(true, PFNGLGETTRANSLATEDSHADERSOURCEANGLEPROC, glGetTranslatedShaderSourceANGLE);
|
||||
GL_IMPORT(true, PFNGLGETPROGRAMBINARYOESPROC, glGetProgramBinaryOES);
|
||||
GL_IMPORT(true, PFNGLPROGRAMBINARYOESPROC, glProgramBinaryOES);
|
||||
|
||||
GL_IMPORT(true, PFNGLBINDVERTEXARRAYOESPROC, glBindVertexArrayOES);
|
||||
GL_IMPORT(true, PFNGLDELETEVERTEXARRAYSOESPROC, glDeleteVertexArraysOES);
|
||||
GL_IMPORT(true, PFNGLGENVERTEXARRAYSOESPROC, glGenVertexArraysOES);
|
||||
|
||||
#endif // BGFX_CONFIG_RENDERER_
|
||||
|
||||
#if !BGFX_CONFIG_RENDERER_OPENGLES3
|
||||
GL_IMPORT(true, PFNGLVERTEXATTRIBDIVISORBGFXPROC, glVertexAttribDivisor);
|
||||
GL_IMPORT(true, PFNGLDRAWARRAYSINSTANCEDBGFXPROC, glDrawArraysInstanced);
|
||||
GL_IMPORT(true, PFNGLDRAWELEMENTSINSTANCEDBGFXPROC, glDrawElementsInstanced);
|
||||
#endif // !BGFX_CONFIG_RENDERER_OPENGLES3
|
||||
/*
|
||||
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#ifndef GL_IMPORT
|
||||
# error GL_IMPORT(_optional, _proto, _func) must be defined!
|
||||
#endif // GL_IMPORT
|
||||
|
||||
#if BGFX_CONFIG_RENDERER_OPENGL
|
||||
// OpenGL 2.1 Reference Pages
|
||||
// http://www.opengl.org/sdk/docs/man/
|
||||
|
||||
#if BX_PLATFORM_WINDOWS
|
||||
GL_IMPORT(false, PFNGLGETERRORPROC, glGetError);
|
||||
GL_IMPORT(false, PFNGLREADPIXELSPROC, glReadPixels);
|
||||
GL_IMPORT(false, PFNGLTEXIMAGE2DPROC, glTexImage2D);
|
||||
GL_IMPORT(false, PFNGLTEXSUBIMAGE2DPROC, glTexSubImage2D);
|
||||
GL_IMPORT(false, PFNGLPIXELSTOREI, glPixelStorei);
|
||||
GL_IMPORT(false, PFNGLTEXPARAMETERIPROC, glTexParameteri);
|
||||
GL_IMPORT(false, PFNGLTEXPARAMETERIVPROC, glTexParameteriv);
|
||||
GL_IMPORT(false, PFNGLTEXPARAMETERFPROC, glTexParameterf);
|
||||
GL_IMPORT(false, PFNGLBINDTEXTUREPROC, glBindTexture);
|
||||
GL_IMPORT(false, PFNGLGENTEXTURESPROC, glGenTextures);
|
||||
GL_IMPORT(false, PFNGLDELETETEXTURESPROC, glDeleteTextures);
|
||||
GL_IMPORT(false, PFNGLCOLORMASKPROC, glColorMask);
|
||||
GL_IMPORT(false, PFNGLDEPTHFUNCPROC, glDepthFunc);
|
||||
GL_IMPORT(false, PFNGLDISABLEPROC, glDisable);
|
||||
GL_IMPORT(false, PFNGLVIEWPORTPROC, glViewport);
|
||||
GL_IMPORT(false, PFNGLDRAWELEMENTSPROC, glDrawElements);
|
||||
GL_IMPORT(false, PFNGLGETINTEGERVPROC, glGetIntegerv);
|
||||
GL_IMPORT(false, PFNGLGETFLOATVPROC, glGetFloatv);
|
||||
GL_IMPORT(false, PFNGLGETSTRINGPROC, glGetString);
|
||||
GL_IMPORT(false, PFNGLDRAWARRAYSPROC, glDrawArrays);
|
||||
GL_IMPORT(false, PFNGLBLENDFUNCPROC, glBlendFunc);
|
||||
GL_IMPORT(false, PFNGLBLENDEQUATIONPROC, glBlendEquation);
|
||||
GL_IMPORT(false, PFNGLPOINTSIZEPROC, glPointSize);
|
||||
GL_IMPORT(false, PFNGLCULLFACEPROC, glCullFace);
|
||||
GL_IMPORT(false, PFNGLCLEARPROC, glClear);
|
||||
GL_IMPORT(false, PFNGLSCISSORPROC, glScissor);
|
||||
GL_IMPORT(false, PFNGLENABLEPROC, glEnable);
|
||||
GL_IMPORT(false, PFNGLCLEARSTENCILPROC, glClearStencil);
|
||||
GL_IMPORT(false, PFNGLDEPTHMASKPROC, glDepthMask);
|
||||
GL_IMPORT(false, PFNGLCLEARDEPTHPROC, glClearDepth);
|
||||
GL_IMPORT(false, PFNGLCLEARCOLORPROC, glClearColor);
|
||||
GL_IMPORT(false, PFNGLSTENCILFUNCPROC, glStencilFunc);
|
||||
GL_IMPORT(false, PFNGLSTENCILMASKPROC, glStencilMask);
|
||||
GL_IMPORT(false, PFNGLSTENCILOPPROC, glStencilOp);
|
||||
#endif // BX_PLATFORM_WINDOWS
|
||||
|
||||
GL_IMPORT(false, PFNGLACTIVETEXTUREPROC, glActiveTexture);
|
||||
GL_IMPORT(false, PFNGLCOMPRESSEDTEXIMAGE2DPROC, glCompressedTexImage2D);
|
||||
GL_IMPORT(false, PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC, glCompressedTexSubImage2D);
|
||||
GL_IMPORT(false, PFNGLCOMPRESSEDTEXIMAGE3DPROC, glCompressedTexImage3D);
|
||||
GL_IMPORT(false, PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC, glCompressedTexSubImage3D);
|
||||
GL_IMPORT(false, PFNGLBINDBUFFERPROC, glBindBuffer);
|
||||
GL_IMPORT(false, PFNGLDELETEBUFFERSPROC, glDeleteBuffers);
|
||||
GL_IMPORT(false, PFNGLGENBUFFERSPROC, glGenBuffers);
|
||||
GL_IMPORT(false, PFNGLBUFFERDATAPROC, glBufferData);
|
||||
GL_IMPORT(false, PFNGLBUFFERSUBDATAPROC, glBufferSubData);
|
||||
GL_IMPORT(false, PFNGLCREATEPROGRAMPROC, glCreateProgram);
|
||||
GL_IMPORT(false, PFNGLCREATESHADERPROC, glCreateShader);
|
||||
GL_IMPORT(false, PFNGLDELETEPROGRAMPROC, glDeleteProgram);
|
||||
GL_IMPORT(false, PFNGLDELETESHADERPROC, glDeleteShader);
|
||||
GL_IMPORT(false, PFNGLATTACHSHADERPROC, glAttachShader);
|
||||
GL_IMPORT(false, PFNGLCOMPILESHADERPROC, glCompileShader);
|
||||
GL_IMPORT(false, PFNGLSHADERSOURCEPROC, glShaderSource);
|
||||
GL_IMPORT(false, PFNGLGETSHADERIVPROC, glGetShaderiv);
|
||||
GL_IMPORT(false, PFNGLGETSHADERINFOLOGPROC, glGetShaderInfoLog);
|
||||
GL_IMPORT(false, PFNGLLINKPROGRAMPROC, glLinkProgram);
|
||||
GL_IMPORT(false, PFNGLGETPROGRAMIVPROC, glGetProgramiv);
|
||||
GL_IMPORT(false, PFNGLGETPROGRAMINFOLOGPROC, glGetProgramInfoLog);
|
||||
GL_IMPORT(false, PFNGLUSEPROGRAMPROC, glUseProgram);
|
||||
GL_IMPORT(false, PFNGLGETACTIVEATTRIBPROC, glGetActiveAttrib);
|
||||
GL_IMPORT(false, PFNGLGETATTRIBLOCATIONPROC, glGetAttribLocation);
|
||||
GL_IMPORT(false, PFNGLGETACTIVEUNIFORMPROC, glGetActiveUniform);
|
||||
GL_IMPORT(false, PFNGLGETUNIFORMLOCATIONPROC, glGetUniformLocation);
|
||||
GL_IMPORT(false, PFNGLENABLEVERTEXATTRIBARRAYPROC, glEnableVertexAttribArray);
|
||||
GL_IMPORT(false, PFNGLDISABLEVERTEXATTRIBARRAYPROC, glDisableVertexAttribArray);
|
||||
GL_IMPORT(false, PFNGLVERTEXATTRIBPOINTERPROC, glVertexAttribPointer);
|
||||
GL_IMPORT(false, PFNGLVERTEXATTRIB1FPROC, glVertexAttrib1f);
|
||||
GL_IMPORT(false, PFNGLVERTEXATTRIB2FPROC, glVertexAttrib2f);
|
||||
GL_IMPORT(false, PFNGLVERTEXATTRIB3FPROC, glVertexAttrib3f);
|
||||
GL_IMPORT(false, PFNGLVERTEXATTRIB4FPROC, glVertexAttrib4f);
|
||||
GL_IMPORT(false, PFNGLBINDFRAMEBUFFERPROC, glBindFramebuffer);
|
||||
GL_IMPORT(false, PFNGLGENFRAMEBUFFERSPROC, glGenFramebuffers);
|
||||
GL_IMPORT(false, PFNGLDELETEFRAMEBUFFERSPROC, glDeleteFramebuffers);
|
||||
GL_IMPORT(false, PFNGLCHECKFRAMEBUFFERSTATUSPROC, glCheckFramebufferStatus);
|
||||
GL_IMPORT(false, PFNGLFRAMEBUFFERRENDERBUFFERPROC, glFramebufferRenderbuffer);
|
||||
GL_IMPORT(false, PFNGLFRAMEBUFFERTEXTURE2DPROC, glFramebufferTexture2D);
|
||||
GL_IMPORT(false, PFNGLBINDRENDERBUFFERPROC, glBindRenderbuffer);
|
||||
GL_IMPORT(false, PFNGLGENRENDERBUFFERSPROC, glGenRenderbuffers);
|
||||
GL_IMPORT(false, PFNGLDELETERENDERBUFFERSPROC, glDeleteRenderbuffers);
|
||||
GL_IMPORT(false, PFNGLRENDERBUFFERSTORAGEPROC, glRenderbufferStorage);
|
||||
GL_IMPORT(false, PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC, glRenderbufferStorageMultisample);
|
||||
GL_IMPORT(false, PFNGLUNIFORM1IPROC, glUniform1i);
|
||||
GL_IMPORT(false, PFNGLUNIFORM1IVPROC, glUniform1iv);
|
||||
GL_IMPORT(false, PFNGLUNIFORM1FPROC, glUniform1f);
|
||||
GL_IMPORT(false, PFNGLUNIFORM1FVPROC, glUniform1fv);
|
||||
GL_IMPORT(false, PFNGLUNIFORM2FVPROC, glUniform2fv);
|
||||
GL_IMPORT(false, PFNGLUNIFORM3FVPROC, glUniform3fv);
|
||||
GL_IMPORT(false, PFNGLUNIFORM4FVPROC, glUniform4fv);
|
||||
GL_IMPORT(false, PFNGLUNIFORMMATRIX3FVPROC, glUniformMatrix3fv);
|
||||
GL_IMPORT(false, PFNGLUNIFORMMATRIX4FVPROC, glUniformMatrix4fv);
|
||||
GL_IMPORT(false, PFNGLTEXIMAGE3DPROC, glTexImage3D);
|
||||
GL_IMPORT(false, PFNGLTEXSUBIMAGE3DPROC, glTexSubImage3D);
|
||||
GL_IMPORT(false, PFNGLCOPYTEXSUBIMAGE3DPROC, glCopyTexSubImage3D);
|
||||
GL_IMPORT(false, PFNGLTEXIMAGE2DMULTISAMPLEPROC, glTexImage2DMultisample);
|
||||
|
||||
GL_IMPORT(false, PFNGLGENQUERIESPROC, glGenQueries);
|
||||
GL_IMPORT(false, PFNGLDELETEQUERIESPROC, glDeleteQueries);
|
||||
GL_IMPORT(false, PFNGLBEGINQUERYPROC, glBeginQuery);
|
||||
GL_IMPORT(false, PFNGLENDQUERYPROC, glEndQuery);
|
||||
GL_IMPORT(false, PFNGLGETQUERYIVPROC, glGetQueryiv);
|
||||
GL_IMPORT(false, PFNGLGETQUERYOBJECTIVPROC, glGetQueryObjectiv);
|
||||
GL_IMPORT(false, PFNGLGETQUERYOBJECTUIVPROC, glGetQueryObjectuiv);
|
||||
|
||||
GL_IMPORT(true, PFNGLGETPROGRAMBINARYPROC, glGetProgramBinary);
|
||||
GL_IMPORT(true, PFNGLPROGRAMBINARYPROC, glProgramBinary);
|
||||
GL_IMPORT(true, PFNGLPROGRAMPARAMETERIPROC, glProgramParameteri);
|
||||
|
||||
GL_IMPORT(true, PFNGLBLITFRAMEBUFFEREXTPROC, glBlitFramebufferEXT);
|
||||
|
||||
GL_IMPORT(true, PFNGLQUERYCOUNTERPROC, glQueryCounter);
|
||||
GL_IMPORT(true, PFNGLGETQUERYOBJECTI64VPROC, glGetQueryObjecti64v);
|
||||
GL_IMPORT(true, PFNGLGETQUERYOBJECTUI64VPROC, glGetQueryObjectui64v);
|
||||
GL_IMPORT(true, PFNGLGETQUERYOBJECTI64VEXTPROC, glGetQueryObjecti64vEXT);
|
||||
GL_IMPORT(true, PFNGLGETQUERYOBJECTUI64VEXTPROC, glGetQueryObjectui64vEXT);
|
||||
|
||||
GL_IMPORT(true, PFNGLSAMPLECOVERAGEARBPROC, glSampleCoverageARB);
|
||||
|
||||
GL_IMPORT(true, PFNGLBINDVERTEXARRAYPROC, glBindVertexArray);
|
||||
GL_IMPORT(true, PFNGLDELETEVERTEXARRAYSPROC, glDeleteVertexArrays);
|
||||
GL_IMPORT(true, PFNGLGENVERTEXARRAYSPROC, glGenVertexArrays);
|
||||
|
||||
GL_IMPORT(true, PFNGLSTENCILFUNCSEPARATEPROC, glStencilFuncSeparate);
|
||||
GL_IMPORT(true, PFNGLSTENCILMASKSEPARATEPROC, glStencilMaskSeparate);
|
||||
GL_IMPORT(true, PFNGLSTENCILOPSEPARATEPROC, glStencilOpSeparate);
|
||||
|
||||
GL_IMPORT(true, PFNGLBLENDFUNCSEPARATEPROC, glBlendFuncSeparate);
|
||||
GL_IMPORT(true, PFNGLBLENDEQUATIONSEPARATEPROC, glBlendEquationSeparate);
|
||||
|
||||
#if BGFX_CONFIG_DEBUG_GREMEDY
|
||||
GL_IMPORT(true, PFNGLSTRINGMARKERGREMEDYPROC, glStringMarkerGREMEDY);
|
||||
GL_IMPORT(true, PFNGLFRAMETERMINATORGREMEDYPROC, glFrameTerminatorGREMEDY);
|
||||
#endif // BGFX_CONFIG_DEBUG_GREMEDY
|
||||
|
||||
#elif BGFX_CONFIG_RENDERER_OPENGLES2
|
||||
|
||||
// OpenGL ES 2.0 Reference Pages
|
||||
// http://www.khronos.org/opengles/sdk/docs/man/
|
||||
|
||||
GL_IMPORT(true, PFNGLGETTRANSLATEDSHADERSOURCEANGLEPROC, glGetTranslatedShaderSourceANGLE);
|
||||
GL_IMPORT(true, PFNGLGETPROGRAMBINARYOESPROC, glGetProgramBinaryOES);
|
||||
GL_IMPORT(true, PFNGLPROGRAMBINARYOESPROC, glProgramBinaryOES);
|
||||
|
||||
GL_IMPORT(true, PFNGLBINDVERTEXARRAYOESPROC, glBindVertexArrayOES);
|
||||
GL_IMPORT(true, PFNGLDELETEVERTEXARRAYSOESPROC, glDeleteVertexArraysOES);
|
||||
GL_IMPORT(true, PFNGLGENVERTEXARRAYSOESPROC, glGenVertexArraysOES);
|
||||
|
||||
#endif // BGFX_CONFIG_RENDERER_
|
||||
|
||||
#if !BGFX_CONFIG_RENDERER_OPENGLES3
|
||||
GL_IMPORT(true, PFNGLVERTEXATTRIBDIVISORBGFXPROC, glVertexAttribDivisor);
|
||||
GL_IMPORT(true, PFNGLDRAWARRAYSINSTANCEDBGFXPROC, glDrawArraysInstanced);
|
||||
GL_IMPORT(true, PFNGLDRAWELEMENTSINSTANCEDBGFXPROC, glDrawElementsInstanced);
|
||||
#endif // !BGFX_CONFIG_RENDERER_OPENGLES3
|
||||
|
|
|
@ -12,17 +12,6 @@
|
|||
|
||||
namespace bgfx
|
||||
{
|
||||
#if BX_PLATFORM_LINUX
|
||||
static ::Display* s_display;
|
||||
static ::Window s_window;
|
||||
|
||||
void x11SetDisplayWindow(::Display* _display, ::Window _window)
|
||||
{
|
||||
s_display = _display;
|
||||
s_window = _window;
|
||||
}
|
||||
#endif // BX_PLATFORM_LINUX
|
||||
|
||||
struct Extension
|
||||
{
|
||||
enum Enum
|
||||
|
@ -114,17 +103,6 @@ namespace bgfx
|
|||
{ "GL_NVX_gpu_memory_info", false, true },
|
||||
};
|
||||
|
||||
#if BGFX_USE_WGL
|
||||
PFNWGLGETPROCADDRESSPROC wglGetProcAddress;
|
||||
PFNWGLMAKECURRENTPROC wglMakeCurrent;
|
||||
PFNWGLCREATECONTEXTPROC wglCreateContext;
|
||||
PFNWGLDELETECONTEXTPROC wglDeleteContext;
|
||||
#endif // BGFX_USE_WGL
|
||||
|
||||
#define GL_IMPORT(_optional, _proto, _func) _proto _func
|
||||
#include "glimports.h"
|
||||
#undef GL_IMPORT
|
||||
|
||||
static void GL_APIENTRY stubVertexAttribDivisor(GLuint /*_index*/, GLuint /*_divisor*/)
|
||||
{
|
||||
}
|
||||
|
@ -151,17 +129,6 @@ namespace bgfx
|
|||
|
||||
typedef void (*PostSwapBuffersFn)(uint32_t _width, uint32_t _height);
|
||||
|
||||
#if BX_PLATFORM_NACL
|
||||
void naclSwapCompleteCb(void* _data, int32_t _result);
|
||||
|
||||
PP_CompletionCallback naclSwapComplete =
|
||||
{
|
||||
naclSwapCompleteCb,
|
||||
NULL,
|
||||
PP_COMPLETIONCALLBACK_FLAG_NONE
|
||||
};
|
||||
#endif // BX_PLATFORM_NACL
|
||||
|
||||
static void rgbaToBgra(uint8_t* _data, uint32_t _width, uint32_t _height)
|
||||
{
|
||||
uint32_t dstpitch = _width*4;
|
||||
|
@ -192,22 +159,6 @@ namespace bgfx
|
|||
, m_flip(false)
|
||||
, m_postSwapBuffers(NULL)
|
||||
, m_hash( (BX_PLATFORM_WINDOWS<<1) | BX_ARCH_64BIT)
|
||||
#if BX_PLATFORM_NACL
|
||||
, m_context(0)
|
||||
, m_instance(0)
|
||||
, m_instInterface(NULL)
|
||||
, m_graphicsInterface(NULL)
|
||||
, m_instancedArrays(NULL)
|
||||
#elif BGFX_USE_WGL
|
||||
, m_context(NULL)
|
||||
, m_hdc(NULL)
|
||||
#elif BGFX_USE_EGL
|
||||
, m_context(NULL)
|
||||
, m_display(NULL)
|
||||
, m_surface(NULL)
|
||||
#elif BX_PLATFORM_LINUX
|
||||
, m_context(0)
|
||||
#endif // BX_PLATFORM_
|
||||
{
|
||||
memset(&m_resolution, 0, sizeof(m_resolution) );
|
||||
}
|
||||
|
@ -232,312 +183,14 @@ namespace bgfx
|
|||
if (_width != 0
|
||||
|| _height != 0)
|
||||
{
|
||||
#if BX_PLATFORM_NACL
|
||||
if (0 == m_context)
|
||||
if (!m_glctx.isValid() )
|
||||
{
|
||||
BX_TRACE("create context");
|
||||
|
||||
int32_t attribs[] =
|
||||
{
|
||||
PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8,
|
||||
PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 24,
|
||||
PP_GRAPHICS3DATTRIB_STENCIL_SIZE, 8,
|
||||
PP_GRAPHICS3DATTRIB_SAMPLES, 0,
|
||||
PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS, 0,
|
||||
PP_GRAPHICS3DATTRIB_WIDTH, int32_t(_width),
|
||||
PP_GRAPHICS3DATTRIB_HEIGHT, int32_t(_height),
|
||||
PP_GRAPHICS3DATTRIB_NONE
|
||||
};
|
||||
|
||||
m_context = m_graphicsInterface->Create(m_instance, 0, attribs);
|
||||
m_instInterface->BindGraphics(m_instance, m_context);
|
||||
glSetCurrentContextPPAPI(m_context);
|
||||
m_graphicsInterface->SwapBuffers(m_context, naclSwapComplete);
|
||||
|
||||
#if 0
|
||||
# define GL_IMPORT(_optional, _proto, _func) \
|
||||
{ \
|
||||
_func = (_proto)eglGetProcAddress(#_func); \
|
||||
BGFX_FATAL(_optional || NULL != _func, Fatal::UnableToInitialize, "Failed to create OpenGL context. eglGetProcAddress(\"%s\")", #_func); \
|
||||
}
|
||||
# include "glimports.h"
|
||||
# undef GL_IMPORT
|
||||
#endif
|
||||
m_glctx.create(_width, _height);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_graphicsInterface->ResizeBuffers(m_context, _width, _height);
|
||||
m_glctx.resize(_width, _height);
|
||||
}
|
||||
|
||||
#elif BGFX_USE_WGL
|
||||
if (NULL == m_hdc)
|
||||
{
|
||||
m_opengl32dll = LoadLibrary("opengl32.dll");
|
||||
BGFX_FATAL(NULL != m_opengl32dll, Fatal::UnableToInitialize, "Failed to load opengl32.dll.");
|
||||
|
||||
wglGetProcAddress = (PFNWGLGETPROCADDRESSPROC)GetProcAddress(m_opengl32dll, "wglGetProcAddress");
|
||||
BGFX_FATAL(NULL != wglGetProcAddress, Fatal::UnableToInitialize, "Failed get wglGetProcAddress.");
|
||||
|
||||
wglMakeCurrent = (PFNWGLMAKECURRENTPROC)GetProcAddress(m_opengl32dll, "wglMakeCurrent");
|
||||
BGFX_FATAL(NULL != wglMakeCurrent, Fatal::UnableToInitialize, "Failed get wglMakeCurrent.");
|
||||
|
||||
wglCreateContext = (PFNWGLCREATECONTEXTPROC)GetProcAddress(m_opengl32dll, "wglCreateContext");
|
||||
BGFX_FATAL(NULL != wglCreateContext, Fatal::UnableToInitialize, "Failed get wglCreateContext.");
|
||||
|
||||
wglDeleteContext = (PFNWGLDELETECONTEXTPROC)GetProcAddress(m_opengl32dll, "wglDeleteContext");
|
||||
BGFX_FATAL(NULL != wglDeleteContext, Fatal::UnableToInitialize, "Failed get wglDeleteContext.");
|
||||
|
||||
m_hdc = GetDC(g_bgfxHwnd);
|
||||
BGFX_FATAL(NULL != m_hdc, Fatal::UnableToInitialize, "GetDC failed!");
|
||||
|
||||
PIXELFORMATDESCRIPTOR pfd;
|
||||
memset(&pfd, 0, sizeof(pfd) );
|
||||
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
|
||||
pfd.nVersion = 1;
|
||||
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(m_hdc, &pfd);
|
||||
BGFX_FATAL(0 != pixelFormat, Fatal::UnableToInitialize, "ChoosePixelFormat failed!");
|
||||
|
||||
DescribePixelFormat(m_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(m_hdc, pixelFormat, &pfd);
|
||||
BGFX_FATAL(0 != result, Fatal::UnableToInitialize, "SetPixelFormat failed!");
|
||||
|
||||
m_context = wglCreateContext(m_hdc);
|
||||
BGFX_FATAL(NULL != m_context, Fatal::UnableToInitialize, "wglCreateContext failed!");
|
||||
|
||||
result = wglMakeCurrent(m_hdc, m_context);
|
||||
BGFX_FATAL(0 != result, Fatal::UnableToInitialize, "wglMakeCurrent failed!");
|
||||
|
||||
# define GL_IMPORT(_optional, _proto, _func) \
|
||||
{ \
|
||||
_func = (_proto)wglGetProcAddress(#_func); \
|
||||
if (_func == NULL) \
|
||||
{ \
|
||||
_func = (_proto)GetProcAddress(m_opengl32dll, #_func); \
|
||||
} \
|
||||
BGFX_FATAL(_optional || NULL != _func, Fatal::UnableToInitialize, "Failed to create OpenGL context. wglGetProcAddress(\"%s\")", #_func); \
|
||||
}
|
||||
# include "glimports.h"
|
||||
# undef GL_IMPORT
|
||||
}
|
||||
#elif BX_PLATFORM_LINUX
|
||||
|
||||
if (0 == m_context)
|
||||
{
|
||||
XLockDisplay(s_display);
|
||||
|
||||
int major, minor;
|
||||
bool version = glXQueryVersion(s_display, &major, &minor);
|
||||
BGFX_FATAL(version, Fatal::UnableToInitialize, "Failed to query GLX version");
|
||||
BGFX_FATAL( (major == 1 && minor >= 3) || major > 1
|
||||
, Fatal::UnableToInitialize
|
||||
, "GLX version is not >=1.3 (%d.%d)."
|
||||
, major
|
||||
, minor
|
||||
);
|
||||
|
||||
const int attrsGlx[] =
|
||||
{
|
||||
GLX_RENDER_TYPE, GLX_RGBA_BIT,
|
||||
GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
|
||||
GLX_DOUBLEBUFFER, true,
|
||||
GLX_RED_SIZE, 8,
|
||||
GLX_BLUE_SIZE, 8,
|
||||
GLX_GREEN_SIZE, 8,
|
||||
GLX_ALPHA_SIZE, 8,
|
||||
GLX_DEPTH_SIZE, 24,
|
||||
GLX_STENCIL_SIZE, 8,
|
||||
None,
|
||||
};
|
||||
|
||||
// Find suitable config
|
||||
GLXFBConfig bestConfig = NULL;
|
||||
|
||||
int numConfigs;
|
||||
GLXFBConfig* configs = glXChooseFBConfig(s_display, DefaultScreen(s_display), attrsGlx, &numConfigs);
|
||||
|
||||
BX_TRACE("glX num configs %d", numConfigs);
|
||||
|
||||
XVisualInfo* visualInfo = 0;
|
||||
for (int ii = 0; ii < numConfigs; ++ii)
|
||||
{
|
||||
visualInfo = glXGetVisualFromFBConfig(s_display, configs[ii]);
|
||||
if (NULL != visualInfo)
|
||||
{
|
||||
BX_TRACE("---");
|
||||
bool valid = true;
|
||||
for (uint32_t attr = 6; attr < countof(attrsGlx)-1 && attrsGlx[attr] != None; attr += 2)
|
||||
{
|
||||
int value;
|
||||
glXGetFBConfigAttrib(s_display, configs[ii], attrsGlx[attr], &value);
|
||||
BX_TRACE("glX %d/%d %2d: %4x, %8x (%8x%s)"
|
||||
, ii
|
||||
, numConfigs
|
||||
, attr/2
|
||||
, attrsGlx[attr]
|
||||
, value
|
||||
, attrsGlx[attr + 1]
|
||||
, value < attrsGlx[attr + 1] ? " *" : ""
|
||||
);
|
||||
|
||||
if (value < attrsGlx[attr + 1])
|
||||
{
|
||||
valid = false;
|
||||
#if !BGFX_CONFIG_DEBUG
|
||||
break;
|
||||
#endif // BGFX_CONFIG_DEBUG
|
||||
}
|
||||
}
|
||||
|
||||
if (valid)
|
||||
{
|
||||
bestConfig = configs[ii];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
XFree(visualInfo);
|
||||
visualInfo = 0;
|
||||
}
|
||||
|
||||
XFree(configs);
|
||||
BGFX_FATAL(visualInfo, Fatal::UnableToInitialize, "Failed to find a suitable X11 display configuration.");
|
||||
|
||||
BX_TRACE("Create GL 2.1 context.");
|
||||
m_context = glXCreateContext(s_display, visualInfo, 0, GL_TRUE);
|
||||
BGFX_FATAL(NULL != m_context, Fatal::UnableToInitialize, "Failed to create GL 2.1 context.");
|
||||
|
||||
XFree(visualInfo);
|
||||
|
||||
typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
|
||||
glXCreateContextAttribsARBProc glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)glXGetProcAddress((const GLubyte*)"glXCreateContextAttribsARB");
|
||||
if (NULL != glXCreateContextAttribsARB)
|
||||
{
|
||||
BX_TRACE("Create GL 3.0 context.");
|
||||
const int contextAttrs[] =
|
||||
{
|
||||
GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
|
||||
GLX_CONTEXT_MINOR_VERSION_ARB, 0,
|
||||
None,
|
||||
};
|
||||
|
||||
GLXContext context = glXCreateContextAttribsARB(s_display, bestConfig, 0, true, contextAttrs);
|
||||
|
||||
if (NULL != context)
|
||||
{
|
||||
glXDestroyContext(s_display, m_context);
|
||||
m_context = context;
|
||||
}
|
||||
}
|
||||
|
||||
glXMakeCurrent(s_display, s_window, m_context);
|
||||
|
||||
# define GL_IMPORT(_optional, _proto, _func) \
|
||||
{ \
|
||||
_func = (_proto)glXGetProcAddress((const GLubyte*)#_func); \
|
||||
BGFX_FATAL(_optional || NULL != _func, Fatal::UnableToInitialize, "Failed to create OpenGL context. glXGetProcAddress %s", #_func); \
|
||||
}
|
||||
# include "glimports.h"
|
||||
# undef GL_IMPORT
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glXSwapBuffers(s_display, s_window);
|
||||
|
||||
XUnlockDisplay(s_display);
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
#elif BGFX_USE_EGL
|
||||
if (NULL == m_context)
|
||||
{
|
||||
EGLNativeDisplayType ndt = EGL_DEFAULT_DISPLAY;
|
||||
EGLNativeWindowType nwt = (EGLNativeWindowType)NULL;
|
||||
# if BX_PLATFORM_WINDOWS
|
||||
ndt = GetDC(g_bgfxHwnd);
|
||||
nwt = g_bgfxHwnd;
|
||||
# endif // BX_PLATFORM_
|
||||
m_display = eglGetDisplay(ndt);
|
||||
BGFX_FATAL(m_display != EGL_NO_DISPLAY, Fatal::UnableToInitialize, "Failed to create display 0x%08x", m_display);
|
||||
|
||||
EGLint major = 0;
|
||||
EGLint minor = 0;
|
||||
EGLBoolean success = eglInitialize(m_display, &major, &minor);
|
||||
BGFX_FATAL(success && major >= 1 && minor >= 3, Fatal::UnableToInitialize, "Failed to initialize %d.%d", major, minor);
|
||||
|
||||
EGLint attrs[] =
|
||||
{
|
||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
||||
|
||||
# if BX_PLATFORM_ANDROID
|
||||
EGL_DEPTH_SIZE, 16,
|
||||
# else
|
||||
EGL_DEPTH_SIZE, 24,
|
||||
# endif // BX_PLATFORM_
|
||||
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
EGLint contextAttrs[] =
|
||||
{
|
||||
# if BGFX_CONFIG_RENDERER_OPENGLES2
|
||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
||||
# elif BGFX_CONFIG_RENDERER_OPENGLES3
|
||||
EGL_CONTEXT_CLIENT_VERSION, 3,
|
||||
# endif // BGFX_CONFIG_RENDERER_
|
||||
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
EGLint numConfig = 0;
|
||||
EGLConfig config = 0;
|
||||
success = eglChooseConfig(m_display, attrs, &config, 1, &numConfig);
|
||||
BGFX_FATAL(success, Fatal::UnableToInitialize, "eglChooseConfig");
|
||||
|
||||
m_surface = eglCreateWindowSurface(m_display, config, nwt, NULL);
|
||||
BGFX_FATAL(m_surface != EGL_NO_SURFACE, Fatal::UnableToInitialize, "Failed to create surface.");
|
||||
|
||||
m_context = eglCreateContext(m_display, config, EGL_NO_CONTEXT, contextAttrs);
|
||||
BGFX_FATAL(m_context != EGL_NO_CONTEXT, Fatal::UnableToInitialize, "Failed to create context.");
|
||||
|
||||
success = eglMakeCurrent(m_display, m_surface, m_surface, m_context);
|
||||
BGFX_FATAL(success, Fatal::UnableToInitialize, "Failed to set context.");
|
||||
|
||||
# if BX_PLATFORM_EMSCRIPTEN
|
||||
emscripten_set_canvas_size(_width, _height);
|
||||
# else
|
||||
# define GL_IMPORT(_optional, _proto, _func) \
|
||||
{ \
|
||||
_func = (_proto)eglGetProcAddress(#_func); \
|
||||
BX_TRACE(#_func " 0x%08x", _func); \
|
||||
BGFX_FATAL(_optional || NULL != _func, Fatal::UnableToInitialize, "Failed to create OpenGLES context. eglGetProcAddress(\"%s\")", #_func); \
|
||||
}
|
||||
# include "glimports.h"
|
||||
# undef GL_IMPORT
|
||||
# endif // !BX_PLATFORM_EMSCRIPTEN
|
||||
}
|
||||
#endif // BX_PLATFORM_
|
||||
}
|
||||
|
||||
m_flip = true;
|
||||
|
@ -547,18 +200,7 @@ namespace bgfx
|
|||
{
|
||||
if (m_flip)
|
||||
{
|
||||
#if BX_PLATFORM_NACL
|
||||
glSetCurrentContextPPAPI(m_context);
|
||||
m_graphicsInterface->SwapBuffers(m_context, naclSwapComplete);
|
||||
#elif BGFX_USE_WGL
|
||||
wglMakeCurrent(m_hdc, m_context);
|
||||
SwapBuffers(m_hdc);
|
||||
#elif BGFX_USE_EGL
|
||||
eglMakeCurrent(m_display, m_surface, m_surface, m_context);
|
||||
eglSwapBuffers(m_display, m_surface);
|
||||
#elif BX_PLATFORM_LINUX
|
||||
glXSwapBuffers(s_display, s_window);
|
||||
#endif // BX_PLATFORM_
|
||||
m_glctx.swap();
|
||||
}
|
||||
|
||||
if (NULL != m_postSwapBuffers)
|
||||
|
@ -646,7 +288,8 @@ namespace bgfx
|
|||
|
||||
void init()
|
||||
{
|
||||
setRenderContextSize(BGFX_DEFAULT_WIDTH, BGFX_DEFAULT_HEIGHT);
|
||||
m_glctx.create(BGFX_DEFAULT_WIDTH, BGFX_DEFAULT_HEIGHT);
|
||||
|
||||
#if BGFX_CONFIG_RENDERER_OPENGL
|
||||
m_queries.create();
|
||||
#endif // BGFX_CONFIG_RENDERER_OPENGL
|
||||
|
@ -660,22 +303,7 @@ namespace bgfx
|
|||
m_queries.destroy();
|
||||
#endif // BGFX_CONFIG_RENDERER_OPENGL
|
||||
|
||||
#if BGFX_USE_WGL
|
||||
if (NULL != m_hdc)
|
||||
{
|
||||
wglMakeCurrent(NULL, NULL);
|
||||
wglDeleteContext(m_context);
|
||||
m_context = NULL;
|
||||
}
|
||||
|
||||
FreeLibrary(m_opengl32dll);
|
||||
#elif BGFX_USE_EGL
|
||||
eglMakeCurrent(EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
||||
eglDestroyContext(m_display, m_context);
|
||||
eglDestroySurface(m_display, m_surface);
|
||||
eglTerminate(m_display);
|
||||
m_context = NULL;
|
||||
#endif // BGFX_USE_
|
||||
m_glctx.destroy();
|
||||
}
|
||||
|
||||
IndexBuffer m_indexBuffers[BGFX_CONFIG_MAX_INDEX_BUFFERS];
|
||||
|
@ -709,23 +337,7 @@ namespace bgfx
|
|||
PostSwapBuffersFn m_postSwapBuffers;
|
||||
uint64_t m_hash;
|
||||
|
||||
#if BX_PLATFORM_NACL
|
||||
PP_Resource m_context;
|
||||
PP_Instance m_instance;
|
||||
const PPB_Instance* m_instInterface;
|
||||
const PPB_Graphics3D* m_graphicsInterface;
|
||||
const PPB_OpenGLES2InstancedArrays* m_instancedArrays;
|
||||
#elif BGFX_USE_WGL
|
||||
HMODULE m_opengl32dll;
|
||||
HGLRC m_context;
|
||||
HDC m_hdc;
|
||||
#elif BGFX_USE_EGL
|
||||
EGLContext m_context;
|
||||
EGLDisplay m_display;
|
||||
EGLSurface m_surface;
|
||||
#elif BX_PLATFORM_LINUX
|
||||
GLXContext m_context;
|
||||
#endif // BX_PLATFORM_NACL
|
||||
GlContext m_glctx;
|
||||
};
|
||||
|
||||
RendererContext s_renderCtx;
|
||||
|
@ -733,29 +345,29 @@ namespace bgfx
|
|||
#if BX_PLATFORM_NACL
|
||||
static void GL_APIENTRY naclVertexAttribDivisor(GLuint _index, GLuint _divisor)
|
||||
{
|
||||
s_renderCtx.m_instancedArrays->VertexAttribDivisorANGLE(s_renderCtx.m_context, _index, _divisor);
|
||||
s_renderCtx.m_glctx.m_instancedArrays->VertexAttribDivisorANGLE(s_renderCtx.m_glctx.m_context, _index, _divisor);
|
||||
}
|
||||
|
||||
static void GL_APIENTRY naclDrawArraysInstanced(GLenum _mode, GLint _first, GLsizei _count, GLsizei _primcount)
|
||||
{
|
||||
s_renderCtx.m_instancedArrays->DrawArraysInstancedANGLE(s_renderCtx.m_context, _mode, _first, _count, _primcount);
|
||||
s_renderCtx.m_glctx.m_instancedArrays->DrawArraysInstancedANGLE(s_renderCtx.m_glctx.m_context, _mode, _first, _count, _primcount);
|
||||
}
|
||||
|
||||
static void GL_APIENTRY naclDrawElementsInstanced(GLenum _mode, GLsizei _count, GLenum _type, const GLvoid* _indices, GLsizei _primcount)
|
||||
{
|
||||
s_renderCtx.m_instancedArrays->DrawElementsInstancedANGLE(s_renderCtx.m_context, _mode, _count, _type, _indices, _primcount);
|
||||
s_renderCtx.m_glctx.m_instancedArrays->DrawElementsInstancedANGLE(s_renderCtx.m_glctx.m_context, _mode, _count, _type, _indices, _primcount);
|
||||
}
|
||||
|
||||
void naclSetIntefraces(PP_Instance _instance, const PPB_Instance* _instInterface, const PPB_Graphics3D* _graphicsInterface, PostSwapBuffersFn _postSwapBuffers)
|
||||
{
|
||||
s_renderCtx.m_instance = _instance;
|
||||
s_renderCtx.m_instInterface = _instInterface;
|
||||
s_renderCtx.m_graphicsInterface = _graphicsInterface;
|
||||
s_renderCtx.m_glctx.m_instance = _instance;
|
||||
s_renderCtx.m_glctx.m_instInterface = _instInterface;
|
||||
s_renderCtx.m_glctx.m_graphicsInterface = _graphicsInterface;
|
||||
s_renderCtx.m_postSwapBuffers = _postSwapBuffers;
|
||||
s_renderCtx.m_instancedArrays = glGetInstancedArraysInterfacePPAPI();
|
||||
s_renderCtx.m_glctx.m_instancedArrays = glGetInstancedArraysInterfacePPAPI();
|
||||
s_renderCtx.setRenderContextSize(BGFX_DEFAULT_WIDTH, BGFX_DEFAULT_HEIGHT);
|
||||
|
||||
if (NULL != s_renderCtx.m_instancedArrays)
|
||||
if (NULL != s_renderCtx.m_glctx.m_instancedArrays)
|
||||
{
|
||||
s_vertexAttribDivisor = naclVertexAttribDivisor;
|
||||
s_drawArraysInstanced = naclDrawArraysInstanced;
|
||||
|
|
|
@ -83,6 +83,16 @@
|
|||
# include <GLES2/gl2platform.h>
|
||||
# include <GLES2/gl2.h>
|
||||
# include <GLES2/gl2ext.h>
|
||||
# define glProgramBinary glProgramBinaryOES
|
||||
# define glGetProgramBinary glGetProgramBinaryOES
|
||||
# define glBindVertexArray glBindVertexArrayOES
|
||||
# define glDeleteVertexArrays glDeleteVertexArraysOES
|
||||
# define glGenVertexArrays glGenVertexArraysOES
|
||||
# define GL_PROGRAM_BINARY_LENGTH GL_PROGRAM_BINARY_LENGTH_OES
|
||||
# define GL_HALF_FLOAT GL_HALF_FLOAT_OES
|
||||
# define GL_RGB10_A2 GL_RGB10_A2_EXT
|
||||
# define GL_UNSIGNED_INT_2_10_10_10_REV GL_UNSIGNED_INT_2_10_10_10_REV_EXT
|
||||
# define GL_SAMPLER_3D GL_SAMPLER_3D_OES
|
||||
# elif BGFX_CONFIG_RENDERER_OPENGLES3
|
||||
# include <GLES3/gl3platform.h>
|
||||
# include <GLES3/gl3.h>
|
||||
|
@ -90,9 +100,9 @@
|
|||
# endif // BGFX_CONFIG_RENDERER_
|
||||
|
||||
# if BX_PLATFORM_EMSCRIPTEN || BX_PLATFORM_WINDOWS
|
||||
# include <EGL/egl.h>
|
||||
# undef BGFX_USE_EGL
|
||||
# define BGFX_USE_EGL 1
|
||||
# include "glcontext_egl.h"
|
||||
# endif // BX_PLATFORM_
|
||||
|
||||
# if BX_PLATFORM_EMSCRIPTEN
|
||||
|
@ -132,14 +142,11 @@ typedef void (*PFNGLGETTRANSLATEDSHADERSOURCEANGLEPROC)(GLuint shader, GLsizei b
|
|||
#endif // BGFX_CONFIG_RENDERER_OPENGL
|
||||
|
||||
#if BX_PLATFORM_NACL
|
||||
# include <ppapi/gles2/gl2ext_ppapi.h>
|
||||
# include <ppapi/c/pp_completion_callback.h>
|
||||
# include <ppapi/c/ppb_instance.h>
|
||||
# include <ppapi/c/ppb_graphics_3d.h>
|
||||
# include "glcontext_ppapi.h"
|
||||
#elif BX_PLATFORM_WINDOWS
|
||||
# include <windows.h>
|
||||
#elif BX_PLATFORM_LINUX
|
||||
# include <X11/Xlib.h>
|
||||
# include "glcontext_glx.h"
|
||||
#endif // BX_PLATFORM_
|
||||
|
||||
#if BGFX_CONFIG_DEBUG_GREMEDY && (BX_PLATFORM_WINDOWS || BX_PLATFORM_LINUX)
|
||||
|
@ -147,45 +154,7 @@ typedef void (*PFNGLGETTRANSLATEDSHADERSOURCEANGLEPROC)(GLuint shader, GLsizei b
|
|||
#endif // BGFX_CONFIG_DEBUG_GREMEDY && (BX_PLATFORM_WINDOWS || BX_PLATFORM_LINUX)
|
||||
|
||||
#if BGFX_USE_WGL
|
||||
# include <wgl/wglext.h>
|
||||
typedef PROC (APIENTRYP PFNWGLGETPROCADDRESSPROC) (LPCSTR lpszProc);
|
||||
typedef BOOL (APIENTRYP PFNWGLMAKECURRENTPROC) (HDC hdc, HGLRC hglrc);
|
||||
typedef HGLRC (APIENTRYP PFNWGLCREATECONTEXTPROC) (HDC hdc);
|
||||
typedef BOOL (APIENTRYP PFNWGLDELETECONTEXTPROC) (HGLRC hglrc);
|
||||
//
|
||||
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 PFNGLTEXIMAGE2DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
|
||||
typedef void (APIENTRYP PFNGLTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
|
||||
typedef void (APIENTRYP PFNGLTEXPARAMETERIPROC) (GLenum target, GLenum pname, GLint param);
|
||||
typedef void (APIENTRYP PFNGLTEXPARAMETERIVPROC) (GLenum target, GLenum pname, const GLint *params);
|
||||
typedef void (APIENTRYP PFNGLTEXPARAMETERFPROC) (GLenum target, GLenum pname, GLfloat param);
|
||||
typedef void (APIENTRYP PFNGLPIXELSTOREI) (GLenum pname, GLint param);
|
||||
typedef void (APIENTRYP PFNGLBINDTEXTUREPROC) (GLenum target, GLuint texture);
|
||||
typedef void (APIENTRYP PFNGLGENTEXTURESPROC) (GLsizei n, 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 PFNGLDEPTHFUNCPROC) (GLenum func);
|
||||
typedef void (APIENTRYP PFNGLDISABLEPROC) (GLenum cap);
|
||||
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 PFNGLGETINTEGERVPROC) (GLenum pname, GLint *params);
|
||||
typedef void (APIENTRYP PFNGLGETFLOATVPROC) (GLenum pname, GLfloat *params);
|
||||
typedef const GLubyte * (APIENTRYP PFNGLGETSTRINGPROC) (GLenum name);
|
||||
typedef void (APIENTRYP PFNGLDRAWARRAYSPROC) (GLenum mode, GLint first, GLsizei count);
|
||||
typedef void (APIENTRYP PFNGLBLENDFUNCPROC) (GLenum sfactor, GLenum dfactor);
|
||||
typedef void (APIENTRYP PFNGLPOINTSIZEPROC) (GLfloat size);
|
||||
typedef void (APIENTRYP PFNGLCULLFACEPROC) (GLenum mode);
|
||||
typedef void (APIENTRYP PFNGLCLEARPROC) (GLbitfield mask);
|
||||
typedef void (APIENTRYP PFNGLSCISSORPROC) (GLint x, GLint y, GLsizei width, GLsizei height);
|
||||
typedef void (APIENTRYP PFNGLENABLEPROC) (GLenum cap);
|
||||
typedef void (APIENTRYP PFNGLCLEARSTENCILPROC) (GLint s);
|
||||
typedef void (APIENTRYP PFNGLDEPTHMASKPROC) (GLboolean flag);
|
||||
typedef void (APIENTRYP PFNGLCLEARDEPTHPROC) (GLdouble depth);
|
||||
typedef void (APIENTRYP PFNGLCLEARCOLORPROC) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
|
||||
typedef void (APIENTRYP PFNGLSTENCILFUNCPROC) (GLenum func, GLint ref, GLuint mask);
|
||||
typedef void (APIENTRYP PFNGLSTENCILMASKPROC) (GLuint mask);
|
||||
typedef void (APIENTRYP PFNGLSTENCILOPPROC) (GLenum fail, GLenum zfail, GLenum zpass);
|
||||
# include "glcontext_wgl.h"
|
||||
#endif // BGFX_USE_WGL
|
||||
|
||||
#ifndef GL_APIENTRY
|
||||
|
@ -200,19 +169,6 @@ typedef void (APIENTRYP PFNGLSTENCILOPPROC) (GLenum fail, GLenum zfail, GLenum z
|
|||
# define glClearDepth glClearDepthf
|
||||
#endif // !BGFX_CONFIG_RENDERER_OPENGL
|
||||
|
||||
#if BGFX_CONFIG_RENDERER_OPENGLES2
|
||||
# define glProgramBinary glProgramBinaryOES
|
||||
# define glGetProgramBinary glGetProgramBinaryOES
|
||||
# define glBindVertexArray glBindVertexArrayOES
|
||||
# define glDeleteVertexArrays glDeleteVertexArraysOES
|
||||
# define glGenVertexArrays glGenVertexArraysOES
|
||||
# define GL_PROGRAM_BINARY_LENGTH GL_PROGRAM_BINARY_LENGTH_OES
|
||||
# define GL_HALF_FLOAT GL_HALF_FLOAT_OES
|
||||
# define GL_RGB10_A2 GL_RGB10_A2_EXT
|
||||
# define GL_UNSIGNED_INT_2_10_10_10_REV GL_UNSIGNED_INT_2_10_10_10_REV_EXT
|
||||
# define GL_SAMPLER_3D GL_SAMPLER_3D_OES
|
||||
#endif // BGFX_CONFIG_RENDERER_OPENGLES2
|
||||
|
||||
namespace bgfx
|
||||
{
|
||||
typedef void (GL_APIENTRYP PFNGLVERTEXATTRIBDIVISORBGFXPROC)(GLuint _index, GLuint _divisor);
|
||||
|
@ -258,12 +214,6 @@ namespace bgfx
|
|||
#define GREMEDY_SETMARKER(_string) _GREMEDY_SETMARKER(_string)
|
||||
#define GREMEDY_FRAMETERMINATOR() _GREMEDY_FRAMETERMINATOR()
|
||||
|
||||
#if BGFX_USE_WGL
|
||||
extern PFNWGLGETPROCADDRESSPROC wglGetProcAddress;
|
||||
extern PFNWGLMAKECURRENTPROC wglMakeCurrent;
|
||||
extern PFNWGLCREATECONTEXTPROC wglCreateContext;
|
||||
#endif // BGFX_USE_WGL
|
||||
|
||||
#define GL_IMPORT(_optional, _proto, _func) extern _proto _func
|
||||
#include "glimports.h"
|
||||
#undef GL_IMPORT
|
||||
|
|
Loading…
Reference in New Issue