Browse Source

Lotsa fixes.

Mark Sibly 8 years ago
parent
commit
7a241f4bff

+ 36 - 21
modules/mojo/graphics/glexts/glexts.cpp

@@ -1,54 +1,69 @@
 
 
 #include "glexts.h"
 #include "glexts.h"
 
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include <bbmonkey.h>
 
 
 extern "C" void* SDL_GL_GetProcAddress( const char *proc );
 extern "C" void* SDL_GL_GetProcAddress( const char *proc );
 extern "C" int SDL_GL_ExtensionSupported( const char *extension );
 extern "C" int SDL_GL_ExtensionSupported( const char *extension );
 
 
+#if __EMSCRIPTEN__
+extern "C" GL_APICALL void GL_APIENTRY glDrawBuffers( GLsizei n,const GLenum *bufs );
+#endif
+
 namespace bbGLexts{
 namespace bbGLexts{
 
 
 	bool GL_draw_buffers=true;
 	bool GL_draw_buffers=true;
 	bool GL_texture_float;
 	bool GL_texture_float;
 	bool GL_texture_half_float;
 	bool GL_texture_half_float;
 	bool GL_depth_texture;
 	bool GL_depth_texture;
-
-	void(*glDrawBuffers)( int n,const GLenum *bufs );
 	
 	
-	void init(){
+	PFNGLDRAWBUFFERSPROC glDrawBuffers;
 	
 	
-	#if __EMSCRIPTEN__
+	void init(){
 	
 	
-		if( GL_draw_buffers=SDL_GL_ExtensionSupported( "GL_WEBGL_draw_buffers" ) ){
+		#if __EMSCRIPTEN__
 
 
+		if( GL_draw_buffers=SDL_GL_ExtensionSupported( "GL_WEBGL_draw_buffers" ) ){
+	
 			// Don't actually call this, will crash emscripten...extension is 'just there'!
 			// Don't actually call this, will crash emscripten...extension is 'just there'!
 			//
 			//
 			// glDrawBuffers=(void(*)(int,const GLenum*)) SDL_GL_GetProcAddress( "glDrawBuffersWEBGL" );
 			// glDrawBuffers=(void(*)(int,const GLenum*)) SDL_GL_GetProcAddress( "glDrawBuffersWEBGL" );
-			
+				
 			glDrawBuffers=::glDrawBuffers;
 			glDrawBuffers=::glDrawBuffers;
 		}
 		}
 		
 		
-	#else
+		#else
 	
 	
 		if( GL_draw_buffers=SDL_GL_ExtensionSupported( "GL_EXT_draw_buffers" ) ){
 		if( GL_draw_buffers=SDL_GL_ExtensionSupported( "GL_EXT_draw_buffers" ) ){
+		
+			glDrawBuffers=(PFNGLDRAWBUFFERSPROC)SDL_GL_GetProcAddress( "glDrawBuffersEXT" );
 			
 			
-			glDrawBuffers=(void(*)(int,const GLenum*)) SDL_GL_GetProcAddress( "glDrawBuffersEXT" );
+		}else if( GL_draw_buffers=SDL_GL_ExtensionSupported( "GL_NV_draw_buffers" ) ){
+
+			glDrawBuffers=(PFNGLDRAWBUFFERSPROC)SDL_GL_GetProcAddress( "glDrawBuffersNV" );
 		}
 		}
 		
 		
-	#endif
-
-		GL_texture_float=SDL_GL_ExtensionSupported( "GL_OES_texture_float" );
+		#endif
 		
 		
-		GL_texture_half_float=SDL_GL_ExtensionSupported( "GL_OES_texture_half_float" );
+		GL_texture_float=SDL_GL_ExtensionSupported( "GL_EXT_texture_float" ) ||
+			SDL_GL_ExtensionSupported( "GL_ANGLE_texture_half_float" ) ||
+			SDL_GL_ExtensionSupported( "GL_WEBGL_texture_float" ) ||
+			SDL_GL_ExtensionSupported( "GL_OES_texture_float" );
 		
 		
-		GL_depth_texture=SDL_GL_ExtensionSupported( "GL_OES_depth_texture" );
-	
-		printf( "GL_draw_buffers=%i\n",int( GL_draw_buffers ) );
-		printf( "GL_texture_float=%i\n",int( GL_texture_float ) );
-		printf( "GL_texture_half_float=%i\n",int( GL_texture_half_float ) );
-		printf( "GL_depth_texture=%i\n",int( GL_depth_texture ) );
+		GL_texture_half_float=SDL_GL_ExtensionSupported( "GL_EXT_texture_half_float" ) ||
+			SDL_GL_ExtensionSupported( "GL_ANGLE_texture_half_float" ) ||
+			SDL_GL_ExtensionSupported( "GL_WEBGL_texture_half_float" ) ||
+			SDL_GL_ExtensionSupported( "GL_OES_texture_half_float" );
+		
+		GL_depth_texture=SDL_GL_ExtensionSupported( "GL_EXT_depth_texture" ) || 
+			SDL_GL_ExtensionSupported( "GL_ANGLE_depth_texture" ) ||
+			SDL_GL_ExtensionSupported( "GL_WEBGL_depth_texture" ) ||
+			SDL_GL_ExtensionSupported( "GL_OES_depth_texture" );
+		
+		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 ) );
+		bb_printf( "GL_depth_texture=%i\n",int( GL_depth_texture ) );
 		
 		
 		fflush( stdout );
 		fflush( stdout );
 	}
 	}

