Pārlūkot izejas kodu

Added render state support.

woollybah 10 gadi atpakaļ
vecāks
revīzija
c7d88f6424

+ 7 - 21
b3dglgraphics.mod/b3dglgraphics.bmx

@@ -33,6 +33,7 @@ ModuleInfo "Copyright: 2014 Mark Mcvittie, Bruce A Henderson"
 ModuleInfo "History: 1.00 Initial Release"
 
 
+Import brl.systemdefault
 Import b3d.Openb3d
 Import BRL.GLMax2d
 
@@ -62,27 +63,10 @@ Function Graphics3D( width%, height%, depth%=0, Mode%=0, rate%=60, flags%=-1, us
 		Graphics( width,height,depth,rate,flags )		
 	EndIf
 	
-	glewInit() ' required for ARB funcs
-	
-	' save the Max2D settings for later - by Oddball
-	glPushAttrib(GL_ALL_ATTRIB_BITS)
-	glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS)
-	glMatrixMode(GL_MODELVIEW)
-	glPushMatrix()
-	glMatrixMode(GL_PROJECTION)
-	glPushMatrix()
-	glMatrixMode(GL_TEXTURE)
-	glPushMatrix()
-	glMatrixMode(GL_COLOR)
-	glPushMatrix()
+	TGlobal.GraphicsInit()
 	
 	Graphics3D_( width,height,depth,Mode,rate )
 	
-	glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,GL_SEPARATE_SPECULAR_COLOR)
-	glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,GL_TRUE)
-	
-	glClearDepth(1.0)
-	
 End Function
 
 Rem
@@ -91,15 +75,17 @@ End Rem
 Function Text( x%, y%, str$ )
 
 	' set active texture to texture 0 so gldrawtext will work correctly
-	glActiveTextureARB(GL_TEXTURE0)
-	glClientActiveTextureARB(GL_TEXTURE0)
+	If THardwareInfo.VBOSupport 'SMALLFIXES hack to keep non vbo GFX from crashing
+		glActiveTextureARB(GL_TEXTURE0)
+		glClientActiveTextureARB(GL_TEXTURE0)
+	EndIf
 		
 	glDisable(GL_LIGHTING)
 	glColor3f(1.0,1.0,1.0)
 	
 	' enable blend to hide text background
 	glEnable(GL_BLEND)
-	GLDrawText( str,x,y )
+	GLDrawText str,x,y
 	
 	glDisable(GL_BLEND)
 	glEnable(GL_LIGHTING)

+ 7 - 22
b3dglsdlgraphics.mod/b3dglsdlgraphics.bmx

@@ -62,27 +62,10 @@ Function Graphics3D( width%, height%, depth%=0, Mode%=0, rate%=60, flags%=-1, us
 		Graphics( width,height,depth,rate,flags )		
 	EndIf
 	
-	glewInit() ' required for ARB funcs
-
-	' save the Max2D settings for later - by Oddball
-	glPushAttrib(GL_ALL_ATTRIB_BITS)
-	glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS)
-	glMatrixMode(GL_MODELVIEW)
-	glPushMatrix()
-	glMatrixMode(GL_PROJECTION)
-	glPushMatrix()
-	glMatrixMode(GL_TEXTURE)
-	glPushMatrix()
-	glMatrixMode(GL_COLOR)
-	glPushMatrix()
+	TGlobal.GraphicsInit()
 	
 	Graphics3D_( width,height,depth,Mode,rate )
 	
-	glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,GL_SEPARATE_SPECULAR_COLOR)
-	glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,GL_TRUE)
-	
-	glClearDepth(1.0)
-	
 End Function
 
 
@@ -92,15 +75,17 @@ End Rem
 Function Text( x%, y%, str$ )
 
 	' set active texture to texture 0 so gldrawtext will work correctly
