woollybah 6 лет назад
Родитель
Сommit
c17e005033

+ 1 - 1
bgfxgraphics.mod/bgfxgraphics.bmx

@@ -123,7 +123,7 @@ Type TGfxGraphicsDriver Extends TGraphicsDriver
 	Rem
 	Rem
 	bbdoc: 
 	bbdoc: 
 	End Rem
 	End Rem
-	Method InitGraphics(width:Int, height:Int, rendererType:Int = BGFX_RENDERER_TYPE_COUNT)
+	Method InitGraphics(width:Int, height:Int, rendererType:EBGFXRenderType = EBGFXRenderType.COUNT)
 		If Not TBGFX.Init(width, height, rendererType) Then
 		If Not TBGFX.Init(width, height, rendererType) Then
 			Throw "Failed to initialise graphics"
 			Throw "Failed to initialise graphics"
 		End If
 		End If

+ 29 - 4
bgfxmax2d.mod/bgfxmax2d.bmx

@@ -1,4 +1,4 @@
-' Copyright (c) 2015-2018 Bruce A Henderson
+' Copyright (c) 2015-2019 Bruce A Henderson
 ' All rights reserved.
 ' All rights reserved.
 ' 
 ' 
 ' Redistribution and use in source and binary forms, with or without
 ' Redistribution and use in source and binary forms, with or without
@@ -27,7 +27,8 @@ Strict
 Module gfx.bgfxmax2d
 Module gfx.bgfxmax2d
 
 
 Import brl.max2d
 Import brl.max2d
-Import gfx.bgfxgraphics
+Import gfx.bgfxsdlgraphics
+'Import gfx.bgfxgraphics
 
 
 Private
 Private
 
 
@@ -41,6 +42,7 @@ Type TBGFXMax2DDriver Extends TMax2DDriver
 	
 	
 	Method New()
 	Method New()
 		bgfx = New TBGFXRender
 		bgfx = New TBGFXRender
+'		AddHook EmitEventHook,EventHook,Null,0
 	End Method
 	End Method
 
 
 	Method Create:TBGFXMax2DDriver()
 	Method Create:TBGFXMax2DDriver()
@@ -106,11 +108,15 @@ Type TBGFXMax2DDriver Extends TMax2DDriver
 	End Method
 	End Method
 
 
 	Method SetClsColor( red:Int,green:Int,blue:Int )
 	Method SetClsColor( red:Int,green:Int,blue:Int )
-		' TODO
+		TBGFX.SetViewClear(0, BGFX_CLEAR_COLOR|BGFX_CLEAR_DEPTH, red Shl 24 | green Shl 16 | blue Shl 8 | $ff, 1, 0)
 	End Method
 	End Method
 
 
 	Method SetViewport( x:Int,y:Int,width:Int,height:Int )
 	Method SetViewport( x:Int,y:Int,width:Int,height:Int )
-		' TODO
+		If x = 0 And y = 0 And width = GraphicsWidth() And height = GraphicsHeight() Then
+			TBGFX.SetViewScissor(0, 0, 0, 0, 0)
+		Else
+			TBGFX.SetViewScissor(0, Short(x), Short(y), Short(width), Short(height))
+		End If
 	End Method
 	End Method
 
 
 	Method SetTransform( xx#,xy#,yx#,yy# )
 	Method SetTransform( xx#,xy#,yx#,yy# )
@@ -122,6 +128,7 @@ Type TBGFXMax2DDriver Extends TMax2DDriver
 	End Method
 	End Method
 	
 	
 	Method Cls()
 	Method Cls()
+		GfxGraphicsDriver().SetViewRect()
 		bgfx.Touch(0)
 		bgfx.Touch(0)
 	End Method
 	End Method
 
 
@@ -158,6 +165,24 @@ Type TBGFXMax2DDriver Extends TMax2DDriver
 	Method SetResolution( width#,height# )
 	Method SetResolution( width#,height# )
 		' TODO
 		' TODO
 	End Method
 	End Method
+Rem
+	Function EventHook:Object( id:Int, data:Object, context:Object )
+		Local ev:TEvent=TEvent(data)
+		If Not ev Return data
+
+		Select ev.id
+			Case EVENT_WINDOWSIZE
+				Print "window size"
+				TBGFX.Reset(ev.x, ev.y, BGFX_RESET_VSYNC | BGFX_RESET_HIDPI)
+		End Select
+		
+		Return data
+	End Function
+End Rem	
+
+	Method CanResize:Int()
+		Return True
+	End Method
 
 
 End Type
 End Type
 
 

+ 22 - 1
bgfxmax2d.mod/examples/basic.bmx

@@ -2,13 +2,34 @@ SuperStrict
 
 
 Framework gfx.bgfxmax2d
 Framework gfx.bgfxmax2d
 
 
-
 Graphics 800, 600, 0
 Graphics 800, 600, 0
 
 
+
+SetClsColor 0, 0, 0
+
+Local stats:Int = BGFX_DEBUG_TEXT
+
+Local ESC:String = Chr(27)
+
 While Not KeyDown(KEY_ESCAPE)
 While Not KeyDown(KEY_ESCAPE)
 
 
 	Cls
 	Cls
 	
 	
+	If KeyHit(key_f1) Then
+		If stats = BGFX_DEBUG_TEXT Then
+			stats = BGFX_DEBUG_STATS
+		Else
+			stats = BGFX_DEBUG_TEXT
+		End If
+	End If
+	
+	TBGFX.DebugTextClear()
+	TBGFX.DebugTextPrint(0, 0, $0f, "Press F1 to toggle stats.")
+	TBGFX.DebugTextPrint(0, 1, $0f, "Color can be changed with ANSI " + ESC + "[9;me" + ESC + "[10;ms" + ESC + "[11;mc" + ESC + "[12;ma" + ESC + "[13;mp" + ESC + "[14;me" + ESC + "[0m code too.")
+	TBGFX.DebugTextPrint(65, 1, $0f, ESC + "[;0m    " + ESC + "[;1m    " + ESC + "[; 2m    " + ESC + "[; 3m    " + ESC + "[; 4m    " + ESC + "[; 5m    " + ESC + "[; 6m    " + ESC + "[; 7m    " + ESC + "[0m")
+	TBGFX.DebugTextPrint(65, 2, $0f, ESC + "[;8m    " + ESC + "[;9m    " + ESC + "[;10m    " + ESC + "[;11m    " + ESC + "[;12m    " + ESC + "[;13m    " + ESC + "[;14m    " + ESC + "[;15m    " + ESC + "[0m")
+		
+	TBGFX.SetDebug(stats)
 	
 	
 	Flip
 	Flip
 
 

+ 295 - 0
bgfxsdlgraphics.mod/bgfxsdlgraphics.bmx

@@ -0,0 +1,295 @@
+' Copyright (c) 2015-2019 Bruce A Henderson
+' All rights reserved.
+' 
+' Redistribution and use in source and binary forms, with or without
+' modification, are permitted provided that the following conditions are met:
+' 
+' * Redistributions of source code must retain the above copyright notice, this
+'   list of conditions and the following disclaimer.
+' 
+' * Redistributions in binary form must reproduce the above copyright notice,
+'   this list of conditions and the following disclaimer in the documentation
+'   and/or other materials provided with the distribution.
+' 
+' THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+' IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+' DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+' FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+' DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+' SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+' CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+' OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+' OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+'
+SuperStrict
+
+Module gfx.bgfxsdlgraphics
+
+
+Import "common.bmx"
+
+Private
+Global _currentContext:TGraphicsContext
+Public
+
+Type TGraphicsContext
+	Field Mode:Int
+	Field width:Int
+	Field height:Int
+	Field depth:Int
+	Field hertz:Int
+	Field flags:Int
+	Field sync:Int
+
+	Field window:TSDLWindow
+'	Field context:TSDLGLContext
+	Field info:Byte Ptr
+	Field data:Object
+End Type
+
+Private
+
+Extern
+	Function bbGfxGraphicsShareContexts()
+	Function bbGfxGraphicsGraphicsModes:Int( display:Int, buf:Byte Ptr, size:Int )
+	Function bbGfxGraphicsAttachGraphics:Byte Ptr( widget:Byte Ptr,flags:Int )
+	Function bbGfxGraphicsCreateGraphics:Byte Ptr( width:Int, height:Int, depth:Int, hertz:Int, flags:Int )
+	Function bbGfxGraphicsGetSettings( context:Byte Ptr, width:Int Var, height:Int Var, depth:Int Var, hertz:Int Var, flags:Int Var )
+	Function bbGfxGraphicsClose( context:Byte Ptr )	
+	Function bbGfxGraphicsSetGraphics( context:Byte Ptr )
+	Function bbGfxGraphicsFlip( sync:Int )
+	Function bbGfxGraphicsCls()
+	Function bbGfxSetPlatformData(handle:Byte Ptr)
+End Extern
+
+Public
+
+Type TGfxGraphics Extends TGraphics
+
+	Method Driver:TGfxGraphicsDriver()
+		Assert _context
+		Return GfxGraphicsDriver()
+	End Method
+	
+	Method GetSettings:Int( width:Int Var,height:Int Var,depth:Int Var,hertz:Int Var,flags:Int Var )
+		Assert _context
+		width=_context.width
+		height=_context.height
+		depth=_context.depth
+		hertz=_context.hertz
+		flags=_context.flags
+	End Method
+	
+	Method Close:Int()
+		If Not _context Return 0
+
+		If _currentContext = _context Then
+			_currentContext = Null
+		End If
+
+		If _context.window Then
+			_context.window.Destroy()
+		End If
+		_context=Null
+	End Method
+
+	Method GetHandle:Byte Ptr()
+		If _context Then
+			Return _context.window.GetWindowHandle()
+		End If
+	End Method
+
+	Method Resize:Int(width:Int, height:Int)
+		TBGFX.Reset(width, height, BGFX_RESET_VSYNC | BGFX_RESET_HIDPI)
+	End Method
+
+	Field _context:TGraphicsContext
+	
+End Type
+
+Type TGfxGraphicsDriver Extends TGraphicsDriver
+
+	Global _inited:Int
+
+	Method GraphicsModes:TGraphicsMode[]()
+		Local buf:Int[1024*4]
+		Local count:Int=bbGfxGraphicsGraphicsModes( 0,buf,1024 )
+		Local modes:TGraphicsMode[count],p:Int Ptr=buf
+		For Local i:Int=0 Until count
+			Local t:TGraphicsMode=New TGraphicsMode
+			t.width=p[0]
+			t.height=p[1]
+			t.depth=p[2]
+			t.hertz=p[3]
+			modes[i]=t
+			p:+4
+		Next
+		Return modes
+	End Method
+	
+	Method AttachGraphics:TGfxGraphics( widget:Byte Ptr,flags:Int )
+		'Local t:TGfxGraphics=New TGfxGraphics
+		't._context=bbGLGraphicsAttachGraphics( widget,flags )
+		'Return t
+	End Method
+	
+	Method CreateGraphics:TGfxGraphics( width:Int, height:Int, depth:Int, hertz:Int, flags:Int )
+		Local t:TGfxGraphics=New TGfxGraphics
+		t._context=GfxGraphicsCreateGraphics( width,height,depth,hertz,flags )
+
+		If Not _inited Then
+			Local rtype:EBGFXRenderType
+?win32
+			' hard coded for now until I can work out how to get the others to render correctly...
+			rtype = EBGFXRenderType.DIRECT3D9
+?Not win32
+			rtype = EBGFXRenderType.OPENGL
+?		
+			InitGraphics(width, height, rtype)
+		End If
+
+		Return t
+	End Method
+
+	Method GfxGraphicsCreateGraphics:TGraphicsContext(width:Int,height:Int,depth:Int,hertz:Int,flags:Int)
+		Local context:TGraphicsContext = New TGraphicsContext
+
+		Local windowFlags:UInt '= SDL_WINDOW_ALLOW_HIGHDPI
+		Local gFlags:UInt
+		Local glFlags:UInt = flags
+Rem
+		If flags & SDL_GRAPHICS_NATIVE Then
+
+			flags :~ SDL_GRAPHICS_NATIVE
+
+			gFlags = flags & (SDL_GRAPHICS_BACKBUFFER | SDL_GRAPHICS_ALPHABUFFER | SDL_GRAPHICS_DEPTHBUFFER | SDL_GRAPHICS_STENCILBUFFER | SDL_GRAPHICS_ACCUMBUFFER)
+
+			flags :~ SDL_GRAPHICS_GL
+
+			flags :~ (SDL_GRAPHICS_BACKBUFFER | SDL_GRAPHICS_ALPHABUFFER | SDL_GRAPHICS_DEPTHBUFFER | SDL_GRAPHICS_STENCILBUFFER | SDL_GRAPHICS_ACCUMBUFFER)
+
+			windowFlags :| flags
+
+			If glFlags Then
+				If gFlags & SDL_GRAPHICS_BACKBUFFER Then SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1)
+				If gFlags & SDL_GRAPHICS_ALPHABUFFER Then SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 1)
+				If gFlags & SDL_GRAPHICS_DEPTHBUFFER Then SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24)
+				If gFlags & SDL_GRAPHICS_STENCILBUFFER Then SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1)
+			End If
+
+		Else
+
+			If depth Then
+				windowFlags :| SDL_WINDOW_FULLSCREEN
+				' mode = MODE_DISPLAY
+			Else
+				If flags & $80000000 Then
+					windowFlags :| SDL_WINDOW_FULLSCREEN_DESKTOP
+				End If
+				' mode = MODE_WINDOW
+			End If
+
+			gFlags = flags & (GRAPHICS_BACKBUFFER | GRAPHICS_ALPHABUFFER | GRAPHICS_DEPTHBUFFER | GRAPHICS_STENCILBUFFER | GRAPHICS_ACCUMBUFFER)
+
+			If glFlags Then
+				If gFlags & GRAPHICS_BACKBUFFER Then SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1)
+				If gFlags & GRAPHICS_ALPHABUFFER Then SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 1)
+				If gFlags & GRAPHICS_DEPTHBUFFER Then SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24)
+				If gFlags & GRAPHICS_STENCILBUFFER Then SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1)
+			End If
+		End If
+
+End Rem
+		'End If
+
+		context.window = TSDLWindow.Create(AppTitle, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, windowFlags)
+		'If glFlags Then
+		'	context.context = context.window.GLCreateContext()
+		'	SDL_GL_SetSwapInterval(-1)
+		'	context.sync = -1
+		'End If
+
+		context.width = width
+		context.height = height
+		context.depth = depth
+		context.hertz = hertz
+		context.flags = flags
+		
+		bbGfxSetPlatformData(context.window.WindowPtr)
+		
+		TBGFX.RenderFrame()
+
+		AddHook EmitEventHook,GraphicsHook,context,0
+
+		Return context
+	End Method
+
+	Method SetGraphics:Int( g:TGraphics )
+		Local context:Byte Ptr
+		Local t:TGfxGraphics=TGfxGraphics( g )
+		If t context=t._context
+		bbGfxGraphicsSetGraphics context
+	End Method
+	
+	Method Flip:Int( sync:Int )
+		bbGfxGraphicsFlip sync
+	End Method
+	
+	Method SetViewRect()
+		TBGFX.SetViewRectRatio(0, 0, 0, 0)
+	End Method
+	
+	Rem
+	bbdoc: 
+	End Rem
+	Method InitGraphics(width:Int, height:Int, rendererType:EBGFXRenderType = EBGFXRenderType.COUNT)
+		If Not TBGFX.Init(width, height, rendererType) Then
+			Throw "Failed to initialise graphics"
+		End If
+		_inited = True
+	End Method
+
+	Function GraphicsHook:Object( id:Int,data:Object,context:Object )
+		Local ev:TEvent=TEvent(data)
+		If Not ev Return data
+
+		Select ev.id
+			Case EVENT_WINDOWSIZE
+				Local ctxt:TGraphicsContext = TGraphicsContext(context)
+				If ctxt Then
+					If ctxt.window.GetID() = ev.data Then
+						ctxt.width = ev.x
+						ctxt.height = ev.y
+						GraphicsResize(ev.x, ev.y)
+					End If
+				End If
+		End Select
+
+		Return data
+	End Function
+
+	Method CanResize:Int()
+		Return True
+	End Method
+
+End Type
+
+
+Function GfxGraphicsDriver:TGfxGraphicsDriver()
+	Global _driver:TGfxGraphicsDriver=New TGfxGraphicsDriver
+	Return _driver
+End Function
+
+Rem
+bbdoc: Create graphics
+returns: A graphics object
+about:
+This is a convenience function that allows you to easily create a graphics context.
+End Rem
+Function GfxGraphics:TGraphics( width:Int, height:Int, depth:Int = 0, hertz:Int = 60, flags:Int = 0 )
+	SetGraphicsDriver GfxGraphicsDriver()
+	Return Graphics( width,height,depth,hertz,flags )
+End Function
+	
+SetGraphicsDriver GfxGraphicsDriver()

