Explorar el Código

WIP: Refactoring OpenGL RAPI in order to support (more restrictive) 4.1 and ES versions
- Conditional compilation for SSBO related code so it can be turned off when not supported

BearishSun hace 8 años
padre
commit
79b973bc30

+ 18 - 1
Source/BansheeGLRenderAPI/BsGLBuffer.cpp

@@ -48,6 +48,11 @@ namespace bs { namespace ct
 
 	void* GLBuffer::lock(UINT32 offset, UINT32 length, GpuLockOptions options)
 	{
+		// If no buffer ID it's assumed this type of buffer is unsupported and we silently fail (it's up to the creator
+		// if the buffer to check for support and potentially print a warning)
+		if(mBufferId == 0)
+			return nullptr;
+
 		GLenum access = 0;
 
 		glBindBuffer(mTarget, mBufferId);
@@ -87,6 +92,9 @@ namespace bs { namespace ct
 
 	void GLBuffer::unlock()
 	{
+		if(mBufferId == 0)
+			return;
+
 		glBindBuffer(mTarget, mBufferId);
 		BS_CHECK_GL_ERROR();
 
@@ -102,6 +110,9 @@ namespace bs { namespace ct
 
 	void GLBuffer::readData(UINT32 offset, UINT32 length, void* pDest)
 	{
+		if(mBufferId == 0)
+			return;
+
 		void* bufferData = lock(offset, length, GBL_READ_ONLY);
 		memcpy(pDest, bufferData, length);
 		unlock();
@@ -110,6 +121,9 @@ namespace bs { namespace ct
 	void GLBuffer::writeData(UINT32 offset, UINT32 length,
 		const void* pSource, BufferWriteType writeFlags)
 	{
+		if(mBufferId == 0)
+			return;
+
 		GpuLockOptions lockOption = GBL_WRITE_ONLY;
 		if (writeFlags == BWT_DISCARD)
 			lockOption = GBL_WRITE_ONLY_DISCARD;
@@ -123,7 +137,10 @@ namespace bs { namespace ct
 
 	void GLBuffer::copyData(GLBuffer& dstBuffer, UINT32 srcOffset, UINT32 dstOffset, UINT32 length)
 	{
-		glBindBuffer(GL_COPY_READ_BUFFER, getGLBufferId());
+		if(mBufferId == 0)
+			return;
+
+		glBindBuffer(GL_COPY_READ_BUFFER, mBufferId);
 		BS_CHECK_GL_ERROR();
 
 		glBindBuffer(GL_COPY_WRITE_BUFFER, dstBuffer.getGLBufferId());

+ 4 - 0
Source/BansheeGLRenderAPI/BsGLGpuBuffer.cpp

@@ -39,9 +39,13 @@ namespace bs { namespace ct
 		// Create buffer
 		if(mProperties.getType() == GBT_STRUCTURED)
 		{
+#if BS_OPENGL_4_2 || BS_OPENGLES_3_1
 			const auto& props = getProperties();
 			UINT32 size = props.getElementCount() * props.getElementSize();
 			mBuffer.initialize(GL_SHADER_STORAGE_BUFFER, size, props.getUsage());
+#else
+			LOGWRN("SSBOs are not supported on the current OpenGL version.");
+#endif
 		}
 		else
 		{

+ 2 - 0
Source/BansheeGLRenderAPI/BsGLRenderAPI.cpp

@@ -650,6 +650,7 @@ namespace bs { namespace ct
 								}
 							}
 							break;
+#if BS_OPENGL_4_3 || BS_OPENGLES_3_1
 						case GPOT_RWSTRUCTURED_BUFFER: // Shared storage block (read/write, structured)
 							{
 								UINT32 unit = getSharedStorageUnit(binding);
@@ -674,6 +675,7 @@ namespace bs { namespace ct
 								}
 							}
 							break;
+#endif
 						default:
 							break;
 						}