Quellcode durchsuchen

Getting OpenGL renderer back to working order
Defines declared outside of code blocks in BSLFX file will now be correctly recognized within code blocks

BearishSun vor 10 Jahren
Ursprung
Commit
c07cde04d7

+ 1 - 1
BansheeEditorExec/BsEditorExec.cpp

@@ -64,7 +64,7 @@ int CALLBACK WinMain(
 
 	__try
 	{
-		EditorApplication::startUp(EditorRenderAPI::DX11);
+		EditorApplication::startUp(EditorRenderAPI::OpenGL);
 		EditorApplication::instance().runMainLoop();
 		EditorApplication::shutDown();
 	}

+ 0 - 7
BansheeGLRenderAPI/Source/BsGLFrameBufferObject.cpp

@@ -87,13 +87,6 @@ namespace BansheeEngine
                     BS_EXCEPT(InvalidParametersException, ss.str());
                 }
 
-                if(mColor[x].buffer->getGLFormat() != glformat)
-                {
-                    StringStream ss;
-                    ss << "Attachment " << x << " has incompatible format.";
-                    BS_EXCEPT(InvalidParametersException, ss.str());
-                }
-
 				// Note: I'm attaching textures to FBO while renderbuffers might yield better performance if I
 				// don't need to read from them
 

+ 28 - 21
BansheeGLRenderAPI/Source/BsGLRenderAPI.cpp

@@ -551,40 +551,47 @@ namespace BansheeEngine
 		THROW_IF_NOT_CORE_THREAD;
 
 		// Switch context if different from current one
-		SPtr<GLContext> newContext;
-		target->getCustomAttribute("GLCONTEXT", &newContext);
-		if(newContext && mCurrentContext != newContext) 
+		if (target != nullptr)
 		{
-			switchContext(newContext);
+			SPtr<GLContext> newContext;
+			target->getCustomAttribute("GLCONTEXT", &newContext);
+			if (newContext && mCurrentContext != newContext)
+			{
+				switchContext(newContext);
+			}
 		}
 
 		// This must happen after context switch to ensure previous context is still alive
 		mActiveRenderTarget = target;
 
 		GLFrameBufferObject* fbo = nullptr;
-		target->getCustomAttribute("FBO", &fbo);
-		if(fbo)
-			fbo->bind();
-		else
-			// Old style context (window/pbuffer) or copying render texture
-			glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
 
-		if (GLEW_EXT_framebuffer_sRGB)
+		if(target != nullptr)
+			target->getCustomAttribute("FBO", &fbo);
+
+		if (fbo != nullptr)
 		{
-			// Enable / disable sRGB states
-			if (target->getProperties().isHwGammaEnabled())
-			{
-				glEnable(GL_FRAMEBUFFER_SRGB_EXT);
+			fbo->bind();
 
-				// Note: could test GL_FRAMEBUFFER_SRGB_CAPABLE_EXT here before
-				// enabling, but GL spec says incapable surfaces ignore the setting
-				// anyway. We test the capability to enable isHardwareGammaEnabled.
-			}
-			else
+			if (GLEW_EXT_framebuffer_sRGB)
 			{
-				glDisable(GL_FRAMEBUFFER_SRGB_EXT);
+				// Enable / disable sRGB states
+				if (target->getProperties().isHwGammaEnabled())
+				{
+					glEnable(GL_FRAMEBUFFER_SRGB_EXT);
+
+					// Note: could test GL_FRAMEBUFFER_SRGB_CAPABLE_EXT here before
+					// enabling, but GL spec says incapable surfaces ignore the setting
+					// anyway. We test the capability to enable isHardwareGammaEnabled.
+				}
+				else
+				{
+					glDisable(GL_FRAMEBUFFER_SRGB_EXT);
+				}
 			}
 		}
+		else
+			glBindFramebuffer(GL_FRAMEBUFFER, 0);
 
 		applyViewport();
 

+ 3 - 1
BansheeGLRenderAPI/Source/BsGLSLParamParser.cpp