-	glActiveTextureARB(GL_TEXTURE0)
-	glClientActiveTextureARB(GL_TEXTURE0)
-
+	If THardwareInfo.VBOSupport 'SMALLFIXES hack to keep non vbo GFX from crashing
+		glActiveTextureARB(GL_TEXTURE0)
+		glClientActiveTextureARB(GL_TEXTURE0)
+	EndIf
+		
 	glDisable(GL_LIGHTING)
 	glColor3f(1.0,1.0,1.0)
 	
 	' enable blend to hide text background
 	glEnable(GL_BLEND)
-	GLDrawText( str,x,y )
+	GLDrawText str,x,y
 	
 	glDisable(GL_BLEND)
 	glEnable(GL_LIGHTING)

+ 7 - 0
openb3d.mod/functions.bmx

@@ -1941,6 +1941,13 @@ Function RenderWorld()
 	RenderWorld_()
 End Function
 
+Rem
+bbdoc: Set render (client or server-side) state capability flags
+End Rem
+Function SetRenderState( capability:Int, flag:Int )
+	SetRenderState_( capability, flag )
+End Function
+
 Rem
 bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=TFormedX">Online doc</a>
 End Rem

+ 230 - 15
openb3d.mod/openb3dlib.bmx

@@ -27,6 +27,7 @@ Strict
 Import brl.map
 Import brl.Graphics
 Import b3d.OpenB3dLib
+Import brl.standardio
 
 'Import "source.bmx"
 
@@ -160,6 +161,7 @@ Extern
 	Function GetSurfaceBrush_:Byte Ptr( surf:Byte Ptr )	="GetSurfaceBrush"
 	Function Graphics3D_( width:Int, height:Int, depth:Int, Mode:Int, rate:Int )="Graphics3D"
 	Function GraphicsResize_( width:Int, height:Int )="GraphicsResize"
+	Function SetRenderState_( capability:Int, flag:Int ) = "SetRenderState"
 	Function HandleSprite_( sprite:Byte Ptr, h_x:Float, h_y:Float )="HandleSprite"
 	Function HideEntity_( ent:Byte Ptr )="HideEntity"
 	Function LightColor_( light:Byte Ptr, red:Float, green:Float, blue:Float )="LightColor"
@@ -312,6 +314,11 @@ Global globals:TGlobal=New TGlobal
 Public
 
 
+' Constants
+' ---------
+
+Const USE_MAX2D:Int=True ' true to enable max2d/minib3d integration
+
 
 ' Blitz2D functions
 ' -----------------
@@ -353,28 +360,16 @@ Function EndMax2D()
 	glMatrixMode(GL_COLOR)
 	glPushMatrix()
 	
-	' Enable States
-	glEnable(GL_LIGHTING)
-	glEnable(GL_DEPTH_TEST)
-	glEnable(GL_FOG)
-	glEnable(GL_CULL_FACE)
-	glEnable(GL_SCISSOR_TEST)
-	
-	glEnable(GL_NORMALIZE)
-	
-	glEnableClientState(GL_VERTEX_ARRAY)
-	glEnableClientState(GL_COLOR_ARRAY)
-	glEnableClientState(GL_NORMAL_ARRAY)
-	
+	TGlobal.EnableStates()
 	glDisable(GL_TEXTURE_2D)
 	
 	glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,GL_SEPARATE_SPECULAR_COLOR)
 	glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,GL_TRUE)
 	
-	glClearDepth(1.0)
+	glClearDepth(1.0)						
 	glDepthFunc(GL_LEQUAL)
 	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
-	
+
 	glAlphaFunc(GL_GEQUAL,0.5)
 	
 End Function
@@ -405,6 +400,63 @@ Type TGlobal
 	Global tex:TTexture=New TTexture
 	Global voxelspr:TVoxelSprite=New TVoxelSprite
 
