Selaa lähdekoodia

Enabled anisotropic filtering.

Mark Sibly 8 vuotta sitten
vanhempi
commit
9b079e9ca5

+ 3 - 0
modules/mojo/graphics/glexts/glexts.cpp

@@ -17,6 +17,7 @@ namespace bbGLexts{
 	bool GL_texture_half_float;
 	bool GL_depth_texture;
 	bool GL_seamless_cube_map;
+	bool GL_texture_filter_anisotropic;
 	
 	PFNGLDRAWBUFFERSPROC glDrawBuffers;
 	
@@ -67,6 +68,8 @@ namespace bbGLexts{
 		
 		GL_seamless_cube_map=SDL_GL_ExtensionSupported( "GL_ARB_seamless_cube_map" );
 			
+		GL_texture_filter_anisotropic=SDL_GL_ExtensionSupported( "GL_EXT_texture_filter_anisotropic" );
+	
 //		bb_printf( "GL_draw_buffers=%i\n",int( GL_draw_buffers ) );
 //		bb_printf( "GL_texture_float=%i\n",int( GL_texture_float ) );
 //		bb_printf( "GL_texture_half_float=%i\n",int( GL_texture_half_float ) );

+ 1 - 0
modules/mojo/graphics/glexts/glexts.h

@@ -15,6 +15,7 @@ namespace bbGLexts{
 	extern bool GL_texture_half_float;
 	extern bool GL_depth_texture;
 	extern bool GL_seamless_cube_map;
+	extern bool GL_texture_filter_anisotropic;
 	
 	typedef void (GL_APIENTRY *PFNGLDRAWBUFFERSPROC)( GLsizei n,const GLenum *bufs );
 

+ 10 - 1
modules/mojo/graphics/glexts/glexts.monkey2

@@ -8,6 +8,10 @@ Namespace mojo.graphics.glexts
 
 #Endif
 
+Const GL_TEXTURE_MAX_ANISOTROPY:=$84FE
+
+Const GL_MAX_TEXTURE_MAX_ANISOTROPY:=$84FF
+
 Const GL_TEXTURE_CUBE_MAP_SEAMLESS:=$884f
 
 Const GL_DRAW_BUFFER:=$0c01
@@ -38,6 +42,7 @@ Const GL_COLOR_ATTACHMENT14:Int=$8CEE
 Const GL_COLOR_ATTACHMENT15:Int=$8CEF
 
 'GLES2 targets
+'
 #If __TARGET__="windows" Or __MOBILE_TARGET__ Or __WEB_TARGET__
 
 Const GL_draw_buffer:Bool=False
@@ -50,6 +55,7 @@ Const GL_draw_buffers:Bool="bbGLexts::GL_draw_buffers"
 Const GL_depth_texture:bool="bbGLexts::GL_depth_texture"
 Const GL_texture_float:Bool="bbGLexts::GL_texture_float"
 Const GL_texture_half_float:bool="bbGLexts::GL_texture_half_float"
+Const GL_texture_filter_anisotropic:Bool="bbGLexts::GL_texture_filter_anisotropic"
 
 Function glDrawBuffers( n:Int,bufs:GLenum Ptr )="bbGLexts::glDrawBuffers"
 
@@ -66,7 +72,8 @@ Function glReadBuffer( mode:GLenum )
 	RuntimeError( "glReadBuffer unsupported" )
 End
 
-'GL targets
+'OpenGL targets
+'
 #Elseif __TARGET__="macos" Or __TARGET__="linux"
 
 Const GL_draw_buffer:Bool=True
@@ -76,6 +83,7 @@ Const GL_depth_texture:bool=True
 Const GL_texture_float:Bool=True
 Const GL_texture_half_float:bool=True
 Const GL_seamless_cube_map:bool=True
+Const GL_texture_filter_anisotropic:Bool=True
 
 Extern
 
@@ -98,6 +106,7 @@ Const GL_depth_texture:bool=False
 Const GL_texture_float:Bool=False
 Const GL_texture_half_float:bool=False
 Const GL_seamless_cube_map:Bool=False
+Const GL_texture_filter_anisotropic:Bool=False
 
 Function glDrawBuffers( n:Int,bufs:GLenum Ptr )
 	RuntimeError( "glDrawBuffers unsupported" )

+ 22 - 12
modules/mojo/graphics/texture.monkey2

@@ -91,8 +91,6 @@ Enum CubeFace
 	NegativeZ
 End
 
-#rem monkeydoc @hidden
-#end
 Class Texture Extends Resource
 	
 	Private
@@ -413,20 +411,32 @@ Class Texture Extends Resource
 			If _retroMode
 				glTexParameteri( _glTarget,GL_TEXTURE_MAG_FILTER,GL_NEAREST )
 				glTexParameteri( _glTarget,GL_TEXTURE_MIN_FILTER,GL_NEAREST )
-			Else If _flags & TextureFlags.Mipmap
-				If _flags & TextureFlags.Filter
+			Else
+				 If _flags & TextureFlags.Mipmap
+					If _flags & TextureFlags.Filter
+						glTexParameteri( _glTarget,GL_TEXTURE_MAG_FILTER,GL_LINEAR )
+						glTexParameteri( _glTarget,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR )
+					Else
+						glTexParameteri( _glTarget,GL_TEXTURE_MAG_FILTER,GL_NEAREST )
+						glTexParameteri( _glTarget,GL_TEXTURE_MIN_FILTER,GL_NEAREST_MIPMAP_NEAREST )
+					Endif
+				Else If _flags & TextureFlags.Filter
 					glTexParameteri( _glTarget,GL_TEXTURE_MAG_FILTER,GL_LINEAR )
-					glTexParameteri( _glTarget,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR )
+					glTexParameteri( _glTarget,GL_TEXTURE_MIN_FILTER,GL_LINEAR )
 				Else
 					glTexParameteri( _glTarget,GL_TEXTURE_MAG_FILTER,GL_NEAREST )
-					glTexParameteri( _glTarget,GL_TEXTURE_MIN_FILTER,GL_NEAREST_MIPMAP_NEAREST )
+					glTexParameteri( _glTarget,GL_TEXTURE_MIN_FILTER,GL_NEAREST )
 				Endif
-			Else If _flags & TextureFlags.Filter
-				glTexParameteri( _glTarget,GL_TEXTURE_MAG_FILTER,GL_LINEAR )
-				glTexParameteri( _glTarget,GL_TEXTURE_MIN_FILTER,GL_LINEAR )
-			Else
-				glTexParameteri( _glTarget,GL_TEXTURE_MAG_FILTER,GL_NEAREST )
-				glTexParameteri( _glTarget,GL_TEXTURE_MIN_FILTER,GL_NEAREST )
+				
+				If _flags & TextureFlags.FilterMipmap
+					If glexts.GL_texture_filter_anisotropic
+						Local max:Int=0
+						glGetIntegerv( GL_MAX_TEXTURE_MAX_ANISOTROPY,Varptr max )
+						Local n:=Min( Int(App.GetConfig( "GL_texture_max_anisotropy",max )),max )
+						glTexParameteri( _glTarget,GL_TEXTURE_MAX_ANISOTROPY,n )
+					Endif
+				Endif
+								
 			Endif
 			
 			glCheck()

+ 98 - 0
modules/mojo3d/tests/anisotropic.monkey2

@@ -0,0 +1,98 @@
+
+Namespace myapp
+
+#Import "<std>"
+#Import "<mojo>"
+#Import "<mojo3d>"
+
+#Import "assets/"
+
+#Import "util"
+
+Using std..
+Using mojo..
+Using mojo3d..
+
+Const MaxAnisotropy:=0			'set to 0 to use use HW default (usually 16) 1 to for lowest.
+
+Class MyWindow Extends Window
+	
+	Field _scene:Scene
+	
+	Field _camera:Camera
+	
+	Field _light:Light
+	
+	Field _ground:Model
+	
+	Method New( title:String="Simple mojo app",width:Int=640,height:Int=480,flags:WindowFlags=WindowFlags.Resizable )
+
+		Super.New( title,width,height,flags )
+		
+		Print gles20.glGetString( gles20.GL_EXTENSIONS ).Replace( " ","~n" )
+		
+		'create scene
+		'		
+		_scene=Scene.GetCurrent()
+		_scene.EnvColor=Color.Black
+		_scene.ClearColor=Color.Black
+		_scene.AmbientLight=Color.Black
+
+		'create camera
+		'
+		_camera=New Camera
+		_camera.Near=1
+		_camera.Far=1000
+		_camera.Move( 0,2,0 )
+
+		'create light
+		'
+		'_light=New Light
+		'_light.RotateX( 90 )
+		
+		'createa simple 'grid' texture
+		'
+		Local pixmap:=New Pixmap( 16,16 )
+		pixmap.Clear( Color.Black )
+		For Local i:=0 Until 16
+			pixmap.SetPixelARGB( i,0,~0 )
+			pixmap.SetPixelARGB( 0,i,~0 )
+		Next
+		Local texture:=New Texture( pixmap,TextureFlags.FilterMipmap|TextureFlags.WrapST )
+		
+		'create material
+		'
+		Local material:=New PbrMaterial( Color.Black,0,1 )
+		material.EmissiveTexture=texture
+		material.EmissiveFactor=Color.Red
+
+		material.ScaleTextureMatrix( 500,500 )
+		
+		'create ground
+		'		
+		_ground=Model.CreateBox( New Boxf( -500,-1,-500,500,0,500 ),10,10,10,material )
+	End
+	
+	Method OnRender( canvas:Canvas ) Override
+
+		RequestRender()
+		
+		util.Fly( _camera,Self )
+		
+		_scene.Render( canvas,_camera )
+	End
+	
+End
+
+Function Main()
+	
+	Local config:=New StringMap<String>
+	
+	If MaxAnisotropy config["GL_texture_max_anisotropy"]=MaxAnisotropy
+
+	New AppInstance( config )
+	
+	New MyWindow
+	
+	App.Run()
+End