+ 4 - 6
modules/mojo/graphics/glexts/glexts.h

@@ -8,19 +8,17 @@
 #include <GLES2/gl2.h>
 #include <GLES2/gl2.h>
 #endif
 #endif
 
 
-#if __EMSCRIPTEN__
-extern "C" void glDrawBuffers( int n,const GLenum *bufs );
-#endif
-
 namespace bbGLexts{
 namespace bbGLexts{
 
 
 	extern bool GL_draw_buffers;
 	extern bool GL_draw_buffers;
 	extern bool GL_texture_float;
 	extern bool GL_texture_float;
 	extern bool GL_texture_half_float;
 	extern bool GL_texture_half_float;
 	extern bool GL_depth_texture;
 	extern bool GL_depth_texture;
+	
+	typedef void (GL_APIENTRY *PFNGLDRAWBUFFERSPROC)( GLsizei n,const GLenum *bufs );
 
 
-	extern void(*glDrawBuffers)( int n,const GLenum *bufs );
-
+	extern PFNGLDRAWBUFFERSPROC glDrawBuffers;
+	
 	void init();
 	void init();
 }
 }
 
 

+ 0 - 4
modules/mojo/graphics/glexts/glexts.monkey2

@@ -47,11 +47,7 @@ Const GL_texture_float:Bool="bbGLexts::GL_texture_float"
 Const GL_texture_half_float:bool="bbGLexts::GL_texture_half_float"
 Const GL_texture_half_float:bool="bbGLexts::GL_texture_half_float"
 Const GL_depth_texture:bool="bbGLexts::GL_depth_texture"
 Const GL_depth_texture:bool="bbGLexts::GL_depth_texture"
 
 
-#If __WEB_TARGET__
-Function glDrawBuffers( n:Int,bufs:GLenum Ptr )
-#Else
 Function glDrawBuffers( n:Int,bufs:GLenum Ptr )="bbGLexts::glDrawBuffers"
 Function glDrawBuffers( n:Int,bufs:GLenum Ptr )="bbGLexts::glDrawBuffers"
-#Endif
 
 
 Function InitGLexts()="bbGLexts::init"
 Function InitGLexts()="bbGLexts::init"
 	
 	

+ 7 - 0
modules/mojo/graphics/graphicsdevice.monkey2

@@ -417,6 +417,12 @@ Class GraphicsDevice
 	Function InitGL()
 	Function InitGL()
 
 
 		glCheck()
 		glCheck()
+		
+		#If __CONFIG__="debug"
+		Print "GL_VERSION="+glGetString( GL_VERSION )
+		Print "GL_VENDOR="+glGetString( GL_VENDOR )
+		Print "GL_RENDERER="+glGetString( GL_VENDOR )
+		#Endif
 			
 			
 		InitGLexts()
 		InitGLexts()
 		
 		
@@ -467,6 +473,7 @@ Class GraphicsDevice
 				If GL_read_buffer glReadBuffer( _defaultReadBuf )
 				If GL_read_buffer glReadBuffer( _defaultReadBuf )
 				
 				
 			Endif
 			Endif
+			
 
 
 		Endif
 		Endif
 	
 	

+ 7 - 7
modules/mojo/graphics/rendertarget.monkey2

@@ -63,17 +63,17 @@ Class RenderTarget Extends Resource
 	End
 	End
 	
 	
 	Method Bind()
 	Method Bind()
-		
+	
 		glBindFramebuffer( GL_FRAMEBUFFER,ValidateGLFramebuffer() )
 		glBindFramebuffer( GL_FRAMEBUFFER,ValidateGLFramebuffer() )
-		
+
 		If glexts.GL_draw_buffers 
 		If glexts.GL_draw_buffers 
 			glDrawBuffers( _drawBufs.Length,_drawBufs.Data )
 			glDrawBuffers( _drawBufs.Length,_drawBufs.Data )
 		Endif
 		Endif
-		
-		#If __TARGET__="macos" Or __TARGET__="linux"
-		glReadBuffer( GL_NONE )
-		#endif
-		
+
+		If glexts.GL_read_buffer
+			glReadBuffer( GL_NONE )
+		Endif
+
 		CheckStatus()
 		CheckStatus()
 	End
 	End
 	
 	

+ 52 - 2
modules/mojo/graphics/texture.monkey2