+	Function GraphicsInit()
+	
+		TextureFilter("",9)
+?Not linuxarm
+		glewInit() ' required for ARB funcs
+?
+		' get hardware info and set vbo_enabled accordingly (use THardwareInfo.VBOSupport)
+		THardwareInfo.GetInfo()
+		
+		If USE_MAX2D=True
+		
+			' save the Max2D settings for later - by Oddball
+			glPushAttrib(GL_ALL_ATTRIB_BITS)
+			glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS)
+			glMatrixMode(GL_MODELVIEW)
+			glPushMatrix()
+			glMatrixMode(GL_PROJECTION)
+			glPushMatrix()
+			glMatrixMode(GL_TEXTURE)
+			glPushMatrix()
+			glMatrixMode(GL_COLOR)
+			glPushMatrix()
+		
+		EndIf
+		
+		EnableStates()
+		
+		glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,GL_SEPARATE_SPECULAR_COLOR)
+		glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,GL_TRUE)
+		
+		glClearDepth(1.0)						
+		glDepthFunc(GL_LEQUAL)
+		glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
+		
+		glAlphaFunc(GL_GEQUAL,0.5)
+		
+	End Function
+	
+	Function EnableStates()
+	
+		glEnable(GL_LIGHTING)
+   		glEnable(GL_DEPTH_TEST)
+		glEnable(GL_FOG)
+		glEnable(GL_CULL_FACE)
+		glEnable(GL_SCISSOR_TEST)
+		
+		glEnable(GL_NORMALIZE)
+		
+		glEnableClientState(GL_VERTEX_ARRAY)
+		'glEnableClientState(GL_COLOR_ARRAY)
+		'glEnableClientState(GL_NORMAL_ARRAY)
+		
+		SetRenderState(GL_COLOR_ARRAY,1) ' when drawing with Max2d
+		SetRenderState(GL_NORMAL_ARRAY,1) ' when using flat shading
+		
+	End Function
+
 End Type
 
 Rem
@@ -578,6 +630,169 @@ Type TGeosphere Extends TTerrain
 	
 End Type
 
+Rem
+bbdoc: Hardware-info
+about: Contains @{Function GetInfo()} and @{DisplayInfo(LogFile:Int=False)}.
+End Rem
+Type THardwareInfo
+
+	' by klepto2
+	Global ScreenWidth:Int = DesktopWidth() ' added
+	Global ScreenHeight:Int = DesktopHeight()
+	Global ScreenDepth:Int = DesktopDepth()
+	Global ScreenHertz:Int = DesktopHertz()
+
+	Global Vendor:String
+	Global Renderer:String
+	Global OGLVersion:String
+
+	Global Extensions:String
+	Global VBOSupport:Int		' Vertex Buffer Object
+	Global GLTCSupport:Int		' OpenGL's TextureCompression
+	Global S3TCSupport:Int		' S3's TextureCompression
+	Global AnIsoSupport:Int		' An-Istropic Filtering
+	Global MultiTexSupport:Int	' MultiTexturing
+	Global TexBlendSupport:Int	' TextureBlend
+	Global CubemapSupport:Int	' CubeMapping
+	Global DepthmapSupport:Int	' DepthTexturing
+	Global VPSupport:Int		' VertexProgram (ARBvp1.0)
+	Global FPSupport:Int		' FragmentProgram (ARBfp1.0)
+	Global ShaderSupport:Int	' glSlang Shader Program
+	Global VSSupport:Int		' glSlang VertexShader
+	Global FSSupport:Int		' glSlang FragmentShader
+	Global SLSupport:Int		' OpenGL Shading Language 1.00
+
+	Global MaxTextures:Int
+	Global MaxTexSize:Int
+	Global MaxLights:Int
+
+	Function GetInfo()
+	
+		Local Extensions:String
+
+		' Get HardwareInfo
+		Vendor = String.FromCString(Byte Ptr(glGetString(GL_VENDOR)))
+		Renderer = String.FromCString(Byte Ptr(glGetString(GL_RENDERER))) 
+		OGLVersion = String.FromCString(Byte Ptr(glGetString(GL_VERSION)))
+
+		' Get Extensions
+		Extensions = String.FromCString(Byte Ptr(glGetString(GL_EXTENSIONS)))
+		THardwareInfo.Extensions = Extensions
+
+		' Check for Extensions
+		THardwareInfo.VBOSupport = Extensions.Find("GL_ARB_vertex_buffer_object") > -1
+		THardwareInfo.GLTCSupport = Extensions.Find("GL_ARB_texture_compression")
+		THardwareInfo.S3TCSupport = Extensions.Find("GL_EXT_texture_compression_s3tc") > -1
+		THardwareInfo.AnIsoSupport = Extensions.Find("GL_EXT_texture_filter_anisotropic")
+		THardwareInfo.MultiTexSupport = Extensions.Find("GL_ARB_multitexture") > -1
+		THardwareInfo.TexBlendSupport = Extensions.Find("GL_EXT_texture_env_combine") > -1
+		If Not THardwareInfo.TexBlendSupport 'SMALLFIXES use the ARB version that works the same
+			THardwareInfo.TexBlendSupport = Extensions.Find("GL_ARB_texture_env_combine") > -1
+		EndIf
+		THardwareInfo.CubemapSupport = Extensions.Find("GL_ARB_texture_cube_map") > -1
+		THardwareInfo.DepthmapSupport = Extensions.Find("GL_ARB_depth_texture") > -1
+		THardwareInfo.VPSupport = Extensions.Find("GL_ARB_vertex_program") > -1
+		THardwareInfo.FPSupport = Extensions.Find("GL_ARB_fragment_program") > -1
+		THardwareInfo.ShaderSupport = Extensions.Find("GL_ARB_shader_objects") > -1
+		THardwareInfo.VSSupport = Extensions.Find("GL_ARB_vertex_shader") > -1
+		THardwareInfo.FSSupport = Extensions.Find("GL_ARB_fragment_shader") > -1
+		THardwareInfo.SLSupport = Extensions.Find("GL_ARB_shading_language_100") > - 1
+		
+		If THardwareInfo.VSSupport = False Or THardwareInfo.FSSupport = False
+			THardwareInfo.ShaderSupport = False
+		EndIf
+
+		' Get some numerics
+		glGetIntegerv(GL_MAX_TEXTURE_UNITS, Varptr(THardwareInfo.MaxTextures))
+		glGetIntegerv(GL_MAX_TEXTURE_SIZE, Varptr(THardwareInfo.MaxTexSize))
+		glGetIntegerv(GL_MAX_LIGHTS, Varptr(THardwareInfo.MaxLights))
+		
+	End Function
+
+	Function DisplayInfo(LogFile:Int=False)
+	
+		Local position:Int, Space:Int, stream:TStream
+
+		If LogFile
+		
+			stream = WriteStream("HardwareInfo.txt") 
+			stream.WriteLine("Hardwareinfo:")
+			stream.WriteLine("")
+
+			' Display Desktopinfo
+			stream.WriteLine("Width:  "+ScreenWidth)
+			stream.WriteLine("Height: "+ScreenHeight)
+			stream.WriteLine("Depth:  "+ScreenDepth)
+			stream.WriteLine("Hertz:  "+ScreenHertz)
+			stream.WriteLine("")
+			
+			' Display Driverinfo
+			stream.WriteLine("Vendor:         "+Vendor)
+			stream.WriteLine("Renderer:       "+Renderer)
+			stream.WriteLine("OpenGL-Version: "+OGLVersion)
+			stream.WriteLine("")
+
+			' Display Hardwareranges
+			stream.WriteLine("Max Texture Units: "+MaxTextures)
+			stream.WriteLine("Max Texture Size:  "+MaxTexSize)
+			stream.WriteLine("Max Lights:        "+MaxLights)
+			stream.WriteLine("")
+
+			' Display OpenGL-Extensions
+			stream.WriteLine("OpenGL Extensions:")
+			While position < Extensions.length
+				Space = Extensions.Find(" ", position)
+				If Space = -1 Then Exit
+				stream.WriteLine(Extensions[position..Space])
+				position = Space+1
+			Wend
+
+			stream.WriteLine("")
+			stream.WriteLine("- Ready -")
+			stream.Close()
+			
+		Else
+		
+			Print("Hardwareinfo:")
+			Print("")
+			
+			' Display Desktopinfo
+			Print("Width:  "+ScreenWidth)
+			Print("Height: "+ScreenHeight)
+			Print("Depth:  "+ScreenDepth)
+			Print("Hertz:  "+ScreenHertz)
+			Print("")
+			
+			' Display Driverinfo
+			Print("Vendor:         "+Vendor)
+			Print("Renderer:       "+Renderer)
+			Print("OpenGL-Version: "+OGLVersion)
+			Print("")
+
+			' Display Hardwareranges
+			Print("Max Texture Units: "+MaxTextures)
+			Print("Max Texture Size:  "+MaxTexSize)
+			Print("Max Lights:        "+MaxLights)
+			Print("")
+
+			' Display OpenGL-Extensions
+			Print("OpenGL Extensions:")
+			While position < Extensions.length
+				Space = Extensions.Find(" ", position)
+				If Space = -1 Then Exit
+				Print(Extensions[position..Space])
+				position = Space+1
+			Wend
+
+			Print("")
+			Print("- Ready -")
+			
+		EndIf
+		
+	End Function
+	
+End Type
+
 Type TLight Extends TEntity
 
 	Method NewLight:TLight( inst:Byte Ptr )

+ 23 - 11
openb3dlib.mod/openb3d/src/functions.cpp

@@ -23,10 +23,6 @@ void BackBufferToTex(Texture* tex,int frame){
 	tex->BackBufferToTex(frame);
 }
 
-void DepthBufferToTex(Texture* tex,int frame){
-	tex->DepthBufferToTex(frame);
-}
-
 void CameraToTex(Texture* tex, Camera* cam, int frame){
 	tex->CameraToTex(cam,frame);
 }
@@ -35,6 +31,29 @@ void TexToBuffer(Texture* tex,unsigned char* buffer, int frame){
 	tex->TexToBuffer(buffer,frame);
 }
 
+// wrapper only
+
+void DepthBufferToTex(Texture* tex,int frame){
+	tex->DepthBufferToTex(frame);
+}
+
+void GraphicsResize(int width,int height){
+	Global::width=width;
+	Global::height=height;
+}
+
+void SetRenderState(int capability,int flag){
+	
+	switch(capability){
+	case GL_COLOR_ARRAY: // for vertex colors
+		Global::fx2=flag;
+		break;
+	case GL_NORMAL_ARRAY: // for normal vectors
+		Global::fx1=flag;
+		break;
+	}
+}
+
 
 /*
 bbdoc: Minib3d Only
@@ -869,13 +888,6 @@ void Graphics3D(int width,int height,int depth,int mode,int rate){
 	Global::height=height;
 }
 
-/*
-*/
-void GraphicsResize(int width,int height){
-	Global::width=width;
-	Global::height=height;
-}
-
 /*
 bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=HandleSprite">Online Help</a>
 */

+ 5 - 5
openb3dlib.mod/openb3d/src/functions.h

@@ -6,9 +6,13 @@ extern "C" {
 
 void BufferToTex(Texture* tex,unsigned char* buffer, int frame);
 void BackBufferToTex(Texture* tex,int frame);
-void DepthBufferToTex(Texture* tex,int frame);
+void CameraToTex(Texture* tex, Camera* cam, int frame);
 void TexToBuffer(Texture* tex,unsigned char* buffer, int frame);
 
+// wrapper only
+void DepthBufferToTex(Texture* tex,int frame);
+void GraphicsResize(int width,int height);
+void SetRenderState(int capability,int flag);
 
 /*
 bbdoc: Minib3d Only
@@ -590,10 +594,6 @@ bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=Graphics3D">O
 */
 void Graphics3D(int width,int height,int depth,int mode,int rate);
 
-/*
-*/
-void GraphicsResize(int width,int height);
-
 /*
 bbdoc: <a href="http://www.blitzbasic.com/b3ddocs/command.php?name=HandleSprite">Online Help</a>
 */