mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-28 18:45:54 -05:00
EGL: Added ability to use EGL on Linux.
This commit is contained in:
parent
524b28a9f7
commit
c65f04ae05
6 changed files with 68 additions and 32 deletions
17
src/bgfx.cpp
17
src/bgfx.cpp
|
@ -21,17 +21,27 @@ namespace bgfx
|
|||
|
||||
#if BX_PLATFORM_ANDROID
|
||||
::ANativeWindow* g_bgfxAndroidWindow = NULL;
|
||||
|
||||
void androidSetWindow(::ANativeWindow* _window)
|
||||
{
|
||||
g_bgfxAndroidWindow = _window;
|
||||
}
|
||||
#elif BX_PLATFORM_IOS
|
||||
void* g_bgfxEaglLayer = NULL;
|
||||
|
||||
void iosSetEaglLayer(void* _layer)
|
||||
{
|
||||
g_bgfxEaglLayer = _layer;
|
||||
}
|
||||
#elif BX_PLATFORM_LINUX
|
||||
::Display* g_bgfxX11Display;
|
||||
::Window g_bgfxX11Window;
|
||||
|
||||
void x11SetDisplayWindow(::Display* _display, ::Window _window)
|
||||
{
|
||||
g_bgfxX11Display = _display;
|
||||
g_bgfxX11Window = _window;
|
||||
}
|
||||
#elif BX_PLATFORM_OSX
|
||||
void* g_bgfxNSWindow = NULL;
|
||||
|
||||
|
@ -1424,9 +1434,16 @@ again:
|
|||
_type = RendererType::Direct3D11;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (s_rendererCreator[RendererType::OpenGL].supported)
|
||||
{
|
||||
_type = RendererType::OpenGL;
|
||||
}
|
||||
else if (s_rendererCreator[RendererType::OpenGLES].supported)
|
||||
{
|
||||
_type = RendererType::OpenGLES;
|
||||
}
|
||||
}
|
||||
|
||||
if (!s_rendererCreator[_type].supported)
|
||||
{
|
||||
|
|
|
@ -200,6 +200,9 @@ namespace bgfx
|
|||
extern ::ANativeWindow* g_bgfxAndroidWindow;
|
||||
#elif BX_PLATFORM_IOS
|
||||
extern void* g_bgfxEaglLayer;
|
||||
#elif BX_PLATFORM_LINUX
|
||||
extern ::Display* g_bgfxX11Display;
|
||||
extern ::Window g_bgfxX11Window;
|
||||
#elif BX_PLATFORM_OSX
|
||||
extern void* g_bgfxNSWindow;
|
||||
#elif BX_PLATFORM_WINDOWS
|
||||
|
|
|
@ -63,8 +63,8 @@ EGL_IMPORT
|
|||
|
||||
void* eglOpen()
|
||||
{
|
||||
void* handle = bx::dlopen("libEGL.dll");
|
||||
BGFX_FATAL(NULL != handle, Fatal::UnableToInitialize, "Failed to load libEGL dynamic library.");
|
||||
void* handle = bx::dlopen("libEGL." BX_DL_EXT);
|
||||
BGFX_FATAL(NULL != handle, Fatal::UnableToInitialize, "Failed to load libEGL dynamic library. %s", dlerror());
|
||||
|
||||
#define EGL_IMPORT_FUNC(_proto, _func) \
|
||||
_func = (_proto)bx::dlsym(handle, #_func); \
|
||||
|
@ -184,6 +184,9 @@ EGL_IMPORT
|
|||
# if BX_PLATFORM_WINDOWS
|
||||
ndt = GetDC(g_bgfxHwnd);
|
||||
nwh = g_bgfxHwnd;
|
||||
# elif BX_PLATFORM_LINUX
|
||||
ndt = g_bgfxX11Display;
|
||||
nwh = g_bgfxX11Window;
|
||||
# endif // BX_PLATFORM_
|
||||
m_display = eglGetDisplay(ndt);
|
||||
BGFX_FATAL(m_display != EGL_NO_DISPLAY, Fatal::UnableToInitialize, "Failed to create display %p", m_display);
|
||||
|
@ -278,6 +281,7 @@ EGL_IMPORT
|
|||
|
||||
void GlContext::resize(uint32_t _width, uint32_t _height, bool _vsync)
|
||||
{
|
||||
BX_UNUSED(_width, _height);
|
||||
# if BX_PLATFORM_ANDROID
|
||||
EGLint format;
|
||||
eglGetConfigAttrib(m_display, m_config, EGL_NATIVE_VISUAL_ID, &format);
|
||||
|
@ -334,8 +338,8 @@ EGL_IMPORT
|
|||
void GlContext::import()
|
||||
{
|
||||
BX_TRACE("Import:");
|
||||
# if BX_PLATFORM_WINDOWS
|
||||
void* glesv2 = bx::dlopen("libGLESv2.dll");
|
||||
# if BX_PLATFORM_WINDOWS || BX_PLATFORM_LINUX
|
||||
void* glesv2 = bx::dlopen("libGLESv2." BX_DL_EXT);
|
||||
# define GL_EXTENSION(_optional, _proto, _func, _import) \
|
||||
{ \
|
||||
if (NULL == _func) \
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
#if (BX_PLATFORM_FREEBSD || BX_PLATFORM_LINUX) && (BGFX_CONFIG_RENDERER_OPENGLES || BGFX_CONFIG_RENDERER_OPENGL)
|
||||
# include "renderer_gl.h"
|
||||
|
||||
# if BGFX_USE_GLX
|
||||
# define GLX_GLXEXT_PROTOTYPES
|
||||
# include <glx/glxext.h>
|
||||
|
||||
|
@ -22,43 +24,34 @@ namespace bgfx
|
|||
# define GL_IMPORT(_optional, _proto, _func, _import) _proto _func
|
||||
# include "glimports.h"
|
||||
|
||||
static ::Display* s_display;
|
||||
static ::Window s_window;
|
||||
|
||||
struct SwapChainGL
|
||||
{
|
||||
SwapChainGL(::Window _window, XVisualInfo* _visualInfo, GLXContext _context)
|
||||
: m_window(_window)
|
||||
{
|
||||
m_context = glXCreateContext(s_display, _visualInfo, _context, GL_TRUE);
|
||||
m_context = glXCreateContext(g_bgfxX11Display, _visualInfo, _context, GL_TRUE);
|
||||
}
|
||||
|
||||
~SwapChainGL()
|
||||
{
|
||||
glXMakeCurrent(s_display, 0, 0);
|
||||
glXDestroyContext(s_display, m_context);
|
||||
glXMakeCurrent(g_bgfxX11Display, 0, 0);
|
||||
glXDestroyContext(g_bgfxX11Display, m_context);
|
||||
}
|
||||
|
||||
void makeCurrent()
|
||||
{
|
||||
glXMakeCurrent(s_display, m_window, m_context);
|
||||
glXMakeCurrent(g_bgfxX11Display, m_window, m_context);
|
||||
}
|
||||
|
||||
void swapBuffers()
|
||||
{
|
||||
glXSwapBuffers(s_display, m_window);
|
||||
glXSwapBuffers(g_bgfxX11Display, m_window);
|
||||
}
|
||||
|
||||
Window m_window;
|
||||
GLXContext m_context;
|
||||
};
|
||||
|
||||
void x11SetDisplayWindow(::Display* _display, ::Window _window)
|
||||
{
|
||||
s_display = _display;
|
||||
s_window = _window;
|
||||
}
|
||||
|
||||
void GlContext::create(uint32_t _width, uint32_t _height)
|
||||
{
|
||||
BX_UNUSED(_width, _height);
|
||||
|
@ -181,13 +174,13 @@ namespace bgfx
|
|||
|
||||
import();
|
||||
|
||||
glXMakeCurrent(s_display, s_window, m_context);
|
||||
glXMakeCurrent(g_bgfxX11Display, g_bgfxX11Window, m_context);
|
||||
|
||||
glXSwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddress( (const GLubyte*)"glXSwapIntervalEXT");
|
||||
if (NULL != glXSwapIntervalEXT)
|
||||
{
|
||||
BX_TRACE("Using glXSwapIntervalEXT.");
|
||||
glXSwapIntervalEXT(s_display, s_window, 0);
|
||||
glXSwapIntervalEXT(g_bgfxX11Display, g_bgfxX11Window, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -210,7 +203,7 @@ namespace bgfx
|
|||
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glXSwapBuffers(s_display, s_window);
|
||||
glXSwapBuffers(s_display, g_bgfxX11Window);
|
||||
}
|
||||
|
||||
void GlContext::destroy()
|
||||
|
@ -226,7 +219,7 @@ namespace bgfx
|
|||
|
||||
if (NULL != glXSwapIntervalEXT)
|
||||
{
|
||||
glXSwapIntervalEXT(s_display, s_window, interval);
|
||||
glXSwapIntervalEXT(g_bgfxX11Display, g_bgfxX11Window, interval);
|
||||
}
|
||||
else if (NULL != glXSwapIntervalMESA)
|
||||
{
|
||||
|
@ -257,8 +250,8 @@ namespace bgfx
|
|||
{
|
||||
if (NULL == _swapChain)
|
||||
{
|
||||
glXMakeCurrent(s_display, s_window, m_context);
|
||||
glXSwapBuffers(s_display, s_window);
|
||||
glXMakeCurrent(g_bgfxX11Display, g_bgfxX11Window, m_context);
|
||||
glXSwapBuffers(g_bgfxX11Display, g_bgfxX11Window);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -271,7 +264,7 @@ namespace bgfx
|
|||
{
|
||||
if (NULL == _swapChain)
|
||||
{
|
||||
glXMakeCurrent(s_display, s_window, m_context);
|
||||
glXMakeCurrent(g_bgfxX11Display, g_bgfxX11Window, m_context);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -295,4 +288,6 @@ namespace bgfx
|
|||
|
||||
} // namespace bgfx
|
||||
|
||||
# endif // BGFX_USE_GLX
|
||||
|
||||
#endif // (BX_PLATFORM_FREEBSD || BX_PLATFORM_LINUX) && (BGFX_CONFIG_RENDERER_OPENGLES || BGFX_CONFIG_RENDERER_OPENGL)
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#ifndef BGFX_GLCONTEXT_GLX_H_HEADER_GUARD
|
||||
#define BGFX_GLCONTEXT_GLX_H_HEADER_GUARD
|
||||
|
||||
#if BX_PLATFORM_LINUX || BX_PLATFORM_FREEBSD
|
||||
#if BGFX_USE_GLX
|
||||
|
||||
# include <X11/Xlib.h>
|
||||
# include <GL/glx.h>
|
||||
|
@ -45,6 +45,6 @@ namespace bgfx
|
|||
};
|
||||
} // namespace bgfx
|
||||
|
||||
#endif // BX_PLATFORM_LINUX || BX_PLATFORM_FREEBSD
|
||||
#endif // BGFX_USE_GLX
|
||||
|
||||
#endif // BGFX_GLCONTEXT_GLX_H_HEADER_GUARD
|
||||
|
|
|
@ -6,9 +6,26 @@
|
|||
#ifndef BGFX_RENDERER_GL_H_HEADER_GUARD
|
||||
#define BGFX_RENDERER_GL_H_HEADER_GUARD
|
||||
|
||||
#define BGFX_USE_EGL (BGFX_CONFIG_RENDERER_OPENGLES && (BX_PLATFORM_ANDROID || BX_PLATFORM_EMSCRIPTEN || BX_PLATFORM_QNX || BX_PLATFORM_RPI || BX_PLATFORM_WINDOWS) )
|
||||
#define BGFX_USE_EGL (BGFX_CONFIG_RENDERER_OPENGLES && (0 \
|
||||
|| BX_PLATFORM_ANDROID \
|
||||
|| BX_PLATFORM_EMSCRIPTEN \
|
||||
|| BX_PLATFORM_LINUX \
|
||||
|| BX_PLATFORM_QNX \
|
||||
|| BX_PLATFORM_RPI \
|
||||
|| BX_PLATFORM_WINDOWS \
|
||||
) )
|
||||
|
||||
#define BGFX_USE_WGL (BGFX_CONFIG_RENDERER_OPENGL && BX_PLATFORM_WINDOWS)
|
||||
#define BGFX_USE_GL_DYNAMIC_LIB (BX_PLATFORM_LINUX || BX_PLATFORM_OSX || BX_PLATFORM_WINDOWS)
|
||||
#define BGFX_USE_GLX (BGFX_CONFIG_RENDERER_OPENGL && (0 \
|
||||
|| BX_PLATFORM_LINUX \
|
||||
|| BX_PLATFORM_FREEBSD \
|
||||
) )
|
||||
|
||||
#define BGFX_USE_GL_DYNAMIC_LIB (0 \
|
||||
|| BX_PLATFORM_LINUX \
|
||||
|| BX_PLATFORM_OSX \
|
||||
|| BX_PLATFORM_WINDOWS \
|
||||
)
|
||||
|
||||
#if BGFX_CONFIG_RENDERER_OPENGL
|
||||
# if BGFX_CONFIG_RENDERER_OPENGL >= 31
|
||||
|
|
Loading…
Reference in a new issue