Parcourir la source

Fixing 3D texture rendering in OpenGL
Fixing texture/image OpenGL binding

BearishSun il y a 9 ans
Parent
commit
91ee2c732e

BIN
Data/Engine/GUISkin.asset


BIN
Data/Engine/Includes/VolumeRenderBase.bslinc.asset


BIN
Data/Engine/ResourceManifest.asset


BIN
Data/Engine/Shaders/PPCreateTonemapLUT.bsl.asset


BIN
Data/Engine/Timestamp.asset


BIN
Data/Engine/arial.ttf.asset


+ 7 - 7
Data/Raw/Engine/Includes/VolumeRenderBase.bslinc

@@ -90,7 +90,7 @@ Technique : base("VolumeRenderBase") =
 			out VStoGS
 			{
 				vec2 uv0;
-				flat uint layerIdx;
+				flat int layerIdx;
 			} VSOutput;
 			
 			out gl_PerVertex
@@ -102,7 +102,7 @@ Technique : base("VolumeRenderBase") =
 			{
 				gl_Position = vec4(bs_position, 0, 1);
 				VSOutput.uv0 = bs_texcoord0;
-				VSOutput.layerIdx = gl_InstanceID;
+				VSOutput.layerIdx = int(gl_InstanceID);
 			}
 		};
 		
@@ -114,13 +114,12 @@ Technique : base("VolumeRenderBase") =
 			in VStoGS
 			{
 				vec2 uv0;
-				flat uint layerIdx;
+				flat int layerIdx;
 			} GSInput[3];
 		
 			out GStoFS
 			{
 				vec2 uv0;
-				flat uint layerIdx;
 			} GSOutput;
 		
 			in gl_PerVertex 
@@ -133,21 +132,22 @@ Technique : base("VolumeRenderBase") =
 				vec4 gl_Position;
 			};
 		
+			out int gl_Layer;
+		
 			void main()
 			{
+				gl_Layer = GSInput[0].layerIdx;
+			
 				gl_Position = gl_in[0].gl_Position;
 				GSOutput.uv0 = GSInput[0].uv0;
-				GSOutput.layerIdx = GSInput[0].layerIdx;
 				EmitVertex();
 				
 				gl_Position = gl_in[1].gl_Position;
 				GSOutput.uv0 = GSInput[1].uv0;
-				GSOutput.layerIdx = GSInput[1].layerIdx;
 				EmitVertex();
 				
 				gl_Position = gl_in[2].gl_Position;
 				GSOutput.uv0 = GSInput[2].uv0;
-				GSOutput.layerIdx = GSInput[2].layerIdx;
 				EmitVertex();
 			}
 		};

+ 2 - 2
Data/Raw/Engine/Shaders/PPCreateTonemapLUT.bsl

@@ -211,10 +211,10 @@ Technique
 			in GStoFS
 			{
 				vec2 uv0;
-				flat uint layerIdx;
 			} input;
 			
 			out vec4 fragColor;
+			in int gl_Layer;
 			
 			void main()
 			{
@@ -226,7 +226,7 @@ Technique
 				// By default pixel centers will be sampled, but we want to encode the entire range, so
 				// offset the sampling by half a pixel, and extend the entire range by one pixel.
 				vec2 uv = input.uv0 - (0.5f / LUT_SIZE);
-				vec3 logColor = vec3(uv * LUT_SIZE / float(LUT_SIZE - 1), input.layerIdx / float(LUT_SIZE - 1));
+				vec3 logColor = vec3(uv * LUT_SIZE / float(LUT_SIZE - 1), gl_Layer / float(LUT_SIZE - 1));
 				
 				vec3 linearColor;
 				LogToLinearColor(logColor, linearColor);

+ 0 - 1
Source/BansheeGLRenderAPI/Include/BsGLRenderAPI.h

@@ -453,7 +453,6 @@ namespace BansheeEngine
 
 		UINT32 mTextureUnitOffsets[6];
 		UINT32 mMaxBoundTexUnits[6];
-		UINT32 mImageUnitOffsets[6];
 		UINT32 mMaxBoundImageUnits[6];
 		UINT32 mUBOffsets[6];
 

+ 10 - 17
Source/BansheeGLRenderAPI/Source/BsGLRenderAPI.cpp

@@ -55,7 +55,6 @@ namespace BansheeEngine
 		, mActivePipeline(nullptr)
 		, mTextureUnitOffsets {}
 		, mMaxBoundTexUnits {}
-		, mImageUnitOffsets {}
 		, mMaxBoundImageUnits {}
 		, mUBOffsets {}
 		, mCurrentDrawOperation(DOT_TRIANGLE_LIST)
@@ -421,6 +420,9 @@ namespace BansheeEngine
 		// Set border color
 		setTextureBorderColor(texUnit, stateProps.getBorderColor());
 
+		mTextureInfos[texUnit].samplerIdx = unit;
+		mMaxBoundTexUnits[gptype] = std::max(mMaxBoundTexUnits[gptype], (UINT32)texUnit + 1);
+
 		BS_INC_RENDER_STAT(NumSamplerBinds);
 	}
 
