OpenGLRenderer: Flip screenspace
This commit is contained in:
parent
ac7b523bc7
commit
d4f60c174e
|
|
@ -41,6 +41,7 @@ namespace Nz
|
||||||
unsigned int glMajorVersion = 3;
|
unsigned int glMajorVersion = 3;
|
||||||
unsigned int glMinorVersion = 0;
|
unsigned int glMinorVersion = 0;
|
||||||
bool glES = false;
|
bool glES = false;
|
||||||
|
bool flipYPosition = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ namespace Nz
|
||||||
ShaderAstCloner& operator=(const ShaderAstCloner&) = default;
|
ShaderAstCloner& operator=(const ShaderAstCloner&) = default;
|
||||||
ShaderAstCloner& operator=(ShaderAstCloner&&) = default;
|
ShaderAstCloner& operator=(ShaderAstCloner&&) = default;
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
ShaderNodes::ExpressionPtr CloneExpression(const ShaderNodes::ExpressionPtr& expr);
|
ShaderNodes::ExpressionPtr CloneExpression(const ShaderNodes::ExpressionPtr& expr);
|
||||||
ShaderNodes::StatementPtr CloneStatement(const ShaderNodes::StatementPtr& statement);
|
ShaderNodes::StatementPtr CloneStatement(const ShaderNodes::StatementPtr& statement);
|
||||||
ShaderNodes::VariablePtr CloneVariable(const ShaderNodes::VariablePtr& statement);
|
ShaderNodes::VariablePtr CloneVariable(const ShaderNodes::VariablePtr& statement);
|
||||||
|
|
@ -62,6 +62,7 @@ namespace Nz
|
||||||
ShaderNodes::StatementPtr PopStatement();
|
ShaderNodes::StatementPtr PopStatement();
|
||||||
ShaderNodes::VariablePtr PopVariable();
|
ShaderNodes::VariablePtr PopVariable();
|
||||||
|
|
||||||
|
private:
|
||||||
std::vector<ShaderNodes::ExpressionPtr> m_expressionStack;
|
std::vector<ShaderNodes::ExpressionPtr> m_expressionStack;
|
||||||
std::vector<ShaderNodes::StatementPtr> m_statementStack;
|
std::vector<ShaderNodes::StatementPtr> m_statementStack;
|
||||||
std::vector<ShaderNodes::VariablePtr> m_variableStack;
|
std::vector<ShaderNodes::VariablePtr> m_variableStack;
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
return context.IsExtensionSupported(std::string(ext));
|
return context.IsExtensionSupported(std::string(ext));
|
||||||
};
|
};
|
||||||
|
env.flipYPosition = true;
|
||||||
|
|
||||||
GlslWriter writer;
|
GlslWriter writer;
|
||||||
writer.SetEnv(env);
|
writer.SetEnv(env);
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,44 @@
|
||||||
#include <Nazara/Renderer/GlslWriter.hpp>
|
#include <Nazara/Renderer/GlslWriter.hpp>
|
||||||
#include <Nazara/Core/Algorithm.hpp>
|
#include <Nazara/Core/Algorithm.hpp>
|
||||||
#include <Nazara/Core/CallOnExit.hpp>
|
#include <Nazara/Core/CallOnExit.hpp>
|
||||||
|
#include <Nazara/Renderer/ShaderBuilder.hpp>
|
||||||
|
#include <Nazara/Renderer/ShaderAstCloner.hpp>
|
||||||
#include <Nazara/Renderer/ShaderAstValidator.hpp>
|
#include <Nazara/Renderer/ShaderAstValidator.hpp>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <Nazara/Renderer/Debug.hpp>
|
#include <Nazara/Renderer/Debug.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
struct AstAdapter : ShaderAstCloner
|
||||||
|
{
|
||||||
|
void Visit(ShaderNodes::AssignOp& node) override
|
||||||
|
{
|
||||||
|
if (!flipYPosition)
|
||||||
|
return ShaderAstCloner::Visit(node);
|
||||||
|
|
||||||
|
if (node.left->GetType() != ShaderNodes::NodeType::Identifier)
|
||||||
|
return ShaderAstCloner::Visit(node);
|
||||||
|
|
||||||
|
const auto& identifier = static_cast<const ShaderNodes::Identifier&>(*node.left);
|
||||||
|
if (identifier.var->GetType() != ShaderNodes::VariableType::BuiltinVariable)
|
||||||
|
return ShaderAstCloner::Visit(node);
|
||||||
|
|
||||||
|
const auto& builtinVar = static_cast<const ShaderNodes::BuiltinVariable&>(*identifier.var);
|
||||||
|
if (builtinVar.entry != ShaderNodes::BuiltinEntry::VertexPosition)
|
||||||
|
return ShaderAstCloner::Visit(node);
|
||||||
|
|
||||||
|
auto fixYConstant = ShaderBuilder::Constant(Nz::Vector4f(1.f, -1.f, 1.f, 1.f));
|
||||||
|
auto mulFix = ShaderBuilder::Multiply(CloneExpression(node.right), fixYConstant);
|
||||||
|
|
||||||
|
PushExpression(ShaderNodes::AssignOp::Build(node.op, CloneExpression(node.left), mulFix));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool flipYPosition = false;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
GlslWriter::GlslWriter() :
|
GlslWriter::GlslWriter() :
|
||||||
m_currentState(nullptr)
|
m_currentState(nullptr)
|
||||||
{
|
{
|
||||||
|
|
@ -237,7 +269,10 @@ namespace Nz
|
||||||
|
|
||||||
EnterScope();
|
EnterScope();
|
||||||
{
|
{
|
||||||
Visit(func.statement);
|
AstAdapter adapter;
|
||||||
|
adapter.flipYPosition = m_environment.flipYPosition;
|
||||||
|
|
||||||
|
Visit(adapter.Clone(func.statement));
|
||||||
}
|
}
|
||||||
LeaveScope();
|
LeaveScope();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue