ソースを参照

Refactored graphics flags.

Enable GRAPHICS_SWAPINTERVAL1 option for sdlrendermax2d .
Brucey 3 年 前
コミット
5589dc065c

+ 0 - 25
sdlgraphics.mod/common.bmx

@@ -62,30 +62,5 @@ Import "glue.c"
 Extern
 	Function bbSDLGraphicsGraphicsModes:Int( display:Int, buf:Byte Ptr,size:Int )
 End Extern
-Rem
-Const SDL_WINDOW_FULLSCREEN:Int = $00000001         ' fullscreen window
-Const SDL_WINDOW_OPENGL:Int = $00000002             ' window usable with OpenGL context
-Const SDL_WINDOW_SHOWN:Int = $00000004              ' window is visible
-Const SDL_WINDOW_HIDDEN:Int = $00000008             ' window is Not visible
-Const SDL_WINDOW_BORDERLESS:Int = $00000010         ' no window decoration
-Const SDL_WINDOW_RESIZABLE:Int = $00000020          ' window can be resized
-Const SDL_WINDOW_MINIMIZED:Int = $00000040          ' window is minimized
-Const SDL_WINDOW_MAXIMIZED:Int = $00000080          ' window is maximized
-Const SDL_WINDOW_INPUT_GRABBED:Int = $00000100      ' window has grabbed Input focus
-Const SDL_WINDOW_INPUT_FOCUS:Int = $00000200        ' window has Input focus
-Const SDL_WINDOW_MOUSE_FOCUS:Int = $00000400        ' window has mouse focus
-Const SDL_WINDOW_FULLSCREEN_DESKTOP:Int = SDL_WINDOW_FULLSCREEN | $00001000
-Const SDL_WINDOW_FOREIGN:Int = $00000800            ' window Not created by SDL
-Const SDL_WINDOW_ALLOW_HIGHDPI:Int = $00002000       ' window should be created in high-DPI Mode If supported
-End Rem
-Const GRAPHICS_RPI_TV_FULLSCREEN:Int = $1000
-Const GRAPHICS_WIN32_DX:Int = $1000000
-
-Const SDL_GRAPHICS_BACKBUFFER:Int    = $00800000
-Const SDL_GRAPHICS_ALPHABUFFER:Int   = $01000000
-Const SDL_GRAPHICS_DEPTHBUFFER:Int   = $02000000
-Const SDL_GRAPHICS_STENCILBUFFER:Int = $04000000
-Const SDL_GRAPHICS_ACCUMBUFFER:Int   = $08000000
 
 Const SDL_GRAPHICS_GL:Int            = $20000000
-Const SDL_GRAPHICS_NATIVE:Int        = $40000000

+ 16 - 42
sdlgraphics.mod/sdlgraphics.bmx

@@ -142,53 +142,27 @@ Type TSDLGraphicsDriver Extends TGraphicsDriver
 	Method SDLGraphicsCreateGraphics:TGraphicsContext(width:Int,height:Int,depth:Int,hertz:Int,flags:Long,x:Int,y:Int)
 		Local context:TGraphicsContext = New TGraphicsContext
 
-		Local windowFlags:UInt = SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_OPENGL
-		Local gFlags:UInt
-		Local glFlags:UInt = flags & SDL_GRAPHICS_GL
+		If depth > 0 Then
+			flags :| SDL_WINDOW_FULLSCREEN
 
-		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)
+			If flags & GRAPHICS_FULLSCREEN_DESKTOP Then
+				flags :| SDL_WINDOW_FULLSCREEN_DESKTOP
 			End If
+		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
+		If depth = 0 And flags & GRAPHICS_BORDERLESS Then
+			flags :| SDL_WINDOW_BORDERLESS
+		End If
 
-			gFlags = flags & (GRAPHICS_BACKBUFFER | GRAPHICS_ALPHABUFFER | GRAPHICS_DEPTHBUFFER | GRAPHICS_STENCILBUFFER | GRAPHICS_ACCUMBUFFER)
+		If flags & SDL_GRAPHICS_GL Then
+			flags :| SDL_WINDOW_OPENGL
 
-			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
+			If flags & GRAPHICS_BACKBUFFER Then SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1)
+			If flags & GRAPHICS_ALPHABUFFER Then SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 1)
+			If flags & GRAPHICS_DEPTHBUFFER Then SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24)
+			If flags & GRAPHICS_STENCILBUFFER Then SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1)
 		End If
 
-
-		'End If
 		If x < 0 Then
 			x = SDL_WINDOWPOS_CENTERED
 		End If
@@ -196,8 +170,8 @@ Type TSDLGraphicsDriver Extends TGraphicsDriver
 			y = SDL_WINDOWPOS_CENTERED
 		End If
 
-		context.window = TSDLWindow.Create(AppTitle, x, y, width, height, windowFlags)
-		If glFlags Then
+		context.window = TSDLWindow.Create(AppTitle, x, y, width, height, ULong(flags))
+		If flags & SDL_GRAPHICS_GL Then
 			context.context = context.window.GLCreateContext()
 			SDL_GL_SetSwapInterval(-1)
 			context.sync = -1

+ 23 - 0
sdlrender.mod/common.bmx

@@ -92,6 +92,7 @@ Extern
 	Function SDL_GetRenderer:Byte Ptr(window:Byte Ptr)
 	Function SDL_RenderGeometry:Int(handle:Byte Ptr, texture:Byte Ptr, vertices:SDLVertex Ptr, numVertices:Int, indices:Int Ptr, numIndices:Int)
 	Function SDL_GetRendererInfo(handle:Byte Ptr, info:SDLRendererInfo Var)
+	Function SDL_GetRenderDriverInfo:Int(index:Int, info:SDLRendererInfo Var)
 
 	Function SDL_GetTextureAlphaMod:Int(handle:Byte Ptr, alpha:Byte Ptr)
 	Function SDL_GetTextureBlendMode:Int(handle:Byte Ptr, blendMode:Int Ptr)
@@ -168,6 +169,7 @@ bbdoc: the renderer supports rendering to texture
 End Rem
 Const SDL_RENDERER_TARGETTEXTURE:Int = $08
 
+
 Struct SDLFPoint
 	Field x:Float
 	Field y:Float
@@ -193,14 +195,35 @@ Struct SDLVertex
     Field texCoord:SDLFPoint
 End Struct
 
+Rem
+bbdoc: A structure that contains information on the capabilities of a render driver or the current render context.
+End Rem
 Struct SDLRendererInfo
 	Field name:Byte Ptr
+	Rem
+	bbdoc: A mask of supported renderer flags
+	End Rem
 	Field flags:UInt
+	Rem
+	bbdoc: The number of available texture formats
+	End Rem
 	Field numTextureFormats:UInt
+	Rem
+	bbdoc: The available texture formats
+	End Rem
 	Field StaticArray textureFormats:UInt[16]
+	Rem
+	bbdoc: The maximum texture width
+	End Rem
 	Field maxTextureWidth:Int
+	Rem
+	bbdoc: The maximum texture height
+	End Rem
 	Field maxTextureHeight:Int
 
+	Rem
+	bbdoc: Returns the name of the renderer
+	End Rem
 	Method GetName:String()
 		Return String.FromUTF8String(name)
 	End Method

+ 14 - 2
sdlrender.mod/sdlrender.bmx

@@ -48,6 +48,13 @@ Type TSDLRenderer
 	Rem
 	bbdoc: Creates a 2D rendering context for a window.
 	about: Note that providing no flags gives priority to available #SDL_RENDERER_ACCELERATED renderers
+	@flags can be one or more of the following values -
+	|----------------------------|------------------------------------------------|
+	| SDL_RENDERER_SOFTWARE      | the renderer is a software fallback            |
+    | SDL_RENDERER_ACCELERATED   | the renderer uses hardware acceleration        |
+    | SDL_RENDERER_PRESENTVSYNC  | present is synchronized with the refresh rate  |
+    | SDL_RENDERER_TARGETTEXTURE | the renderer supports rendering to texture     |
+	|----------------------------|------------------------------------------------|
 	End Rem
 	Function Create:TSDLRenderer(window:TSDLWindow, index:Int = -1, flags:UInt = 0)
 		Return _create(SDL_CreateRenderer(window.windowPtr, index, flags))
@@ -467,5 +474,10 @@ Function SDLGetNumRenderDrivers:Int()
 	Return SDL_GetNumRenderDrivers()
 End Function
 
-
-
+Rem
+bbdoc: Gets info about a specific 2D rendering driver for the current display.
+returns: 0 on success or a negative error code on failure; call #SDLGetError for more information.
+End Rem
+Function SDLGetRenderDriverInfo:Int(index:Int, info:SDLRendererInfo Var)
+	Return SDL_GetRenderDriverInfo(index, info)
+End Function

+ 8 - 4
sdlrendermax2d.mod/sdlrendermax2d.bmx

@@ -164,8 +164,12 @@ Type TSDLRenderMax2DDriver Extends TMax2DDriver
 
 		SDLGraphicsDriver().SetGraphics gfx
 
-		renderer = TSDLRenderer.Create(gfx._context.window)
-		'ResetGLContext t
+		Local flags:UInt
+		If gfx._context.flags & GRAPHICS_SWAPINTERVAL1 Then
+			flags :| SDL_RENDERER_PRESENTVSYNC
+		End If
+
+		renderer = TSDLRenderer.Create(gfx._context.window, -1, flags)
 		
 		t.MakeCurrent
 	End Method
@@ -243,9 +247,9 @@ Type TSDLRenderMax2DDriver Extends TMax2DDriver
 	
 	Method SetViewport( x:Int,y:Int,w:Int,h:Int ) Override
 		If x=0 And y=0 And w=GraphicsWidth() And h=GraphicsHeight()
-			renderer.SetViewport()
+			renderer.SetClipRect()
 		Else
-			renderer.SetViewport(x, y, w, h)
+			renderer.SetClipRect(x, y, w, h)
 		EndIf
 	End Method
 

+ 30 - 21
sdlvideo.mod/common.bmx

@@ -164,87 +164,96 @@ Const SDL_WINDOWPOS_CENTERED:Int = $2FFF0000
 Rem
 bbdoc: fullscreen window
 End Rem
-Const SDL_WINDOW_FULLSCREEN:UInt = $00000001
+Const SDL_WINDOW_FULLSCREEN:ULong = $00000001:ULong Shl 32
 Rem
 bbdoc: window usable with OpenGL context
 End Rem
-Const SDL_WINDOW_OPENGL:UInt = $00000002
+Const SDL_WINDOW_OPENGL:ULong = $00000002:ULong Shl 32
 Rem
 bbdoc: window is visible
 End Rem
-Const SDL_WINDOW_SHOWN:UInt = $00000004
+Const SDL_WINDOW_SHOWN:ULong = $00000004:ULong Shl 32
 Rem
 bbdoc: window is not visible
 End Rem
-Const SDL_WINDOW_HIDDEN:UInt = $00000008
+Const SDL_WINDOW_HIDDEN:ULong = $00000008:ULong Shl 32
 Rem
 bbdoc: no window decoration
 End Rem
-Const SDL_WINDOW_BORDERLESS:UInt = $00000010
+Const SDL_WINDOW_BORDERLESS:ULong = $00000010:ULong Shl 32
 Rem
 bbdoc: window can be resized
 End Rem
-Const SDL_WINDOW_RESIZABLE:UInt = $00000020
+Const SDL_WINDOW_RESIZABLE:ULong = $00000020:ULong Shl 32
 Rem
 bbdoc: window is minimized
 End Rem
-Const SDL_WINDOW_MINIMIZED:UInt = $00000040
+Const SDL_WINDOW_MINIMIZED:ULong = $00000040:ULong Shl 32
 Rem
 bbdoc: window is maximized
 End Rem
-Const SDL_WINDOW_MAXIMIZED:UInt = $00000080
+Const SDL_WINDOW_MAXIMIZED:ULong = $00000080:ULong Shl 32
 Rem
 bbdoc: window has grabbed input focus
 End Rem
-Const SDL_WINDOW_INPUT_GRABBED:UInt = $00000100
+Const SDL_WINDOW_INPUT_GRABBED:ULong = $00000100:ULong Shl 32
 Rem
 bbdoc: window has input focus
 End Rem
-Const SDL_WINDOW_INPUT_FOCUS:UInt = $00000200
+Const SDL_WINDOW_INPUT_FOCUS:ULong = $00000200:ULong Shl 32
 Rem
 bbdoc: window has mouse focus
 End Rem
-Const SDL_WINDOW_MOUSE_FOCUS:UInt = $00000400
+Const SDL_WINDOW_MOUSE_FOCUS:ULong = $00000400:ULong Shl 32
 Rem
 bbdoc: full screen desktop
 End Rem
-Const SDL_WINDOW_FULLSCREEN_DESKTOP:UInt = SDL_WINDOW_FULLSCREEN | $00001000
+Const SDL_WINDOW_FULLSCREEN_DESKTOP:ULong = SDL_WINDOW_FULLSCREEN | ($00001000:ULong Shl 32)
 Rem
 bbdoc: window not created by SDL
 End Rem
-Const SDL_WINDOW_FOREIGN:UInt = $00000800
+Const SDL_WINDOW_FOREIGN:ULong = $00000800:ULong Shl 32
 Rem
 bbdoc: window should be created in high-DPI mode if supported
 End Rem
-Const SDL_WINDOW_ALLOW_HIGHDPI:UInt = $00002000
+Const SDL_WINDOW_ALLOW_HIGHDPI:ULong = $00002000:ULong Shl 32
 Rem
 bbdoc: window has mouse captured (unrelated to INPUT_GRABBED)
 End Rem
-Const SDL_WINDOW_MOUSE_CAPTURE:UInt = $00004000
+Const SDL_WINDOW_MOUSE_CAPTURE:ULong = $00004000:ULong Shl 32
 Rem
 bbdoc: window should always be above others
 End Rem
-Const SDL_WINDOW_ALWAYS_ON_TOP:UInt = $00008000
+Const SDL_WINDOW_ALWAYS_ON_TOP:ULong = $00008000:ULong Shl 32
 Rem
 bbdoc: window should not be added to the taskbar
 End Rem
-Const SDL_WINDOW_SKIP_TASKBAR:UInt = $00010000
+Const SDL_WINDOW_SKIP_TASKBAR:ULong = $00010000:ULong Shl 32
 Rem
 bbdoc: window should be treated as a utility window
 End Rem
-Const SDL_WINDOW_UTILITY:UInt = $00020000
+Const SDL_WINDOW_UTILITY:ULong = $00020000:ULong Shl 32
 Rem
 bbdoc: window should be treated as a tooltip
 End Rem
-Const SDL_WINDOW_TOOLTIP:UInt = $00040000
+Const SDL_WINDOW_TOOLTIP:ULong = $00040000:ULong Shl 32
 Rem
 bbdoc: window should be treated as a popup menu
 End Rem
-Const SDL_WINDOW_POPUP_MENU:UInt = $00080000
+Const SDL_WINDOW_POPUP_MENU:ULong = $00080000:ULong Shl 32
+Rem
+bbdoc: window has grabbed keyboard input
+End Rem
+Const SDL_WINDOW_KEYBOARD_GRABBED:ULong = $00100000:ULong Shl 32
 Rem
 bbdoc: window usable for Vulkan surface
 End Rem
-Const SDL_WINDOW_VULKAN:UInt = $10000000
+Const SDL_WINDOW_VULKAN:ULong = $10000000:ULong Shl 32
+Rem
+bbdoc: window usable for Metal view
+End Rem
+Const SDL_WINDOW_METAL:ULong = $20000000:ULong Shl 32
+
 
 Rem
 bbdoc: the minimum number of bits for the red channel of the color buffer; defaults to 3

+ 5 - 5
sdlvideo.mod/sdlvideo.bmx

@@ -49,8 +49,8 @@ Type TSDLWindow
 	bbdoc: Creates a window with the specified position, dimensions, and flags.
 	returns: The window that was created or Null on failure.
 	End Rem
-	Function Create:TSDLWindow(title:String, x:Int, y:Int, w:Int, h:Int, flags:UInt)
-		Return _create(bmx_sdl_video_CreateWindow(title, x, y, w, h, flags))
+	Function Create:TSDLWindow(title:String, x:Int, y:Int, w:Int, h:Int, flags:ULong)
+		Return _create(bmx_sdl_video_CreateWindow(title, x, y, w, h, UInt(flags Shr 32)))
 	End Function
 	
 	Rem
@@ -255,11 +255,11 @@ Type TSDLWindow
 	Rem
 	bbdoc: Sets the window's fullscreen state.
 	returns: 0 on success or a negative error code on failure.
-	about: @flags may be SDL_WINDOW_FULLSCREEN, for "real" fullscreen with a videomode change; SDL_WINDOW_FULLSCREEN_DESKTOP
+	about: @flags may be #SDL_WINDOW_FULLSCREEN, for "real" fullscreen with a videomode change; #SDL_WINDOW_FULLSCREEN_DESKTOP
 	for "fake" fullscreen that takes the size of the desktop; and 0 for windowed mode.
 	End Rem
-	Method SetFullScreen:Int(flags:UInt)
-		Return SDL_SetWindowFullscreen(windowPtr, flags)
+	Method SetFullScreen:Int(flags:ULong)
+		Return SDL_SetWindowFullscreen(windowPtr, UInt(flags Shr 32))
 	End Method
 	
 	Rem