@@ -377,7 +377,13 @@ Class Texture Extends Resource
 				For Local i:=0 Until 6
 				For Local i:=0 Until 6
 					If _managed
 					If _managed
 						Local image:=_managed.Window( offsets[i*2]*Width,offsets[i*2+1]*Height,Width,Height )
 						Local image:=_managed.Window( offsets[i*2]*Width,offsets[i*2+1]*Height,Width,Height )
-						UploadTexImage2D( cubeFaces[i],image )
+						If _flags & TextureFlags.Mipmap
+'							UploadTexImage2D( cubeFaces[i],image )
+							UploadTexImageCubeMap( cubeFaces[i],image )
+							_dirty&=~Dirty.Mipmaps
+						Else
+							UploadTexImage2D( cubeFaces[i],image )
+						Endif
 					Else
 					Else
 						ClearTexImage2D( cubeFaces[i] )
 						ClearTexImage2D( cubeFaces[i] )
 					Endif
 					Endif
@@ -399,7 +405,6 @@ Class Texture Extends Resource
 			If _flags & TextureFlags.Mipmap glGenerateMipmap( _glTarget )
 			If _flags & TextureFlags.Mipmap glGenerateMipmap( _glTarget )
 				
 				
 			glCheck()
 			glCheck()
-
 		End
 		End
 		
 		
 		_dirty=Null
 		_dirty=Null
@@ -458,6 +463,51 @@ Class Texture Extends Resource
 	Field _glFormat:GLenum
 	Field _glFormat:GLenum
 	Field _glType:GLenum
 	Field _glType:GLenum
 	
 	
+	Method UploadTexImageCubeMap( glTarget:GLenum,image:Pixmap )
+	
+		Local format:=PixelFormat.RGBA32
+		Local gliformat:=glInternalFormat( format )
+		Local glformat:=glFormat( format )
+		Local gltype:=glType( format )
+	
+		Local data:=image.Convert( format )
+		
+		Local width:=Width,height:=Height,mip:=0
+		
+		While width>=1 And height>=1
+		
+'			Print "Uploading cube texture, width="+width+", height="+height+", mip="+mip
+		
+			glTexImage2D( glTarget,mip,gliformat,width,height,0,glformat,gltype,Null )
+			
+			For Local y:=0 Until height
+				
+				Local p:=data.PixelPtr( 0,y )
+				
+				'write miplevel to alpha!
+				For Local x:=0 Until width
+					p[x*4+3]=mip
+				Next
+		
+				glTexSubImage2D( glTarget,mip,0,y,width,1,glformat,gltype,p )
+			Next
+			
+			glFlush() 'macos nvidia bug!
+		
+			If width=1 And height=1 Exit
+			
+			Local hdata:=data.MipHalve()
+			data.Discard()
+			data=hdata
+			width/=2
+			height/=2
+			mip+=1
+		
+		Wend
+		
+		data.Discard()
+	End
+	
 	Method UploadTexImage2D( glTarget:GLenum,image:Pixmap )
 	Method UploadTexImage2D( glTarget:GLenum,image:Pixmap )
 		glCheck()
 		glCheck()
 		
 		

+ 11 - 6
modules/mojo/graphics/uniformblock.monkey2

@@ -9,6 +9,13 @@ Class UniformBlock Extends Resource
 		_name=name
 		_name=name
 	End
 	End
 	
 	
+	Method New( uniforms:UniformBlock )
+		_name=uniforms._name
+		For Local i:=0 Until _uniforms.Length
+			_uniforms[i]=uniforms._uniforms[i]
+		Next
+	End
+	
 	Property Name:Int()
 	Property Name:Int()
 		Return _name
 		Return _name
 	End
 	End
@@ -124,7 +131,7 @@ Class UniformBlock Extends Resource
 	Method GetMat4fv:Float Ptr( id:Int )
 	Method GetMat4fv:Float Ptr( id:Int )
 		Return GetFloatPtr( id,Type.Mat4f )
 		Return GetFloatPtr( id,Type.Mat4f )
 	End
 	End
-	
+
 	'***** Mat4f array *****
 	'***** Mat4f array *****
 	'
 	'
 	Method SetMat4fArray( uniform:String,value:Mat4f[] )
 	Method SetMat4fArray( uniform:String,value:Mat4f[] )
@@ -175,10 +182,6 @@ Class UniformBlock Extends Resource
 	
 	
 	Private
 	Private
 	
 	
-	Field _name:Int
-	
-	Field _seq:Int
-	
 	Global _gseq:Int
 	Global _gseq:Int
 	Global _ids:=New StringMap<Int>[8]
 	Global _ids:=New StringMap<Int>[8]
 	
 	
@@ -225,7 +228,9 @@ Class UniformBlock Extends Resource
 		
 		
 	End
 	End
 	
 	
-	Field _uniforms:=New Uniform[32]
+	Field _name:Int
+	Field _seq:Int
+	Field _uniforms:=New Uniform[64]
 	
 	
 	Method SetFloatData<T>( uniform:String,data:T,type:Type )
 	Method SetFloatData<T>( uniform:String,data:T,type:Type )
 		Local id:=GetUniformId( uniform )
 		Local id:=GetUniformId( uniform )