+ 37 - 0
bgfxsdlgraphics.mod/common.bmx

@@ -0,0 +1,37 @@
+' Copyright (c) 2015-2019 Bruce A Henderson
+' All rights reserved.
+' 
+' Redistribution and use in source and binary forms, with or without
+' modification, are permitted provided that the following conditions are met:
+' 
+' * Redistributions of source code must retain the above copyright notice, this
+'   list of conditions and the following disclaimer.
+' 
+' * Redistributions in binary form must reproduce the above copyright notice,
+'   this list of conditions and the following disclaimer in the documentation
+'   and/or other materials provided with the distribution.
+' 
+' THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+' IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+' DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+' FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+' DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+' SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+' CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+' OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+' OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+'
+SuperStrict
+
+Import BRL.Graphics
+Import gfx.bgfx
+Import SDL.SDLSystem
+Import SDL.SDLVideo
+'?Not bmxng
+'Import BRL.System
+'?bmxng
+'Import BRL.SystemDefault
+'?
+
+Import "source.bmx"

+ 304 - 0
bgfxsdlgraphics.mod/glue.c

@@ -0,0 +1,304 @@
+/*
+ Copyright (c) 2014-2019 Bruce A Henderson
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+    1. The origin of this software must not be misrepresented; you must not
+    claim that you wrote the original software. If you use this software
+    in a product, an acknowledgment in the product documentation would be
+    appreciated but is not required.
+
+    2. Altered source versions must be plainly marked as such, and must not be
+    misrepresented as being the original software.
+
+    3. This notice may not be removed or altered from any source
+    distribution.
+*/
+
+#include "SDL_video.h"
+#include "SDL_mouse.h"
+#include "SDL_syswm.h"
+
+#include "bgfx/c99/bgfx.h"
+#include <brl.mod/blitz.mod/blitz.h>
+
+enum{
+	MODE_SHARED=0,
+	MODE_WIDGET=1,
+	MODE_WINDOW=2,
+	MODE_DISPLAY=3
+};
+
+enum{
+	FLAGS_BACKBUFFER    = 0x02,
+	FLAGS_ALPHABUFFER   = 0x04,
+	FLAGS_DEPTHBUFFER   = 0x08,
+	FLAGS_STENCILBUFFER = 0x10,
+	FLAGS_ACCUMBUFFER   = 0x20,
+	FLAGS_BORDERLESS    = 0x40,
+	FLAGS_RPI_TV_FULLSCREEN = 0x1000,
+	FLAGS_DX            = 0x1000000,
+	FLAGS_FULLSCREEN    = 0x80000000
+};
+
+typedef struct BBGfxContext BBGfxContext;
+
+struct BBGfxContext{
+	BBGfxContext *succ;
+	int mode,width,height,depth,hertz,flags,sync;
+	SDL_Window * window;
+	//SDL_GLContext context;
+	SDL_SysWMinfo info;
+};
+
+
+int bbGfxGraphicsGraphicsModes( int display, int *imodes,int maxcount );
+void bbGfxGraphicsFlip( int sync );
+void bbGfxGraphicsSetGraphics( BBGfxContext *context );
+void bbGfxGraphicsGetSettings( BBGfxContext *context, int * width,int * height,int * depth,int * hertz,int * flags);
+void bbGfxGraphicsClose( BBGfxContext *context );
+void bmx_SDL_Poll();
+void bmx_SDL_WaitEvent();
+void * bbSDLGraphicsGetHandle(BBGfxContext *context);
+BBGfxContext *bbGfxGraphicsCreateGraphics( int width,int height,int depth,int hz,int flags );
+void bbGfxGraphicsCls();
+void bbGfxSetPlatformData(SDL_Window * window);
+
+static BBGfxContext *_contexts;
+static BBGfxContext *_currentContext;
+
+int bbGfxGraphicsGraphicsModes( int display, int *imodes,int maxcount ) {
+	SDL_DisplayMode mode;
+	int count,i;
+
+	count = SDL_GetNumDisplayModes(display);
+	if (count>maxcount) count=maxcount;
+	for (i=0;i<count;i++) {
+		SDL_GetDisplayMode(display, i, &mode);
+
+		*imodes++=mode.w;
+		*imodes++=mode.h;
+		*imodes++=SDL_BITSPERPIXEL(mode.format);
+		*imodes++=mode.refresh_rate;
+	}
+	return count;
+}
+
+static void * bbGfxGetWindowHandle(SDL_Window * window) {
+	SDL_SysWMinfo wmi;
+	SDL_VERSION(&wmi.version);
+	if (!SDL_GetWindowWMInfo(window, &wmi) ) {
+		return NULL;
+	}
+
+#if BX_PLATFORM_LINUX || BX_PLATFORM_BSD
+#if ENTRY_CONFIG_USE_WAYLAND
+	wl_egl_window *win_impl = (wl_egl_window*)SDL_GetWindowData(window, "wl_egl_window");
+	if (!win_impl) {
+		int width, height;
+		SDL_GetWindowSize(window, &width, &height);
+		struct wl_surface* surface = wmi.info.wl.surface;
+		if (!surface) {
+			return NULL;
+		}
+		win_impl = wl_egl_window_create(surface, width, height);
+		SDL_SetWindowData(window, "wl_egl_window", win_impl);
+	}
+	return (void*)(uintptr_t)win_impl;
+#else
+	return (void*)wmi.info.x11.window;
+#endif
+#elif BX_PLATFORM_OSX
+	return wmi.info.cocoa.window;
+#elif BX_PLATFORM_WINDOWS
+	return wmi.info.win.window;
+#elif BX_PLATFORM_STEAMLINK
+	return wmi.info.vivante.window;
+#endif // BX_PLATFORM_
+}
+
+BBGfxContext *bbGfxGraphicsCreateGraphics( int width,int height,int depth,int hz,int flags ) {
+
+	int mode;
+	char * appTitle = bbStringToUTF8String( bbAppTitle );
+	
+	int windowFlags = 0;
+
+//	if ((flags & FLAGS_DX) == 0) {
+//		windowFlags = SDL_WINDOW_OPENGL;
+//	}
+	
+	if (flags & FLAGS_BORDERLESS) windowFlags |= SDL_WINDOW_BORDERLESS;
+	
+	if( depth ){
+		windowFlags |= SDL_WINDOW_FULLSCREEN;
+		mode=MODE_DISPLAY;
+	} else {
+		if (flags & FLAGS_FULLSCREEN) {
+			windowFlags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
+		}
+		mode=MODE_WINDOW;
+	}
+/*
+	if ((flags & FLAGS_DX) == 0) {
+		if (flags & FLAGS_BACKBUFFER) SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+		if (flags & FLAGS_ALPHABUFFER) SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 1);
+		if (flags & FLAGS_DEPTHBUFFER) SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
+		if (flags & FLAGS_STENCILBUFFER) SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1);
+	}
+*/
+	SDL_Window *window = SDL_CreateWindow(appTitle, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
+		width, height, windowFlags | SDL_WINDOW_ALLOW_HIGHDPI);
+		
+	if (window == NULL) {
+printf("error... %s\n", SDL_GetError());fflush(stdout);
+		return NULL;
+	}
+
+	//SDL_GLContext context = 0;
+	
+//	if ((flags & FLAGS_DX) == 0) {
+	//	SDL_GL_SetSwapInterval(-1);
+	//
+		//context = SDL_GL_CreateContext(window);
+	//}
+
+	BBGfxContext *bbcontext=(BBGfxContext*)malloc( sizeof(BBGfxContext) );
+	memset( bbcontext,0,sizeof(BBGfxContext) );
+	bbcontext->mode=mode;	
+	bbcontext->width=width;	
+	bbcontext->height=height;
+#ifdef __RASPBERRYPI__
+	bbcontext->depth=16;
+#else
+	bbcontext->depth=24;	
+#endif
+	bbcontext->hertz=hz;
+	bbcontext->flags=flags;
+	bbcontext->sync=-1;	
+	bbcontext->window=window;
+	//bbcontext->context=context;
+	SDL_GetWindowWMInfo(window, &bbcontext->info);
+
+printf("HAH\n");fflush(stdout);
+	bgfx_platform_data_t pd;
+#if BX_PLATFORM_LINUX || BX_PLATFORM_BSD
+#if ENTRY_CONFIG_USE_WAYLAND
+	pd.ndt          = wmi.info.wl.display;
+#else
+	pd.ndt          = wmi.info.x11.display;
+#endif
+#elif BX_PLATFORM_OSX
+	pd.ndt          = NULL;
+#elif BX_PLATFORM_WINDOWS
+	pd.ndt          = NULL;
+#elif BX_PLATFORM_STEAMLINK
+	pd.ndt          = wmi.info.vivante.display;
+#endif // BX_PLATFORM_
+	pd.nwh          = bbGfxGetWindowHandle(window);
+	pd.context      = NULL;
+	pd.backBuffer   = NULL;
+	pd.backBufferDS = NULL;
+	bgfx_set_platform_data(&pd);
+
+	return bbcontext;
+}
+
+void bbGfxSetPlatformData(SDL_Window * window) {
+	SDL_SysWMinfo info;
+	SDL_GetWindowWMInfo(window, &info);
+
+	bgfx_platform_data_t pd;
+#if BX_PLATFORM_LINUX || BX_PLATFORM_BSD
+#if ENTRY_CONFIG_USE_WAYLAND
+	pd.ndt          = wmi.info.wl.display;
+#else
+	pd.ndt          = wmi.info.x11.display;
+#endif
+#elif BX_PLATFORM_OSX
+	pd.ndt          = NULL;
+#elif BX_PLATFORM_WINDOWS
+	pd.ndt          = NULL;
+#elif BX_PLATFORM_STEAMLINK
+	pd.ndt          = wmi.info.vivante.display;
+#endif // BX_PLATFORM_
+	pd.nwh          = bbGfxGetWindowHandle(window);
+	pd.context      = NULL;
+	pd.backBuffer   = NULL;
+	pd.backBufferDS = NULL;
+	bgfx_set_platform_data(&pd);	
+}
+
+void bbGfxGraphicsFlip( int sync ) {
+	//if( !_currentContext ) return;
+//printf("flip\n");fflush(stdout);
+//bgfx_set_view_rect_ratio(0, 0, 0, BGFX_BACKBUFFER_RATIO_EQUAL);
+
+	bmx_bgfx_frame(0);
+
+	bmx_SDL_Poll();
+}
+
+void bbGfxGraphicsClose( BBGfxContext *context ){
+	BBGfxContext **p,*t;
+	
+	for( p=&_contexts;(t=*p) && (t!=context);p=&t->succ ){}
+	if( !t ) return;
+	
+	if( t==_currentContext ){
+		bbGfxGraphicsSetGraphics( 0 );
+	}
+	
+	if( t->mode==MODE_DISPLAY || t->mode==MODE_WINDOW ){
+		SDL_DestroyWindow(context->window);
+	}
+}
+
+void bbGfxGraphicsSetGraphics( BBGfxContext *context ) {
+	//if( context ){
+	//	SDL_GL_MakeCurrent(context->window, context->context);
+	//}
+	_currentContext=context;
+}
+
+void bmx_SDL_WarpMouseInWindow(int x, int y) {
+	if( _currentContext ){
+		SDL_WarpMouseInWindow(_currentContext->window, x, y);
+	} else {
+		SDL_WarpMouseInWindow(SDL_GL_GetCurrentWindow(), x, y);
+	}
+}
+
+void bbGfxGraphicsGetSettings( BBGfxContext *context, int * width,int * height,int * depth,int * hertz,int * flags) {
+	if( context ){
+		SDL_GetWindowSize(context->window, &context->width, &context->height);
+		*width=context->width;
+		*height=context->height;
+		*depth=context->depth;
+		*hertz=context->hertz;
+		*flags=context->flags;
+	}
+}
+
+void bbGfxGraphicsCls() {
+printf("bbGfxGraphicsCls\n");fflush(stdout);
+	bgfx_encoder_t* encoder = bgfx_encoder_begin(true);
+	bgfx_encoder_touch(encoder, 0);
+	bgfx_encoder_end(encoder);
+}
+
+/*
+void bbSDLExit(){
+	bbGfxGraphicsClose( _currentContext );
+	_currentContext=0;
+#ifdef __RASPBERRYPI__
+	SDL_VideoQuit();
+#endif
+}
+*/

