Previous 199869 Revisions Next

r32174 Thursday 18th September, 2014 at 09:27:07 UTC by Miodrag Milanović
(OSD BRANCH) Updated BGFX to latest
[/branches/osd/src/lib/bgfx]bgfx.cpp bgfx_p.h glcontext_eagl.h glcontext_eagl.mm glcontext_egl.cpp glcontext_egl.h glcontext_glx.cpp glcontext_glx.h glcontext_nsgl.h glcontext_nsgl.mm glcontext_ppapi.cpp glcontext_ppapi.h glcontext_wgl.cpp glcontext_wgl.h makefile renderer_d3d11.cpp renderer_d3d11.h renderer_d3d9.cpp renderer_d3d9.h renderer_gl.cpp renderer_gl.h renderer_null.cpp
[/branches/osd/src/lib/bgfx/common/font]makefile
[/branches/osd/src/lib/bgfx/common/imgui]makefile
[/branches/osd/src/lib/bgfx/common/nanovg]makefile nanovg_bgfx.cpp
[/branches/osd/src/lib/bgfx/include]bgfx.c99.h bgfx.h
[/branches/osd/src/lib/bx]mpscqueue.h* os.h platform.h spscqueue.h

branches/osd/src/lib/bx/mpscqueue.h
r0r32174
1/*
2 * Copyright 2010-2013 Branimir Karadzic. All rights reserved.
3 * License: http://www.opensource.org/licenses/BSD-2-Clause
4 */
5
6#ifndef BX_MPSCQUEUE_H_HEADER_GUARD
7#define BX_MPSCQUEUE_H_HEADER_GUARD
8
9#include "spscqueue.h"
10
11namespace bx
12{
13   template <typename Ty>
14   class MpScUnboundedQueue
15   {
16      BX_CLASS(MpScUnboundedQueue
17         , NO_COPY
18         , NO_ASSIGNMENT
19         );
20
21   public:
22      MpScUnboundedQueue()
23      {
24      }
25
26      ~MpScUnboundedQueue()
27      {
28      }
29
30      void push(Ty* _ptr) // producer only
31      {
32         m_write.lock();
33         m_queue.push(_ptr);
34         m_write.unlock();
35      }
36
37      Ty* peek() // consumer only
38      {
39         return m_queue.peek();
40      }
41
42      Ty* pop() // consumer only
43      {
44         return m_queue.pop();
45      }
46
47   private:
48      LwMutex m_write;
49      SpScUnboundedQueue<Ty> m_queue;
50   };
51
52} // namespace bx
53
54#endif // BX_MPSCQUEUE_H_HEADER_GUARD
Property changes on: branches/osd/src/lib/bx/mpscqueue.h
Added: svn:mime-type
   + text/plain
Added: svn:eol-style
   + native
