mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 00:02:55 +00:00
Base for technique loading
This commit is contained in:
parent
a47370613b
commit
d8f490ec94
17
src/ObjLoading/Techset/Parsing/TechniqueFileParser.cpp
Normal file
17
src/ObjLoading/Techset/Parsing/TechniqueFileParser.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
#include "TechniqueFileParser.h"
|
||||
|
||||
using namespace techset;
|
||||
|
||||
TechniqueParser::TechniqueParser(SimpleLexer* lexer, ITechniqueDefinitionAcceptor* acceptor)
|
||||
: AbstractParser(lexer, std::make_unique<TechniqueParserState>(acceptor))
|
||||
{
|
||||
}
|
||||
|
||||
const std::vector<AbstractParser<SimpleParserValue, TechniqueParserState>::sequence_t*>& TechniqueParser::GetTestsForState()
|
||||
{
|
||||
// TODO: Tests
|
||||
static std::vector<sequence_t*> tests({
|
||||
});
|
||||
|
||||
return tests;
|
||||
}
|
18
src/ObjLoading/Techset/Parsing/TechniqueFileParser.h
Normal file
18
src/ObjLoading/Techset/Parsing/TechniqueFileParser.h
Normal file
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "TechniqueFileParserState.h"
|
||||
#include "Parsing/Simple/SimpleLexer.h"
|
||||
#include "Parsing/Simple/SimpleParserValue.h"
|
||||
#include "Parsing/Impl/AbstractParser.h"
|
||||
|
||||
namespace techset
|
||||
{
|
||||
class TechniqueParser final : public AbstractParser<SimpleParserValue, TechniqueParserState>
|
||||
{
|
||||
protected:
|
||||
const std::vector<sequence_t*>& GetTestsForState() override;
|
||||
|
||||
public:
|
||||
TechniqueParser(SimpleLexer* lexer, ITechniqueDefinitionAcceptor* acceptor);
|
||||
};
|
||||
}
|
11
src/ObjLoading/Techset/Parsing/TechniqueFileParserState.cpp
Normal file
11
src/ObjLoading/Techset/Parsing/TechniqueFileParserState.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
#include "TechniqueFileParserState.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
using namespace techset;
|
||||
|
||||
TechniqueParserState::TechniqueParserState(ITechniqueDefinitionAcceptor* acceptor)
|
||||
: m_acceptor(acceptor)
|
||||
{
|
||||
assert(acceptor);
|
||||
}
|
14
src/ObjLoading/Techset/Parsing/TechniqueFileParserState.h
Normal file
14
src/ObjLoading/Techset/Parsing/TechniqueFileParserState.h
Normal file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "Techset/TechniqueDefinitionAcceptor.h"
|
||||
|
||||
namespace techset
|
||||
{
|
||||
class TechniqueParserState
|
||||
{
|
||||
public:
|
||||
ITechniqueDefinitionAcceptor* const m_acceptor;
|
||||
|
||||
explicit TechniqueParserState(ITechniqueDefinitionAcceptor* acceptor);
|
||||
};
|
||||
}
|
54
src/ObjLoading/Techset/TechniqueDefinition.cpp
Normal file
54
src/ObjLoading/Techset/TechniqueDefinition.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
#include "TechniqueDefinition.h"
|
||||
|
||||
using namespace techset;
|
||||
|
||||
ShaderArgumentLiteralConstant::ShaderArgumentLiteralConstant()
|
||||
: m_value{}
|
||||
{
|
||||
}
|
||||
|
||||
ShaderArgumentLiteralConstant::ShaderArgumentLiteralConstant(const float v0, const float v1, const float v2, const float v3)
|
||||
: m_value{v0, v1, v2, v3}
|
||||
{
|
||||
}
|
||||
|
||||
ShaderArgumentLiteralConstant::ShaderArgumentLiteralConstant(float value[4])
|
||||
: m_value{value[0], value[1], value[2], value[3]}
|
||||
{
|
||||
}
|
||||
|
||||
bool techset::operator<(const ShaderArgumentLiteralConstant& lhs, const ShaderArgumentLiteralConstant& rhs)
|
||||
{
|
||||
if (lhs.m_value[0] < rhs.m_value[0])
|
||||
return true;
|
||||
if (lhs.m_value[0] > rhs.m_value[0])
|
||||
return false;
|
||||
if (lhs.m_value[1] < rhs.m_value[1])
|
||||
return true;
|
||||
if (lhs.m_value[1] > rhs.m_value[1])
|
||||
return false;
|
||||
if (lhs.m_value[2] < rhs.m_value[2])
|
||||
return true;
|
||||
if (lhs.m_value[2] > rhs.m_value[2])
|
||||
return false;
|
||||
if (lhs.m_value[3] < rhs.m_value[3])
|
||||
return true;
|
||||
if (lhs.m_value[3] > rhs.m_value[3])
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool techset::operator<=(const ShaderArgumentLiteralConstant& lhs, const ShaderArgumentLiteralConstant& rhs)
|
||||
{
|
||||
return !(rhs < lhs);
|
||||
}
|
||||
|
||||
bool techset::operator>(const ShaderArgumentLiteralConstant& lhs, const ShaderArgumentLiteralConstant& rhs)
|
||||
{
|
||||
return rhs < lhs;
|
||||
}
|
||||
|
||||
bool techset::operator>=(const ShaderArgumentLiteralConstant& lhs, const ShaderArgumentLiteralConstant& rhs)
|
||||
{
|
||||
return !(lhs < rhs);
|
||||
}
|
70
src/ObjLoading/Techset/TechniqueDefinition.h
Normal file
70
src/ObjLoading/Techset/TechniqueDefinition.h
Normal file
@ -0,0 +1,70 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace techset
|
||||
{
|
||||
enum class ShaderArgumentType
|
||||
{
|
||||
CODE_CONSTANT,
|
||||
LITERAL_CONSTANT,
|
||||
MATERIAL_CONSTANT
|
||||
};
|
||||
|
||||
class ShaderArgumentLiteralConstant
|
||||
{
|
||||
public:
|
||||
float m_value[4];
|
||||
|
||||
ShaderArgumentLiteralConstant();
|
||||
ShaderArgumentLiteralConstant(float v0, float v1, float v2, float v3);
|
||||
explicit ShaderArgumentLiteralConstant(float value[4]);
|
||||
|
||||
friend bool operator<(const ShaderArgumentLiteralConstant& lhs, const ShaderArgumentLiteralConstant& rhs);
|
||||
friend bool operator<=(const ShaderArgumentLiteralConstant& lhs, const ShaderArgumentLiteralConstant& rhs);
|
||||
friend bool operator>(const ShaderArgumentLiteralConstant& lhs, const ShaderArgumentLiteralConstant& rhs);
|
||||
friend bool operator>=(const ShaderArgumentLiteralConstant& lhs, const ShaderArgumentLiteralConstant& rhs);
|
||||
};
|
||||
|
||||
class ShaderArgumentDefinition
|
||||
{
|
||||
public:
|
||||
ShaderArgumentType m_type;
|
||||
std::string m_shader_argument_name;
|
||||
size_t m_shader_argument_index;
|
||||
|
||||
std::vector<std::string> m_code_constant_accessors;
|
||||
|
||||
ShaderArgumentLiteralConstant m_literal_constant;
|
||||
|
||||
bool m_material_constant_is_hash;
|
||||
size_t m_material_constant_hash;
|
||||
std::string m_material_constant_name;
|
||||
};
|
||||
|
||||
class ShaderDefinition
|
||||
{
|
||||
public:
|
||||
size_t m_version_major;
|
||||
size_t m_version_minor;
|
||||
std::string m_shader_name;
|
||||
std::vector<ShaderArgumentDefinition> m_arguments;
|
||||
};
|
||||
|
||||
class VertexStreamRoutingDefinition
|
||||
{
|
||||
std::string m_destination_name;
|
||||
std::string m_source_name;
|
||||
};
|
||||
|
||||
class TechniqueDefinition
|
||||
{
|
||||
public:
|
||||
std::string m_state_map;
|
||||
std::unique_ptr<ShaderDefinition> m_vertex_shader;
|
||||
std::unique_ptr<ShaderDefinition> m_pixel_shader;
|
||||
std::vector<VertexStreamRoutingDefinition> m_vertex_stream_routing;
|
||||
};
|
||||
}
|
104
src/ObjLoading/Techset/TechniqueDefinitionAcceptor.cpp
Normal file
104
src/ObjLoading/Techset/TechniqueDefinitionAcceptor.cpp
Normal file
@ -0,0 +1,104 @@
|
||||
#include "TechniqueDefinitionAcceptor.h"
|
||||
|
||||
using namespace techset;
|
||||
|
||||
ShaderArgument::ShaderArgument()
|
||||
: m_argument_index(0u)
|
||||
{
|
||||
}
|
||||
|
||||
ShaderArgument::ShaderArgument(std::string argumentName, const size_t argumentIndex)
|
||||
: m_argument_name(std::move(argumentName)),
|
||||
m_argument_index(argumentIndex)
|
||||
{
|
||||
}
|
||||
|
||||
ShaderArgumentCodeSource::ShaderArgumentCodeSource()
|
||||
: m_index_accessor_specified(false),
|
||||
m_index_accessor(0u)
|
||||
{
|
||||
}
|
||||
|
||||
ShaderArgumentCodeSource::ShaderArgumentCodeSource(std::vector<std::string> accessors)
|
||||
: m_accessors(std::move(accessors)),
|
||||
m_index_accessor_specified(false),
|
||||
m_index_accessor(0u)
|
||||
{
|
||||
}
|
||||
|
||||
ShaderArgumentCodeSource::ShaderArgumentCodeSource(std::vector<std::string> accessors, const size_t indexAccessor)
|
||||
: m_accessors(std::move(accessors)),
|
||||
m_index_accessor_specified(true),
|
||||
m_index_accessor(indexAccessor)
|
||||
{
|
||||
}
|
||||
|
||||
ShaderArgumentLiteralSource::ShaderArgumentLiteralSource()
|
||||
: m_value{}
|
||||
{
|
||||
}
|
||||
|
||||
ShaderArgumentLiteralSource::ShaderArgumentLiteralSource(const float v0, const float v1, const float v2, const float v3)
|
||||
: m_value{v0, v1, v2, v3}
|
||||
{
|
||||
}
|
||||
|
||||
ShaderArgumentLiteralSource::ShaderArgumentLiteralSource(float value[4])
|
||||
: m_value{value[0], value[1], value[2], value[3]}
|
||||
{
|
||||
}
|
||||
|
||||
bool techset::operator<(const ShaderArgumentLiteralSource& lhs, const ShaderArgumentLiteralSource& rhs)
|
||||
{
|
||||
if (lhs.m_value[0] < rhs.m_value[0])
|
||||
return true;
|
||||
if (lhs.m_value[0] > rhs.m_value[0])
|
||||
return false;
|
||||
if (lhs.m_value[1] < rhs.m_value[1])
|
||||
return true;
|
||||
if (lhs.m_value[1] > rhs.m_value[1])
|
||||
return false;
|
||||
if (lhs.m_value[2] < rhs.m_value[2])
|
||||
return true;
|
||||
if (lhs.m_value[2] > rhs.m_value[2])
|
||||
return false;
|
||||
if (lhs.m_value[3] < rhs.m_value[3])
|
||||
return true;
|
||||
if (lhs.m_value[3] > rhs.m_value[3])
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool techset::operator<=(const ShaderArgumentLiteralSource& lhs, const ShaderArgumentLiteralSource& rhs)
|
||||
{
|
||||
return !(rhs < lhs);
|
||||
}
|
||||
|
||||
bool techset::operator>(const ShaderArgumentLiteralSource& lhs, const ShaderArgumentLiteralSource& rhs)
|
||||
{
|
||||
return rhs < lhs;
|
||||
}
|
||||
|
||||
bool techset::operator>=(const ShaderArgumentLiteralSource& lhs, const ShaderArgumentLiteralSource& rhs)
|
||||
{
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
|
||||
ShaderArgumentMaterialSource::ShaderArgumentMaterialSource()
|
||||
: m_is_hash(false),
|
||||
m_hash(0u)
|
||||
{
|
||||
}
|
||||
|
||||
ShaderArgumentMaterialSource::ShaderArgumentMaterialSource(const size_t hash)
|
||||
: m_is_hash(true),
|
||||
m_hash(hash)
|
||||
{
|
||||
}
|
||||
|
||||
ShaderArgumentMaterialSource::ShaderArgumentMaterialSource(std::string name)
|
||||
: m_is_hash(false),
|
||||
m_hash(0u),
|
||||
m_name(std::move(name))
|
||||
{
|
||||
}
|
84
src/ObjLoading/Techset/TechniqueDefinitionAcceptor.h
Normal file
84
src/ObjLoading/Techset/TechniqueDefinitionAcceptor.h
Normal file
@ -0,0 +1,84 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace techset
|
||||
{
|
||||
enum class ShaderSelector
|
||||
{
|
||||
VERTEX_SHADER,
|
||||
PIXEL_SHADER
|
||||
};
|
||||
|
||||
class ShaderArgument
|
||||
{
|
||||
public:
|
||||
std::string m_argument_name;
|
||||
size_t m_argument_index;
|
||||
|
||||
ShaderArgument();
|
||||
ShaderArgument(std::string argumentName, size_t argumentIndex);
|
||||
};
|
||||
|
||||
class ShaderArgumentCodeSource
|
||||
{
|
||||
public:
|
||||
std::vector<std::string> m_accessors;
|
||||
bool m_index_accessor_specified;
|
||||
size_t m_index_accessor;
|
||||
|
||||
ShaderArgumentCodeSource();
|
||||
explicit ShaderArgumentCodeSource(std::vector<std::string> accessors);
|
||||
ShaderArgumentCodeSource(std::vector<std::string> accessors, size_t indexAccessor);
|
||||
};
|
||||
|
||||
class ShaderArgumentLiteralSource
|
||||
{
|
||||
public:
|
||||
float m_value[4];
|
||||
|
||||
ShaderArgumentLiteralSource();
|
||||
ShaderArgumentLiteralSource(float v0, float v1, float v2, float v3);
|
||||
explicit ShaderArgumentLiteralSource(float value[4]);
|
||||
|
||||
friend bool operator<(const ShaderArgumentLiteralSource& lhs, const ShaderArgumentLiteralSource& rhs);
|
||||
friend bool operator<=(const ShaderArgumentLiteralSource& lhs, const ShaderArgumentLiteralSource& rhs);
|
||||
friend bool operator>(const ShaderArgumentLiteralSource& lhs, const ShaderArgumentLiteralSource& rhs);
|
||||
friend bool operator>=(const ShaderArgumentLiteralSource& lhs, const ShaderArgumentLiteralSource& rhs);
|
||||
};
|
||||
|
||||
class ShaderArgumentMaterialSource
|
||||
{
|
||||
public:
|
||||
bool m_is_hash;
|
||||
size_t m_hash;
|
||||
std::string m_name;
|
||||
|
||||
ShaderArgumentMaterialSource();
|
||||
explicit ShaderArgumentMaterialSource(size_t hash);
|
||||
explicit ShaderArgumentMaterialSource(std::string name);
|
||||
};
|
||||
|
||||
class ITechniqueDefinitionAcceptor
|
||||
{
|
||||
protected:
|
||||
ITechniqueDefinitionAcceptor() = default;
|
||||
public:
|
||||
virtual ~ITechniqueDefinitionAcceptor() = default;
|
||||
ITechniqueDefinitionAcceptor(const ITechniqueDefinitionAcceptor& other) = default;
|
||||
ITechniqueDefinitionAcceptor(ITechniqueDefinitionAcceptor&& other) noexcept = default;
|
||||
ITechniqueDefinitionAcceptor& operator=(const ITechniqueDefinitionAcceptor& other) = default;
|
||||
ITechniqueDefinitionAcceptor& operator=(ITechniqueDefinitionAcceptor&& other) noexcept = default;
|
||||
|
||||
virtual void AcceptStateMap(const std::string& stateMapName) = 0;
|
||||
|
||||
virtual bool AcceptVertexShader(size_t shaderVersionMajor, size_t shaderVersionMinor, const std::string& vertexShaderName, std::string& errorMessage) = 0;
|
||||
virtual bool AcceptPixelShader(size_t shaderVersionMajor, size_t shaderVersionMinor, const std::string& vertexShaderName, std::string& errorMessage) = 0;
|
||||
|
||||
virtual bool AcceptShaderCodeArgument(ShaderSelector shader, ShaderArgument shaderArgument, ShaderArgumentCodeSource source, std::string& errorMessage) = 0;
|
||||
virtual bool AcceptShaderLiteralArgument(ShaderSelector shader, ShaderArgument shaderArgument, ShaderArgumentLiteralSource source, std::string& errorMessage) = 0;
|
||||
virtual bool AcceptShaderMaterialArgument(ShaderSelector shader, ShaderArgument shaderArgument, ShaderArgumentMaterialSource source, std::string& errorMessage) = 0;
|
||||
|
||||
virtual bool AcceptVertexStreamRouting(const std::string& destination, const std::string& source, std::string& errorMessage) = 0;
|
||||
};
|
||||
}
|
36
src/ObjLoading/Techset/TechniqueFileReader.cpp
Normal file
36
src/ObjLoading/Techset/TechniqueFileReader.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#include "TechniqueFileReader.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "Parsing/TechniqueFileParser.h"
|
||||
#include "Parsing/Impl/CommentRemovingStreamProxy.h"
|
||||
#include "Parsing/Impl/ParserSingleInputStream.h"
|
||||
#include "Parsing/Simple/SimpleLexer.h"
|
||||
|
||||
using namespace techset;
|
||||
|
||||
TechniqueFileReader::TechniqueFileReader(std::istream& stream, std::string fileName, ITechniqueDefinitionAcceptor* acceptor)
|
||||
: m_file_name(std::move(fileName)),
|
||||
m_acceptor(acceptor)
|
||||
{
|
||||
m_base_stream = std::make_unique<ParserSingleInputStream>(stream, m_file_name);
|
||||
m_comment_proxy = std::make_unique<CommentRemovingStreamProxy>(m_base_stream.get());
|
||||
}
|
||||
|
||||
bool TechniqueFileReader::ReadTechniqueDefinition() const
|
||||
{
|
||||
SimpleLexer::Config lexerConfig;
|
||||
lexerConfig.m_emit_new_line_tokens = false;
|
||||
lexerConfig.m_read_strings = true;
|
||||
lexerConfig.m_read_numbers = true;
|
||||
const auto lexer = std::make_unique<SimpleLexer>(m_comment_proxy.get(), std::move(lexerConfig));
|
||||
|
||||
const auto parser = std::make_unique<TechniqueParser>(lexer.get(), m_acceptor);
|
||||
|
||||
const auto success = parser->Parse();
|
||||
if (success)
|
||||
return true;
|
||||
|
||||
std::cout << "Parsing technique file \"" << m_file_name << "\" failed!\n";
|
||||
return false;
|
||||
}
|
24
src/ObjLoading/Techset/TechniqueFileReader.h
Normal file
24
src/ObjLoading/Techset/TechniqueFileReader.h
Normal file
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "TechniqueDefinitionAcceptor.h"
|
||||
#include "Parsing/IParserLineStream.h"
|
||||
|
||||
namespace techset
|
||||
{
|
||||
class TechniqueFileReader
|
||||
{
|
||||
std::string m_file_name;
|
||||
ITechniqueDefinitionAcceptor* m_acceptor;
|
||||
std::unique_ptr<IParserLineStream> m_base_stream;
|
||||
std::unique_ptr<IParserLineStream> m_comment_proxy;
|
||||
|
||||
public:
|
||||
TechniqueFileReader(std::istream& stream, std::string fileName, ITechniqueDefinitionAcceptor* acceptor);
|
||||
|
||||
_NODISCARD bool ReadTechniqueDefinition() const;
|
||||
};
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user