Browse Source

Feature: OpenGL render API can now work with older OpenGL versions, including OpenGL 4.1 and partial support for OpenGL ES
- This is beneficial for macOS which only supports OpenGL 4.1, and paves the way to mobile ports which support OpenGL ES
- The actual commit includes the last part of OpenGL refactor: Texture view support can now be conditionally compiled

BearishSun 8 years ago
parent
commit
37d256d01f

+ 18 - 1
Source/BansheeGLRenderAPI/BsGLRenderAPI.cpp

@@ -504,6 +504,7 @@ namespace bs { namespace ct
 						GLTexture* glTex = static_cast<GLTexture*>(texture.get());
 						GLTexture* glTex = static_cast<GLTexture*>(texture.get());
 						if (glTex != nullptr)
 						if (glTex != nullptr)
 						{
 						{
+#if BS_OPENGL_4_3 || BS_OPENGLES_3_1 
 							SPtr<TextureView> texView = glTex->requestView(
 							SPtr<TextureView> texView = glTex->requestView(
 								surface.mipLevel,
 								surface.mipLevel,
 								surface.numMipLevels,
 								surface.numMipLevels,
@@ -514,6 +515,22 @@ namespace bs { namespace ct
 							GLTextureView* glTexView = static_cast<GLTextureView*>(texView.get());
 							GLTextureView* glTexView = static_cast<GLTextureView*>(texView.get());
 
 
 							GLenum newTextureType = glTexView->getGLTextureTarget();
 							GLenum newTextureType = glTexView->getGLTextureTarget();
+							GLuint texId = glTexView->getGLID();
+#else
+							// Texture views are not supported, so if user requested a part of the texture surface report
+							// a warning
+							auto& props = texture->getProperties();
+							if (surface.mipLevel != 0 || surface.face != 0 ||
+								(surface.numMipLevels != 0 && surface.numMipLevels != props.getNumMipmaps()) ||
+								(surface.numFaces != 0 && surface.numFaces != props.getNumFaces()))
+							{
+								LOGWRN("Attempting to bind only a part of a texture, but texture views are not supported. "
+									"Entire texture will be bound instead.");
+							}
+
+							GLenum newTextureType = glTex->getGLTextureTarget();
+							GLuint texId = glTex->getGLID();
+#endif
 
 
 							if (mTextureInfos[unit].type != newTextureType)
 							if (mTextureInfos[unit].type != newTextureType)
 							{
 							{
@@ -521,7 +538,7 @@ namespace bs { namespace ct
 								BS_CHECK_GL_ERROR();
 								BS_CHECK_GL_ERROR();
 							}
 							}
 
 
-							glBindTexture(newTextureType, glTexView->getGLID());
+							glBindTexture(newTextureType, texId);
 							BS_CHECK_GL_ERROR();
 							BS_CHECK_GL_ERROR();
 
 
 							mTextureInfos[unit].type = newTextureType;
 							mTextureInfos[unit].type = newTextureType;

+ 7 - 4
Source/BansheeGLRenderAPI/BsGLTextureView.cpp

@@ -8,10 +8,8 @@ namespace bs { namespace ct {
 		:TextureView(desc), mViewID(0)
 		:TextureView(desc), mViewID(0)
 	{
 	{
 		const TextureProperties& props = texture->getProperties();
 		const TextureProperties& props = texture->getProperties();
-		GLuint originalTexture = texture->getGLID();
 
 
 		GLenum target;
 		GLenum target;
-
 		switch (props.getTextureType())
 		switch (props.getTextureType())
 		{
 		{
 		case TEX_TYPE_1D:
 		case TEX_TYPE_1D:
@@ -64,6 +62,7 @@ namespace bs { namespace ct {
 		break;
 		break;
 		}
 		}
 
 
+#if BS_OPENGL_4_3 || BS_OPENGLES_3_1
 		glGenTextures(1, &mViewID);
 		glGenTextures(1, &mViewID);
 		BS_CHECK_GL_ERROR();
 		BS_CHECK_GL_ERROR();
 
 
@@ -77,13 +76,17 @@ namespace bs { namespace ct {
 			desc.firstArraySlice, 
 			desc.firstArraySlice, 
 			desc.numArraySlices);
 			desc.numArraySlices);
 		BS_CHECK_GL_ERROR();
 		BS_CHECK_GL_ERROR();
+#endif
 
 
 		mTarget = GLTexture::getGLTextureTarget(props.getTextureType(), props.getNumSamples(), desc.numArraySlices);
 		mTarget = GLTexture::getGLTextureTarget(props.getTextureType(), props.getNumSamples(), desc.numArraySlices);
 	}
 	}
 
 
 	GLTextureView::~GLTextureView()
 	GLTextureView::~GLTextureView()
 	{
 	{
-		glDeleteTextures(1, &mViewID);
-		BS_CHECK_GL_ERROR();
+		if(mViewID != 0)
+		{
+			glDeleteTextures(1, &mViewID);
+			BS_CHECK_GL_ERROR();
+		}
 	}
 	}
 }}
 }}