Pārlūkot izejas kodu

WIP: macOS port
- Removed dependency on GLEW
- Fixed a couple of places where SSBO was attempted to be created
- Fixed a crash on shutdown

Marko Pintera 7 gadi atpakaļ
vecāks
revīzija
91a0717417

+ 2 - 2
Source/BansheeGLRenderAPI/BsGLOcclusionQuery.cpp

@@ -96,7 +96,7 @@ namespace bs { namespace ct
 		if (mBinary)
 		{
 			GLboolean anyPassed = GL_FALSE;
-			glGetQueryObjectuiv(mQueryObj, GL_QUERY_RESULT_ARB, (GLuint*)&anyPassed);
+			glGetQueryObjectuiv(mQueryObj, GL_QUERY_RESULT, (GLuint*)&anyPassed);
 			BS_CHECK_GL_ERROR();
 
 			mNumSamples = anyPassed == GL_TRUE ? 1 : 0;
@@ -104,7 +104,7 @@ namespace bs { namespace ct
 		else
 		{
 			GLuint numSamples = 0;
-			glGetQueryObjectuiv(mQueryObj, GL_QUERY_RESULT_ARB, (GLuint*)&numSamples);
+			glGetQueryObjectuiv(mQueryObj, GL_QUERY_RESULT, (GLuint*)&numSamples);
 			BS_CHECK_GL_ERROR();
 
 			mNumSamples = (UINT32)numSamples;

+ 4 - 0
Source/BansheeGLRenderAPI/BsGLPixelFormat.cpp

@@ -251,6 +251,7 @@ namespace bs { namespace ct
 			return GL_RGBA32I;
 		case PF_RGBA32U:
 			return GL_RGBA32UI;
+#if BS_OPENGL_4_1
 		case PF_BC1a:
 		case PF_BC1:
 			if (hwGamma)
@@ -271,6 +272,8 @@ namespace bs { namespace ct
 			return GL_COMPRESSED_RED_RGTC1;
 		case PF_BC5:
 			return GL_COMPRESSED_RG_RGTC2;
+#endif
+#if BS_OPENGL_4_2
 		case PF_BC6H:
 			return GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT;
 		case PF_BC7:
@@ -278,6 +281,7 @@ namespace bs { namespace ct
 				return GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM;
 			else
 				return GL_COMPRESSED_RGBA_BPTC_UNORM;
+#endif
 		case PF_D16:
 			return GL_DEPTH_COMPONENT16;
 		case PF_D32:

+ 2 - 1
Source/BansheeGLRenderAPI/BsGLPrerequisites.h

@@ -39,7 +39,8 @@
 #   include <GL/glu.h>
 #   define GL_GLEXT_PROTOTYPES
 #elif BS_PLATFORM == BS_PLATFORM_OSX
-#	include "GL/glew.h"
+#   include <OpenGL/gl3.h>
+#   include <OpenGL/gl3ext.h>
 #endif
 
 #if BS_THREAD_SUPPORT == 1

+ 9 - 34
Source/BansheeGLRenderAPI/BsGLRenderAPI.cpp

@@ -1674,16 +1674,8 @@ namespace bs { namespace ct
 			break;
 		}
 
-		if(GLEW_VERSION_1_4 || GLEW_ARB_imaging)
-		{
-			glBlendEquation(func);
-			BS_CHECK_GL_ERROR();
-		}
-		else if(GLEW_EXT_blend_minmax && (func == GL_MIN || func == GL_MAX))
-		{
-			glBlendEquationEXT(func);
-			BS_CHECK_GL_ERROR();
-		}
+		glBlendEquation(func);
+		BS_CHECK_GL_ERROR();
 	}
 
 	void GLRenderAPI::setSceneBlending(BlendFactor sourceFactor, BlendFactor destFactor, 
@@ -1752,23 +1744,6 @@ namespace bs { namespace ct
 		BS_CHECK_GL_ERROR();
 	}
 
-	void GLRenderAPI::setAlphaTest(CompareFunction func, unsigned char value)
-	{
-		if(func == CMPF_ALWAYS_PASS)
-		{
-			glDisable(GL_ALPHA_TEST);
-			BS_CHECK_GL_ERROR();
-		}
-		else
-		{
-			glEnable(GL_ALPHA_TEST);
-			BS_CHECK_GL_ERROR();
-
-			glAlphaFunc(convertCompareFunction(func), value / 255.0f);
-			BS_CHECK_GL_ERROR();
-		}
-	}
-
 	void GLRenderAPI::setAlphaToCoverage(bool enable)
 	{
 		static bool lasta2c = false;
@@ -2242,9 +2217,9 @@ namespace bs { namespace ct
 		case SOP_DECREMENT:
 			return GL_DECR;
 		case SOP_INCREMENT_WRAP:
-			return GL_INCR_WRAP_EXT;
+			return GL_INCR_WRAP;
 		case SOP_DECREMENT_WRAP:
-			return GL_DECR_WRAP_EXT;
+			return GL_DECR_WRAP;
 		case SOP_INVERT:
 			return GL_INVERT;
 		}
@@ -2382,17 +2357,17 @@ namespace bs { namespace ct
 			primType = GL_POINTS;
 			break;
 		case DOT_LINE_LIST:
-			primType = useAdjacency ? GL_LINES_ADJACENCY_EXT : GL_LINES;
+			primType = useAdjacency ? GL_LINES_ADJACENCY : GL_LINES;
 			break;
 		case DOT_LINE_STRIP:
-			primType = useAdjacency ? GL_LINE_STRIP_ADJACENCY_EXT : GL_LINE_STRIP;
+			primType = useAdjacency ? GL_LINE_STRIP_ADJACENCY : GL_LINE_STRIP;
 			break;
 		default:
 		case DOT_TRIANGLE_LIST:
-			primType = useAdjacency ? GL_TRIANGLES_ADJACENCY_EXT : GL_TRIANGLES;
+			primType = useAdjacency ? GL_TRIANGLES_ADJACENCY : GL_TRIANGLES;
 			break;
 		case DOT_TRIANGLE_STRIP:
-			primType = useAdjacency ? GL_TRIANGLE_STRIP_ADJACENCY_EXT : GL_TRIANGLE_STRIP;
+			primType = useAdjacency ? GL_TRIANGLE_STRIP_ADJACENCY : GL_TRIANGLE_STRIP;
 			break;
 		case DOT_TRIANGLE_FAN:
 			primType = GL_TRIANGLE_FAN;
@@ -2550,7 +2525,7 @@ namespace bs { namespace ct
 		GLint maxOutputVertices;
 
 #if BS_OPENGL_4_1 || BS_OPENGLES_3_2
-		glGetIntegerv(GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT, &maxOutputVertices);
+		glGetIntegerv(GL_MAX_GEOMETRY_OUTPUT_VERTICES, &maxOutputVertices);
 		BS_CHECK_GL_ERROR();
 #else
 		maxOutputVertices = 0;

+ 0 - 6
Source/BansheeGLRenderAPI/BsGLRenderAPI.h

@@ -235,12 +235,6 @@ namespace bs { namespace ct
 		void setSceneBlending(BlendFactor sourceFactor, BlendFactor destFactor, BlendFactor sourceFactorAlpha, 
 			BlendFactor destFactorAlpha, BlendOperation op, BlendOperation alphaOp);
 
-		/**
-		 * Sets alpha test that allows you to reject pixels that fail the comparison function versus the provided reference
-		 * value.
-		 */
-		void setAlphaTest(CompareFunction func, unsigned char value);
-
 		/**
 		 * Enable alpha to coverage. Alpha to coverage allows you to perform blending without needing to worry about order
 		 * of rendering like regular blending does. It requires multi-sampling to be active in order to work, and you need

+ 5 - 0
Source/BansheeGLRenderAPI/BsGLSupport.cpp

@@ -2,16 +2,21 @@
 //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
 #include "BsGLSupport.h"
 #include "BsGLTexture.h"
+
+#if BS_PLATFORM != BS_PLATFORM_OSX
 #include "GL/glew.h"
 
 GLenum glewContextInit(bs::ct::GLSupport* glSupport);
+#endif
 
 namespace bs { namespace ct
 {
 	void GLSupport::initializeExtensions()
 	{
+#if BS_PLATFORM != BS_PLATFORM_OSX
 		glewContextInit(this);
 		BS_CHECK_GL_ERROR();
+#endif
 
 		// Set version string
 		const GLubyte* pcVer = glGetString(GL_VERSION);

+ 9 - 8
Source/BansheeGLRenderAPI/CMakeSources.cmake

@@ -35,13 +35,6 @@ set(BS_BANSHEEGLRENDERAPI_INC_NOFILTER
 	"BsGLTextureView.h"
 )
 
-set(BS_BANSHEEGLRENDERAPI_SRC_WIN32
-	"Win32/BsWin32Context.cpp"
-	"Win32/BsWin32GLSupport.cpp"
-	"Win32/BsWin32RenderWindow.cpp"
-	"Win32/BsWin32VideoModeInfo.cpp"
-)
-
 set(BS_BANSHEEGLRENDERAPI_SRC_NOFILTER
 	"BsGLVertexArrayObjectManager.cpp"
 	"BsGLVertexBuffer.cpp"
@@ -69,7 +62,6 @@ set(BS_BANSHEEGLRENDERAPI_SRC_NOFILTER
 	"BsGLCommandBuffer.cpp"
 	"BsGLCommandBufferManager.cpp"
 	"BsGLTextureView.cpp"
-	"glew.cpp"
 )
 
 set(BS_BANSHEEGLRENDERAPI_INC_GLSL
@@ -87,6 +79,14 @@ set(BS_BANSHEEGLRENDERAPI_INC_WIN32
 	"Win32/BsWin32VideoModeInfo.h"
 )
 
+set(BS_BANSHEEGLRENDERAPI_SRC_WIN32
+	"Win32/BsWin32Context.cpp"
+	"Win32/BsWin32GLSupport.cpp"
+	"Win32/BsWin32RenderWindow.cpp"
+	"Win32/BsWin32VideoModeInfo.cpp"
+	"glew.cpp"
+)
+
 set(BS_BANSHEEGLRENDERAPI_INC_LINUX
 	"Linux/BsLinuxContext.h"
 	"Linux/BsLinuxGLSupport.h"
@@ -99,6 +99,7 @@ set(BS_BANSHEEGLRENDERAPI_SRC_LINUX
 	"Linux/BsLinuxGLSupport.cpp"
 	"Linux/BsLinuxRenderWindow.cpp"
 	"Linux/BsLinuxVideoModeInfo.cpp"
+	"glew.cpp"
 )
 
 set(BS_BANSHEEGLRENDERAPI_INC_MACOS

+ 2 - 0
Source/BansheeGLRenderAPI/MacOS/BsMacOSRenderWindow.mm

@@ -79,6 +79,8 @@ namespace bs
 			bs_delete(mWindow);
 			mWindow = nullptr;
 		}
+
+		RenderWindow::destroy();
 	}
 
 	SPtr<ct::CoreObject> MacOSRenderWindow::createCore() const

+ 23 - 19
Source/RenderBeast/BsImageBasedLighting.cpp

@@ -51,30 +51,34 @@ namespace bs { namespace ct
 		mNumProbes = (UINT32)mReflProbeData.size();
 
 		// Move refl. probe data into a GPU buffer
-		UINT32 size = mNumProbes * sizeof(ReflProbeData);
-		UINT32 curBufferSize;
+		bool supportsStructuredBuffers = gRenderBeast()->getFeatureSet() == RenderBeastFeatureSet::Desktop;
+		if(supportsStructuredBuffers)
+		{
+			UINT32 size = mNumProbes * sizeof(ReflProbeData);
+			UINT32 curBufferSize;
 
-		if (mProbeBuffer != nullptr)
-			curBufferSize = mProbeBuffer->getSize();
-		else
-			curBufferSize = 0;
+			if (mProbeBuffer != nullptr)
+				curBufferSize = mProbeBuffer->getSize();
+			else
+				curBufferSize = 0;
 
-		if (size > curBufferSize || curBufferSize == 0)
-		{
-			// Allocate at least one block even if no probes, to avoid issues with null buffers
-			UINT32 bufferSize = std::max(1, Math::ceilToInt(size / (float)BUFFER_INCREMENT)) * BUFFER_INCREMENT;
+			if (size > curBufferSize || curBufferSize == 0)
+			{
+				// Allocate at least one block even if no probes, to avoid issues with null buffers
+				UINT32 bufferSize = std::max(1, Math::ceilToInt(size / (float) BUFFER_INCREMENT)) * BUFFER_INCREMENT;
 
-			GPU_BUFFER_DESC bufferDesc;
-			bufferDesc.type = GBT_STRUCTURED;
-			bufferDesc.elementCount = bufferSize / sizeof(ReflProbeData);
-			bufferDesc.elementSize = sizeof(ReflProbeData);
-			bufferDesc.format = BF_UNKNOWN;
+				GPU_BUFFER_DESC bufferDesc;
+				bufferDesc.type = GBT_STRUCTURED;
+				bufferDesc.elementCount = bufferSize / sizeof(ReflProbeData);
+				bufferDesc.elementSize = sizeof(ReflProbeData);
+				bufferDesc.format = BF_UNKNOWN;
 
-			mProbeBuffer = GpuBuffer::create(bufferDesc);
-		}
+				mProbeBuffer = GpuBuffer::create(bufferDesc);
+			}
 
-		if (size > 0)
-			mProbeBuffer->writeData(0, size, mReflProbeData.data(), BWT_DISCARD);
+			if (size > 0)
+				mProbeBuffer->writeData(0, size, mReflProbeData.data(), BWT_DISCARD);
+		}
 	}
 
 	RendererReflectionProbe::RendererReflectionProbe(ReflectionProbe* probe)

+ 23 - 19
Source/RenderBeast/BsLightRendering.cpp

@@ -225,30 +225,34 @@ namespace bs { namespace ct
 			}
 		}
 
-		UINT32 size = (UINT32)mVisibleLightData.size() * sizeof(LightData);
-		UINT32 curBufferSize;
+		bool supportsStructuredBuffers = gRenderBeast()->getFeatureSet() == RenderBeastFeatureSet::Desktop;
+		if(supportsStructuredBuffers)
+		{
+			UINT32 size = (UINT32) mVisibleLightData.size() * sizeof(LightData);
+			UINT32 curBufferSize;
 
-		if (mLightBuffer != nullptr)
-			curBufferSize = mLightBuffer->getSize();
-		else
-			curBufferSize = 0;
+			if (mLightBuffer != nullptr)
+				curBufferSize = mLightBuffer->getSize();
+			else
+				curBufferSize = 0;
 
-		if (size > curBufferSize || curBufferSize == 0)
-		{
-			// Allocate at least one block even if no lights, to avoid issues with null buffers
-			UINT32 bufferSize = std::max(1, Math::ceilToInt(size / (float)BUFFER_INCREMENT)) * BUFFER_INCREMENT;
+			if (size > curBufferSize || curBufferSize == 0)
+			{
+				// Allocate at least one block even if no lights, to avoid issues with null buffers
+				UINT32 bufferSize = std::max(1, Math::ceilToInt(size / (float) BUFFER_INCREMENT)) * BUFFER_INCREMENT;
 
-			GPU_BUFFER_DESC bufferDesc;
-			bufferDesc.type = GBT_STRUCTURED;
-			bufferDesc.elementCount = bufferSize / sizeof(LightData);
-			bufferDesc.elementSize = sizeof(LightData);
-			bufferDesc.format = BF_UNKNOWN;
+				GPU_BUFFER_DESC bufferDesc;
+				bufferDesc.type = GBT_STRUCTURED;
+				bufferDesc.elementCount = bufferSize / sizeof(LightData);
+				bufferDesc.elementSize = sizeof(LightData);
+				bufferDesc.format = BF_UNKNOWN;
 
-			mLightBuffer = GpuBuffer::create(bufferDesc);
-		}
+				mLightBuffer = GpuBuffer::create(bufferDesc);
+			}
 
-		if (size > 0)
-			mLightBuffer->writeData(0, size, mVisibleLightData.data(), BWT_DISCARD);
+			if (size > 0)
+				mLightBuffer->writeData(0, size, mVisibleLightData.data(), BWT_DISCARD);
+		}
 	}
 
 	void VisibleLightData::gatherInfluencingLights(const Bounds& bounds,