branches/osd/src/lib/bx/spscqueue.h
r32173r32174
203203
204204} // namespace bx
205205
206#endif // BX_RINGBUFFER_H_HEADER_GUARD
206#endif // BX_SPSCQUEUE_H_HEADER_GUARD
branches/osd/src/lib/bx/os.h
r32173r32174
5454#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360
5555      ::Sleep(_ms);
5656#elif BX_PLATFORM_WINRT
57        BX_UNUSED(_ms);
58        debugOutput("sleep is not implemented"); debugBreak();
57      BX_UNUSED(_ms);
58      debugOutput("sleep is not implemented"); debugBreak();
5959#else
6060      timespec req = {(time_t)_ms/1000, (long)((_ms%1000)*1000000)};
6161      timespec rem = {0, 0};
r32173r32174
7070#elif BX_PLATFORM_XBOX360
7171      ::Sleep(0);
7272#elif BX_PLATFORM_WINRT
73        debugOutput("yield is not implemented"); debugBreak();
73      debugOutput("yield is not implemented"); debugBreak();
7474#else
7575      ::sched_yield();
7676#endif // BX_PLATFORM_
r32173r32174
134134#if BX_PLATFORM_WINDOWS
135135      ::SetEnvironmentVariableA(_name, _value);
136136#elif BX_PLATFORM_WINRT
137        BX_UNUSED(_name, _value);
137      BX_UNUSED(_name, _value);
138138#else
139139      ::setenv(_name, _value, 1);
140140#endif // BX_PLATFORM_
r32173r32174
145145#if BX_PLATFORM_WINDOWS
146146      ::SetEnvironmentVariableA(_name, NULL);
147147#elif BX_PLATFORM_WINRT
148        BX_UNUSED(_name);
148      BX_UNUSED(_name);
149149#else
150150      ::unsetenv(_name);
151151#endif // BX_PLATFORM_
r32173r32174
154154   inline int chdir(const char* _path)
155155   {
156156#if BX_PLATFORM_WINRT
157        BX_UNUSED(_path);
157      BX_UNUSED(_path);
158158#elif BX_COMPILER_MSVC
159159      return ::_chdir(_path);
160160#else
r32173r32174
165165   inline char* pwd(char* _buffer, uint32_t _size)
166166   {
167167#if BX_PLATFORM_WINRT
168        BX_UNUSED(_buffer, _size);
168      BX_UNUSED(_buffer, _size);
169169#elif BX_COMPILER_MSVC
170170      return ::_getcwd(_buffer, (int)_size);
171171#else
branches/osd/src/lib/bx/platform.h
r32173r32174
3838// http://sourceforge.net/apps/mediawiki/predef/index.php?title=Compilers
3939#if defined(_MSC_VER)
4040#   undef BX_COMPILER_MSVC
41#   define BX_COMPILER_MSVC 1
41#   define BX_COMPILER_MSVC _MSC_VER
4242#elif defined(__clang__)
4343// clang defines __GNUC__
4444#   undef BX_COMPILER_CLANG
4545#   define BX_COMPILER_CLANG 1
4646#elif defined(__GNUC__)
4747#   undef BX_COMPILER_GCC
48#   define BX_COMPILER_GCC 1
48#   define BX_COMPILER_GCC (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
4949#else
5050#   error "BX_COMPILER_* is not defined!"
5151#endif //
r32173r32174
158158#endif // BX_CONFIG_ENABLE_MSVC_LEVEL4_WARNINGS
159159
160160#if BX_COMPILER_GCC
161#   define BX_COMPILER_NAME "GCC"
161#   define BX_COMPILER_NAME "GCC " \
162            BX_STRINGIZE(__GNUC__) "." \
163            BX_STRINGIZE(__GNUC_MINOR__) "." \
164            BX_STRINGIZE(__GNUC_PATCHLEVEL__)
162165#elif BX_COMPILER_CLANG
163166#   define BX_COMPILER_NAME "Clang"
164167#elif BX_COMPILER_MSVC
165#   define BX_COMPILER_NAME "MSVC"
168#   if BX_COMPILER_MSVC >= 1800
169#      define BX_COMPILER_NAME "MSVC 12.0"
170#   elif BX_COMPILER_MSVC >= 1700
171#      define BX_COMPILER_NAME "MSVC 11.0"
172#   elif BX_COMPILER_MSVC >= 1600
173#      define BX_COMPILER_NAME "MSVC 10.0"
174#   elif BX_COMPILER_MSVC >= 1500
175#      define BX_COMPILER_NAME "MSVC 9.0"
176#   else
177#      define BX_COMPILER_NAME "MSVC"
178#   endif //
166179#endif // BX_COMPILER_
167180
168181#if BX_PLATFORM_ANDROID
branches/osd/src/lib/bgfx/renderer_gl.h
r32173r32174
815815   struct FrameBufferGL
816816   {
817817      FrameBufferGL()
818         : m_num(0)
818         : m_swapChain(NULL)
819         , m_denseIdx(UINT16_MAX)
820         , m_num(0)
819821      {
820822         memset(m_fbo, 0, sizeof(m_fbo) );
821823      }
822824
823825      void create(uint8_t _num, const TextureHandle* _handles);
824      void destroy();
826      void create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat);
827      uint16_t destroy();
825828      void resolve();
826829
827      uint8_t m_num;
830      SwapChainGL* m_swapChain;
828831      GLuint m_fbo[2];
829832      uint32_t m_width;
830833      uint32_t m_height;
834      uint16_t m_denseIdx;
835      uint8_t m_num;
831836   };
832837
833838   struct ProgramGL
branches/osd/src/lib/bgfx/renderer_d3d9.h
r32173r32174
353353   struct FrameBufferD3D9
354354   {
355355      FrameBufferD3D9()
356         : m_num(0)
356         : m_hwnd(NULL)
357         , m_denseIdx(UINT16_MAX)
358         , m_num(0)
357359         , m_needResolve(0)
358360      {
359361         m_depthHandle.idx = invalidHandle;
360362      }
361363
362364      void create(uint8_t _num, const TextureHandle* _handles);
363      void destroy();
365      void create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat);
366      uint16_t destroy();
367      HRESULT present();
364368      void resolve() const;
365369      void preReset();
366370      void postReset();
r32173r32174
368372
369373      IDirect3DSurface9* m_color[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS-1];
370374      IDirect3DSurface9* m_depthStencil;
375      IDirect3DSwapChain9* m_swapChain;
376      HWND m_hwnd;
377
371378      TextureHandle m_colorHandle[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS-1];
372379      TextureHandle m_depthHandle;
380      uint16_t m_denseIdx;
373381      uint8_t m_num;
374382      bool m_needResolve;
375383   };
branches/osd/src/lib/bgfx/glcontext_nsgl.h
r32173r32174
1010
1111namespace bgfx
1212{
13   struct SwapChainGL;
14
1315   struct GlContext
1416   {
1517      GlContext()
r32173r32174
2022      void create(uint32_t _width, uint32_t _height);
2123      void destroy();
2224      void resize(uint32_t _width, uint32_t _height, bool _vsync);
23      void swap();
25
26      SwapChainGL* createSwapChain(void* _nwh);
27      void destorySwapChain(SwapChainGL*  _swapChain);
28      void swap(SwapChainGL* _swapChain = NULL);
29      void makeCurrent(SwapChainGL* _swapChain = NULL);
30
2431      void import();
2532
2633      bool isValid() const
branches/osd/src/lib/bgfx/include/bgfx.c99.h
r32173r32174
972972BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_from_handles(uint8_t _num, bgfx_texture_handle_t* _handles, bool _destroyTextures);
973973
974974/**
975 *  Create frame buffer for multiple window rendering.
976 *
977 *  @param _nwh OS' target native window handle.
978 *  @param _width Window back buffer width.
979 *  @param _height Window back buffer height.
980 *  @param _depthFormat Window back buffer depth format.
981 *
982 *  NOTE:
983 *    Frame buffer cannnot be used for sampling.
984 */
985BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_from_nwh(void* _nwh, uint16_t _width, uint16_t _height, bgfx_texture_format_t _depthFormat);
986
987/**
975988 *  Destroy frame buffer.
976989 */
977990BGFX_C_API void bgfx_destroy_frame_buffer(bgfx_frame_buffer_handle_t _handle);
r32173r32174
11071120 *  @param _depth Depth clear value.
11081121 *  @param _stencil Stencil clear value.
11091122 */
1110BGFX_C_API void bgfx_set_view_clear_mrt7(uint8_t _id, uint8_t _flags, float _depth, uint8_t _stencil, uint8_t _0, uint8_t _1, uint8_t _2, uint8_t _3, uint8_t _4, uint8_t _5, uint8_t _6, uint8_t _7);
1123BGFX_C_API void bgfx_set_view_clear_mrt(uint8_t _id, uint8_t _flags, float _depth, uint8_t _stencil, uint8_t _0, uint8_t _1, uint8_t _2, uint8_t _3, uint8_t _4, uint8_t _5, uint8_t _6, uint8_t _7);
11111124
11121125/**
11131126 *  Set view clear flags for multiple views.
branches/osd/src/lib/bgfx/include/bgfx.h
r32173r32174
815815   ///
816816   FrameBufferHandle createFrameBuffer(uint8_t _num, TextureHandle* _handles, bool _destroyTextures = false);
817817
818   /// Create frame buffer for multiple window rendering.
819   ///
820   /// @param _nwh OS' target native window handle.
821   /// @param _width Window back buffer width.
822   /// @param _height Window back buffer height.
823   /// @param _depthFormat Window back buffer depth format.
824   ///
825   /// NOTE:
826   ///   Frame buffer cannnot be used for sampling.
827   ///
828   FrameBufferHandle createFrameBuffer(void* _nwh, uint16_t _width, uint16_t _height, TextureFormat::Enum _depthFormat = TextureFormat::UnknownDepth);
829
818830   /// Destroy frame buffer.
819831   void destroyFrameBuffer(FrameBufferHandle _handle);
820832
r32173r32174
971983   ///   frame buffer handle will draw primitives from this view into
972984   ///   default back buffer.
973985   ///
986   /// NOTE:
987   ///   Not persistent after bgfx::reset call.
988   ///
974989   void setViewFrameBuffer(uint8_t _id, FrameBufferHandle _handle);
975990
976991   /// Set view frame buffer for multiple views.
r32173r32174
980995   ///   frame buffer handle will draw primitives from this view into
981996   ///   default back buffer.
982997   ///
998   /// NOTE:
999   ///   Not persistent after bgfx::reset call.
1000   ///
9831001   void setViewFrameBufferMask(uint32_t _viewMask, FrameBufferHandle _handle);
9841002
9851003   /// Set view view and projection matrices, all draw primitives in this
r32173r32174
10051023   ///   BGFX_STATE_CULL_* - Backface culling mode.
10061024   ///   BGFX_STATE_RGB_WRITE - Enable RGB write.
10071025   ///   BGFX_STATE_MSAA - Enable MSAA.
1008   ///   BGFX_STATE_PT_[LINES/POINTS] - Primitive type.
1026   ///   BGFX_STATE_PT_[TRISTRIP/LINES/POINTS] - Primitive type.
10091027   ///
10101028   /// @param _rgba Sets blend factor used by BGFX_STATE_BLEND_FACTOR and
10111029   ///   BGFX_STATE_BLEND_INV_FACTOR blend modes.
branches/osd/src/lib/bgfx/glcontext_egl.h
r32173r32174
1212
1313namespace bgfx
1414{
15   struct SwapChainGL;
16
1517   struct GlContext
1618   {
1719      GlContext()
r32173r32174
2426      void create(uint32_t _width, uint32_t _height);
2527      void destroy();
2628      void resize(uint32_t _width, uint32_t _height, bool _vsync);
27      void swap();
29
30      SwapChainGL* createSwapChain(void* _nwh);
31      void destorySwapChain(SwapChainGL*  _swapChain);
32      void swap(SwapChainGL* _swapChain = NULL);
33      void makeCurrent(SwapChainGL* _swapChain = NULL);
34
2835      void import();
2936
3037      bool isValid() const
branches/osd/src/lib/bgfx/glcontext_eagl.h
r32173r32174
1010
1111namespace bgfx
1212{
13   struct SwapChainGL;
14
1315   struct GlContext
1416   {
1517      GlContext()
r32173r32174
2022      void create(uint32_t _width, uint32_t _height);
2123      void destroy();
2224      void resize(uint32_t _width, uint32_t _height, bool _vsync);
23      void swap();
25
26      SwapChainGL* createSwapChain(void* _nwh);
27      void destorySwapChain(SwapChainGL*  _swapChain);
28      void swap(SwapChainGL* _swapChain = NULL);
29      void makeCurrent(SwapChainGL* _swapChain = NULL);
30
2431      void import();
2532
33      GLuint getFbo()
34      {
35         return m_fbo;
36      }
37
2638      bool isValid() const
2739      {
2840         return 0 != m_context;
branches/osd/src/lib/bgfx/glcontext_ppapi.h
r32173r32174
1515
1616namespace bgfx
1717{
18   struct SwapChainGL;
19
1820   struct GlContext
1921   {
2022      GlContext()
r32173r32174
2426      void create(uint32_t _width, uint32_t _height);
2527      void destroy();
2628      void resize(uint32_t _width, uint32_t _height, bool _vsync);
27      void swap();
29
30      SwapChainGL* createSwapChain(void* _nwh);
31      void destorySwapChain(SwapChainGL*  _swapChain);
32      void swap(SwapChainGL* _swapChain = NULL);
33      void makeCurrent(SwapChainGL* _swapChain = NULL);
34
2835      void import();
2936      bool isValid() const;
3037   };
branches/osd/src/lib/bgfx/renderer_d3d11.h
r32173r32174
273273   struct FrameBufferD3D11
274274   {
275275      FrameBufferD3D11()
276         : m_num(0)
276         : m_denseIdx(UINT16_MAX)
277         , m_num(0)
277278      {
278279      }
279280
280281      void create(uint8_t _num, const TextureHandle* _handles);
281      void destroy();
282      void create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat);
283      uint16_t destroy();
282284      void resolve();
283285      void clear(const Clear& _clear, const float _palette[][4]);
284286
285287      ID3D11RenderTargetView* m_rtv[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS-1];
286288      ID3D11ShaderResourceView* m_srv[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS-1];
287289      ID3D11DepthStencilView* m_dsv;
290      IDXGISwapChain* m_swapChain;
291      uint16_t m_denseIdx;
288292      uint8_t m_num;
289293   };
290294
branches/osd/src/lib/bgfx/glcontext_glx.cpp
r32173r32174
212212      }
213213   }
214214
215   void GlContext::swap()
215   SwapChainGL* GlContext::createSwapChain(void* /*_nwh*/)
216216   {
217      BX_CHECK(false, "Shouldn't be called!");
218      return NULL;
219   }
220
221   void GlContext::destorySwapChain(SwapChainGL*  /*_swapChain*/)
222   {
223      BX_CHECK(false, "Shouldn't be called!");
224   }
225
226   void GlContext::swap(SwapChainGL* _swapChain)
227   {
228      BX_CHECK(NULL == _swapChain, "Shouldn't be called!"); BX_UNUSED(_swapChain);
217229      glXSwapBuffers(s_display, s_window);
218230   }
219231
232   void GlContext::makeCurrent(SwapChainGL* /*_swapChain*/)
233   {
234   }
235
220236   void GlContext::import()
221237   {
222238#   define GL_EXTENSION(_optional, _proto, _func, _import) \
branches/osd/src/lib/bgfx/glcontext_nsgl.mm
r32173r32174
8888      [glContext setValues:&interval forParameter:NSOpenGLCPSwapInterval];
8989   }
9090
91   void GlContext::swap()
91   SwapChainGL* GlContext::createSwapChain(void* /*_nwh*/)
9292   {
93      BX_CHECK(false, "Shouldn't be called!");
94      return NULL;
95   }
96
97   void GlContext::destorySwapChain(SwapChainGL*  /*_swapChain*/)
98   {
99      BX_CHECK(false, "Shouldn't be called!");
100   }
101
102   void GlContext::swap(SwapChainGL* _swapChain)
103   {
104      BX_CHECK(NULL == _swapChain, "Shouldn't be called!"); BX_UNUSED(_swapChain);
93105      NSOpenGLContext* glContext = (NSOpenGLContext*)m_context;
94106      [glContext makeCurrentContext];
95107      [glContext flushBuffer];
96108   }
97109
110   void GlContext::makeCurrent(SwapChainGL* /*_swapChain*/)
111   {
112   }
113
98114   void GlContext::import()
99115   {
100116      BX_TRACE("Import:");
branches/osd/src/lib/bgfx/glcontext_wgl.h
r32173r32174
1515typedef PROC (APIENTRYP PFNWGLGETPROCADDRESSPROC) (LPCSTR lpszProc);
1616typedef BOOL (APIENTRYP PFNWGLMAKECURRENTPROC) (HDC hdc, HGLRC hglrc);
1717typedef HGLRC (APIENTRYP PFNWGLCREATECONTEXTPROC) (HDC hdc);
18typedef BOOL (APIENTRYP PFNWGLDELETECONTEXTPROC) (HGLRC hglrc);
18typedef BOOL (APIENTRYP PFNWGLDELETECONTEXTPROC) (HGLRC hglrc);
1919//
2020typedef GLenum (APIENTRYP PFNGLGETERRORPROC) (void);
2121typedef void (APIENTRYP PFNGLREADPIXELSPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels);
r32173r32174
5656   extern PFNWGLCREATECONTEXTPROC wglCreateContext;
5757   extern PFNWGLDELETECONTEXTPROC wglDeleteContext;
5858
59   struct SwapChainGL;
60
5961   struct GlContext
6062   {
6163      GlContext()
r32173r32174
6870      void create(uint32_t _width, uint32_t _height);
6971      void destroy();
7072      void resize(uint32_t _width, uint32_t _height, bool _vsync);
71      void swap();
73
74      SwapChainGL* createSwapChain(void* _nwh);
75      void destorySwapChain(SwapChainGL*  _swapChain);
76      void swap(SwapChainGL* _swapChain = NULL);
77      void makeCurrent(SwapChainGL* _swapChain = NULL);
78
7279      void import();
7380
7481      bool isValid() const
r32173r32174
7683         return NULL != m_context;
7784      }
7885
86      int32_t m_contextAttrs[9];
87      int m_pixelFormat;
88      PIXELFORMATDESCRIPTOR m_pfd;
7989      void* m_opengl32dll;
8090      HGLRC m_context;
8191      HDC m_hdc;
branches/osd/src/lib/bgfx/bgfx.cpp
r32173r32174
503503         
504504         struct Mem
505505         {
506            Mem(const void* _data, size_t _size)
507               : data(_data)
508               , size(_size)
509            {
510            }
511
506512            const void*  data;
507            const size_t size;
513            size_t size;
508514         };
509515
510516         const Memory* fragMem[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS];
r32173r32174
514520
515521            const Mem mem[] =
516522            {
517               { fs_clear0_dx9, sizeof(fs_clear0_dx9) },
518               { fs_clear1_dx9, sizeof(fs_clear1_dx9) },
519               { fs_clear2_dx9, sizeof(fs_clear2_dx9) },
520               { fs_clear3_dx9, sizeof(fs_clear3_dx9) },
521               { fs_clear4_dx9, sizeof(fs_clear4_dx9) },
522               { fs_clear5_dx9, sizeof(fs_clear5_dx9) },
523               { fs_clear6_dx9, sizeof(fs_clear6_dx9) },
524               { fs_clear7_dx9, sizeof(fs_clear7_dx9) },
523               Mem(fs_clear0_dx9, sizeof(fs_clear0_dx9) ),
524               Mem(fs_clear1_dx9, sizeof(fs_clear1_dx9) ),
525               Mem(fs_clear2_dx9, sizeof(fs_clear2_dx9) ),
526               Mem(fs_clear3_dx9, sizeof(fs_clear3_dx9) ),
527               Mem(fs_clear4_dx9, sizeof(fs_clear4_dx9) ),
528               Mem(fs_clear5_dx9, sizeof(fs_clear5_dx9) ),
529               Mem(fs_clear6_dx9, sizeof(fs_clear6_dx9) ),
530               Mem(fs_clear7_dx9, sizeof(fs_clear7_dx9) ),
525531            };
526532
527533            for (uint32_t ii = 0, num = g_caps.maxFBAttachments; ii < num; ++ii)
528534            {
529               fragMem[ii] = makeRef(mem[ii].data, mem[ii].size);
535               fragMem[ii] = makeRef(mem[ii].data, uint32_t(mem[ii].size) );
530536            }
531537         }
532538         else if (RendererType::Direct3D11 == g_caps.rendererType)
r32173r32174
535541
536542            const Mem mem[] =
537543            {
538               { fs_clear0_dx11, sizeof(fs_clear0_dx11) },
539               { fs_clear1_dx11, sizeof(fs_clear1_dx11) },
540               { fs_clear2_dx11, sizeof(fs_clear2_dx11) },
541               { fs_clear3_dx11, sizeof(fs_clear3_dx11) },
542               { fs_clear4_dx11, sizeof(fs_clear4_dx11) },
543               { fs_clear5_dx11, sizeof(fs_clear5_dx11) },
544               { fs_clear6_dx11, sizeof(fs_clear6_dx11) },
545               { fs_clear7_dx11, sizeof(fs_clear7_dx11) },
544               Mem(fs_clear0_dx11, sizeof(fs_clear0_dx11) ),
545               Mem(fs_clear1_dx11, sizeof(fs_clear1_dx11) ),
546               Mem(fs_clear2_dx11, sizeof(fs_clear2_dx11) ),
547               Mem(fs_clear3_dx11, sizeof(fs_clear3_dx11) ),
548               Mem(fs_clear4_dx11, sizeof(fs_clear4_dx11) ),
549               Mem(fs_clear5_dx11, sizeof(fs_clear5_dx11) ),
550               Mem(fs_clear6_dx11, sizeof(fs_clear6_dx11) ),
551               Mem(fs_clear7_dx11, sizeof(fs_clear7_dx11) ),
546552            };
547553
548554            for (uint32_t ii = 0, num = g_caps.maxFBAttachments; ii < num; ++ii)
549555            {
550               fragMem[ii] = makeRef(mem[ii].data, mem[ii].size);
556               fragMem[ii] = makeRef(mem[ii].data, uint32_t(mem[ii].size) );
551557            }
552558         }
553559         else if (RendererType::OpenGLES == g_caps.rendererType
r32173r32174
557563
558564            const Mem mem[] =
559565            {
560               { fs_clear0_glsl, sizeof(fs_clear0_glsl) },
561               { fs_clear1_glsl, sizeof(fs_clear1_glsl) },
562               { fs_clear2_glsl, sizeof(fs_clear2_glsl) },
563               { fs_clear3_glsl, sizeof(fs_clear3_glsl) },
564               { fs_clear4_glsl, sizeof(fs_clear4_glsl) },
565               { fs_clear5_glsl, sizeof(fs_clear5_glsl) },
566               { fs_clear6_glsl, sizeof(fs_clear6_glsl) },
567               { fs_clear7_glsl, sizeof(fs_clear7_glsl) },
566               Mem(fs_clear0_glsl, sizeof(fs_clear0_glsl) ),
567               Mem(fs_clear1_glsl, sizeof(fs_clear1_glsl) ),
568               Mem(fs_clear2_glsl, sizeof(fs_clear2_glsl) ),
569               Mem(fs_clear3_glsl, sizeof(fs_clear3_glsl) ),
570               Mem(fs_clear4_glsl, sizeof(fs_clear4_glsl) ),
571               Mem(fs_clear5_glsl, sizeof(fs_clear5_glsl) ),
572               Mem(fs_clear6_glsl, sizeof(fs_clear6_glsl) ),
573               Mem(fs_clear7_glsl, sizeof(fs_clear7_glsl) ),
568574            };
569575
570576            for (uint32_t ii = 0, num = g_caps.maxFBAttachments; ii < num; ++ii)
571577            {
572               fragMem[ii] = makeRef(mem[ii].data, mem[ii].size);
578               fragMem[ii] = makeRef(mem[ii].data, uint32_t(mem[ii].size) );
573579            }
574580         }
575581
r32173r32174
693699      BX_WARN(invalidHandle != m_key.m_program, "Program with invalid handle");
694700      if (invalidHandle != m_key.m_program)
695701      {
696         m_key.m_depth = _depth;
697         m_key.m_view = _id;
698         m_key.m_seq = s_ctx->m_seq[_id] & s_ctx->m_seqMask[_id];
702         m_key.m_depth  = _depth;
703         m_key.m_view   = _id;
704         m_key.m_seq    = s_ctx->m_seq[_id] & s_ctx->m_seqMask[_id];
699705         s_ctx->m_seq[_id]++;
706
700707         uint64_t key = m_key.encodeDraw();
701         m_sortKeys[m_num] = key;
708         m_sortKeys[m_num]   = key;
702709         m_sortValues[m_num] = m_numRenderItems;
703710         ++m_num;
704711
r32173r32174
743750            viewMask >>= ntz;
744751            id += ntz;
745752
746            m_key.m_view = id;
747            m_key.m_seq = s_ctx->m_seq[id] & s_ctx->m_seqMask[id];
753            m_key.m_view   = id;
754            m_key.m_seq    = s_ctx->m_seq[id] & s_ctx->m_seqMask[id];
748755            s_ctx->m_seq[id]++;
756
749757            uint64_t key = m_key.encodeDraw();
750            m_sortKeys[m_num] = key;
758            m_sortKeys[m_num]   = key;
751759            m_sortValues[m_num] = m_numRenderItems;
752760            ++m_num;
753761         }
r32173r32174
788796      m_key.m_program = _handle.idx;
789797      if (invalidHandle != m_key.m_program)
790798      {
791         m_key.m_depth = 0;
792         m_key.m_view = _id;
793         m_key.m_seq = s_ctx->m_seq[_id] & s_ctx->m_seqMask[_id];
799         m_key.m_depth  = 0;
800         m_key.m_view   = _id;
801         m_key.m_seq    = s_ctx->m_seq[_id] & s_ctx->m_seqMask[_id];
794802         s_ctx->m_seq[_id]++;
803
795804         uint64_t key = m_key.encodeCompute();
796         m_sortKeys[m_num] = key;
805         m_sortKeys[m_num]   = key;
797806         m_sortValues[m_num] = m_numRenderItems;
798807         ++m_num;
799808
r32173r32174
10881097         CHECK_HANDLE_LEAK(m_textureHandle);
10891098         CHECK_HANDLE_LEAK(m_frameBufferHandle);
10901099         CHECK_HANDLE_LEAK(m_uniformHandle);
1091
10921100#undef CHECK_HANDLE_LEAK
10931101      }
10941102   }
r32173r32174
17751783               FrameBufferHandle handle;
17761784               _cmdbuf.read(handle);
17771785
1778               uint8_t num;
1779               _cmdbuf.read(num);
1786               bool window;
1787               _cmdbuf.read(window);
17801788
1781               TextureHandle textureHandles[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS];
1782               for (uint32_t ii = 0; ii < num; ++ii)
1789               if (window)
17831790               {
1784                  _cmdbuf.read(textureHandles[ii]);
1791                  void* nwh;
1792                  _cmdbuf.read(nwh);
1793
1794                  uint16_t width;
1795                  _cmdbuf.read(width);
1796
1797                  uint16_t height;
1798                  _cmdbuf.read(height);
1799
1800                  TextureFormat::Enum depthFormat;
1801                  _cmdbuf.read(depthFormat);
1802
1803                  m_renderCtx->createFrameBuffer(handle, nwh, width, height, depthFormat);
17851804               }
1805               else
1806               {
1807                  uint8_t num;
1808                  _cmdbuf.read(num);
17861809
1787               m_renderCtx->createFrameBuffer(handle, num, textureHandles);
1810                  TextureHandle textureHandles[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS];
1811                  for (uint32_t ii = 0; ii < num; ++ii)
1812                  {
1813                     _cmdbuf.read(textureHandles[ii]);
1814                  }
1815
1816                  m_renderCtx->createFrameBuffer(handle, num, textureHandles);
1817               }
17881818            }
17891819            break;
17901820
r32173r32174
24732503      return handle;
24742504   }
24752505
2506   FrameBufferHandle createFrameBuffer(void* _nwh, uint16_t _width, uint16_t _height, TextureFormat::Enum _depthFormat)
2507   {
2508      BGFX_CHECK_MAIN_THREAD();
2509      return s_ctx->createFrameBuffer(_nwh, _width, _height, _depthFormat);
2510   }
2511
24762512   void destroyFrameBuffer(FrameBufferHandle _handle)
24772513   {
24782514      BGFX_CHECK_MAIN_THREAD();
r32173r32174
31663202   return handle.c;
31673203}
31683204
3205BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_from_nwh(void* _nwh, uint16_t _width, uint16_t _height, bgfx_texture_format_t _depthFormat)
3206{
3207   union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle;
3208   handle.cpp = bgfx::createFrameBuffer(_nwh, _width, _height, bgfx::TextureFormat::Enum(_depthFormat) );
3209   return handle.c;
3210}
3211
31693212BGFX_C_API void bgfx_destroy_frame_buffer(bgfx_frame_buffer_handle_t _handle)
31703213{
31713214   union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle = { _handle };
r32173r32174
32203263   bgfx::setViewClear(_id, _flags, _rgba, _depth, _stencil);
32213264}
32223265
3223BGFX_C_API void bgfx_set_view_clear_mrt7(uint8_t _id, uint8_t _flags, float _depth, uint8_t _stencil, uint8_t _0, uint8_t _1, uint8_t _2, uint8_t _3, uint8_t _4, uint8_t _5, uint8_t _6, uint8_t _7)
3266BGFX_C_API void bgfx_set_view_clear_mrt(uint8_t _id, uint8_t _flags, float _depth, uint8_t _stencil, uint8_t _0, uint8_t _1, uint8_t _2, uint8_t _3, uint8_t _4, uint8_t _5, uint8_t _6, uint8_t _7)
32243267{
32253268   bgfx::setViewClear(_id, _flags, _depth, _stencil, _0, _1, _2, _3, _4, _5, _6, _7);
32263269}
branches/osd/src/lib/bgfx/renderer_gl.cpp
r32173r32174
344344
345345         ATI_meminfo,
346346
347         CHROMIUM_color_buffer_float_rgb,
348         CHROMIUM_color_buffer_float_rgba,
347349         CHROMIUM_depth_texture,
348350         CHROMIUM_framebuffer_multisample,
349351         CHROMIUM_texture_compression_dxt3,
r32173r32174
356358         EXT_compressed_ETC1_RGB8_sub_texture,
357359         EXT_debug_label,
358360         EXT_debug_marker,
361         EXT_draw_buffers,
359362         EXT_frag_depth,
360363         EXT_framebuffer_blit,
361364         EXT_framebuffer_object,
r32173r32174
499502
500503      { "ATI_meminfo",                           false,                             true  },
501504
505      { "CHROMIUM_color_buffer_float_rgb",       false,                             true  },
506      { "CHROMIUM_color_buffer_float_rgba",      false,                             true  },
502507      { "CHROMIUM_depth_texture",                false,                             true  },
503508      { "CHROMIUM_framebuffer_multisample",      false,                             true  },
504509      { "CHROMIUM_texture_compression_dxt3",     false,                             true  },
r32173r32174
511516      { "EXT_compressed_ETC1_RGB8_sub_texture",  false,                             true  }, // GLES2 extension.
512517      { "EXT_debug_label",                       false,                             true  },
513518      { "EXT_debug_marker",                      false,                             true  },
519      { "EXT_draw_buffers",                      false,                             true  }, // GLES2 extension.
514520      { "EXT_frag_depth",                        false,                             true  }, // GLES2 extension.
515521      { "EXT_framebuffer_blit",                  BGFX_CONFIG_RENDERER_OPENGL >= 30, true  },
516522      { "EXT_framebuffer_object",                BGFX_CONFIG_RENDERER_OPENGL >= 30, true  },
r32173r32174
826832   struct RendererContextGL : public RendererContextI
827833   {
828834      RendererContextGL()
829         : m_rtMsaa(false)
835         : m_numWindows(1)
836         , m_rtMsaa(false)
830837         , m_capture(NULL)
831838         , m_captureSize(0)
832839         , m_maxAnisotropy(0.0f)
r32173r32174
11691176         g_caps.maxTextureSize = glGet(GL_MAX_TEXTURE_SIZE);
11701177
11711178         if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL)
1172         ||  BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30) )
1179         ||  BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30)
1180         ||  s_extension[Extension::EXT_draw_buffers].m_supported)
11731181         {
11741182            g_caps.maxFBAttachments = bx::uint32_min(glGet(GL_MAX_COLOR_ATTACHMENTS), BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS);
11751183         }
r32173r32174
13761384      {
13771385         if (m_flip)
13781386         {
1387            for (uint32_t ii = 1, num = m_numWindows; ii < num; ++ii)
1388            {
1389               m_glctx.swap(m_frameBuffers[m_windows[ii].idx].m_swapChain);
1390            }
13791391            m_glctx.swap();
13801392         }
13811393      }
r32173r32174
14911503         m_frameBuffers[_handle.idx].create(_num, _textureHandles);
14921504      }
14931505
1506      void createFrameBuffer(FrameBufferHandle _handle, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat) BX_OVERRIDE
1507      {
1508         uint16_t denseIdx = m_numWindows++;
1509         m_windows[denseIdx] = _handle;
1510         m_frameBuffers[_handle.idx].create(denseIdx, _nwh, _width, _height, _depthFormat);
1511      }
1512
14941513      void destroyFrameBuffer(FrameBufferHandle _handle) BX_OVERRIDE
14951514      {
1496         m_frameBuffers[_handle.idx].destroy();
1515         uint16_t denseIdx = m_frameBuffers[_handle.idx].destroy();
1516         if (UINT16_MAX != denseIdx)
1517         {
1518            --m_numWindows;
1519            if (m_numWindows > 1)
1520            {
1521               FrameBufferHandle handle = m_windows[m_numWindows];
1522               m_windows[denseIdx] = handle;
1523               m_frameBuffers[handle.idx].m_denseIdx = denseIdx;
1524            }
1525         }
14971526      }
14981527
14991528      void createUniform(UniformHandle _handle, UniformType::Enum _type, uint16_t _num, const char* _name) BX_OVERRIDE
r32173r32174
16551684            frameBuffer.resolve();
16561685         }
16571686
1687         m_glctx.makeCurrent(NULL);
1688
16581689         if (!isValid(_fbh) )
16591690         {
16601691            GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_msaaBackBufferFbo) );
r32173r32174
16621693         else
16631694         {
16641695            FrameBufferGL& frameBuffer = m_frameBuffers[_fbh.idx];
1665            GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer.m_fbo[0]) );
1666            _height = frameBuffer.m_height;
1696            if (UINT16_MAX != frameBuffer.m_denseIdx)
1697            {
1698               m_glctx.makeCurrent(frameBuffer.m_swapChain);
1699               GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, 0) );
1700            }
1701            else
1702            {
1703               m_glctx.makeCurrent(NULL);
1704               GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer.m_fbo[0]) );
1705               _height = frameBuffer.m_height;
1706            }
16671707         }
16681708
16691709         m_fbh = _fbh;
r32173r32174
17641804
17651805#if BX_PLATFORM_IOS
17661806               // iOS: need to figure out how to deal with FBO created by context.
1767               m_backBufferFbo = m_glctx.m_fbo;
1768               m_msaaBackBufferFbo = m_glctx.m_fbo;
1807               m_backBufferFbo = m_msaaBackBufferFbo = m_glctx.getFbo();
17691808#endif // BX_PLATFORM_IOS
17701809            }
17711810            else
r32173r32174
22032242         }
22042243      }
22052244
2245      uint16_t m_numWindows;
2246      FrameBufferHandle m_windows[BGFX_CONFIG_MAX_FRAME_BUFFERS];
2247
22062248      IndexBufferGL m_indexBuffers[BGFX_CONFIG_MAX_INDEX_BUFFERS];
22072249      VertexBufferGL m_vertexBuffers[BGFX_CONFIG_MAX_VERTEX_BUFFERS];
22082250      ShaderGL m_shaders[BGFX_CONFIG_MAX_SHADERS];
r32173r32174
33873429                  && bx::findIdentifierMatch(code, s_OES_standard_derivatives)
33883430                  ;
33893431
3432               bool usesFragData  = !!bx::findIdentifierMatch(code, "gl_FragData");
3433
33903434               bool usesFragDepth = !!bx::findIdentifierMatch(code, "gl_FragDepth");
33913435
33923436               bool usesShadowSamplers = !!bx::findIdentifierMatch(code, s_EXT_shadow_samplers);
r32173r32174
34043448                  writeString(&writer, "#extension GL_OES_standard_derivatives : enable\n");
34053449               }
34063450
3451               if (usesFragData)
3452               {
3453                  BX_WARN(s_extension[Extension::EXT_draw_buffers].m_supported, "EXT_draw_buffers is used but not supported by GLES2 driver.");
3454                  writeString(&writer
3455                     , "#extension GL_EXT_draw_buffers : enable\n"
3456                     );
3457               }
3458
34073459               bool insertFragDepth = false;
34083460               if (usesFragDepth)
34093461               {
r32173r32174
37003752      GL_CHECK(glGenFramebuffers(1, &m_fbo[0]) );
37013753      GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_fbo[0]) );
37023754
3755//      m_denseIdx = UINT16_MAX;
37033756      bool needResolve = false;
37043757
37053758      GLenum buffers[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS];
r32173r32174
38073860      GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, s_renderGL->m_msaaBackBufferFbo) );
38083861   }
38093862
3810   void FrameBufferGL::destroy()
3863   void FrameBufferGL::create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat)
38113864   {
3865      BX_UNUSED(_depthFormat);
3866      m_swapChain = s_renderGL->m_glctx.createSwapChain(_nwh);
3867      m_width     = _width;
3868      m_height    = _height;
3869      m_denseIdx  = _denseIdx;
3870   }
3871
3872   uint16_t FrameBufferGL::destroy()
3873   {
38123874      GL_CHECK(glDeleteFramebuffers(0 == m_fbo[1] ? 1 : 2, m_fbo) );
38133875      memset(m_fbo, 0, sizeof(m_fbo) );
38143876      m_num = 0;
3877
3878      if (NULL != m_swapChain)
3879      {
3880         s_renderGL->m_glctx.destorySwapChain(m_swapChain);
3881         m_swapChain = NULL;
3882      }
3883
3884      uint16_t denseIdx = m_denseIdx;
3885      m_denseIdx = UINT16_MAX;
3886     
3887      return denseIdx;
38153888   }
38163889
38173890   void FrameBufferGL::resolve()
r32173r32174
38403913
38413914   void RendererContextGL::submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter)
38423915   {
3916      m_glctx.makeCurrent(NULL);
3917
38433918      const GLuint defaultVao = s_renderGL->m_vao;
38443919      if (0 != defaultVao)
38453920      {
r32173r32174
47334808         }
47344809      }
47354810
4811      m_glctx.makeCurrent(NULL);
47364812      int64_t now = bx::getHPCounter();
47374813      elapsed += now;
47384814
branches/osd/src/lib/bgfx/renderer_d3d9.cpp
r32173r32174
259259      RendererContextD3D9()
260260         : m_d3d9(NULL)
261261         , m_device(NULL)
262         , m_backBufferColor(NULL)
263         , m_backBufferDepthStencil(NULL)
264262         , m_captureTexture(NULL)
265263         , m_captureSurface(NULL)
266264         , m_captureResolve(NULL)
r32173r32174
292290         m_params.FullScreen_RefreshRateInHz = 0;
293291         m_params.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
294292         m_params.SwapEffect = D3DSWAPEFFECT_DISCARD;
295         m_params.hDeviceWindow = g_bgfxHwnd;
293         m_params.hDeviceWindow = NULL;
296294         m_params.Windowed = true;
297295
298296         RECT rect;
r32173r32174
304302         BGFX_FATAL(NULL != m_d3d9dll, Fatal::UnableToInitialize, "Failed to load d3d9.dll.");
305303
306304#if BGFX_CONFIG_DEBUG_PIX
307         m_D3DPERF_SetMarker = (D3DPERF_SetMarkerFunc)bx::dlsym(m_d3d9dll, "D3DPERF_SetMarker");
305         m_D3DPERF_SetMarker = (D3DPERF_SetMarkerFunc )bx::dlsym(m_d3d9dll, "D3DPERF_SetMarker");
308306         m_D3DPERF_BeginEvent = (D3DPERF_BeginEventFunc)bx::dlsym(m_d3d9dll, "D3DPERF_BeginEvent");
309         m_D3DPERF_EndEvent = (D3DPERF_EndEventFunc)bx::dlsym(m_d3d9dll, "D3DPERF_EndEvent");
307         m_D3DPERF_EndEvent   = (D3DPERF_EndEventFunc  )bx::dlsym(m_d3d9dll, "D3DPERF_EndEvent");
310308
311309         BX_CHECK(NULL != m_D3DPERF_SetMarker
312310              && NULL != m_D3DPERF_BeginEvent
r32173r32174
373371
374372         uint32_t behaviorFlags[] =
375373         {
376            D3DCREATE_HARDWARE_VERTEXPROCESSING|D3DCREATE_PUREDEVICE|D3DCREATE_FPU_PRESERVE,
377            D3DCREATE_MIXED_VERTEXPROCESSING|D3DCREATE_FPU_PRESERVE,
378            D3DCREATE_SOFTWARE_VERTEXPROCESSING|D3DCREATE_FPU_PRESERVE,
374            D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE | D3DCREATE_PUREDEVICE,
375            D3DCREATE_MIXED_VERTEXPROCESSING    | D3DCREATE_FPU_PRESERVE,
376            D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE,
379377         };
380378
381379         for (uint32_t ii = 0; ii < BX_COUNTOF(behaviorFlags) && NULL == m_device; ++ii)
r32173r32174
402400
403401         BGFX_FATAL(m_device, Fatal::UnableToInitialize, "Unable to create Direct3D9 device.");
404402
403         m_numWindows = 1;
404
405405#if BGFX_CONFIG_RENDERER_DIRECT3D9EX
406406         if (NULL != m_d3d9ex)
407407         {
r32173r32174
711711         m_frameBuffers[_handle.idx].create(_num, _textureHandles);
712712      }
713713
714      void createFrameBuffer(FrameBufferHandle _handle, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat) BX_OVERRIDE
715      {
716         uint16_t denseIdx = m_numWindows++;
717         m_windows[denseIdx] = _handle;
718         m_frameBuffers[_handle.idx].create(denseIdx, _nwh, _width, _height, _depthFormat);
719      }
720
714721      void destroyFrameBuffer(FrameBufferHandle _handle) BX_OVERRIDE
715722      {
716         m_frameBuffers[_handle.idx].destroy();
723         uint16_t denseIdx = m_frameBuffers[_handle.idx].destroy();
724         if (UINT16_MAX != denseIdx)
725         {
726            --m_numWindows;
727            if (m_numWindows > 1)
728            {
729               FrameBufferHandle handle = m_windows[m_numWindows];
730               m_windows[denseIdx] = handle;
731               m_frameBuffers[handle.idx].m_denseIdx = denseIdx;
732            }
733         }
717734      }
718735
719736      void createUniform(UniformHandle _handle, UniformType::Enum _type, uint16_t _num, const char* _name) BX_OVERRIDE
r32173r32174
902919
903920      void updateResolution(const Resolution& _resolution)
904921      {
905         if (m_params.BackBufferWidth != _resolution.m_width
906            ||  m_params.BackBufferHeight != _resolution.m_height
907            ||  m_flags != _resolution.m_flags)
922         if (m_params.BackBufferWidth  != _resolution.m_width
923         ||  m_params.BackBufferHeight != _resolution.m_height
924         ||  m_flags != _resolution.m_flags)
908925         {
909926            m_flags = _resolution.m_flags;
910927
r32173r32174
921938            m_params.BackBufferFormat = dm.Format;
922939#endif // BX_PLATFORM_WINDOWS
923940
924            m_params.BackBufferWidth = _resolution.m_width;
941            m_params.BackBufferWidth = _resolution.m_width;
925942            m_params.BackBufferHeight = _resolution.m_height;
926943            m_params.FullScreen_RefreshRateInHz = BGFX_RESET_FULLSCREEN == (m_flags&BGFX_RESET_FULLSCREEN_MASK) ? 60 : 0;
927944            m_params.PresentationInterval = !!(m_flags&BGFX_RESET_VSYNC) ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE;
r32173r32174
929946            updateMsaa();
930947
931948            Msaa& msaa = s_msaa[(m_flags&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT];
932            m_params.MultiSampleType = msaa.m_type;
949            m_params.MultiSampleType    = msaa.m_type;
933950            m_params.MultiSampleQuality = msaa.m_quality;
934951
935952            m_resolution = _resolution;
r32173r32174
10331050            }
10341051#endif // BGFX_CONFIG_RENDERER_DIRECT3D9EX
10351052
1036            HRESULT hr;
1037            hr = m_device->Present(NULL, NULL, NULL, NULL);
1053            for (uint32_t ii = 0, num = m_numWindows; ii < num; ++ii)
1054            {
1055               HRESULT hr;
1056               if (0 == ii)
1057               {
1058                  hr = m_swapChain->Present(NULL, NULL, g_bgfxHwnd, NULL, 0);
1059               }
1060               else
1061               {
1062                  hr = m_frameBuffers[m_windows[ii].idx].present();
1063               }
10381064
10391065#if BX_PLATFORM_WINDOWS
1040            if (isLost(hr) )
1041            {
1042               do
1066               if (isLost(hr) )
10431067               {
1044                  do
1068                  do
10451069                  {
1070                     do
1071                     {
1072                        hr = m_device->TestCooperativeLevel();
1073                     }
1074                     while (D3DERR_DEVICENOTRESET != hr);
1075
1076                     reset();
10461077                     hr = m_device->TestCooperativeLevel();
10471078                  }
1048                  while (D3DERR_DEVICENOTRESET != hr);
1079                  while (FAILED(hr) );
10491080
1050                  reset();
1051                  hr = m_device->TestCooperativeLevel();
1081                  break;
10521082               }
1053               while (FAILED(hr) );
1083               else if (FAILED(hr) )
1084               {
1085                  BX_TRACE("Present failed with err 0x%08x.", hr);
1086               }
1087#endif // BX_PLATFORM_
10541088            }
1055            else if (FAILED(hr) )
1056            {
1057               BX_TRACE("Present failed with err 0x%08x.", hr);
1058            }
1059#endif // BX_PLATFORM_
10601089         }
10611090      }
10621091
r32173r32174
10821111
10831112         DX_RELEASE(m_backBufferColor, 0);
10841113         DX_RELEASE(m_backBufferDepthStencil, 0);
1114         DX_RELEASE(m_swapChain, 0);
10851115
10861116         capturePreReset();
10871117
r32173r32174
11081138
11091139      void postReset()
11101140      {
1111         DX_CHECK(m_device->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &m_backBufferColor) );
1141         DX_CHECK(m_device->GetSwapChain(0, &m_swapChain) );
1142         DX_CHECK(m_swapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &m_backBufferColor) );
11121143         DX_CHECK(m_device->GetDepthStencilSurface(&m_backBufferDepthStencil) );
11131144
11141145         capturePostReset();
r32173r32174
11791210      {
11801211         if (m_flags&BGFX_RESET_CAPTURE)
11811212         {
1182            uint32_t width = m_params.BackBufferWidth;
1213            uint32_t width = m_params.BackBufferWidth;
11831214            uint32_t height = m_params.BackBufferHeight;
1184            D3DFORMAT fmt = m_params.BackBufferFormat;
1215            D3DFORMAT fmt   = m_params.BackBufferFormat;
11851216
11861217            DX_CHECK(m_device->CreateTexture(width
11871218               , height
r32173r32174
15671598      IDirect3DDevice9* m_device;
15681599      D3DPOOL m_pool;
15691600
1601      IDirect3DSwapChain9* m_swapChain;
1602      uint16_t m_numWindows;
1603      FrameBufferHandle m_windows[BGFX_CONFIG_MAX_FRAME_BUFFERS];
1604
15701605      IDirect3DSurface9* m_backBufferColor;
15711606      IDirect3DSurface9* m_backBufferDepthStencil;
15721607
r32173r32174
25022537      }
25032538   }
25042539
2505   void FrameBufferD3D9::destroy()
2540   void FrameBufferD3D9::create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat)
25062541   {
2507      for (uint32_t ii = 0, num = m_num; ii < num; ++ii)
2508      {
2509         m_colorHandle[ii].idx = invalidHandle;
2542      BX_UNUSED(_width, _height, _depthFormat);
25102543
2511         IDirect3DSurface9* ptr = m_color[ii];
2512         if (NULL != ptr)
2513         {
2514            ptr->Release();
2515            m_color[ii] = NULL;
2516         }
2517      }
2544      m_hwnd = (HWND)_nwh;
2545      DX_CHECK(s_renderD3D9->m_device->CreateAdditionalSwapChain(&s_renderD3D9->m_params, &m_swapChain) );
2546      DX_CHECK(m_swapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &m_color[0]) );
2547      m_colorHandle[0].idx = invalidHandle;
2548      m_depthStencil = NULL;
2549      m_denseIdx = _denseIdx;
2550      m_num = 1;
2551      m_needResolve = false;
2552   }
25182553
2519      if (NULL != m_depthStencil)
2554   uint16_t FrameBufferD3D9::destroy()
2555   {
2556      if (NULL != m_hwnd)
25202557      {
2521         if (0 == m_num)
2558         DX_RELEASE(m_color[0],  0);
2559         DX_RELEASE(m_swapChain, 0);
2560      }
2561      else
2562      {
2563         for (uint32_t ii = 0, num = m_num; ii < num; ++ii)
25222564         {
2523            IDirect3DSurface9* ptr = m_color[0];
2565            m_colorHandle[ii].idx = invalidHandle;
2566
2567            IDirect3DSurface9* ptr = m_color[ii];
25242568            if (NULL != ptr)
25252569            {
25262570               ptr->Release();
2527               m_color[0] = NULL;
2571               m_color[ii] = NULL;
25282572            }
25292573         }
25302574
2531         m_depthStencil->Release();
2532         m_depthStencil = NULL;
2575         if (NULL != m_depthStencil)
2576         {
2577            if (0 == m_num)
2578            {
2579               IDirect3DSurface9* ptr = m_color[0];
2580               if (NULL != ptr)
2581               {
2582                  ptr->Release();
2583                  m_color[0] = NULL;
2584               }
2585            }
2586
2587            m_depthStencil->Release();
2588            m_depthStencil = NULL;
2589         }
25332590      }
25342591
2592      m_hwnd = NULL;
25352593      m_num = 0;
25362594      m_depthHandle.idx = invalidHandle;
2595
2596      uint16_t denseIdx = m_denseIdx;
2597      m_denseIdx = UINT16_MAX;
2598
2599      return denseIdx;
25372600   }
25382601
2602   HRESULT FrameBufferD3D9::present()
2603   {
2604      return m_swapChain->Present(NULL, NULL, m_hwnd, NULL, 0);
2605   }
2606
25392607   void FrameBufferD3D9::resolve() const
25402608   {
25412609      if (m_needResolve)
r32173r32174
25562624
25572625   void FrameBufferD3D9::preReset()
25582626   {
2559      for (uint32_t ii = 0, num = m_num; ii < num; ++ii)
2627      if (NULL != m_hwnd)
25602628      {
2561         m_color[ii]->Release();
2562         m_color[ii] = NULL;
2629         DX_RELEASE(m_color[0],  0);
2630         DX_RELEASE(m_swapChain, 0);
25632631      }
2564
2565      if (isValid(m_depthHandle) )
2632      else
25662633      {
2567         if (0 == m_num)
2634         for (uint32_t ii = 0, num = m_num; ii < num; ++ii)
25682635         {
2569            m_color[0]->Release();
2570            m_color[0] = NULL;
2636            m_color[ii]->Release();
2637            m_color[ii] = NULL;
25712638         }
25722639
2573         m_depthStencil->Release();
2574         m_depthStencil = NULL;
2640         if (isValid(m_depthHandle) )
2641         {
2642            if (0 == m_num)
2643            {
2644               m_color[0]->Release();
2645               m_color[0] = NULL;
2646            }
2647
2648            m_depthStencil->Release();
2649            m_depthStencil = NULL;
2650         }
25752651      }
25762652   }
25772653
25782654   void FrameBufferD3D9::postReset()
25792655   {
2580      for (uint32_t ii = 0, num = m_num; ii < num; ++ii)
2656      if (NULL != m_hwnd)
25812657      {
2582         TextureD3D9& texture = s_renderD3D9->m_textures[m_colorHandle[ii].idx];
2583         if (NULL != texture.m_surface)
2584         {
2585            m_color[ii] = texture.m_surface;
2586            m_color[ii]->AddRef();
2587         }
2588         else
2589         {
2590            DX_CHECK(texture.m_texture2d->GetSurfaceLevel(0, &m_color[ii]) );
2591         }
2658         DX_CHECK(s_renderD3D9->m_device->CreateAdditionalSwapChain(&s_renderD3D9->m_params, &m_swapChain) );
2659         DX_CHECK(m_swapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &m_color[0]) );
25922660      }
2593
2594      if (isValid(m_depthHandle) )
2661      else
25952662      {
2596         TextureD3D9& texture = s_renderD3D9->m_textures[m_depthHandle.idx];
2597         if (NULL != texture.m_surface)
2663         for (uint32_t ii = 0, num = m_num; ii < num; ++ii)
25982664         {
2599            m_depthStencil = texture.m_surface;
2600            m_depthStencil->AddRef();
2665            TextureHandle th = m_colorHandle[ii];
2666
2667            if (isValid(th) )
2668            {
2669               TextureD3D9& texture = s_renderD3D9->m_textures[th.idx];
2670               if (NULL != texture.m_surface)
2671               {
2672                  m_color[ii] = texture.m_surface;
2673                  m_color[ii]->AddRef();
2674               }
2675               else
2676               {
2677                  DX_CHECK(texture.m_texture2d->GetSurfaceLevel(0, &m_color[ii]) );
2678               }
2679            }
26012680         }
2602         else
2681
2682         if (isValid(m_depthHandle) )
26032683         {
2604            DX_CHECK(texture.m_texture2d->GetSurfaceLevel(0, &m_depthStencil) );
2605         }
2684            TextureD3D9& texture = s_renderD3D9->m_textures[m_depthHandle.idx];
2685            if (NULL != texture.m_surface)
2686            {
2687               m_depthStencil = texture.m_surface;
2688               m_depthStencil->AddRef();
2689            }
2690            else
2691            {
2692               DX_CHECK(texture.m_texture2d->GetSurfaceLevel(0, &m_depthStencil) );
2693            }
26062694
2607         if (0 == m_num)
2608         {
2609            createNullColorRT();
2695            if (0 == m_num)
2696            {
2697               createNullColorRT();
2698            }
26102699         }
26112700      }
26122701   }
branches/osd/src/lib/bgfx/glcontext_egl.cpp
r32173r32174
237237      eglSwapInterval(m_display, _vsync ? 1 : 0);
238238   }
239239
240   void GlContext::swap()
240   SwapChainGL* GlContext::createSwapChain(void* /*_nwh*/)
241241   {
242      BX_CHECK(false, "Shouldn't be called!");
243      return NULL;
244   }
245
246   void GlContext::destorySwapChain(SwapChainGL*  /*_swapChain*/)
247   {
248      BX_CHECK(false, "Shouldn't be called!");
249   }
250
251   void GlContext::swap(SwapChainGL* _swapChain)
252   {
253      BX_CHECK(NULL == _swapChain, "Shouldn't be called!"); BX_UNUSED(_swapChain);
242254      eglMakeCurrent(m_display, m_surface, m_surface, m_context);
243255      eglSwapBuffers(m_display, m_surface);
244256   }
245257
258   void GlContext::makeCurrent(SwapChainGL* /*_swapChain*/)
259   {
260   }
261
246262   void GlContext::import()
247263   {
248264      BX_TRACE("Import:");
branches/osd/src/lib/bgfx/renderer_null.cpp
r32173r32174
121121      {
122122      }
123123
124      void createFrameBuffer(FrameBufferHandle /*_handle*/, void* /*_nwh*/, uint32_t /*_width*/, uint32_t /*_height*/, TextureFormat::Enum /*_depthFormat*/) BX_OVERRIDE
125      {
126      }
127
124128      void destroyFrameBuffer(FrameBufferHandle /*_handle*/) BX_OVERRIDE
125129      {
126130      }
branches/osd/src/lib/bgfx/glcontext_ppapi.cpp
r32173r32174
158158      s_ppapi.resize(_width, _height, _vsync);
159159   }
160160
161   void GlContext::swap()
161   SwapChainGL* GlContext::createSwapChain(void* /*_nwh*/)
162162   {
163      BX_CHECK(false, "Shouldn't be called!");
164      return NULL;
165   }
166
167   void GlContext::destorySwapChain(SwapChainGL*  /*_swapChain*/)
168   {
169      BX_CHECK(false, "Shouldn't be called!");
170   }
171
172   void GlContext::swap(SwapChainGL* /*_swapChain*/)
173   {
163174      s_ppapi.swap();
164175   }
165176
177   void GlContext::makeCurrent(SwapChainGL* /*_swapChain*/)
178   {
179   }
180
166181   void GlContext::import()
167182   {
168183   }
branches/osd/src/lib/bgfx/renderer_d3d11.cpp
r32173r32174
515515         };
516516
517517         memset(&m_scd, 0, sizeof(m_scd) );
518         m_scd.BufferDesc.Width = BGFX_DEFAULT_WIDTH;
518         m_scd.BufferDesc.Width = BGFX_DEFAULT_WIDTH;
519519         m_scd.BufferDesc.Height = BGFX_DEFAULT_HEIGHT;
520520         m_scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
521521         m_scd.BufferDesc.RefreshRate.Numerator = 60;
r32173r32174
573573                              );
574574         BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Failed to create swap chain.");
575575
576         m_numWindows = 1;
577
576578         if (BX_ENABLED(BGFX_CONFIG_DEBUG) )
577579         {
578580            ID3D11InfoQueue* infoQueue;
r32173r32174
792794         m_frameBuffers[_handle.idx].create(_num, _textureHandles);
793795      }
794796
797      void createFrameBuffer(FrameBufferHandle _handle, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat) BX_OVERRIDE
798      {
799         uint16_t denseIdx = m_numWindows++;
800         m_windows[denseIdx] = _handle;
801         m_frameBuffers[_handle.idx].create(denseIdx, _nwh, _width, _height, _depthFormat);
802      }
803
795804      void destroyFrameBuffer(FrameBufferHandle _handle) BX_OVERRIDE
796805      {
797         m_frameBuffers[_handle.idx].destroy();
806         uint16_t denseIdx = m_frameBuffers[_handle.idx].destroy();
807         if (UINT16_MAX != denseIdx)
808         {
809            --m_numWindows;
810            if (m_numWindows > 1)
811            {
812               FrameBufferHandle handle = m_windows[m_numWindows];
813               m_windows[denseIdx] = handle;
814               m_frameBuffers[handle.idx].m_denseIdx = denseIdx;
815            }
816         }
798817      }
799818
800819      void createUniform(UniformHandle _handle, UniformType::Enum _type, uint16_t _num, const char* _name) BX_OVERRIDE
r32173r32174
10131032         if (NULL != m_swapChain)
10141033         {
10151034            uint32_t syncInterval = !!(m_flags & BGFX_RESET_VSYNC);
1035            for (uint32_t ii = 1, num = m_numWindows; ii < num; ++ii)
1036            {
1037               DX_CHECK(m_frameBuffers[m_windows[ii].idx].m_swapChain->Present(syncInterval, 0) );
1038            }
10161039            DX_CHECK(m_swapChain->Present(syncInterval, 0) );
10171040         }
10181041      }
r32173r32174
18201843      IDXGIAdapter* m_adapter;
18211844      DXGI_ADAPTER_DESC m_adapterDesc;
18221845      IDXGIFactory* m_factory;
1846
18231847      IDXGISwapChain* m_swapChain;
1848      uint16_t m_numWindows;
1849      FrameBufferHandle m_windows[BGFX_CONFIG_MAX_FRAME_BUFFERS];
1850
18241851      ID3D11Device* m_device;
18251852      ID3D11DeviceContext* m_deviceCtx;
18261853      ID3D11RenderTargetView* m_backBufferColor;
r32173r32174
24422469      {
24432470         m_rtv[ii] = NULL;
24442471      }
2445      m_dsv = NULL;
2472      m_dsv       = NULL;
2473      m_swapChain = NULL;
24462474
24472475      m_num = 0;
24482476      for (uint32_t ii = 0; ii < _num; ++ii)
r32173r32174
24752503      }
24762504   }
24772505
2478   void FrameBufferD3D11::destroy()
2506   void FrameBufferD3D11::create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat)
24792507   {
2508      BX_UNUSED(_depthFormat);
2509
2510      DXGI_SWAP_CHAIN_DESC scd;
2511      memcpy(&scd, &s_renderD3D11->m_scd, sizeof(DXGI_SWAP_CHAIN_DESC) );
2512      scd.BufferDesc.Width  = _width;
2513      scd.BufferDesc.Height = _height;
2514      scd.OutputWindow = (HWND)_nwh;
2515
2516      HRESULT hr;
2517      hr = s_renderD3D11->m_factory->CreateSwapChain(s_renderD3D11->m_device
2518         , &scd
2519         , &m_swapChain
2520         );
2521      BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Failed to create swap chain.");
2522
2523      ID3D11Resource* ptr;
2524      DX_CHECK(m_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&ptr) );
2525      DX_CHECK(s_renderD3D11->m_device->CreateRenderTargetView(ptr, NULL, &m_rtv[0]) );
2526      DX_RELEASE(ptr, 0);
2527      m_srv[0]   = NULL;
2528      m_dsv      = NULL;
2529      m_denseIdx = _denseIdx;
2530      m_num      = 1;
2531   }
2532
2533   uint16_t FrameBufferD3D11::destroy()
2534   {
24802535      for (uint32_t ii = 0, num = m_num; ii < num; ++ii)
24812536      {
24822537         DX_RELEASE(m_srv[ii], 0);
r32173r32174
24842539      }
24852540
24862541      DX_RELEASE(m_dsv, 0);
2542      DX_RELEASE(m_swapChain, 0);
24872543
24882544      m_num = 0;
2545
2546      uint16_t denseIdx = m_denseIdx;
2547      m_denseIdx = UINT16_MAX;
2548     
2549      return denseIdx;
24892550   }
24902551
24912552   void FrameBufferD3D11::resolve()
branches/osd/src/lib/bgfx/common/imgui/makefile
r32173r32174
33# License: http://www.opensource.org/licenses/BSD-2-Clause
44#
55
6include ../../../premake/shader-embeded.mk
6include ../../../scripts/shader-embeded.mk
77
88rebuild:
99   @make -s --no-print-directory clean all
branches/osd/src/lib/bgfx/common/nanovg/makefile
r32173r32174
33# License: http://www.opensource.org/licenses/BSD-2-Clause
44#
55
6include ../../../premake/shader-embeded.mk
6include ../../../scripts/shader-embeded.mk
77
88rebuild:
99   @make -s --no-print-directory clean all
branches/osd/src/lib/bgfx/common/nanovg/nanovg_bgfx.cpp
r32173r32174
773773      return ret;
774774   }
775775
776   static int glnvg__allocVerts(struct GLNVGcontext* gl, int n)
776   static int glnvg__allocVerts(GLNVGcontext* gl, int n)
777777   {
778778      int ret = 0;
779779      if (gl->nverts+n > gl->cverts)
780780      {
781         gl->cverts = gl->cverts == 0 ? glnvg__maxi(n, 256) : gl->cverts * 2;
782         gl->verts = (struct NVGvertex*)realloc(gl->verts, sizeof(struct NVGvertex) * gl->cverts);
781         NVGvertex* verts;
782         int cverts = glnvg__maxi(gl->nverts + n, 4096) + gl->cverts/2; // 1.5x Overallocate
783         verts = (NVGvertex*)realloc(gl->verts, sizeof(NVGvertex) * cverts);
784         if (verts == NULL) return -1;
785         gl->verts = verts;
786         gl->cverts = cverts;
783787      }
784788      ret = gl->nverts;
785789      gl->nverts += n;
branches/osd/src/lib/bgfx/common/font/makefile
r32173r32174
33# License: http://www.opensource.org/licenses/BSD-2-Clause
44#
55
6include ../../../premake/shader-embeded.mk
6include ../../../scripts/shader-embeded.mk
77
88rebuild:
99   @make -s --no-print-directory clean all
branches/osd/src/lib/bgfx/bgfx_p.h
r32173r32174
640640   };
641641
642642#define SORT_KEY_RENDER_DRAW UINT64_C(0x0000000800000000)
643
644   BX_STATIC_ASSERT(BGFX_CONFIG_MAX_VIEWS   <= 32);
645   BX_STATIC_ASSERT( (BGFX_CONFIG_MAX_PROGRAMS & (BGFX_CONFIG_MAX_PROGRAMS-1) ) == 0); // must be power of 2
646
643647   struct SortKey
644648   {
645649      uint64_t encodeDraw()
r32173r32174
14221426
14231427      void resetFreeHandles()
14241428      {
1425         m_numFreeIndexBufferHandles = 0;
1426         m_numFreeVertexDeclHandles = 0;
1429         m_numFreeIndexBufferHandles  = 0;
1430         m_numFreeVertexDeclHandles   = 0;
14271431         m_numFreeVertexBufferHandles = 0;
1428         m_numFreeShaderHandles = 0;
1429         m_numFreeProgramHandles = 0;
1430         m_numFreeTextureHandles = 0;
1431         m_numFreeFrameBufferHandles = 0;
1432         m_numFreeUniformHandles = 0;
1432         m_numFreeShaderHandles       = 0;
1433         m_numFreeProgramHandles      = 0;
1434         m_numFreeTextureHandles      = 0;
1435         m_numFreeFrameBufferHandles  = 0;
1436         m_numFreeUniformHandles      = 0;
14331437      }
14341438
14351439      SortKey m_key;
r32173r32174
14791483      uint16_t m_numFreeTextureHandles;
14801484      uint16_t m_numFreeFrameBufferHandles;
14811485      uint16_t m_numFreeUniformHandles;
1486      uint16_t m_numFreeWindowHandles;
14821487
14831488      IndexBufferHandle m_freeIndexBufferHandle[BGFX_CONFIG_MAX_INDEX_BUFFERS];
14841489      VertexDeclHandle m_freeVertexDeclHandle[BGFX_CONFIG_MAX_VERTEX_DECLS];
r32173r32174
16961701      virtual void updateTextureEnd() = 0;
16971702      virtual void destroyTexture(TextureHandle _handle) = 0;
16981703      virtual void createFrameBuffer(FrameBufferHandle _handle, uint8_t _num, const TextureHandle* _textureHandles) = 0;
1704      virtual void createFrameBuffer(FrameBufferHandle _handle, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat) = 0;
16991705      virtual void destroyFrameBuffer(FrameBufferHandle _handle) = 0;
17001706      virtual void createUniform(UniformHandle _handle, UniformType::Enum _type, uint16_t _num, const char* _name) = 0;
17011707      virtual void destroyUniform(UniformHandle _handle) = 0;
r32173r32174
24642470      BGFX_API_FUNC(FrameBufferHandle createFrameBuffer(uint8_t _num, TextureHandle* _handles) )
24652471      {
24662472         FrameBufferHandle handle = { m_frameBufferHandle.alloc() };
2467         BX_WARN(isValid(handle), "Failed to allocate render target handle.");
2473         BX_WARN(isValid(handle), "Failed to allocate frame buffer handle.");
24682474
24692475         if (isValid(handle) )
24702476         {
24712477            CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateFrameBuffer);
24722478            cmdbuf.write(handle);
2479            cmdbuf.write(false);
24732480            cmdbuf.write(_num);
24742481
24752482            FrameBufferRef& ref = m_frameBufferRef[handle.idx];
2476            memset(ref.m_th, 0xff, sizeof(ref.m_th) );
2483            ref.m_window = false;
2484            memset(ref.un.m_th, 0xff, sizeof(ref.un.m_th) );
24772485            for (uint32_t ii = 0; ii < _num; ++ii)
24782486            {
24792487               TextureHandle handle = _handles[ii];
24802488
24812489               cmdbuf.write(handle);
24822490
2483               ref.m_th[ii] = handle;
2491               ref.un.m_th[ii] = handle;
24842492               textureIncRef(handle);
24852493            }
24862494         }
r32173r32174
24882496         return handle;
24892497      }
24902498
2499      BGFX_API_FUNC(FrameBufferHandle createFrameBuffer(void* _nwh, uint16_t _width, uint16_t _height, TextureFormat::Enum _depthFormat) )
2500      {
2501         FrameBufferHandle handle = { m_frameBufferHandle.alloc() };
2502         BX_WARN(isValid(handle), "Failed to allocate frame buffer handle.");
2503
2504         if (isValid(handle) )
2505         {
2506            CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateFrameBuffer);
2507            cmdbuf.write(handle);
2508            cmdbuf.write(true);
2509            cmdbuf.write(_nwh);
2510            cmdbuf.write(_width);
2511            cmdbuf.write(_height);
2512            cmdbuf.write(_depthFormat);
2513
2514            FrameBufferRef& ref = m_frameBufferRef[handle.idx];
2515            ref.m_window = true;
2516            ref.un.m_nwh = _nwh;
2517         }
2518
2519         return handle;
2520      }
2521
24912522      BGFX_API_FUNC(void destroyFrameBuffer(FrameBufferHandle _handle) )
24922523      {
24932524         CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::DestroyFrameBuffer);
r32173r32174
24952526         m_submit->free(_handle);
24962527
24972528         FrameBufferRef& ref = m_frameBufferRef[_handle.idx];
2498         for (uint32_t ii = 0; ii < BX_COUNTOF(ref.m_th); ++ii)
2529         if (!ref.m_window)
24992530         {
2500            TextureHandle th = ref.m_th[ii];
2501            if (isValid(th) )
2531            for (uint32_t ii = 0; ii < BX_COUNTOF(ref.un.m_th); ++ii)
25022532            {
2503               textureDecRef(th);
2533               TextureHandle th = ref.un.m_th[ii];
2534               if (isValid(th) )
2535               {
2536                  textureDecRef(th);
2537               }
25042538            }
25052539         }
25062540      }
r32173r32174
26142648         Rect& rect = m_rect[_id];
26152649         rect.m_x = _x;
26162650         rect.m_y = _y;
2617         rect.m_width = bx::uint16_max(_width, 1);
2651         rect.m_width = bx::uint16_max(_width, 1);
26182652         rect.m_height = bx::uint16_max(_height, 1);
26192653      }
26202654
r32173r32174
26342668         Rect& scissor = m_scissor[_id];
26352669         scissor.m_x = _x;
26362670         scissor.m_y = _y;
2637         scissor.m_width = _width;
2671         scissor.m_width = _width;
26382672         scissor.m_height = _height;
26392673      }
26402674
r32173r32174
28502884         TextureHandle textureHandle = BGFX_INVALID_HANDLE;
28512885         if (isValid(_handle) )
28522886         {
2853            textureHandle = m_frameBufferRef[_handle.idx].m_th[_attachment];
2887            const FrameBufferRef& ref = m_frameBufferRef[_handle.idx];
2888            BX_CHECK(!ref.m_window, "Can't sample window frame buffer.");
2889            textureHandle = ref.un.m_th[_attachment];
28542890            BX_CHECK(isValid(textureHandle), "Frame buffer texture %d is invalid.", _attachment);
28552891         }
28562892
r32173r32174
28782914         TextureHandle textureHandle = BGFX_INVALID_HANDLE;
28792915         if (isValid(_handle) )
28802916         {
2881            textureHandle = m_frameBufferRef[_handle.idx].m_th[_attachment];
2917            const FrameBufferRef& ref = m_frameBufferRef[_handle.idx];
2918            BX_CHECK(!ref.m_window, "Can't sample window frame buffer.");
2919            textureHandle = ref.un.m_th[_attachment];
28822920            BX_CHECK(isValid(textureHandle), "Frame buffer texture %d is invalid.", _attachment);
28832921         }
28842922
r32173r32174
30143052
30153053      struct FrameBufferRef
30163054      {
3017         TextureHandle m_th[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS];
3055         union un
3056         {
3057            TextureHandle m_th[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS];
3058            void* m_nwh;
3059         } un;
3060         bool m_window;
30183061      };
30193062
30203063      typedef stl::unordered_map<stl::string, UniformHandle> UniformHashMap;
branches/osd/src/lib/bgfx/glcontext_wgl.cpp
r32173r32174
2424#   define GL_IMPORT(_optional, _proto, _func, _import) _proto _func
2525#   include "glimports.h"
2626
27   struct SwapChainGL
28   {
29      SwapChainGL(void* _nwh)
30         : m_hwnd( (HWND)_nwh)
31      {
32         m_hdc = GetDC(m_hwnd);
33      }
34
35      ~SwapChainGL()
36      {
37         wglMakeCurrent(NULL, NULL);
38         wglDeleteContext(m_context);
39         ReleaseDC(m_hwnd, m_hdc);
40      }
41
42      void makeCurrent()
43      {
44         wglMakeCurrent(m_hdc, m_context);
45      }
46
47      void swapBuffers()
48      {
49         SwapBuffers(m_hdc);
50      }
51
52      HWND  m_hwnd;
53      HDC   m_hdc;
54      HGLRC m_context;
55   };
56
2757   static HGLRC createContext(HDC _hdc)
2858   {
2959      PIXELFORMATDESCRIPTOR pfd;
r32173r32174
121151
122152         HGLRC context = createContext(hdc);
123153
124         wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
125         wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
154         wglGetExtensionsStringARB  = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
155         wglChoosePixelFormatARB    = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
126156         wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB");
127         wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
157         wglSwapIntervalEXT         = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
128158
129159         if (NULL != wglGetExtensionsStringARB)
130160         {
r32173r32174
151181            };
152182
153183            int result;
154            int pixelFormat;
155184            uint32_t numFormats = 0;
156185            do
157186            {
158               result = wglChoosePixelFormatARB(m_hdc, attrs, NULL, 1, &pixelFormat, &numFormats);
187               result = wglChoosePixelFormatARB(m_hdc, attrs, NULL, 1, &m_pixelFormat, &numFormats);
159188               if (0 == result
160189                  ||  0 == numFormats)
161190               {
r32173r32174
165194
166195            } while (0 == numFormats);
167196
168            PIXELFORMATDESCRIPTOR pfd;
169            DescribePixelFormat(m_hdc, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
197            DescribePixelFormat(m_hdc, m_pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &m_pfd);
170198
171199            BX_TRACE("Pixel format:\n"
172200               "\tiPixelType %d\n"
r32173r32174
174202               "\tcAlphaBits %d\n"
175203               "\tcDepthBits %d\n"
176204               "\tcStencilBits %d\n"
177               , pfd.iPixelType
178               , pfd.cColorBits
179               , pfd.cAlphaBits
180               , pfd.cDepthBits
181               , pfd.cStencilBits
205               , m_pfd.iPixelType
206               , m_pfd.cColorBits
207               , m_pfd.cAlphaBits
208               , m_pfd.cDepthBits
209               , m_pfd.cStencilBits
182210               );
183211
184            result = SetPixelFormat(m_hdc, pixelFormat, &pfd);
212            result = SetPixelFormat(m_hdc, m_pixelFormat, &m_pfd);
185213            // When window is created by SDL and SDL_WINDOW_OPENGL is set SetPixelFormat
186214            // will fail. Just warn and continue. In case it failed for some other reason
187215            // create context will fail and it will error out there.
r32173r32174
213241               m_context = wglCreateContextAttribsARB(m_hdc, 0, contextAttrs);
214242            }
215243            BGFX_FATAL(NULL != m_context, Fatal::UnableToInitialize, "Failed to create context 0x%08x.", GetLastError() );
244
245            BX_STATIC_ASSERT(sizeof(contextAttrs) == sizeof(m_contextAttrs) );
246            memcpy(m_contextAttrs, contextAttrs, sizeof(contextAttrs) );
216247         }
217248
218249         wglMakeCurrent(NULL, NULL);
r32173r32174
261292      }
262293   }
263294
264   void GlContext::swap()
295   SwapChainGL* GlContext::createSwapChain(void* _nwh)
265296   {
266      if (NULL != g_bgfxHwnd)
297      SwapChainGL* swapChain = BX_NEW(g_allocator, SwapChainGL)(_nwh);
298
299      int result = SetPixelFormat(swapChain->m_hdc, m_pixelFormat, &m_pfd);
300      BX_WARN(result, "SetPixelFormat failed (last err: 0x%08x)!", GetLastError() ); BX_UNUSED(result);
301
302      swapChain->m_context = wglCreateContextAttribsARB(swapChain->m_hdc, m_context, m_contextAttrs);
303      BX_CHECK(NULL != swapChain->m_context, "Create swap chain failed: %x", glGetError() );
304      return swapChain;
305   }
306
307   void GlContext::destorySwapChain(SwapChainGL*  _swapChain)
308   {
309      BX_DELETE(g_allocator, _swapChain);
310   }
311
312   void GlContext::makeCurrent(SwapChainGL* _swapChain)
313   {
314      if (NULL == _swapChain)
267315      {
268316         wglMakeCurrent(m_hdc, m_context);
269         SwapBuffers(m_hdc);
270317      }
318      else
319      {
320         _swapChain->makeCurrent();
321      }
271322   }
272323
324   void GlContext::swap(SwapChainGL* _swapChain)
325   {
326      if (NULL == _swapChain)
327      {
328         if (NULL != g_bgfxHwnd)
329         {
330            wglMakeCurrent(m_hdc, m_context);
331            SwapBuffers(m_hdc);
332         }
333      }
334      else
335      {
336         _swapChain->makeCurrent();
337         _swapChain->swapBuffers();
338      }
339   }
340
273341   void GlContext::import()
274342   {
275343      BX_TRACE("Import:");
branches/osd/src/lib/bgfx/glcontext_glx.h
r32173r32174
1313
1414namespace bgfx
1515{
16   struct SwapChainGL;
17
1618   struct GlContext
1719   {
1820      GlContext()
r32173r32174
2325      void create(uint32_t _width, uint32_t _height);
2426      void destroy();
2527      void resize(uint32_t _width, uint32_t _height, bool _vsync);
26      void swap();
28
29      SwapChainGL* createSwapChain(void* _nwh);
30      void destorySwapChain(SwapChainGL*  _swapChain);
31      void swap(SwapChainGL* _swapChain = NULL);
32      void makeCurrent(SwapChainGL* _swapChain = NULL);
33
2734      void import();
2835
2936      bool isValid() const
branches/osd/src/lib/bgfx/glcontext_eagl.mm
r32173r32174
9191      BX_TRACE("resize context");
9292   }
9393
94   void GlContext::swap()
94   SwapChainGL* GlContext::createSwapChain(void* /*_nwh*/)
9595   {
96      BX_CHECK(false, "Shouldn't be called!");
97      return NULL;
98   }
99
100   void GlContext::destorySwapChain(SwapChainGL*  /*_swapChain*/)
101   {
102      BX_CHECK(false, "Shouldn't be called!");
103   }
104
105   void GlContext::swap(SwapChainGL* _swapChain)
106   {
107      BX_CHECK(NULL == _swapChain, "Shouldn't be called!"); BX_UNUSED(_swapChain);
96108      GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, m_colorRbo) );
97109      EAGLContext* context = (EAGLContext*)m_context;
98110      [context presentRenderbuffer:GL_RENDERBUFFER];
99111   }
100112
113   void GlContext::makeCurrent(SwapChainGL* /*_swapChain*/)
114   {
115   }
116
101117   void GlContext::import()
102118   {
103119   }
branches/osd/src/lib/bgfx/makefile
r32173r32174
33# License: http://www.opensource.org/licenses/BSD-2-Clause
44#
55
6include ../premake/shader-embeded.mk
6include ../scripts/shader-embeded.mk
77
88rebuild:
99   @make -s --no-print-directory clean all

Previous 199869 Revisions Next


© 1997-2024 The MAME Team