@@ -45,7 +45,9 @@ namespace BansheeEngine
 			}
 			else
 			{
-				LOGWRN("Cannot determine vertex input attribute type for attribute: " + String(attributeName));
+				// Ignore built-in attributes
+				if(memcmp(attributeName, "gl_", 3) != 0)
+					LOGWRN("Cannot determine vertex input attribute type for attribute: " + String(attributeName));
 			}
 		}
 

+ 0 - 12
BansheeGLRenderAPI/Source/BsGLTexture.cpp

@@ -146,18 +146,6 @@ namespace BansheeEngine
 
 		createSurfaceList();
 
-		PixelBufferPtr buffer = getBuffer(0, 0);
-
-#if BS_DEBUG_MODE
-		if(buffer != nullptr)
-		{
-			if(pixFormat != buffer->getFormat())
-			{
-				BS_EXCEPT(InternalErrorException, "Could not create a texture buffer with wanted format: " + toString(pixFormat));
-			}
-		}
-#endif
-
 		BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_Texture);
 		TextureCore::initialize();
 	}

+ 3 - 10
BansheeGLRenderAPI/Source/GLSL/src/BsGLSLGpuProgram.cpp

@@ -145,18 +145,11 @@ namespace BansheeEngine
 					{
 						assert(sizeof(source[i]) == sizeof(GLchar));
 
-						bool isDefine = source[i - lineLength] == '#';
-
-						GLchar* lineData = (GLchar*)bs_stack_alloc(sizeof(GLchar) * (lineLength + 1 + (isDefine ? 1 : 0)));
+						GLchar* lineData = (GLchar*)bs_stack_alloc(sizeof(GLchar) * (lineLength + 2));
 						memcpy(lineData, &source[i - lineLength], sizeof(GLchar) * lineLength);
 
-						if (isDefine) // Defines require a newline as well as a null terminator, otherwise it doesn't compile properly
-						{
-							lineData[lineLength] = '\n';
-							lineData[lineLength + 1] = '\0';
-						}
-						else
-							lineData[lineLength] = '\0';
+						lineData[lineLength] = '\n';
+						lineData[lineLength + 1] = '\0';
 
 						lines.push_back(lineData);
 						lineLength = 0;

+ 3 - 3
BansheeSL/BsLexerFX.c

@@ -2516,7 +2516,7 @@ YY_RULE_SETUP
 case 210:
 YY_RULE_SETUP
 #line 350 "BsLexerFX.l"
-{ yyextra->numOpenBrackets++; appendCodeBlock(yyextra, yytext[0]); }
+{ yyextra->numOpenBrackets++; appendCodeBlock(yyextra, yytext, 1); }
 	YY_BREAK
 case 211:
 YY_RULE_SETUP
@@ -2530,14 +2530,14 @@ YY_RULE_SETUP
 		unput('0');
 	}
 	else
-		appendCodeBlock(yyextra, yytext[0]);
+		appendCodeBlock(yyextra, yytext, 1);
 }
 	YY_BREAK
 case 212:
 /* rule 212 can match eol */
 YY_RULE_SETUP
 #line 362 "BsLexerFX.l"
-{ appendCodeBlock(yyextra, yytext[0]); }
+{ appendCodeBlock(yyextra, yytext, 1); }
 	YY_BREAK
 /* Logic for manually inserting "Index = codeBlockIndex;". We insert arbitrary numbers which allows us to sequentially */
 /* output all the tokens we need. We use only single-character values so we don't override anything in the text buffer */

+ 3 - 3
BansheeSL/BsLexerFX.l

@@ -347,7 +347,7 @@ Common			{ BEGIN(CODEBLOCK_HEADER); return TOKEN_COMMON; }
 <CODEBLOCK_EQUALS>{WS}	{ /* Skip blank */ }
 <CODEBLOCK_EQUALS>.		{ return yytext[0]; }
 
-<CODEBLOCK>\{			{ yyextra->numOpenBrackets++; appendCodeBlock(yyextra, yytext[0]); }
+<CODEBLOCK>\{			{ yyextra->numOpenBrackets++; appendCodeBlock(yyextra, yytext, 1); }
 <CODEBLOCK>\}			{ 
 	yyextra->numOpenBrackets--; 
 
@@ -357,9 +357,9 @@ Common			{ BEGIN(CODEBLOCK_HEADER); return TOKEN_COMMON; }
 		unput('0');
 	}
 	else
-		appendCodeBlock(yyextra, yytext[0]);
+		appendCodeBlock(yyextra, yytext, 1);
 }