@@ -1735,8 +1737,7 @@ namespace BansheeEngine
 			return 0;
 		}
 
-		UINT32 offset = mImageUnitOffsets[gptype];
-		for (UINT32 i = offset; i < mMaxBoundImageUnits[gptype]; i++)
+		for (UINT32 i = 0; i < mMaxBoundImageUnits[gptype]; i++)
 		{
 			UINT32 imageUnit = i;
 
@@ -1744,8 +1745,8 @@ namespace BansheeEngine
 				return imageUnit;
 		}
 
-		INT32 numSupportedUnits = (INT32)mCurrentCapabilities->getNumLoadStoreTextureUnits(gptype);
-		INT32 numBoundImageUnits = (INT32)mMaxBoundImageUnits[gptype] - (INT32)offset;
+		UINT32 numSupportedUnits = mCurrentCapabilities->getNumLoadStoreTextureUnits(gptype);
+		UINT32 numBoundImageUnits = mMaxBoundImageUnits[gptype];
 		if (numBoundImageUnits < numSupportedUnits)
 			return mMaxBoundImageUnits[gptype];
 
@@ -1790,7 +1791,7 @@ namespace BansheeEngine
 			break;
 		}
 
-		mMaxBoundTexUnits[gptype] = 0;
+		mMaxBoundTexUnits[gptype] = mTextureUnitOffsets[gptype];
 		mMaxBoundImageUnits[gptype] = 0;
 	}
 
@@ -1858,16 +1859,14 @@ namespace BansheeEngine
 		}
 
 		UINT32 curTexUnitOffset = 0;
-		UINT32 curImageUnitOffset = 0;
 		UINT32 curUBOffset = 0;
 		for (UINT32 i = 0; i < 6; i++)
 		{
 			mTextureUnitOffsets[i] = curTexUnitOffset;
-			mImageUnitOffsets[i] = curImageUnitOffset;
+			mMaxBoundTexUnits[i] = curTexUnitOffset;
 			mUBOffsets[i] = curUBOffset;
 
 			curTexUnitOffset += caps->getNumTextureUnits((GpuProgramType)i);
-			curImageUnitOffset += caps->getNumLoadStoreTextureUnits((GpuProgramType)i);
 			curUBOffset += caps->getNumGpuParamBlockBuffers((GpuProgramType)i);
 		}
 
@@ -1891,13 +1890,7 @@ namespace BansheeEngine
 		if(totalNumUniformBlocks > numCombinedUniformBlocks)
 			BS_EXCEPT(InternalErrorException, "Number of combined uniform block buffers less than the number of individual per-stage buffers!?");
 
-		UINT32 totalNumImageUnits = curImageUnitOffset;
-		UINT16 numCombinedImageUnits = caps->getNumCombinedLoadStoreTextureUnits();
-
-		if (totalNumImageUnits > numCombinedImageUnits)
-			BS_EXCEPT(InternalErrorException, "Number of combined load-store texture units less than the number of individual per-stage units!?");
-
-		mNumImageUnits = numCombinedImageUnits;
+		mNumImageUnits = caps->getNumCombinedLoadStoreTextureUnits();
 		mImageInfos = bs_newN<ImageInfo>(mNumImageUnits);
 		for (UINT16 i = 0; i < mNumImageUnits; i++)
 			mImageInfos[i].uniformIdx = (UINT32)-1;
@@ -2172,7 +2165,7 @@ namespace BansheeEngine
 			rsc->setNumLoadStoreTextureUnits(GPT_COMPUTE_PROGRAM, static_cast<UINT16>(lscUnits));
 
 			GLint combinedLoadStoreTextureUnits;
-			glGetIntegerv(GL_MAX_COMBINED_IMAGE_UNIFORMS, &combinedLoadStoreTextureUnits);
+			glGetIntegerv(GL_MAX_IMAGE_UNITS, &combinedLoadStoreTextureUnits);
 			rsc->setNumCombinedLoadStoreTextureUnits(static_cast<UINT16>(combinedLoadStoreTextureUnits));
 		}