trunk/3rdparty/bgfx/examples/common/entry/entry_glfw.cpp
| r0 | r245165 | |
| 1 | /* |
| 2 | * Copyright 2011-2015 Branimir Karadzic. All rights reserved. |
| 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause |
| 4 | */ |
| 5 | |
| 6 | #include "entry_p.h" |
| 7 | |
| 8 | #if ENTRY_CONFIG_USE_GLFW |
| 9 | |
| 10 | #define GLFW_DLL |
| 11 | #include <GLFW/glfw3.h> |
| 12 | #include <bgfxplatform.h> |
| 13 | #include "dbg.h" |
| 14 | |
| 15 | // This is just trivial implementation of GLFW3 integration. |
| 16 | // It's here just for testing purpose. |
| 17 | |
| 18 | namespace entry |
| 19 | { |
| 20 | static void errorCb(int _error, const char* _description) |
| 21 | { |
| 22 | DBG("GLFW error %d: %s", _error, _description); |
| 23 | } |
| 24 | |
| 25 | struct Context |
| 26 | { |
| 27 | Context() |
| 28 | { |
| 29 | } |
| 30 | |
| 31 | int run(int _argc, char** _argv) |
| 32 | { |
| 33 | glfwSetErrorCallback(errorCb); |
| 34 | |
| 35 | glfwInit(); |
| 36 | m_window = glfwCreateWindow(1280, 720, "bgfx", NULL, NULL); |
| 37 | glfwMakeContextCurrent(m_window); |
| 38 | |
| 39 | glfwSetKeyCallback(m_window, keyCb); |
| 40 | |
| 41 | bgfx::glfwSetWindow(m_window); |
| 42 | int result = main(_argc, _argv); |
| 43 | |
| 44 | glfwDestroyWindow(m_window); |
| 45 | glfwTerminate(); |
| 46 | return result; |
| 47 | } |
| 48 | |
| 49 | static void keyCb(GLFWwindow* _window, int _key, int _scancode, int _action, int _mods); |
| 50 | |
| 51 | EventQueue m_eventQueue; |
| 52 | |
| 53 | GLFWwindow* m_window; |
| 54 | }; |
| 55 | |
| 56 | Context s_ctx; |
| 57 | |
| 58 | void Context::keyCb(GLFWwindow* _window, int _key, int _scancode, int _action, int _mods) |
| 59 | { |
| 60 | BX_UNUSED(_window, _scancode, _mods); |
| 61 | if (_key == GLFW_KEY_Q |
| 62 | && _action == GLFW_PRESS |
| 63 | && _mods == GLFW_MOD_CONTROL) |
| 64 | { |
| 65 | s_ctx.m_eventQueue.postExitEvent(); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | const Event* poll() |
| 70 | { |
| 71 | glfwPollEvents(); |
| 72 | |
| 73 | if (glfwWindowShouldClose(s_ctx.m_window) ) |
| 74 | { |
| 75 | s_ctx.m_eventQueue.postExitEvent(); |
| 76 | } |
| 77 | return s_ctx.m_eventQueue.poll(); |
| 78 | } |
| 79 | |
| 80 | const Event* poll(WindowHandle _handle) |
| 81 | { |
| 82 | return s_ctx.m_eventQueue.poll(_handle); |
| 83 | } |
| 84 | |
| 85 | void release(const Event* _event) |
| 86 | { |
| 87 | s_ctx.m_eventQueue.release(_event); |
| 88 | } |
| 89 | |
| 90 | WindowHandle createWindow(int32_t _x, int32_t _y, uint32_t _width, uint32_t _height, uint32_t _flags, const char* _title) |
| 91 | { |
| 92 | BX_UNUSED(_x, _y, _width, _height, _flags, _title); |
| 93 | WindowHandle handle = { UINT16_MAX }; |
| 94 | return handle; |
| 95 | } |
| 96 | |
| 97 | void destroyWindow(WindowHandle _handle) |
| 98 | { |
| 99 | BX_UNUSED(_handle); |
| 100 | } |
| 101 | |
| 102 | void setWindowPos(WindowHandle _handle, int32_t _x, int32_t _y) |
| 103 | { |
| 104 | BX_UNUSED(_handle, _x, _y); |
| 105 | } |
| 106 | |
| 107 | void setWindowSize(WindowHandle _handle, uint32_t _width, uint32_t _height) |
| 108 | { |
| 109 | BX_UNUSED(_handle, _width, _height); |
| 110 | } |
| 111 | |
| 112 | void setWindowTitle(WindowHandle _handle, const char* _title) |
| 113 | { |
| 114 | BX_UNUSED(_handle, _title); |
| 115 | } |
| 116 | |
| 117 | void toggleWindowFrame(WindowHandle _handle) |
| 118 | { |
| 119 | BX_UNUSED(_handle); |
| 120 | } |
| 121 | |
| 122 | void toggleFullscreen(WindowHandle _handle) |
| 123 | { |
| 124 | BX_UNUSED(_handle); |
| 125 | } |
| 126 | |
| 127 | void setMouseLock(WindowHandle _handle, bool _lock) |
| 128 | { |
| 129 | BX_UNUSED(_handle, _lock); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | int main(int _argc, char** _argv) |
| 134 | { |
| 135 | using namespace entry; |
| 136 | return s_ctx.run(_argc, _argv); |
| 137 | } |
| 138 | |
| 139 | #endif // ENTRY_CONFIG_USE_GLFW |
trunk/3rdparty/bgfx/src/bgfx.cpp
| r245164 | r245165 | |
| 19 | 19 | # define BGFX_CHECK_RENDER_THREAD() |
| 20 | 20 | #endif // BGFX_CONFIG_MULTITHREADED && !BX_PLATFORM_OSX && !BX_PLATFORM_IOS |
| 21 | 21 | |
| 22 | | #define BGFX_CHECK_HANDLE(_handle, _max) \ |
| 23 | | BX_CHECK(isValid(_handle) \ |
| 24 | | && _handle.idx < _max \ |
| 25 | | , "Invalid handle. %d (< %d " #_max ")" \ |
| 26 | | , _handle.idx \ |
| 27 | | , _max \ |
| 28 | | ); |
| 29 | | |
| 30 | 22 | #if BX_PLATFORM_ANDROID |
| 31 | 23 | ::ANativeWindow* g_bgfxAndroidWindow = NULL; |
| 32 | 24 | |
| r245164 | r245165 | |
| 44 | 36 | #elif BX_PLATFORM_LINUX |
| 45 | 37 | void* g_bgfxX11Display; |
| 46 | 38 | uint32_t g_bgfxX11Window; |
| 39 | void* g_bgfxGLX; |
| 47 | 40 | |
| 48 | | void x11SetDisplayWindow(void* _display, uint32_t _window) |
| 41 | void x11SetDisplayWindow(void* _display, uint32_t _window, void* _glx) |
| 49 | 42 | { |
| 50 | 43 | g_bgfxX11Display = _display; |
| 51 | 44 | g_bgfxX11Window = _window; |
| 45 | g_bgfxGLX = _glx; |
| 52 | 46 | } |
| 53 | 47 | #elif BX_PLATFORM_OSX |
| 54 | 48 | void* g_bgfxNSWindow = NULL; |
| 49 | void* g_bgfxNSGL = NULL; |
| 55 | 50 | |
| 56 | | void osxSetNSWindow(void* _window) |
| 51 | void osxSetNSWindow(void* _window, void* _nsgl) |
| 57 | 52 | { |
| 58 | 53 | g_bgfxNSWindow = _window; |
| 54 | g_bgfxNSGL = _nsgl; |
| 59 | 55 | } |
| 60 | 56 | #elif BX_PLATFORM_WINDOWS |
| 61 | 57 | ::HWND g_bgfxHwnd = NULL; |
| r245164 | r245165 | |
| 1332 | 1328 | typedef RendererContextI* (*RendererCreateFn)(); |
| 1333 | 1329 | typedef void (*RendererDestroyFn)(); |
| 1334 | 1330 | |
| 1335 | | extern RendererContextI* rendererCreateNULL(); |
| 1336 | | extern void rendererDestroyNULL(); |
| 1331 | #define BGFX_RENDERER_CONTEXT(_namespace) \ |
| 1332 | namespace _namespace \ |
| 1333 | { \ |
| 1334 | extern RendererContextI* rendererCreate(); \ |
| 1335 | extern void rendererDestroy(); \ |
| 1336 | } |
| 1337 | 1337 | |
| 1338 | | extern RendererContextI* rendererCreateGL(); |
| 1339 | | extern void rendererDestroyGL(); |
| 1338 | BGFX_RENDERER_CONTEXT(noop); |
| 1339 | BGFX_RENDERER_CONTEXT(d3d9); |
| 1340 | BGFX_RENDERER_CONTEXT(d3d11); |
| 1341 | BGFX_RENDERER_CONTEXT(d3d12); |
| 1342 | BGFX_RENDERER_CONTEXT(gl); |
| 1343 | BGFX_RENDERER_CONTEXT(vk); |
| 1340 | 1344 | |
| 1341 | | extern RendererContextI* rendererCreateD3D9(); |
| 1342 | | extern void rendererDestroyD3D9(); |
| 1345 | #undef BGFX_RENDERER_CONTEXT |
| 1343 | 1346 | |
| 1344 | | extern RendererContextI* rendererCreateD3D11(); |
| 1345 | | extern void rendererDestroyD3D11(); |
| 1346 | | |
| 1347 | | extern RendererContextI* rendererCreateD3D12(); |
| 1348 | | extern void rendererDestroyD3D12(); |
| 1349 | | |
| 1350 | | extern RendererContextI* rendererCreateVK(); |
| 1351 | | extern void rendererDestroyVK(); |
| 1352 | | |
| 1353 | 1347 | struct RendererCreator |
| 1354 | 1348 | { |
| 1355 | 1349 | RendererCreateFn createFn; |
| r245164 | r245165 | |
| 1360 | 1354 | |
| 1361 | 1355 | static const RendererCreator s_rendererCreator[] = |
| 1362 | 1356 | { |
| 1363 | | { rendererCreateNULL, rendererDestroyNULL, BGFX_RENDERER_NULL_NAME, !!BGFX_CONFIG_RENDERER_NULL }, // Null |
| 1364 | | { rendererCreateD3D9, rendererDestroyD3D9, BGFX_RENDERER_DIRECT3D9_NAME, !!BGFX_CONFIG_RENDERER_DIRECT3D9 }, // Direct3D9 |
| 1365 | | { rendererCreateD3D11, rendererDestroyD3D11, BGFX_RENDERER_DIRECT3D11_NAME, !!BGFX_CONFIG_RENDERER_DIRECT3D11 }, // Direct3D11 |
| 1366 | | { rendererCreateD3D12, rendererDestroyD3D12, BGFX_RENDERER_DIRECT3D12_NAME, !!BGFX_CONFIG_RENDERER_DIRECT3D12 }, // Direct3D12 |
| 1367 | | { rendererCreateGL, rendererDestroyGL, BGFX_RENDERER_OPENGL_NAME, !!BGFX_CONFIG_RENDERER_OPENGLES }, // OpenGLES |
| 1368 | | { rendererCreateGL, rendererDestroyGL, BGFX_RENDERER_OPENGL_NAME, !!BGFX_CONFIG_RENDERER_OPENGL }, // OpenGL |
| 1369 | | { rendererCreateVK, rendererDestroyVK, BGFX_RENDERER_VULKAN_NAME, !!BGFX_CONFIG_RENDERER_VULKAN }, // Vulkan |
| 1357 | { noop::rendererCreate, noop::rendererDestroy, BGFX_RENDERER_NULL_NAME, !!BGFX_CONFIG_RENDERER_NULL }, // Null |
| 1358 | { d3d9::rendererCreate, d3d9::rendererDestroy, BGFX_RENDERER_DIRECT3D9_NAME, !!BGFX_CONFIG_RENDERER_DIRECT3D9 }, // Direct3D9 |
| 1359 | { d3d11::rendererCreate, d3d11::rendererDestroy, BGFX_RENDERER_DIRECT3D11_NAME, !!BGFX_CONFIG_RENDERER_DIRECT3D11 }, // Direct3D11 |
| 1360 | { d3d12::rendererCreate, d3d12::rendererDestroy, BGFX_RENDERER_DIRECT3D12_NAME, !!BGFX_CONFIG_RENDERER_DIRECT3D12 }, // Direct3D12 |
| 1361 | { gl::rendererCreate, gl::rendererDestroy, BGFX_RENDERER_OPENGL_NAME, !!BGFX_CONFIG_RENDERER_OPENGLES }, // OpenGLES |
| 1362 | { gl::rendererCreate, gl::rendererDestroy, BGFX_RENDERER_OPENGL_NAME, !!BGFX_CONFIG_RENDERER_OPENGL }, // OpenGL |
| 1363 | { vk::rendererCreate, vk::rendererDestroy, BGFX_RENDERER_VULKAN_NAME, !!BGFX_CONFIG_RENDERER_VULKAN }, // Vulkan |
| 1370 | 1364 | }; |
| 1371 | 1365 | BX_STATIC_ASSERT(BX_COUNTOF(s_rendererCreator) == RendererType::Count); |
| 1372 | 1366 | |
| r245164 | r245165 | |
| 2770 | 2764 | void setUniform(UniformHandle _handle, const void* _value, uint16_t _num) |
| 2771 | 2765 | { |
| 2772 | 2766 | BGFX_CHECK_MAIN_THREAD(); |
| 2773 | | BGFX_CHECK_HANDLE(_handle, BGFX_CONFIG_MAX_UNIFORMS); |
| 2774 | 2767 | s_ctx->setUniform(_handle, _value, _num); |
| 2775 | 2768 | } |
| 2776 | 2769 | |
| 2777 | 2770 | void setIndexBuffer(IndexBufferHandle _handle, uint32_t _firstIndex, uint32_t _numIndices) |
| 2778 | 2771 | { |
| 2779 | 2772 | BGFX_CHECK_MAIN_THREAD(); |
| 2780 | | BGFX_CHECK_HANDLE(_handle, BGFX_CONFIG_MAX_INDEX_BUFFERS); |
| 2781 | 2773 | s_ctx->setIndexBuffer(_handle, _firstIndex, _numIndices); |
| 2782 | 2774 | } |
| 2783 | 2775 | |
| 2784 | 2776 | void setIndexBuffer(DynamicIndexBufferHandle _handle, uint32_t _firstIndex, uint32_t _numIndices) |
| 2785 | 2777 | { |
| 2786 | 2778 | BGFX_CHECK_MAIN_THREAD(); |
| 2787 | | BGFX_CHECK_HANDLE(_handle, BGFX_CONFIG_MAX_DYNAMIC_INDEX_BUFFERS); |
| 2788 | 2779 | s_ctx->setIndexBuffer(_handle, _firstIndex, _numIndices); |
| 2789 | 2780 | } |
| 2790 | 2781 | |
| r245164 | r245165 | |
| 2809 | 2800 | void setVertexBuffer(VertexBufferHandle _handle, uint32_t _startVertex, uint32_t _numVertices) |
| 2810 | 2801 | { |
| 2811 | 2802 | BGFX_CHECK_MAIN_THREAD(); |
| 2812 | | BGFX_CHECK_HANDLE(_handle, BGFX_CONFIG_MAX_VERTEX_BUFFERS); |
| 2813 | 2803 | s_ctx->setVertexBuffer(_handle, _startVertex, _numVertices); |
| 2814 | 2804 | } |
| 2815 | 2805 | |
| 2816 | 2806 | void setVertexBuffer(DynamicVertexBufferHandle _handle, uint32_t _numVertices) |
| 2817 | 2807 | { |
| 2818 | 2808 | BGFX_CHECK_MAIN_THREAD(); |
| 2819 | | BGFX_CHECK_HANDLE(_handle, BGFX_CONFIG_MAX_DYNAMIC_VERTEX_BUFFERS); |
| 2820 | 2809 | s_ctx->setVertexBuffer(_handle, _numVertices); |
| 2821 | 2810 | } |
| 2822 | 2811 | |
| r245164 | r245165 | |
| 2842 | 2831 | void setInstanceDataBuffer(VertexBufferHandle _handle, uint32_t _startVertex, uint32_t _num) |
| 2843 | 2832 | { |
| 2844 | 2833 | BGFX_CHECK_MAIN_THREAD(); |
| 2845 | | BGFX_CHECK_HANDLE(_handle, BGFX_CONFIG_MAX_VERTEX_BUFFERS); |
| 2846 | 2834 | s_ctx->setInstanceDataBuffer(_handle, _startVertex, _num); |
| 2847 | 2835 | } |
| 2848 | 2836 | |
| 2849 | 2837 | void setInstanceDataBuffer(DynamicVertexBufferHandle _handle, uint32_t _startVertex, uint32_t _num) |
| 2850 | 2838 | { |
| 2851 | 2839 | BGFX_CHECK_MAIN_THREAD(); |
| 2852 | | BGFX_CHECK_HANDLE(_handle, BGFX_CONFIG_MAX_DYNAMIC_VERTEX_BUFFERS); |
| 2853 | 2840 | s_ctx->setInstanceDataBuffer(_handle, _startVertex, _num); |
| 2854 | 2841 | } |
| 2855 | 2842 | |
| 2856 | 2843 | void setProgram(ProgramHandle _handle) |
| 2857 | 2844 | { |
| 2858 | 2845 | BGFX_CHECK_MAIN_THREAD(); |
| 2859 | | BGFX_CHECK_HANDLE(_handle, BGFX_CONFIG_MAX_PROGRAMS); |
| 2860 | 2846 | s_ctx->setProgram(_handle); |
| 2861 | 2847 | } |
| 2862 | 2848 | |
| r245164 | r245165 | |
| 2881 | 2867 | void setBuffer(uint8_t _stage, IndexBufferHandle _handle, Access::Enum _access) |
| 2882 | 2868 | { |
| 2883 | 2869 | BGFX_CHECK_MAIN_THREAD(); |
| 2884 | | BGFX_CHECK_HANDLE(_handle, BGFX_CONFIG_MAX_INDEX_BUFFERS); |
| 2885 | 2870 | s_ctx->setBuffer(_stage, _handle, _access); |
| 2886 | 2871 | } |
| 2887 | 2872 | |
| 2888 | 2873 | void setBuffer(uint8_t _stage, VertexBufferHandle _handle, Access::Enum _access) |
| 2889 | 2874 | { |
| 2890 | 2875 | BGFX_CHECK_MAIN_THREAD(); |
| 2891 | | BGFX_CHECK_HANDLE(_handle, BGFX_CONFIG_MAX_VERTEX_BUFFERS); |
| 2892 | 2876 | s_ctx->setBuffer(_stage, _handle, _access); |
| 2893 | 2877 | } |
| 2894 | 2878 | |
| 2895 | 2879 | void setBuffer(uint8_t _stage, DynamicIndexBufferHandle _handle, Access::Enum _access) |
| 2896 | 2880 | { |
| 2897 | 2881 | BGFX_CHECK_MAIN_THREAD(); |
| 2898 | | BGFX_CHECK_HANDLE(_handle, BGFX_CONFIG_MAX_DYNAMIC_INDEX_BUFFERS); |
| 2899 | 2882 | s_ctx->setBuffer(_stage, _handle, _access); |
| 2900 | 2883 | } |
| 2901 | 2884 | |
| 2902 | 2885 | void setBuffer(uint8_t _stage, DynamicVertexBufferHandle _handle, Access::Enum _access) |
| 2903 | 2886 | { |
| 2904 | 2887 | BGFX_CHECK_MAIN_THREAD(); |
| 2905 | | BGFX_CHECK_HANDLE(_handle, BGFX_CONFIG_MAX_DYNAMIC_VERTEX_BUFFERS); |
| 2906 | 2888 | s_ctx->setBuffer(_stage, _handle, _access); |
| 2907 | 2889 | } |
| 2908 | 2890 | |
trunk/3rdparty/bgfx/src/bgfx_p.h
| r245164 | r245165 | |
| 29 | 29 | #include <string.h> |
| 30 | 30 | #include <alloca.h> |
| 31 | 31 | |
| 32 | #define BGFX_CHECK_HANDLE(_desc, _handleAlloc, _handle) \ |
| 33 | BX_CHECK(isValid(_handle) \ |
| 34 | && _handleAlloc.isValid(_handle.idx) \ |
| 35 | , "Invalid handle. %s handle: %d (max %d)" \ |
| 36 | , _desc \ |
| 37 | , _handle.idx \ |
| 38 | , _handleAlloc.getMaxHandles() \ |
| 39 | ); |
| 40 | |
| 32 | 41 | namespace bgfx |
| 33 | 42 | { |
| 34 | 43 | #if BX_COMPILER_CLANG_ANALYZER |
| r245164 | r245165 | |
| 204 | 213 | #elif BX_PLATFORM_LINUX |
| 205 | 214 | extern void* g_bgfxX11Display; |
| 206 | 215 | extern uint32_t g_bgfxX11Window; |
| 216 | extern void* g_bgfxGLX; |
| 207 | 217 | #elif BX_PLATFORM_OSX |
| 208 | 218 | extern void* g_bgfxNSWindow; |
| 219 | extern void* g_bgfxNSGL; |
| 209 | 220 | #elif BX_PLATFORM_WINDOWS |
| 210 | 221 | extern ::HWND g_bgfxHwnd; |
| 211 | 222 | #elif BX_PLATFORM_WINRT |
| r245164 | r245165 | |
| 1418 | 1429 | { |
| 1419 | 1430 | Binding& sampler = m_draw.m_bind[_stage]; |
| 1420 | 1431 | sampler.m_idx = _handle.idx; |
| 1421 | | sampler.m_un.m_draw.m_flags = (_flags&BGFX_SAMPLER_DEFAULT_FLAGS) ? BGFX_SAMPLER_DEFAULT_FLAGS : _flags; |
| 1432 | sampler.m_un.m_draw.m_flags = (_flags&BGFX_SAMPLER_DEFAULT_FLAGS) |
| 1433 | ? BGFX_SAMPLER_DEFAULT_FLAGS |
| 1434 | : _flags |
| 1435 | ; |
| 1422 | 1436 | |
| 1423 | 1437 | if (isValid(_sampler) |
| 1424 | 1438 | && (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) || BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES) ) ) |
| r245164 | r245165 | |
| 1989 | 2003 | |
| 1990 | 2004 | BGFX_API_FUNC(void destroyIndexBuffer(IndexBufferHandle _handle) ) |
| 1991 | 2005 | { |
| 2006 | BGFX_CHECK_HANDLE("destroyIndexBuffer", m_indexBufferHandle, _handle); |
| 2007 | |
| 1992 | 2008 | CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::DestroyIndexBuffer); |
| 1993 | 2009 | cmdbuf.write(_handle); |
| 1994 | 2010 | m_submit->free(_handle); |
| r245164 | r245165 | |
| 2034 | 2050 | |
| 2035 | 2051 | BGFX_API_FUNC(void destroyVertexBuffer(VertexBufferHandle _handle) ) |
| 2036 | 2052 | { |
| 2053 | BGFX_CHECK_HANDLE("destroyVertexBuffer", m_vertexBufferHandle, _handle); |
| 2054 | |
| 2037 | 2055 | CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::DestroyVertexBuffer); |
| 2038 | 2056 | cmdbuf.write(_handle); |
| 2039 | 2057 | m_submit->free(_handle); |
| r245164 | r245165 | |
| 2135 | 2153 | |
| 2136 | 2154 | BGFX_API_FUNC(void updateDynamicIndexBuffer(DynamicIndexBufferHandle _handle, const Memory* _mem) ) |
| 2137 | 2155 | { |
| 2156 | BGFX_CHECK_HANDLE("updateDynamicIndexBuffer", m_dynamicIndexBufferHandle, _handle); |
| 2157 | |
| 2138 | 2158 | DynamicIndexBuffer& dib = m_dynamicIndexBuffers[_handle.idx]; |
| 2139 | 2159 | BX_CHECK(0 == (dib.m_flags & BGFX_BUFFER_COMPUTE_READ_WRITE), "Can't update GPU buffer from CPU."); |
| 2140 | 2160 | |
| r245164 | r245165 | |
| 2166 | 2186 | |
| 2167 | 2187 | BGFX_API_FUNC(void destroyDynamicIndexBuffer(DynamicIndexBufferHandle _handle) ) |
| 2168 | 2188 | { |
| 2189 | BGFX_CHECK_HANDLE("destroyDynamicIndexBuffer", m_dynamicIndexBufferHandle, _handle); |
| 2190 | |
| 2169 | 2191 | m_freeDynamicIndexBufferHandle[m_numFreeDynamicIndexBufferHandles++] = _handle; |
| 2170 | 2192 | } |
| 2171 | 2193 | |
| r245164 | r245165 | |
| 2279 | 2301 | |
| 2280 | 2302 | BGFX_API_FUNC(void updateDynamicVertexBuffer(DynamicVertexBufferHandle _handle, const Memory* _mem) ) |
| 2281 | 2303 | { |
| 2304 | BGFX_CHECK_HANDLE("updateDynamicVertexBuffer", m_dynamicVertexBufferHandle, _handle); |
| 2305 | |
| 2282 | 2306 | DynamicVertexBuffer& dvb = m_dynamicVertexBuffers[_handle.idx]; |
| 2283 | 2307 | BX_CHECK(0 == (dvb.m_flags & BGFX_BUFFER_COMPUTE_READ_WRITE), "Can't update GPU buffer from CPU."); |
| 2284 | 2308 | |
| r245164 | r245165 | |
| 2311 | 2335 | |
| 2312 | 2336 | BGFX_API_FUNC(void destroyDynamicVertexBuffer(DynamicVertexBufferHandle _handle) ) |
| 2313 | 2337 | { |
| 2338 | BGFX_CHECK_HANDLE("destroyDynamicVertexBuffer", m_dynamicVertexBufferHandle, _handle); |
| 2339 | |
| 2314 | 2340 | m_freeDynamicVertexBufferHandle[m_numFreeDynamicVertexBufferHandles++] = _handle; |
| 2315 | 2341 | } |
| 2316 | 2342 | |
| r245164 | r245165 | |
| 2593 | 2619 | |
| 2594 | 2620 | BGFX_API_FUNC(void destroyShader(ShaderHandle _handle) ) |
| 2595 | 2621 | { |
| 2622 | BGFX_CHECK_HANDLE("destroyShader", m_shaderHandle, _handle); |
| 2623 | |
| 2596 | 2624 | if (!isValid(_handle) ) |
| 2597 | 2625 | { |
| 2598 | 2626 | BX_WARN(false, "Passing invalid shader handle to bgfx::destroyShader."); |
| r245164 | r245165 | |
| 2704 | 2732 | |
| 2705 | 2733 | BGFX_API_FUNC(void destroyProgram(ProgramHandle _handle) ) |
| 2706 | 2734 | { |
| 2735 | BGFX_CHECK_HANDLE("destroyProgram", m_programHandle, _handle); |
| 2736 | |
| 2707 | 2737 | CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::DestroyProgram); |
| 2708 | 2738 | cmdbuf.write(_handle); |
| 2709 | 2739 | m_submit->free(_handle); |
| r245164 | r245165 | |
| 2769 | 2799 | |
| 2770 | 2800 | BGFX_API_FUNC(void destroyTexture(TextureHandle _handle) ) |
| 2771 | 2801 | { |
| 2802 | BGFX_CHECK_HANDLE("destroyTexture", m_textureHandle, _handle); |
| 2803 | |
| 2772 | 2804 | if (!isValid(_handle) ) |
| 2773 | 2805 | { |
| 2774 | 2806 | BX_WARN(false, "Passing invalid texture handle to bgfx::destroyTexture"); |
| r245164 | r245165 | |
| 2832 | 2864 | for (uint32_t ii = 0; ii < _num; ++ii) |
| 2833 | 2865 | { |
| 2834 | 2866 | TextureHandle texHandle = _handles[ii]; |
| 2867 | BGFX_CHECK_HANDLE("createFrameBuffer texture handle", m_textureHandle, texHandle); |
| 2835 | 2868 | |
| 2836 | 2869 | cmdbuf.write(texHandle); |
| 2837 | 2870 | |
| r245164 | r245165 | |
| 2868 | 2901 | |
| 2869 | 2902 | BGFX_API_FUNC(void destroyFrameBuffer(FrameBufferHandle _handle) ) |
| 2870 | 2903 | { |
| 2904 | BGFX_CHECK_HANDLE("destroyFrameBuffer", m_frameBufferHandle, _handle); |
| 2905 | |
| 2871 | 2906 | CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::DestroyFrameBuffer); |
| 2872 | 2907 | cmdbuf.write(_handle); |
| 2873 | 2908 | m_submit->free(_handle); |
| r245164 | r245165 | |
| 2951 | 2986 | |
| 2952 | 2987 | BGFX_API_FUNC(void destroyUniform(UniformHandle _handle) ) |
| 2953 | 2988 | { |
| 2989 | BGFX_CHECK_HANDLE("destroyUniform", m_uniformHandle, _handle); |
| 2990 | |
| 2954 | 2991 | UniformRef& uniform = m_uniformRef[_handle.idx]; |
| 2955 | 2992 | BX_CHECK(uniform.m_refCount > 0, "Destroying already destroyed uniform %d.", _handle.idx); |
| 2956 | 2993 | int32_t refs = --uniform.m_refCount; |
| r245164 | r245165 | |
| 3054 | 3091 | |
| 3055 | 3092 | BGFX_API_FUNC(void setViewFrameBuffer(uint8_t _id, FrameBufferHandle _handle) ) |
| 3056 | 3093 | { |
| 3094 | BGFX_CHECK_HANDLE("setViewFrameBuffer", m_frameBufferHandle, _handle); |
| 3057 | 3095 | m_fb[_id] = _handle; |
| 3058 | 3096 | } |
| 3059 | 3097 | |
| r245164 | r245165 | |
| 3091 | 3129 | |
| 3092 | 3130 | BGFX_API_FUNC(void setViewRemap(uint8_t _id, uint8_t _num, const void* _remap) ) |
| 3093 | 3131 | { |
| 3094 | | const uint32_t num = bx::uint32_min( (BGFX_CONFIG_MAX_VIEWS - _id) + _num, BGFX_CONFIG_MAX_VIEWS) - _id; |
| 3132 | const uint32_t num = bx::uint32_min(_id + _num, BGFX_CONFIG_MAX_VIEWS) - _id; |
| 3095 | 3133 | if (NULL == _remap) |
| 3096 | 3134 | { |
| 3097 | 3135 | for (uint32_t ii = 0; ii < num; ++ii) |
| r245164 | r245165 | |
| 3148 | 3186 | |
| 3149 | 3187 | BGFX_API_FUNC(void setUniform(UniformHandle _handle, const void* _value, uint16_t _num) ) |
| 3150 | 3188 | { |
| 3189 | BGFX_CHECK_HANDLE("setUniform", m_uniformHandle, _handle); |
| 3151 | 3190 | UniformRef& uniform = m_uniformRef[_handle.idx]; |
| 3152 | 3191 | BX_CHECK(uniform.m_num >= _num, "Truncated uniform update. %d (max: %d)", _num, uniform.m_num); |
| 3153 | 3192 | m_submit->writeUniform(uniform.m_type, _handle, _value, bx::uint16_min(uniform.m_num, _num) ); |
| r245164 | r245165 | |
| 3155 | 3194 | |
| 3156 | 3195 | BGFX_API_FUNC(void setIndexBuffer(IndexBufferHandle _handle, uint32_t _firstIndex, uint32_t _numIndices) ) |
| 3157 | 3196 | { |
| 3197 | BGFX_CHECK_HANDLE("setIndexBuffer", m_indexBufferHandle, _handle); |
| 3158 | 3198 | m_submit->setIndexBuffer(_handle, _firstIndex, _numIndices); |
| 3159 | 3199 | } |
| 3160 | 3200 | |
| 3161 | 3201 | BGFX_API_FUNC(void setIndexBuffer(DynamicIndexBufferHandle _handle, uint32_t _firstIndex, uint32_t _numIndices) ) |
| 3162 | 3202 | { |
| 3203 | BGFX_CHECK_HANDLE("setIndexBuffer", m_dynamicIndexBufferHandle, _handle); |
| 3163 | 3204 | m_submit->setIndexBuffer(m_dynamicIndexBuffers[_handle.idx], _firstIndex, _numIndices); |
| 3164 | 3205 | } |
| 3165 | 3206 | |
| r245164 | r245165 | |
| 3170 | 3211 | |
| 3171 | 3212 | BGFX_API_FUNC(void setVertexBuffer(VertexBufferHandle _handle, uint32_t _startVertex, uint32_t _numVertices) ) |
| 3172 | 3213 | { |
| 3214 | BGFX_CHECK_HANDLE("setVertexBuffer", m_vertexBufferHandle, _handle); |
| 3173 | 3215 | m_submit->setVertexBuffer(_handle, _startVertex, _numVertices); |
| 3174 | 3216 | } |
| 3175 | 3217 | |
| 3176 | 3218 | BGFX_API_FUNC(void setVertexBuffer(DynamicVertexBufferHandle _handle, uint32_t _numVertices) ) |
| 3177 | 3219 | { |
| 3220 | BGFX_CHECK_HANDLE("setVertexBuffer", m_dynamicVertexBufferHandle, _handle); |
| 3178 | 3221 | m_submit->setVertexBuffer(m_dynamicVertexBuffers[_handle.idx], _numVertices); |
| 3179 | 3222 | } |
| 3180 | 3223 | |
| r245164 | r245165 | |
| 3192 | 3235 | |
| 3193 | 3236 | BGFX_API_FUNC(void setInstanceDataBuffer(VertexBufferHandle _handle, uint32_t _startVertex, uint32_t _num) ) |
| 3194 | 3237 | { |
| 3238 | BGFX_CHECK_HANDLE("setInstanceDataBuffer", m_vertexBufferHandle, _handle); |
| 3195 | 3239 | const VertexBuffer& vb = m_vertexBuffers[_handle.idx]; |
| 3196 | 3240 | m_submit->setInstanceDataBuffer(_handle, _startVertex, _num, vb.m_stride); |
| 3197 | 3241 | } |
| 3198 | 3242 | |
| 3199 | 3243 | BGFX_API_FUNC(void setInstanceDataBuffer(DynamicVertexBufferHandle _handle, uint32_t _startVertex, uint32_t _num) ) |
| 3200 | 3244 | { |
| 3245 | BGFX_CHECK_HANDLE("setInstanceDataBuffer", m_dynamicVertexBufferHandle, _handle); |
| 3201 | 3246 | const DynamicVertexBuffer& dvb = m_dynamicVertexBuffers[_handle.idx]; |
| 3202 | 3247 | m_submit->setInstanceDataBuffer(dvb.m_handle |
| 3203 | 3248 | , dvb.m_startVertex + _startVertex |
| r245164 | r245165 | |
| 3208 | 3253 | |
| 3209 | 3254 | BGFX_API_FUNC(void setProgram(ProgramHandle _handle) ) |
| 3210 | 3255 | { |
| 3256 | BGFX_CHECK_HANDLE("setProgram", m_programHandle, _handle); |
| 3211 | 3257 | m_submit->setProgram(_handle); |
| 3212 | 3258 | } |
| 3213 | 3259 | |
| 3214 | 3260 | BGFX_API_FUNC(void setTexture(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint32_t _flags) ) |
| 3215 | 3261 | { |
| 3262 | BGFX_CHECK_HANDLE("setTexture", m_textureHandle, _handle); |
| 3216 | 3263 | m_submit->setTexture(_stage, _sampler, _handle, _flags); |
| 3217 | 3264 | } |
| 3218 | 3265 | |
| r245164 | r245165 | |
| 3238 | 3285 | |
| 3239 | 3286 | BGFX_API_FUNC(void setBuffer(uint8_t _stage, IndexBufferHandle _handle, Access::Enum _access) ) |
| 3240 | 3287 | { |
| 3288 | BGFX_CHECK_HANDLE("setBuffer", m_indexBufferHandle, _handle); |
| 3241 | 3289 | m_submit->setBuffer(_stage, _handle, _access); |
| 3242 | 3290 | } |
| 3243 | 3291 | |
| 3244 | 3292 | BGFX_API_FUNC(void setBuffer(uint8_t _stage, VertexBufferHandle _handle, Access::Enum _access) ) |
| 3245 | 3293 | { |
| 3294 | BGFX_CHECK_HANDLE("setBuffer", m_vertexBufferHandle, _handle); |
| 3246 | 3295 | m_submit->setBuffer(_stage, _handle, _access); |
| 3247 | 3296 | } |
| 3248 | 3297 | |
| 3249 | 3298 | BGFX_API_FUNC(void setBuffer(uint8_t _stage, DynamicIndexBufferHandle _handle, Access::Enum _access) ) |
| 3250 | 3299 | { |
| 3300 | BGFX_CHECK_HANDLE("setBuffer", m_dynamicIndexBufferHandle, _handle); |
| 3251 | 3301 | const DynamicIndexBuffer& dib = m_dynamicIndexBuffers[_handle.idx]; |
| 3252 | 3302 | m_submit->setBuffer(_stage, dib.m_handle, _access); |
| 3253 | 3303 | } |
| 3254 | 3304 | |
| 3255 | 3305 | BGFX_API_FUNC(void setBuffer(uint8_t _stage, DynamicVertexBufferHandle _handle, Access::Enum _access) ) |
| 3256 | 3306 | { |
| 3307 | BGFX_CHECK_HANDLE("setBuffer", m_dynamicVertexBufferHandle, _handle); |
| 3257 | 3308 | const DynamicVertexBuffer& dvb = m_dynamicVertexBuffers[_handle.idx]; |
| 3258 | 3309 | m_submit->setBuffer(_stage, dvb.m_handle, _access); |
| 3259 | 3310 | } |
trunk/3rdparty/bgfx/src/glcontext_glx.cpp
| r245164 | r245165 | |
| 12 | 12 | # define GLX_GLXEXT_PROTOTYPES |
| 13 | 13 | # include <glx/glxext.h> |
| 14 | 14 | |
| 15 | | namespace bgfx |
| 15 | namespace bgfx { namespace gl |
| 16 | 16 | { |
| 17 | 17 | typedef int (*PFNGLXSWAPINTERVALMESAPROC)(uint32_t _interval); |
| 18 | 18 | |
| r245164 | r245165 | |
| 55 | 55 | void GlContext::create(uint32_t _width, uint32_t _height) |
| 56 | 56 | { |
| 57 | 57 | BX_UNUSED(_width, _height); |
| 58 | | XLockDisplay( (::Display*)g_bgfxX11Display); |
| 59 | 58 | |
| 60 | | int major, minor; |
| 61 | | bool version = glXQueryVersion( (::Display*)g_bgfxX11Display, &major, &minor); |
| 62 | | BGFX_FATAL(version, Fatal::UnableToInitialize, "Failed to query GLX version"); |
| 63 | | BGFX_FATAL( (major == 1 && minor >= 2) || major > 1 |
| 64 | | , Fatal::UnableToInitialize |
| 65 | | , "GLX version is not >=1.2 (%d.%d)." |
| 66 | | , major |
| 67 | | , minor |
| 68 | | ); |
| 59 | m_context = (GLXContext)g_bgfxGLX; |
| 69 | 60 | |
| 70 | | int32_t screen = DefaultScreen( (::Display*)g_bgfxX11Display); |
| 61 | if (NULL == g_bgfxGLX) |
| 62 | { |
| 63 | XLockDisplay( (::Display*)g_bgfxX11Display); |
| 71 | 64 | |
| 72 | | const char* extensions = glXQueryExtensionsString( (::Display*)g_bgfxX11Display, screen); |
| 73 | | BX_TRACE("GLX extensions:"); |
| 74 | | dumpExtensions(extensions); |
| 65 | int major, minor; |
| 66 | bool version = glXQueryVersion( (::Display*)g_bgfxX11Display, &major, &minor); |
| 67 | BGFX_FATAL(version, Fatal::UnableToInitialize, "Failed to query GLX version"); |
| 68 | BGFX_FATAL( (major == 1 && minor >= 2) || major > 1 |
| 69 | , Fatal::UnableToInitialize |
| 70 | , "GLX version is not >=1.2 (%d.%d)." |
| 71 | , major |
| 72 | , minor |
| 73 | ); |
| 75 | 74 | |
| 76 | | const int attrsGlx[] = |
| 77 | | { |
| 78 | | GLX_RENDER_TYPE, GLX_RGBA_BIT, |
| 79 | | GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, |
| 80 | | GLX_DOUBLEBUFFER, true, |
| 81 | | GLX_RED_SIZE, 8, |
| 82 | | GLX_BLUE_SIZE, 8, |
| 83 | | GLX_GREEN_SIZE, 8, |
| 84 | | // GLX_ALPHA_SIZE, 8, |
| 85 | | GLX_DEPTH_SIZE, 24, |
| 86 | | GLX_STENCIL_SIZE, 8, |
| 87 | | 0, |
| 88 | | }; |
| 75 | int32_t screen = DefaultScreen( (::Display*)g_bgfxX11Display); |
| 89 | 76 | |
| 90 | | // Find suitable config |
| 91 | | GLXFBConfig bestConfig = NULL; |
| 77 | const char* extensions = glXQueryExtensionsString( (::Display*)g_bgfxX11Display, screen); |
| 78 | BX_TRACE("GLX extensions:"); |
| 79 | dumpExtensions(extensions); |
| 92 | 80 | |
| 93 | | int numConfigs; |
| 94 | | GLXFBConfig* configs = glXChooseFBConfig( (::Display*)g_bgfxX11Display, screen, attrsGlx, &numConfigs); |
| 81 | const int attrsGlx[] = |
| 82 | { |
| 83 | GLX_RENDER_TYPE, GLX_RGBA_BIT, |
| 84 | GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, |
| 85 | GLX_DOUBLEBUFFER, true, |
| 86 | GLX_RED_SIZE, 8, |
| 87 | GLX_BLUE_SIZE, 8, |
| 88 | GLX_GREEN_SIZE, 8, |
| 89 | // GLX_ALPHA_SIZE, 8, |
| 90 | GLX_DEPTH_SIZE, 24, |
| 91 | GLX_STENCIL_SIZE, 8, |
| 92 | 0, |
| 93 | }; |
| 95 | 94 | |
| 96 | | BX_TRACE("glX num configs %d", numConfigs); |
| 95 | // Find suitable config |
| 96 | GLXFBConfig bestConfig = NULL; |
| 97 | 97 | |
| 98 | | for (int ii = 0; ii < numConfigs; ++ii) |
| 99 | | { |
| 100 | | m_visualInfo = glXGetVisualFromFBConfig( (::Display*)g_bgfxX11Display, configs[ii]); |
| 101 | | if (NULL != m_visualInfo) |
| 98 | int numConfigs; |
| 99 | GLXFBConfig* configs = glXChooseFBConfig( (::Display*)g_bgfxX11Display, screen, attrsGlx, &numConfigs); |
| 100 | |
| 101 | BX_TRACE("glX num configs %d", numConfigs); |
| 102 | |
| 103 | for (int ii = 0; ii < numConfigs; ++ii) |
| 102 | 104 | { |
| 103 | | BX_TRACE("---"); |
| 104 | | bool valid = true; |
| 105 | | for (uint32_t attr = 6; attr < BX_COUNTOF(attrsGlx)-1 && attrsGlx[attr] != None; attr += 2) |
| 105 | m_visualInfo = glXGetVisualFromFBConfig( (::Display*)g_bgfxX11Display, configs[ii]); |
| 106 | if (NULL != m_visualInfo) |
| 106 | 107 | { |
| 107 | | int value; |
| 108 | | glXGetFBConfigAttrib( (::Display*)g_bgfxX11Display, configs[ii], attrsGlx[attr], &value); |
| 109 | | BX_TRACE("glX %d/%d %2d: %4x, %8x (%8x%s)" |
| 110 | | , ii |
| 111 | | , numConfigs |
| 112 | | , attr/2 |
| 113 | | , attrsGlx[attr] |
| 114 | | , value |
| 115 | | , attrsGlx[attr + 1] |
| 116 | | , value < attrsGlx[attr + 1] ? " *" : "" |
| 117 | | ); |
| 108 | BX_TRACE("---"); |
| 109 | bool valid = true; |
| 110 | for (uint32_t attr = 6; attr < BX_COUNTOF(attrsGlx)-1 && attrsGlx[attr] != None; attr += 2) |
| 111 | { |
| 112 | int value; |
| 113 | glXGetFBConfigAttrib( (::Display*)g_bgfxX11Display, configs[ii], attrsGlx[attr], &value); |
| 114 | BX_TRACE("glX %d/%d %2d: %4x, %8x (%8x%s)" |
| 115 | , ii |
| 116 | , numConfigs |
| 117 | , attr/2 |
| 118 | , attrsGlx[attr] |
| 119 | , value |
| 120 | , attrsGlx[attr + 1] |
| 121 | , value < attrsGlx[attr + 1] ? " *" : "" |
| 122 | ); |
| 118 | 123 | |
| 119 | | if (value < attrsGlx[attr + 1]) |
| 120 | | { |
| 121 | | valid = false; |
| 124 | if (value < attrsGlx[attr + 1]) |
| 125 | { |
| 126 | valid = false; |
| 122 | 127 | #if !BGFX_CONFIG_DEBUG |
| 123 | | break; |
| 128 | break; |
| 124 | 129 | #endif // BGFX_CONFIG_DEBUG |
| 130 | } |
| 125 | 131 | } |
| 132 | |
| 133 | if (valid) |
| 134 | { |
| 135 | bestConfig = configs[ii]; |
| 136 | BX_TRACE("Best config %d.", ii); |
| 137 | break; |
| 138 | } |
| 126 | 139 | } |
| 127 | 140 | |
| 128 | | if (valid) |
| 129 | | { |
| 130 | | bestConfig = configs[ii]; |
| 131 | | BX_TRACE("Best config %d.", ii); |
| 132 | | break; |
| 133 | | } |
| 141 | XFree(m_visualInfo); |
| 142 | m_visualInfo = NULL; |
| 134 | 143 | } |
| 135 | 144 | |
| 136 | | XFree(m_visualInfo); |
| 137 | | m_visualInfo = NULL; |
| 138 | | } |
| 145 | XFree(configs); |
| 146 | BGFX_FATAL(m_visualInfo, Fatal::UnableToInitialize, "Failed to find a suitable X11 display configuration."); |
| 139 | 147 | |
| 140 | | XFree(configs); |
| 141 | | BGFX_FATAL(m_visualInfo, Fatal::UnableToInitialize, "Failed to find a suitable X11 display configuration."); |
| 148 | BX_TRACE("Create GL 2.1 context."); |
| 149 | m_context = glXCreateContext( (::Display*)g_bgfxX11Display, m_visualInfo, 0, GL_TRUE); |
| 150 | BGFX_FATAL(NULL != m_context, Fatal::UnableToInitialize, "Failed to create GL 2.1 context."); |
| 142 | 151 | |
| 143 | | BX_TRACE("Create GL 2.1 context."); |
| 144 | | m_context = glXCreateContext( (::Display*)g_bgfxX11Display, m_visualInfo, 0, GL_TRUE); |
| 145 | | BGFX_FATAL(NULL != m_context, Fatal::UnableToInitialize, "Failed to create GL 2.1 context."); |
| 146 | | |
| 147 | 152 | #if BGFX_CONFIG_RENDERER_OPENGL >= 31 |
| 148 | | glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddress( (const GLubyte*)"glXCreateContextAttribsARB"); |
| 153 | glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddress( (const GLubyte*)"glXCreateContextAttribsARB"); |
| 149 | 154 | |
| 150 | | if (NULL != glXCreateContextAttribsARB) |
| 151 | | { |
| 152 | | BX_TRACE("Create GL 3.1 context."); |
| 153 | | const int contextAttrs[] = |
| 155 | if (NULL != glXCreateContextAttribsARB) |
| 154 | 156 | { |
| 155 | | GLX_CONTEXT_MAJOR_VERSION_ARB, 3, |
| 156 | | GLX_CONTEXT_MINOR_VERSION_ARB, 1, |
| 157 | | GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB, |
| 158 | | 0, |
| 159 | | }; |
| 157 | BX_TRACE("Create GL 3.1 context."); |
| 158 | const int contextAttrs[] = |
| 159 | { |
| 160 | GLX_CONTEXT_MAJOR_VERSION_ARB, 3, |
| 161 | GLX_CONTEXT_MINOR_VERSION_ARB, 1, |
| 162 | GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB, |
| 163 | 0, |
| 164 | }; |
| 160 | 165 | |
| 161 | | GLXContext context = glXCreateContextAttribsARB( (::Display*)g_bgfxX11Display, bestConfig, 0, true, contextAttrs); |
| 166 | GLXContext context = glXCreateContextAttribsARB( (::Display*)g_bgfxX11Display, bestConfig, 0, true, contextAttrs); |
| 162 | 167 | |
| 163 | | if (NULL != context) |
| 164 | | { |
| 165 | | glXDestroyContext( (::Display*)g_bgfxX11Display, m_context); |
| 166 | | m_context = context; |
| 168 | if (NULL != context) |
| 169 | { |
| 170 | glXDestroyContext( (::Display*)g_bgfxX11Display, m_context); |
| 171 | m_context = context; |
| 172 | } |
| 167 | 173 | } |
| 168 | | } |
| 169 | 174 | #else |
| 170 | | BX_UNUSED(bestConfig); |
| 175 | BX_UNUSED(bestConfig); |
| 171 | 176 | #endif // BGFX_CONFIG_RENDERER_OPENGL >= 31 |
| 172 | 177 | |
| 173 | | XUnlockDisplay( (::Display*)g_bgfxX11Display); |
| 178 | XUnlockDisplay( (::Display*)g_bgfxX11Display); |
| 179 | } |
| 174 | 180 | |
| 175 | 181 | import(); |
| 176 | 182 | |
| r245164 | r245165 | |
| 210 | 216 | void GlContext::destroy() |
| 211 | 217 | { |
| 212 | 218 | glXMakeCurrent( (::Display*)g_bgfxX11Display, 0, 0); |
| 213 | | glXDestroyContext( (::Display*)g_bgfxX11Display, m_context); |
| 214 | | XFree(m_visualInfo); |
| 219 | if (NULL == g_bgfxGLX) |
| 220 | { |
| 221 | glXDestroyContext( (::Display*)g_bgfxX11Display, m_context); |
| 222 | XFree(m_visualInfo); |
| 223 | } |
| 224 | m_context = NULL; |
| 225 | m_visualInfo = NULL; |
| 215 | 226 | } |
| 216 | 227 | |
| 217 | 228 | void GlContext::resize(uint32_t /*_width*/, uint32_t /*_height*/, bool _vsync) |
| r245164 | r245165 | |
| 292 | 303 | # include "glimports.h" |
| 293 | 304 | } |
| 294 | 305 | |
| 295 | | } // namespace bgfx |
| 306 | } /* namespace gl */ } // namespace bgfx |
| 296 | 307 | |
| 297 | 308 | # endif // BGFX_USE_GLX |
| 298 | 309 | |
trunk/3rdparty/bgfx/src/glcontext_nsgl.mm
| r245164 | r245165 | |
| 10 | 10 | # include <Cocoa/Cocoa.h> |
| 11 | 11 | # include <bx/os.h> |
| 12 | 12 | |
| 13 | | namespace bgfx |
| 13 | namespace bgfx { namespace gl |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | 16 | # define GL_IMPORT(_optional, _proto, _func, _import) _proto _func |
| r245164 | r245165 | |
| 35 | 35 | { |
| 36 | 36 | } |
| 37 | 37 | }; |
| 38 | | |
| 38 | |
| 39 | 39 | static void* s_opengl = NULL; |
| 40 | 40 | |
| 41 | 41 | void GlContext::create(uint32_t _width, uint32_t _height) |
| r245164 | r245165 | |
| 46 | 46 | BX_CHECK(NULL != s_opengl, "OpenGL dynamic library is not found!"); |
| 47 | 47 | |
| 48 | 48 | NSWindow* nsWindow = (NSWindow*)g_bgfxNSWindow; |
| 49 | m_context = g_bgfxNSGL; |
| 49 | 50 | |
| 50 | | NSOpenGLPixelFormatAttribute profile = |
| 51 | if (NULL == g_bgfxNSGL) |
| 52 | { |
| 53 | NSOpenGLPixelFormatAttribute profile = |
| 51 | 54 | #if BGFX_CONFIG_RENDERER_OPENGL >= 31 |
| 52 | | NSOpenGLProfileVersion3_2Core |
| 55 | NSOpenGLProfileVersion3_2Core |
| 53 | 56 | #else |
| 54 | | NSOpenGLProfileVersionLegacy |
| 57 | NSOpenGLProfileVersionLegacy |
| 55 | 58 | #endif // BGFX_CONFIG_RENDERER_OPENGL >= 31 |
| 56 | | ; |
| 59 | ; |
| 57 | 60 | |
| 58 | | NSOpenGLPixelFormatAttribute pixelFormatAttributes[] = { |
| 59 | | NSOpenGLPFAOpenGLProfile, profile, |
| 60 | | NSOpenGLPFAColorSize, 24, |
| 61 | | NSOpenGLPFAAlphaSize, 8, |
| 62 | | NSOpenGLPFADepthSize, 24, |
| 63 | | NSOpenGLPFAStencilSize, 8, |
| 64 | | NSOpenGLPFADoubleBuffer, true, |
| 65 | | NSOpenGLPFAAccelerated, true, |
| 66 | | NSOpenGLPFANoRecovery, true, |
| 67 | | 0, 0, |
| 68 | | }; |
| 61 | NSOpenGLPixelFormatAttribute pixelFormatAttributes[] = { |
| 62 | NSOpenGLPFAOpenGLProfile, profile, |
| 63 | NSOpenGLPFAColorSize, 24, |
| 64 | NSOpenGLPFAAlphaSize, 8, |
| 65 | NSOpenGLPFADepthSize, 24, |
| 66 | NSOpenGLPFAStencilSize, 8, |
| 67 | NSOpenGLPFADoubleBuffer, true, |
| 68 | NSOpenGLPFAAccelerated, true, |
| 69 | NSOpenGLPFANoRecovery, true, |
| 70 | 0, 0, |
| 71 | }; |
| 69 | 72 | |
| 70 | | NSOpenGLPixelFormat* pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes]; |
| 71 | | BGFX_FATAL(NULL != pixelFormat, Fatal::UnableToInitialize, "Failed to initialize pixel format."); |
| 73 | NSOpenGLPixelFormat* pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes]; |
| 74 | BGFX_FATAL(NULL != pixelFormat, Fatal::UnableToInitialize, "Failed to initialize pixel format."); |
| 72 | 75 | |
| 73 | | NSRect glViewRect = [[nsWindow contentView] bounds]; |
| 74 | | NSOpenGLView* glView = [[NSOpenGLView alloc] initWithFrame:glViewRect pixelFormat:pixelFormat]; |
| 75 | | |
| 76 | | [pixelFormat release]; |
| 77 | | [nsWindow setContentView:glView]; |
| 78 | | |
| 79 | | NSOpenGLContext* glContext = [glView openGLContext]; |
| 80 | | BGFX_FATAL(NULL != glContext, Fatal::UnableToInitialize, "Failed to initialize GL context."); |
| 76 | NSRect glViewRect = [[nsWindow contentView] bounds]; |
| 77 | NSOpenGLView* glView = [[NSOpenGLView alloc] initWithFrame:glViewRect pixelFormat:pixelFormat]; |
| 81 | 78 | |
| 82 | | [glContext makeCurrentContext]; |
| 83 | | GLint interval = 0; |
| 84 | | [glContext setValues:&interval forParameter:NSOpenGLCPSwapInterval]; |
| 85 | | |
| 86 | | m_view = glView; |
| 87 | | m_context = glContext; |
| 79 | [pixelFormat release]; |
| 80 | [nsWindow setContentView:glView]; |
| 88 | 81 | |
| 82 | NSOpenGLContext* glContext = [glView openGLContext]; |
| 83 | BGFX_FATAL(NULL != glContext, Fatal::UnableToInitialize, "Failed to initialize GL context."); |
| 84 | |
| 85 | [glContext makeCurrentContext]; |
| 86 | GLint interval = 0; |
| 87 | [glContext setValues:&interval forParameter:NSOpenGLCPSwapInterval]; |
| 88 | |
| 89 | m_view = glView; |
| 90 | m_context = glContext; |
| 91 | } |
| 92 | |
| 89 | 93 | import(); |
| 90 | 94 | } |
| 91 | 95 | |
| 92 | 96 | void GlContext::destroy() |
| 93 | 97 | { |
| 94 | | NSOpenGLView* glView = (NSOpenGLView*)m_view; |
| 95 | | m_view = 0; |
| 98 | if (NULL == g_bgfxNSGL) |
| 99 | { |
| 100 | NSOpenGLView* glView = (NSOpenGLView*)m_view; |
| 101 | [glView release]; |
| 102 | } |
| 103 | |
| 104 | m_view = 0; |
| 96 | 105 | m_context = 0; |
| 97 | | [glView release]; |
| 98 | | |
| 99 | 106 | bx::dlclose(s_opengl); |
| 100 | 107 | } |
| 101 | 108 | |
| r245164 | r245165 | |
| 165 | 172 | # include "glimports.h" |
| 166 | 173 | } |
| 167 | 174 | |
| 168 | | } // namespace bgfx |
| 175 | } /* namespace gl */ } // namespace bgfx |
| 169 | 176 | |
| 170 | 177 | #endif // BX_PLATFORM_OSX && (BGFX_CONFIG_RENDERER_OPENGLES2|BGFX_CONFIG_RENDERER_OPENGLES3|BGFX_CONFIG_RENDERER_OPENGL) |
trunk/3rdparty/bgfx/src/image.cpp
| r245164 | r245165 | |
| 1235 | 1235 | #define DDS_BC5U BX_MAKEFOURCC('B', 'C', '5', 'U') |
| 1236 | 1236 | #define DDS_DX10 BX_MAKEFOURCC('D', 'X', '1', '0') |
| 1237 | 1237 | |
| 1238 | | #define D3DFMT_A8R8G8B8 21 |
| 1239 | | #define D3DFMT_R5G6B5 23 |
| 1240 | | #define D3DFMT_A1R5G5B5 25 |
| 1241 | | #define D3DFMT_A4R4G4B4 26 |
| 1242 | | #define D3DFMT_A2B10G10R10 31 |
| 1243 | | #define D3DFMT_G16R16 34 |
| 1244 | | #define D3DFMT_A2R10G10B10 35 |
| 1245 | | #define D3DFMT_A16B16G16R16 36 |
| 1246 | | #define D3DFMT_A8L8 51 |
| 1247 | | #define D3DFMT_R16F 111 |
| 1248 | | #define D3DFMT_G16R16F 112 |
| 1249 | | #define D3DFMT_A16B16G16R16F 113 |
| 1250 | | #define D3DFMT_R32F 114 |
| 1251 | | #define D3DFMT_G32R32F 115 |
| 1252 | | #define D3DFMT_A32B32G32R32F 116 |
| 1238 | #define DDS_A8R8G8B8 21 |
| 1239 | #define DDS_R5G6B5 23 |
| 1240 | #define DDS_A1R5G5B5 25 |
| 1241 | #define DDS_A4R4G4B4 26 |
| 1242 | #define DDS_A2B10G10R10 31 |
| 1243 | #define DDS_G16R16 34 |
| 1244 | #define DDS_A2R10G10B10 35 |
| 1245 | #define DDS_A16B16G16R16 36 |
| 1246 | #define DDS_A8L8 51 |
| 1247 | #define DDS_R16F 111 |
| 1248 | #define DDS_G16R16F 112 |
| 1249 | #define DDS_A16B16G16R16F 113 |
| 1250 | #define DDS_R32F 114 |
| 1251 | #define DDS_G32R32F 115 |
| 1252 | #define DDS_A32B32G32R32F 116 |
| 1253 | 1253 | |
| 1254 | | #define DXGI_FORMAT_R32G32B32A32_FLOAT 2 |
| 1255 | | #define DXGI_FORMAT_R32G32B32A32_UINT 3 |
| 1256 | | #define DXGI_FORMAT_R16G16B16A16_FLOAT 10 |
| 1257 | | #define DXGI_FORMAT_R16G16B16A16_UNORM 11 |
| 1258 | | #define DXGI_FORMAT_R16G16B16A16_UINT 12 |
| 1259 | | #define DXGI_FORMAT_R32G32_FLOAT 16 |
| 1260 | | #define DXGI_FORMAT_R32G32_UINT 17 |
| 1261 | | #define DXGI_FORMAT_R10G10B10A2_UNORM 24 |
| 1262 | | #define DXGI_FORMAT_R16G16_FLOAT 34 |
| 1263 | | #define DXGI_FORMAT_R16G16_UNORM 35 |
| 1264 | | #define DXGI_FORMAT_R32_FLOAT 41 |
| 1265 | | #define DXGI_FORMAT_R32_UINT 42 |
| 1266 | | #define DXGI_FORMAT_R8G8_UNORM 49 |
| 1267 | | #define DXGI_FORMAT_R16_FLOAT 54 |
| 1268 | | #define DXGI_FORMAT_R16_UNORM 56 |
| 1269 | | #define DXGI_FORMAT_R8_UNORM 61 |
| 1270 | | #define DXGI_FORMAT_BC1_UNORM 71 |
| 1271 | | #define DXGI_FORMAT_BC2_UNORM 74 |
| 1272 | | #define DXGI_FORMAT_BC3_UNORM 77 |
| 1273 | | #define DXGI_FORMAT_BC4_UNORM 80 |
| 1274 | | #define DXGI_FORMAT_BC5_UNORM 83 |
| 1275 | | #define DXGI_FORMAT_B5G6R5_UNORM 85 |
| 1276 | | #define DXGI_FORMAT_B5G5R5A1_UNORM 86 |
| 1277 | | #define DXGI_FORMAT_B8G8R8A8_UNORM 87 |
| 1278 | | #define DXGI_FORMAT_BC6H_SF16 96 |
| 1279 | | #define DXGI_FORMAT_BC7_UNORM 98 |
| 1280 | | #define DXGI_FORMAT_B4G4R4A4_UNORM 115 |
| 1254 | #define DDS_FORMAT_R32G32B32A32_FLOAT 2 |
| 1255 | #define DDS_FORMAT_R32G32B32A32_UINT 3 |
| 1256 | #define DDS_FORMAT_R16G16B16A16_FLOAT 10 |
| 1257 | #define DDS_FORMAT_R16G16B16A16_UNORM 11 |
| 1258 | #define DDS_FORMAT_R16G16B16A16_UINT 12 |
| 1259 | #define DDS_FORMAT_R32G32_FLOAT 16 |
| 1260 | #define DDS_FORMAT_R32G32_UINT 17 |
| 1261 | #define DDS_FORMAT_R10G10B10A2_UNORM 24 |
| 1262 | #define DDS_FORMAT_R16G16_FLOAT 34 |
| 1263 | #define DDS_FORMAT_R16G16_UNORM 35 |
| 1264 | #define DDS_FORMAT_R32_FLOAT 41 |
| 1265 | #define DDS_FORMAT_R32_UINT 42 |
| 1266 | #define DDS_FORMAT_R8G8_UNORM 49 |
| 1267 | #define DDS_FORMAT_R16_FLOAT 54 |
| 1268 | #define DDS_FORMAT_R16_UNORM 56 |
| 1269 | #define DDS_FORMAT_R8_UNORM 61 |
| 1270 | #define DDS_FORMAT_BC1_UNORM 71 |
| 1271 | #define DDS_FORMAT_BC2_UNORM 74 |
| 1272 | #define DDS_FORMAT_BC3_UNORM 77 |
| 1273 | #define DDS_FORMAT_BC4_UNORM 80 |
| 1274 | #define DDS_FORMAT_BC5_UNORM 83 |
| 1275 | #define DDS_FORMAT_B5G6R5_UNORM 85 |
| 1276 | #define DDS_FORMAT_B5G5R5A1_UNORM 86 |
| 1277 | #define DDS_FORMAT_B8G8R8A8_UNORM 87 |
| 1278 | #define DDS_FORMAT_BC6H_SF16 96 |
| 1279 | #define DDS_FORMAT_BC7_UNORM 98 |
| 1280 | #define DDS_FORMAT_B4G4R4A4_UNORM 115 |
| 1281 | 1281 | |
| 1282 | 1282 | #define DDSD_CAPS 0x00000001 |
| 1283 | 1283 | #define DDSD_HEIGHT 0x00000002 |
| r245164 | r245165 | |
| 1331 | 1331 | { DDS_BC4U, TextureFormat::BC4 }, |
| 1332 | 1332 | { DDS_ATI2, TextureFormat::BC5 }, |
| 1333 | 1333 | { DDS_BC5U, TextureFormat::BC5 }, |
| 1334 | | { D3DFMT_A16B16G16R16, TextureFormat::RGBA16 }, |
| 1335 | | { D3DFMT_A16B16G16R16F, TextureFormat::RGBA16F }, |
| 1334 | { DDS_A16B16G16R16, TextureFormat::RGBA16 }, |
| 1335 | { DDS_A16B16G16R16F, TextureFormat::RGBA16F }, |
| 1336 | 1336 | { DDPF_RGB|DDPF_ALPHAPIXELS, TextureFormat::BGRA8 }, |
| 1337 | 1337 | { DDPF_INDEXED, TextureFormat::R8 }, |
| 1338 | 1338 | { DDPF_LUMINANCE, TextureFormat::R8 }, |
| 1339 | 1339 | { DDPF_ALPHA, TextureFormat::R8 }, |
| 1340 | | { D3DFMT_R16F, TextureFormat::R16F }, |
| 1341 | | { D3DFMT_R32F, TextureFormat::R32F }, |
| 1342 | | { D3DFMT_A8L8, TextureFormat::RG8 }, |
| 1343 | | { D3DFMT_G16R16, TextureFormat::RG16 }, |
| 1344 | | { D3DFMT_G16R16F, TextureFormat::RG16F }, |
| 1345 | | { D3DFMT_G32R32F, TextureFormat::RG32F }, |
| 1346 | | { D3DFMT_A8R8G8B8, TextureFormat::BGRA8 }, |
| 1347 | | { D3DFMT_A16B16G16R16, TextureFormat::RGBA16 }, |
| 1348 | | { D3DFMT_A16B16G16R16F, TextureFormat::RGBA16F }, |
| 1349 | | { D3DFMT_A32B32G32R32F, TextureFormat::RGBA32F }, |
| 1350 | | { D3DFMT_R5G6B5, TextureFormat::R5G6B5 }, |
| 1351 | | { D3DFMT_A4R4G4B4, TextureFormat::RGBA4 }, |
| 1352 | | { D3DFMT_A1R5G5B5, TextureFormat::RGB5A1 }, |
| 1353 | | { D3DFMT_A2B10G10R10, TextureFormat::RGB10A2 }, |
| 1340 | { DDS_R16F, TextureFormat::R16F }, |
| 1341 | { DDS_R32F, TextureFormat::R32F }, |
| 1342 | { DDS_A8L8, TextureFormat::RG8 }, |
| 1343 | { DDS_G16R16, TextureFormat::RG16 }, |
| 1344 | { DDS_G16R16F, TextureFormat::RG16F }, |
| 1345 | { DDS_G32R32F, TextureFormat::RG32F }, |
| 1346 | { DDS_A8R8G8B8, TextureFormat::BGRA8 }, |
| 1347 | { DDS_A16B16G16R16, TextureFormat::RGBA16 }, |
| 1348 | { DDS_A16B16G16R16F, TextureFormat::RGBA16F }, |
| 1349 | { DDS_A32B32G32R32F, TextureFormat::RGBA32F }, |
| 1350 | { DDS_R5G6B5, TextureFormat::R5G6B5 }, |
| 1351 | { DDS_A4R4G4B4, TextureFormat::RGBA4 }, |
| 1352 | { DDS_A1R5G5B5, TextureFormat::RGB5A1 }, |
| 1353 | { DDS_A2B10G10R10, TextureFormat::RGB10A2 }, |
| 1354 | 1354 | }; |
| 1355 | 1355 | |
| 1356 | 1356 | static TranslateDdsFormat s_translateDxgiFormat[] = |
| 1357 | 1357 | { |
| 1358 | | { DXGI_FORMAT_BC1_UNORM, TextureFormat::BC1 }, |
| 1359 | | { DXGI_FORMAT_BC2_UNORM, TextureFormat::BC2 }, |
| 1360 | | { DXGI_FORMAT_BC3_UNORM, TextureFormat::BC3 }, |
| 1361 | | { DXGI_FORMAT_BC4_UNORM, TextureFormat::BC4 }, |
| 1362 | | { DXGI_FORMAT_BC5_UNORM, TextureFormat::BC5 }, |
| 1363 | | { DXGI_FORMAT_BC6H_SF16, TextureFormat::BC6H }, |
| 1364 | | { DXGI_FORMAT_BC7_UNORM, TextureFormat::BC7 }, |
| 1358 | { DDS_FORMAT_BC1_UNORM, TextureFormat::BC1 }, |
| 1359 | { DDS_FORMAT_BC2_UNORM, TextureFormat::BC2 }, |
| 1360 | { DDS_FORMAT_BC3_UNORM, TextureFormat::BC3 }, |
| 1361 | { DDS_FORMAT_BC4_UNORM, TextureFormat::BC4 }, |
| 1362 | { DDS_FORMAT_BC5_UNORM, TextureFormat::BC5 }, |
| 1363 | { DDS_FORMAT_BC6H_SF16, TextureFormat::BC6H }, |
| 1364 | { DDS_FORMAT_BC7_UNORM, TextureFormat::BC7 }, |
| 1365 | 1365 | |
| 1366 | | { DXGI_FORMAT_R8_UNORM, TextureFormat::R8 }, |
| 1367 | | { DXGI_FORMAT_R16_UNORM, TextureFormat::R16 }, |
| 1368 | | { DXGI_FORMAT_R16_FLOAT, TextureFormat::R16F }, |
| 1369 | | { DXGI_FORMAT_R32_UINT, TextureFormat::R32 }, |
| 1370 | | { DXGI_FORMAT_R32_FLOAT, TextureFormat::R32F }, |
| 1371 | | { DXGI_FORMAT_R8G8_UNORM, TextureFormat::RG8 }, |
| 1372 | | { DXGI_FORMAT_R16G16_UNORM, TextureFormat::RG16 }, |
| 1373 | | { DXGI_FORMAT_R16G16_FLOAT, TextureFormat::RG16F }, |
| 1374 | | { DXGI_FORMAT_R32G32_UINT, TextureFormat::RG32 }, |
| 1375 | | { DXGI_FORMAT_R32G32_FLOAT, TextureFormat::RG32F }, |
| 1376 | | { DXGI_FORMAT_B8G8R8A8_UNORM, TextureFormat::BGRA8 }, |
| 1377 | | { DXGI_FORMAT_R16G16B16A16_UNORM, TextureFormat::RGBA16 }, |
| 1378 | | { DXGI_FORMAT_R16G16B16A16_FLOAT, TextureFormat::RGBA16F }, |
| 1379 | | { DXGI_FORMAT_R32G32B32A32_UINT, TextureFormat::RGBA32 }, |
| 1380 | | { DXGI_FORMAT_R32G32B32A32_FLOAT, TextureFormat::RGBA32F }, |
| 1381 | | { DXGI_FORMAT_B5G6R5_UNORM, TextureFormat::R5G6B5 }, |
| 1382 | | { DXGI_FORMAT_B4G4R4A4_UNORM, TextureFormat::RGBA4 }, |
| 1383 | | { DXGI_FORMAT_B5G5R5A1_UNORM, TextureFormat::RGB5A1 }, |
| 1384 | | { DXGI_FORMAT_R10G10B10A2_UNORM, TextureFormat::RGB10A2 }, |
| 1366 | { DDS_FORMAT_R8_UNORM, TextureFormat::R8 }, |
| 1367 | { DDS_FORMAT_R16_UNORM, TextureFormat::R16 }, |
| 1368 | { DDS_FORMAT_R16_FLOAT, TextureFormat::R16F }, |
| 1369 | { DDS_FORMAT_R32_UINT, TextureFormat::R32 }, |
| 1370 | { DDS_FORMAT_R32_FLOAT, TextureFormat::R32F }, |
| 1371 | { DDS_FORMAT_R8G8_UNORM, TextureFormat::RG8 }, |
| 1372 | { DDS_FORMAT_R16G16_UNORM, TextureFormat::RG16 }, |
| 1373 | { DDS_FORMAT_R16G16_FLOAT, TextureFormat::RG16F }, |
| 1374 | { DDS_FORMAT_R32G32_UINT, TextureFormat::RG32 }, |
| 1375 | { DDS_FORMAT_R32G32_FLOAT, TextureFormat::RG32F }, |
| 1376 | { DDS_FORMAT_B8G8R8A8_UNORM, TextureFormat::BGRA8 }, |
| 1377 | { DDS_FORMAT_R16G16B16A16_UNORM, TextureFormat::RGBA16 }, |
| 1378 | { DDS_FORMAT_R16G16B16A16_FLOAT, TextureFormat::RGBA16F }, |
| 1379 | { DDS_FORMAT_R32G32B32A32_UINT, TextureFormat::RGBA32 }, |
| 1380 | { DDS_FORMAT_R32G32B32A32_FLOAT, TextureFormat::RGBA32F }, |
| 1381 | { DDS_FORMAT_B5G6R5_UNORM, TextureFormat::R5G6B5 }, |
| 1382 | { DDS_FORMAT_B4G4R4A4_UNORM, TextureFormat::RGBA4 }, |
| 1383 | { DDS_FORMAT_B5G5R5A1_UNORM, TextureFormat::RGB5A1 }, |
| 1384 | { DDS_FORMAT_R10G10B10A2_UNORM, TextureFormat::RGB10A2 }, |
| 1385 | 1385 | }; |
| 1386 | 1386 | |
| 1387 | 1387 | struct TranslateDdsPixelFormat |
trunk/3rdparty/bgfx/src/renderer_gl.cpp
| r245164 | r245165 | |
| 10 | 10 | # include <bx/timer.h> |
| 11 | 11 | # include <bx/uint32_t.h> |
| 12 | 12 | |
| 13 | | namespace bgfx |
| 13 | namespace bgfx { namespace gl |
| 14 | 14 | { |
| 15 | 15 | static char s_viewName[BGFX_CONFIG_MAX_VIEWS][BGFX_CONFIG_MAX_VIEW_NAME]; |
| 16 | 16 | |
| r245164 | r245165 | |
| 417 | 417 | EXT_blend_color, |
| 418 | 418 | EXT_blend_minmax, |
| 419 | 419 | EXT_blend_subtract, |
| 420 | EXT_color_buffer_half_float, |
| 420 | 421 | EXT_compressed_ETC1_RGB8_sub_texture, |
| 421 | 422 | EXT_debug_label, |
| 422 | 423 | EXT_debug_marker, |
| r245164 | r245165 | |
| 491 | 492 | OES_vertex_half_float, |
| 492 | 493 | OES_vertex_type_10_10_10_2, |
| 493 | 494 | |
| 495 | WEBGL_color_buffer_float, |
| 494 | 496 | WEBGL_compressed_texture_etc1, |
| 495 | 497 | WEBGL_compressed_texture_s3tc, |
| 496 | 498 | WEBGL_compressed_texture_pvrtc, |
| 497 | 499 | WEBGL_depth_texture, |
| 500 | WEBGL_draw_buffers, |
| 498 | 501 | |
| 499 | 502 | WEBKIT_EXT_texture_filter_anisotropic, |
| 500 | 503 | WEBKIT_WEBGL_compressed_texture_s3tc, |
| r245164 | r245165 | |
| 578 | 581 | { "EXT_blend_color", BGFX_CONFIG_RENDERER_OPENGL >= 31, true }, |
| 579 | 582 | { "EXT_blend_minmax", BGFX_CONFIG_RENDERER_OPENGL >= 14, true }, |
| 580 | 583 | { "EXT_blend_subtract", BGFX_CONFIG_RENDERER_OPENGL >= 14, true }, |
| 584 | { "EXT_color_buffer_half_float", false, true }, // GLES2 extension. |
| 581 | 585 | { "EXT_compressed_ETC1_RGB8_sub_texture", false, true }, // GLES2 extension. |
| 582 | 586 | { "EXT_debug_label", false, true }, |
| 583 | 587 | { "EXT_debug_marker", false, true }, |
| r245164 | r245165 | |
| 652 | 656 | { "OES_vertex_half_float", false, true }, |
| 653 | 657 | { "OES_vertex_type_10_10_10_2", false, true }, |
| 654 | 658 | |
| 659 | { "WEBGL_color_buffer_float", false, true }, |
| 655 | 660 | { "WEBGL_compressed_texture_etc1", false, true }, |
| 656 | 661 | { "WEBGL_compressed_texture_s3tc", false, true }, |
| 657 | 662 | { "WEBGL_compressed_texture_pvrtc", false, true }, |
| 658 | 663 | { "WEBGL_depth_texture", false, true }, |
| 664 | { "WEBGL_draw_buffers", false, true }, |
| 659 | 665 | |
| 660 | 666 | { "WEBKIT_EXT_texture_filter_anisotropic", false, true }, |
| 661 | 667 | { "WEBKIT_WEBGL_compressed_texture_s3tc", false, true }, |
| r245164 | r245165 | |
| 1294 | 1300 | |
| 1295 | 1301 | if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) |
| 1296 | 1302 | || BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30) |
| 1297 | | || s_extension[Extension::EXT_draw_buffers].m_supported) |
| 1303 | || s_extension[Extension::EXT_draw_buffers ].m_supported |
| 1304 | || s_extension[Extension::WEBGL_draw_buffers].m_supported) |
| 1298 | 1305 | { |
| 1299 | 1306 | g_caps.maxFBAttachments = bx::uint32_min(glGet(GL_MAX_COLOR_ATTACHMENTS), BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS); |
| 1300 | 1307 | } |
| r245164 | r245165 | |
| 2579 | 2586 | |
| 2580 | 2587 | RendererContextGL* s_renderGL; |
| 2581 | 2588 | |
| 2582 | | RendererContextI* rendererCreateGL() |
| 2589 | RendererContextI* rendererCreate() |
| 2583 | 2590 | { |
| 2584 | 2591 | s_renderGL = BX_NEW(g_allocator, RendererContextGL); |
| 2585 | 2592 | s_renderGL->init(); |
| 2586 | 2593 | return s_renderGL; |
| 2587 | 2594 | } |
| 2588 | 2595 | |
| 2589 | | void rendererDestroyGL() |
| 2596 | void rendererDestroy() |
| 2590 | 2597 | { |
| 2591 | 2598 | s_renderGL->shutdown(); |
| 2592 | 2599 | BX_DELETE(g_allocator, s_renderGL); |
| r245164 | r245165 | |
| 2662 | 2669 | GLENUM(GL_RENDERBUFFER); |
| 2663 | 2670 | |
| 2664 | 2671 | GLENUM(GL_INVALID_ENUM); |
| 2672 | GLENUM(GL_INVALID_FRAMEBUFFER_OPERATION); |
| 2665 | 2673 | GLENUM(GL_INVALID_VALUE); |
| 2666 | 2674 | GLENUM(GL_INVALID_OPERATION); |
| 2667 | 2675 | GLENUM(GL_OUT_OF_MEMORY); |
| r245164 | r245165 | |
| 3794 | 3802 | |
| 3795 | 3803 | if (usesFragData) |
| 3796 | 3804 | { |
| 3797 | | BX_WARN(s_extension[Extension::EXT_draw_buffers].m_supported, "EXT_draw_buffers is used but not supported by GLES2 driver."); |
| 3805 | BX_WARN(s_extension[Extension::EXT_draw_buffers ].m_supported |
| 3806 | || s_extension[Extension::WEBGL_draw_buffers].m_supported |
| 3807 | , "EXT_draw_buffers is used but not supported by GLES2 driver." |
| 3808 | ); |
| 3798 | 3809 | writeString(&writer |
| 3799 | 3810 | , "#extension GL_EXT_draw_buffers : enable\n" |
| 3800 | 3811 | ); |
| r245164 | r245165 | |
| 5354 | 5365 | |
| 5355 | 5366 | GL_CHECK(glFrameTerminatorGREMEDY() ); |
| 5356 | 5367 | } |
| 5357 | | } // namespace bgfx |
| 5368 | } } // namespace bgfx |
| 5358 | 5369 | |
| 5359 | 5370 | #else |
| 5360 | 5371 | |
| 5361 | | namespace bgfx |
| 5372 | namespace bgfx { namespace gl |
| 5362 | 5373 | { |
| 5363 | | RendererContextI* rendererCreateGL() |
| 5374 | RendererContextI* rendererCreate() |
| 5364 | 5375 | { |
| 5365 | 5376 | return NULL; |
| 5366 | 5377 | } |
| 5367 | 5378 | |
| 5368 | | void rendererDestroyGL() |
| 5379 | void rendererDestroy() |
| 5369 | 5380 | { |
| 5370 | 5381 | } |
| 5371 | | } // namespace bgfx |
| 5382 | } /* namespace gl */ } // namespace bgfx |
| 5372 | 5383 | |
| 5373 | 5384 | #endif // (BGFX_CONFIG_RENDERER_OPENGLES || BGFX_CONFIG_RENDERER_OPENGL) |
| 5374 | 5385 | |