-<CODEBLOCK>.|{SINGLEWS}		{ appendCodeBlock(yyextra, yytext[0]); }
+<CODEBLOCK>.|{SINGLEWS}		{ appendCodeBlock(yyextra, yytext, 1); }
 
 	/* Logic for manually inserting "Index = codeBlockIndex;". We insert arbitrary numbers which allows us to sequentially */
 	/* output all the tokens we need. We use only single-character values so we don't override anything in the text buffer */

+ 1 - 1
BansheeSL/Include/BsASTFX.h

@@ -306,7 +306,7 @@ void nodePush(ParseState* parseState, ASTFXNode* node);
 void nodePop(ParseState* parseState);
 
 void beginCodeBlock(ParseState* parseState);
-void appendCodeBlock(ParseState* parseState, char value);
+void appendCodeBlock(ParseState* parseState, const char* value, int size);
 int getCodeBlockIndex(ParseState* parseState);
 
 void addDefine(ParseState* parseState, const char* value);

+ 21 - 4
BansheeSL/Source/BsASTFX.c

@@ -207,15 +207,31 @@ void beginCodeBlock(ParseState* parseState)
 
 	parseState->numCodeStrings++;
 	parseState->codeStrings = codeString;
+
+	// Insert defines for code-blocks as we don't perform pre-processing within code blocks but we still want outer defines
+	// to be recognized by them (Performing pre-processing for code blocks is problematic because it would require parsing
+	// of all the language syntax in order to properly handle macro replacement).
+	for (int i = 0; i < parseState->numDefines; i++)
+	{
+		const char* define = "#define ";
+
+		appendCodeBlock(parseState, define, (int)strlen(define));
+		appendCodeBlock(parseState, parseState->defines[i], (int)strlen(parseState->defines[i]));
+	}
 }
 
-void appendCodeBlock(ParseState* parseState, char value)
+void appendCodeBlock(ParseState* parseState, const char* value, int size)
 {
 	CodeString* codeString = parseState->codeStrings;
 
-	if((codeString->size + 1) > codeString->capacity)
+	if ((codeString->size + size) > codeString->capacity)
 	{
-		int newCapacity = codeString->capacity * 2;
+		int newCapacity = codeString->capacity;
+		do 
+		{
+			newCapacity *= 2;
+		} while ((codeString->size + size) > newCapacity);
+
 		char* newBuffer = mmalloc(parseState->memContext, newCapacity);
 		memcpy(newBuffer, codeString->code, codeString->size);
 		mmfree(codeString->code);
@@ -224,7 +240,8 @@ void appendCodeBlock(ParseState* parseState, char value)
 		codeString->capacity = newCapacity;
 	}
 
-	codeString->code[codeString->size++] = value;
+	memcpy(&codeString->code[codeString->size], value, size);
+	codeString->size += size;
 }
 
 int getCodeBlockIndex(ParseState* parseState)

+ 2 - 0
BansheeSL/Source/BsSLFXCompiler.cpp

@@ -1251,6 +1251,8 @@ namespace BansheeEngine
 						techniqueData.language, GPT_COMPUTE_PROGRAM, getProfile(techniqueData.renderAPI, GPT_COMPUTE_PROGRAM));
 				}
 
+				passDesc.stencilRefValue = passData.stencilRefValue;
+
 				PassPtr pass = Pass::create(passDesc);
 				if (pass != nullptr)
 					passes[passData.seqIdx] = pass;

+ 2 - 2
RenderBeast/Source/BsRenderBeast.cpp

@@ -802,8 +802,8 @@ namespace BansheeEngine
 		RenderAPICore& rapi = RenderAPICore::instance();
 
 		Vector2 output;
-		output.x = rapi.getMaximumDepthInputValue() - rapi.getMinimumDepthInputValue();
-		output.y = -rapi.getMinimumDepthInputValue();
+		output.x = 1.0f / (rapi.getMaximumDepthInputValue() - rapi.getMinimumDepthInputValue());
+		output.y = -rapi.getMinimumDepthInputValue() * output.x;
 
 		return output;
 	}