+ 68 - 0
bgfxsdlgraphics.mod/source.bmx

@@ -0,0 +1,68 @@
+' Copyright (c) 2015-2019 Bruce A Henderson
+' All rights reserved.
+' 
+' Redistribution and use in source and binary forms, with or without
+' modification, are permitted provided that the following conditions are met:
+' 
+' * Redistributions of source code must retain the above copyright notice, this
+'   list of conditions and the following disclaimer.
+' 
+' * Redistributions in binary form must reproduce the above copyright notice,
+'   this list of conditions and the following disclaimer in the documentation
+'   and/or other materials provided with the distribution.
+' 
+' THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+' IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+' DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+' FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+' DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+' SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+' CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+' OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+' OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+'
+SuperStrict
+
+Import "../bx.mod/bx/include/*.h"
+Import "../bgfx.mod/bgfx/include/*.h"
+
+?win32x86
+Import "../../sdl.mod/sdl.mod/include/win32x86/*.h"
+
+?win32x64
+Import "../../sdl.mod/sdl.mod/include/win32x64/*.h"
+
+?osx
+Import "../../sdl.mod/sdl.mod/include/macos/*.h"
+
+?linuxx86
+Import "../../sdl.mod/sdl.mod/include/linuxx86/*.h"
+
+?linuxx64
+Import "../../sdl.mod/sdl.mod/include/linuxx64/*.h"
+
+?raspberrypi
+Import "../../sdl.mod/sdl.mod/include/raspberrypi/*.h"
+
+?android
+Import "../../sdl.mod/sdl.mod/include/android/*.h"
+
+?emscripten
+Import "../../sdl.mod/sdl.mod/include/emscripten/*.h"
+
+?ios
+Import "../../sdl.mod/sdl.mod/include/ios/*.h"
+
+?
+
+Import "../../sdl.mod/sdl.mod/SDL/include/*.h"
+
+
+'?win32
+Import "glue.c"
+'?linux
+' TODO
+'?macos
+' TODO
+'?

+ 1 - 1
texturec.mod/common.bmx

@@ -1,4 +1,4 @@
-' Copyright (c) 2015-2018 Bruce A Henderson
+' Copyright (c) 2015-2019 Bruce A Henderson
 ' All rights reserved.
 ' All rights reserved.
 ' 
 ' 
 ' Redistribution and use in source and binary forms, with or without
 ' Redistribution and use in source and binary forms, with or without