Apply clang-format to code base

This commit is contained in:
clang-format-bot 2022-09-22 21:26:05 +03:00 committed by ζeh Matt
parent f37d0be806
commit ddb0522bbf
No known key found for this signature in database
GPG key ID: 18CE582C71A225B0
2199 changed files with 118692 additions and 114392 deletions

View file

@ -1,13 +1,13 @@
#include "lexer.hpp"
#include <string_view>
#include <string>
#include <variant>
#include <optional>
#include <cstdint>
#include <array>
#include <cmath>
#include <cstdint>
#include <exception>
#include <optional>
#include <string>
#include <string_view>
#include <variant>
#include <components/misc/strings/format.hpp>
@ -27,7 +27,8 @@ namespace fx
, mLine(0)
, mBuffer(buffer)
, mLastToken(Eof{})
{ }
{
}
Token Lexer::next()
{
@ -114,7 +115,7 @@ namespace fx
if (level == 0)
{
mHead--;
auto sv = std::string_view{start, static_cast<std::string_view::size_type>(mHead + 1 - start)};
auto sv = std::string_view{ start, static_cast<std::string_view::size_type>(mHead + 1 - start) };
mLastJumpBlock.content = sv;
return sv;
}
@ -158,7 +159,7 @@ namespace fx
while (true)
{
if (mHead == mTail)
return {Eof{}};
return { Eof{} };
if (head() == '\n')
{
@ -181,38 +182,38 @@ namespace fx
if (std::isdigit(head()) || head() == '.' || head() == '-')
return scanNumber();
switch(head())
switch (head())
{
case '=':
advance();
return {Equal{}};
return { Equal{} };
case '{':
advance();
return {Open_bracket{}};
return { Open_bracket{} };
case '}':
advance();
return {Close_bracket{}};
return { Close_bracket{} };
case '(':
advance();
return {Open_Parenthesis{}};
return { Open_Parenthesis{} };
case ')':
advance();
return {Close_Parenthesis{}};
return { Close_Parenthesis{} };
case '\"':
advance();
return {Quote{}};
return { Quote{} };
case ':':
advance();
return {Colon{}};
return { Colon{} };
case ';':
advance();
return {SemiColon{}};
return { SemiColon{} };
case '|':
advance();
return {VBar{}};
return { VBar{} };
case ',':
advance();
return {Comma{}};
return { Comma{} };
default:
error(Misc::StringUtils::format("unexpected token <%c>", head()));
}
@ -226,30 +227,50 @@ namespace fx
while (mHead != mTail && (std::isalnum(head()) || head() == '_'))
advance();
std::string_view value{start, static_cast<std::string_view::size_type>(mHead - start)};
std::string_view value{ start, static_cast<std::string_view::size_type>(mHead - start) };
if (value == "shared") return Shared{};
if (value == "technique") return Technique{};
if (value == "render_target") return Render_Target{};
if (value == "vertex") return Vertex{};
if (value == "fragment") return Fragment{};
if (value == "compute") return Compute{};
if (value == "sampler_1d") return Sampler_1D{};
if (value == "sampler_2d") return Sampler_2D{};
if (value == "sampler_3d") return Sampler_3D{};
if (value == "uniform_bool") return Uniform_Bool{};
if (value == "uniform_float") return Uniform_Float{};
if (value == "uniform_int") return Uniform_Int{};
if (value == "uniform_vec2") return Uniform_Vec2{};
if (value == "uniform_vec3") return Uniform_Vec3{};
if (value == "uniform_vec4") return Uniform_Vec4{};
if (value == "true") return True{};
if (value == "false") return False{};
if (value == "vec2") return Vec2{};
if (value == "vec3") return Vec3{};
if (value == "vec4") return Vec4{};
if (value == "shared")
return Shared{};
if (value == "technique")
return Technique{};
if (value == "render_target")
return Render_Target{};
if (value == "vertex")
return Vertex{};
if (value == "fragment")
return Fragment{};
if (value == "compute")
return Compute{};
if (value == "sampler_1d")
return Sampler_1D{};
if (value == "sampler_2d")
return Sampler_2D{};
if (value == "sampler_3d")
return Sampler_3D{};
if (value == "uniform_bool")
return Uniform_Bool{};
if (value == "uniform_float")
return Uniform_Float{};
if (value == "uniform_int")
return Uniform_Int{};
if (value == "uniform_vec2")
return Uniform_Vec2{};
if (value == "uniform_vec3")
return Uniform_Vec3{};
if (value == "uniform_vec4")
return Uniform_Vec4{};
if (value == "true")
return True{};
if (value == "false")
return False{};
if (value == "vec2")
return Vec2{};
if (value == "vec3")
return Vec3{};
if (value == "vec4")
return Vec4{};
return Literal{value};
return Literal{ value };
}
Token Lexer::scanStringLiteral()
@ -272,7 +293,7 @@ namespace fx
if (!terminated)
error("unterminated string");
return String{{start, static_cast<std::string_view::size_type>(mHead - start - 1)}};
return String{ { start, static_cast<std::string_view::size_type>(mHead - start - 1) } };
}
Token Lexer::scanNumber()
@ -291,10 +312,10 @@ namespace fx
for (; tmp != endPtr; ++tmp)
{
if ((*tmp == '.'))
return Float{static_cast<float>(buffer)};
return Float{ static_cast<float>(buffer) };
}
return Integer{static_cast<int>(buffer)};
return Integer{ static_cast<int>(buffer) };
}
}
}

View file

@ -1,12 +1,12 @@
#ifndef OPENMW_COMPONENTS_FX_LEXER_H
#define OPENMW_COMPONENTS_FX_LEXER_H
#include <string_view>
#include <string>
#include <variant>
#include <optional>
#include <cstdint>
#include <optional>
#include <stdexcept>
#include <string>
#include <string_view>
#include <variant>
#include <osg/Vec2f>
#include <osg/Vec3f>
@ -20,8 +20,14 @@ namespace fx
{
struct LexerException : std::runtime_error
{
LexerException(const std::string& message) : std::runtime_error(message) {}
LexerException(const char* message) : std::runtime_error(message) {}
LexerException(const std::string& message)
: std::runtime_error(message)
{
}
LexerException(const char* message)
: std::runtime_error(message)
{
}
};
class Lexer

View file

@ -1,54 +1,167 @@
#ifndef OPENMW_COMPONENTS_FX_LEXER_TYPES_H
#define OPENMW_COMPONENTS_FX_LEXER_TYPES_H
#include <variant>
#include <string_view>
#include <variant>
namespace fx
{
namespace Lexer
{
struct Float { inline static constexpr std::string_view repr = "float"; float value = 0.0;};
struct Integer { inline static constexpr std::string_view repr = "integer"; int value = 0;};
struct Boolean { inline static constexpr std::string_view repr = "boolean"; bool value = false;};
struct Literal { inline static constexpr std::string_view repr = "literal"; std::string_view value;};
struct String { inline static constexpr std::string_view repr = "string"; std::string_view value;};
struct Shared { inline static constexpr std::string_view repr = "shared"; };
struct Vertex { inline static constexpr std::string_view repr = "vertex"; };
struct Fragment { inline static constexpr std::string_view repr = "fragment"; };
struct Compute { inline static constexpr std::string_view repr = "compute"; };
struct Technique { inline static constexpr std::string_view repr = "technique"; };
struct Render_Target { inline static constexpr std::string_view repr = "render_target"; };
struct Sampler_1D { inline static constexpr std::string_view repr = "sampler_1d"; };
struct Sampler_2D { inline static constexpr std::string_view repr = "sampler_2d"; };
struct Sampler_3D { inline static constexpr std::string_view repr = "sampler_3d"; };
struct Uniform_Bool { inline static constexpr std::string_view repr = "uniform_bool"; };
struct Uniform_Float { inline static constexpr std::string_view repr = "uniform_float"; };
struct Uniform_Int { inline static constexpr std::string_view repr = "uniform_int"; };
struct Uniform_Vec2 { inline static constexpr std::string_view repr = "uniform_vec2"; };
struct Uniform_Vec3 { inline static constexpr std::string_view repr = "uniform_vec3"; };
struct Uniform_Vec4 { inline static constexpr std::string_view repr = "uniform_vec4"; };
struct Eof { inline static constexpr std::string_view repr = "eof"; };
struct Equal { inline static constexpr std::string_view repr = "equal"; };
struct Open_bracket { inline static constexpr std::string_view repr = "open_bracket"; };
struct Close_bracket { inline static constexpr std::string_view repr = "close_bracket"; };
struct Open_Parenthesis { inline static constexpr std::string_view repr = "open_parenthesis"; };
struct Close_Parenthesis{ inline static constexpr std::string_view repr = "close_parenthesis"; };
struct Quote { inline static constexpr std::string_view repr = "quote"; };
struct SemiColon { inline static constexpr std::string_view repr = "semicolon"; };
struct Comma { inline static constexpr std::string_view repr = "comma"; };
struct VBar { inline static constexpr std::string_view repr = "vbar"; };
struct Colon { inline static constexpr std::string_view repr = "colon"; };
struct True { inline static constexpr std::string_view repr = "true"; };
struct False { inline static constexpr std::string_view repr = "false"; };
struct Vec2 { inline static constexpr std::string_view repr = "vec2"; };
struct Vec3 { inline static constexpr std::string_view repr = "vec3"; };
struct Vec4 { inline static constexpr std::string_view repr = "vec4"; };
struct Float
{
inline static constexpr std::string_view repr = "float";
float value = 0.0;
};
struct Integer
{
inline static constexpr std::string_view repr = "integer";
int value = 0;
};
struct Boolean
{
inline static constexpr std::string_view repr = "boolean";
bool value = false;
};
struct Literal
{
inline static constexpr std::string_view repr = "literal";
std::string_view value;
};
struct String
{
inline static constexpr std::string_view repr = "string";
std::string_view value;
};
struct Shared
{
inline static constexpr std::string_view repr = "shared";
};
struct Vertex
{
inline static constexpr std::string_view repr = "vertex";
};
struct Fragment
{
inline static constexpr std::string_view repr = "fragment";
};
struct Compute
{
inline static constexpr std::string_view repr = "compute";
};
struct Technique
{
inline static constexpr std::string_view repr = "technique";
};
struct Render_Target
{
inline static constexpr std::string_view repr = "render_target";
};
struct Sampler_1D
{
inline static constexpr std::string_view repr = "sampler_1d";
};
struct Sampler_2D
{
inline static constexpr std::string_view repr = "sampler_2d";
};
struct Sampler_3D
{
inline static constexpr std::string_view repr = "sampler_3d";
};
struct Uniform_Bool
{
inline static constexpr std::string_view repr = "uniform_bool";
};
struct Uniform_Float
{
inline static constexpr std::string_view repr = "uniform_float";
};
struct Uniform_Int
{
inline static constexpr std::string_view repr = "uniform_int";
};
struct Uniform_Vec2
{
inline static constexpr std::string_view repr = "uniform_vec2";
};
struct Uniform_Vec3
{
inline static constexpr std::string_view repr = "uniform_vec3";
};
struct Uniform_Vec4
{
inline static constexpr std::string_view repr = "uniform_vec4";
};
struct Eof
{
inline static constexpr std::string_view repr = "eof";
};
struct Equal
{
inline static constexpr std::string_view repr = "equal";
};
struct Open_bracket
{
inline static constexpr std::string_view repr = "open_bracket";
};
struct Close_bracket
{
inline static constexpr std::string_view repr = "close_bracket";
};
struct Open_Parenthesis
{
inline static constexpr std::string_view repr = "open_parenthesis";
};
struct Close_Parenthesis
{
inline static constexpr std::string_view repr = "close_parenthesis";
};
struct Quote
{
inline static constexpr std::string_view repr = "quote";
};
struct SemiColon
{
inline static constexpr std::string_view repr = "semicolon";
};
struct Comma
{
inline static constexpr std::string_view repr = "comma";
};
struct VBar
{
inline static constexpr std::string_view repr = "vbar";
};
struct Colon
{
inline static constexpr std::string_view repr = "colon";
};
struct True
{
inline static constexpr std::string_view repr = "true";
};
struct False
{
inline static constexpr std::string_view repr = "false";
};
struct Vec2
{
inline static constexpr std::string_view repr = "vec2";
};
struct Vec3
{
inline static constexpr std::string_view repr = "vec3";
};
struct Vec4
{
inline static constexpr std::string_view repr = "vec4";
};
using Token = std::variant<Float, Integer, Boolean, String, Literal, Equal, Open_bracket, Close_bracket, Open_Parenthesis,
Close_Parenthesis, Quote, SemiColon, Comma, VBar, Colon, Shared, Technique, Render_Target, Vertex, Fragment,
Compute, Sampler_1D, Sampler_2D, Sampler_3D, Uniform_Bool, Uniform_Float, Uniform_Int, Uniform_Vec2, Uniform_Vec3, Uniform_Vec4,
True, False, Vec2, Vec3, Vec4, Eof>;
using Token = std::variant<Float, Integer, Boolean, String, Literal, Equal, Open_bracket, Close_bracket,
Open_Parenthesis, Close_Parenthesis, Quote, SemiColon, Comma, VBar, Colon, Shared, Technique, Render_Target,
Vertex, Fragment, Compute, Sampler_1D, Sampler_2D, Sampler_3D, Uniform_Bool, Uniform_Float, Uniform_Int,
Uniform_Vec2, Uniform_Vec3, Uniform_Vec4, True, False, Vec2, Vec3, Vec4, Eof>;
}
}

View file

@ -4,10 +4,10 @@
#include <array>
#include <string_view>
#include <osg/Texture>
#include <osg/Image>
#include <osg/BlendFunc>
#include <osg/BlendEquation>
#include <osg/BlendFunc>
#include <osg/Image>
#include <osg/Texture>
#include <components/sceneutil/color.hpp>
@ -17,116 +17,116 @@ namespace fx
{
namespace constants
{
constexpr std::array<std::pair<std::string_view, fx::FlagsType>, 6> TechniqueFlag = {{
{"disable_interiors" , Technique::Flag_Disable_Interiors},
{"disable_exteriors" , Technique::Flag_Disable_Exteriors},
{"disable_underwater" , Technique::Flag_Disable_Underwater},
{"disable_abovewater" , Technique::Flag_Disable_Abovewater},
{"disable_sunglare" , Technique::Flag_Disable_SunGlare},
{"hidden" , Technique::Flag_Hidden},
}};
constexpr std::array<std::pair<std::string_view, fx::FlagsType>, 6> TechniqueFlag = { {
{ "disable_interiors", Technique::Flag_Disable_Interiors },
{ "disable_exteriors", Technique::Flag_Disable_Exteriors },
{ "disable_underwater", Technique::Flag_Disable_Underwater },
{ "disable_abovewater", Technique::Flag_Disable_Abovewater },
{ "disable_sunglare", Technique::Flag_Disable_SunGlare },
{ "hidden", Technique::Flag_Hidden },
} };
constexpr std::array<std::pair<std::string_view, int>, 6> SourceFormat = {{
{"red" , GL_RED},
{"rg" , GL_RG},
{"rgb" , GL_RGB},
{"bgr" , GL_BGR},
{"rgba", GL_RGBA},
{"bgra", GL_BGRA},
}};
constexpr std::array<std::pair<std::string_view, int>, 6> SourceFormat = { {
{ "red", GL_RED },
{ "rg", GL_RG },
{ "rgb", GL_RGB },
{ "bgr", GL_BGR },
{ "rgba", GL_RGBA },
{ "bgra", GL_BGRA },
} };
constexpr std::array<std::pair<std::string_view, int>, 9> SourceType = {{
{"byte" , GL_BYTE},
{"unsigned_byte" , GL_UNSIGNED_BYTE},
{"short" , GL_SHORT},
{"unsigned_short" , GL_UNSIGNED_SHORT},
{"int" , GL_INT},
{"unsigned_int" , GL_UNSIGNED_INT},
{"unsigned_int_24_8", GL_UNSIGNED_INT_24_8},
{"float" , GL_FLOAT},
{"double" , GL_DOUBLE},
}};
constexpr std::array<std::pair<std::string_view, int>, 9> SourceType = { {
{ "byte", GL_BYTE },
{ "unsigned_byte", GL_UNSIGNED_BYTE },
{ "short", GL_SHORT },
{ "unsigned_short", GL_UNSIGNED_SHORT },
{ "int", GL_INT },
{ "unsigned_int", GL_UNSIGNED_INT },
{ "unsigned_int_24_8", GL_UNSIGNED_INT_24_8 },
{ "float", GL_FLOAT },
{ "double", GL_DOUBLE },
} };
constexpr std::array<std::pair<std::string_view, int>, 16> InternalFormat = {{
{"red" , GL_RED},
{"r16f" , GL_R16F},
{"r32f" , GL_R32F},
{"rg" , GL_RG},
{"rg16f" , GL_RG16F},
{"rg32f" , GL_RG32F},
{"rgb" , GL_RGB},
{"rgb16f" , GL_RGB16F},
{"rgb32f" , GL_RGB32F},
{"rgba" , GL_RGBA},
{"rgba16f" , GL_RGBA16F},
{"rgba32f" , GL_RGBA32F},
{"depth_component16" , GL_DEPTH_COMPONENT16},
{"depth_component24" , GL_DEPTH_COMPONENT24},
{"depth_component32" , GL_DEPTH_COMPONENT32},
{"depth_component32f", GL_DEPTH_COMPONENT32F},
}};
constexpr std::array<std::pair<std::string_view, int>, 16> InternalFormat = { {
{ "red", GL_RED },
{ "r16f", GL_R16F },
{ "r32f", GL_R32F },
{ "rg", GL_RG },
{ "rg16f", GL_RG16F },
{ "rg32f", GL_RG32F },
{ "rgb", GL_RGB },
{ "rgb16f", GL_RGB16F },
{ "rgb32f", GL_RGB32F },
{ "rgba", GL_RGBA },
{ "rgba16f", GL_RGBA16F },
{ "rgba32f", GL_RGBA32F },
{ "depth_component16", GL_DEPTH_COMPONENT16 },
{ "depth_component24", GL_DEPTH_COMPONENT24 },
{ "depth_component32", GL_DEPTH_COMPONENT32 },
{ "depth_component32f", GL_DEPTH_COMPONENT32F },
} };
constexpr std::array<std::pair<std::string_view, osg::Texture::InternalFormatMode>, 13> Compression = {{
{"auto" , osg::Texture::USE_USER_DEFINED_FORMAT},
{"arb" , osg::Texture::USE_ARB_COMPRESSION},
{"s3tc_dxt1" , osg::Texture::USE_S3TC_DXT1_COMPRESSION},
{"s3tc_dxt3" , osg::Texture::USE_S3TC_DXT3_COMPRESSION},
{"s3tc_dxt5" , osg::Texture::USE_S3TC_DXT5_COMPRESSION},
{"pvrtc_2bpp" , osg::Texture::USE_PVRTC_2BPP_COMPRESSION},
{"pvrtc_4bpp" , osg::Texture::USE_PVRTC_4BPP_COMPRESSION},
{"etc" , osg::Texture::USE_ETC_COMPRESSION},
{"etc2" , osg::Texture::USE_ETC2_COMPRESSION},
{"rgtc1" , osg::Texture::USE_RGTC1_COMPRESSION},
{"rgtc2" , osg::Texture::USE_RGTC2_COMPRESSION},
{"s3tc_dxt1c" , osg::Texture::USE_S3TC_DXT1c_COMPRESSION},
{"s3tc_dxt1a" , osg::Texture::USE_S3TC_DXT1a_COMPRESSION},
}};
constexpr std::array<std::pair<std::string_view, osg::Texture::InternalFormatMode>, 13> Compression = { {
{ "auto", osg::Texture::USE_USER_DEFINED_FORMAT },
{ "arb", osg::Texture::USE_ARB_COMPRESSION },
{ "s3tc_dxt1", osg::Texture::USE_S3TC_DXT1_COMPRESSION },
{ "s3tc_dxt3", osg::Texture::USE_S3TC_DXT3_COMPRESSION },
{ "s3tc_dxt5", osg::Texture::USE_S3TC_DXT5_COMPRESSION },
{ "pvrtc_2bpp", osg::Texture::USE_PVRTC_2BPP_COMPRESSION },
{ "pvrtc_4bpp", osg::Texture::USE_PVRTC_4BPP_COMPRESSION },
{ "etc", osg::Texture::USE_ETC_COMPRESSION },
{ "etc2", osg::Texture::USE_ETC2_COMPRESSION },
{ "rgtc1", osg::Texture::USE_RGTC1_COMPRESSION },
{ "rgtc2", osg::Texture::USE_RGTC2_COMPRESSION },
{ "s3tc_dxt1c", osg::Texture::USE_S3TC_DXT1c_COMPRESSION },
{ "s3tc_dxt1a", osg::Texture::USE_S3TC_DXT1a_COMPRESSION },
} };
constexpr std::array<std::pair<std::string_view, osg::Texture::WrapMode>, 6> WrapMode = {{
{"clamp" , osg::Texture::CLAMP},
{"clamp_to_edge" , osg::Texture::CLAMP_TO_EDGE},
{"clamp_to_border", osg::Texture::CLAMP_TO_BORDER},
{"repeat" , osg::Texture::REPEAT},
{"mirror" , osg::Texture::MIRROR},
}};
constexpr std::array<std::pair<std::string_view, osg::Texture::WrapMode>, 6> WrapMode = { {
{ "clamp", osg::Texture::CLAMP },
{ "clamp_to_edge", osg::Texture::CLAMP_TO_EDGE },
{ "clamp_to_border", osg::Texture::CLAMP_TO_BORDER },
{ "repeat", osg::Texture::REPEAT },
{ "mirror", osg::Texture::MIRROR },
} };
constexpr std::array<std::pair<std::string_view, osg::Texture::FilterMode>, 6> FilterMode = {{
{"linear" , osg::Texture::LINEAR},
{"linear_mipmap_linear" , osg::Texture::LINEAR_MIPMAP_LINEAR},
{"linear_mipmap_nearest" , osg::Texture::LINEAR_MIPMAP_NEAREST},
{"nearest" , osg::Texture::NEAREST},
{"nearest_mipmap_linear" , osg::Texture::NEAREST_MIPMAP_LINEAR},
{"nearest_mipmap_nearest", osg::Texture::NEAREST_MIPMAP_NEAREST},
}};
constexpr std::array<std::pair<std::string_view, osg::Texture::FilterMode>, 6> FilterMode = { {
{ "linear", osg::Texture::LINEAR },
{ "linear_mipmap_linear", osg::Texture::LINEAR_MIPMAP_LINEAR },
{ "linear_mipmap_nearest", osg::Texture::LINEAR_MIPMAP_NEAREST },
{ "nearest", osg::Texture::NEAREST },
{ "nearest_mipmap_linear", osg::Texture::NEAREST_MIPMAP_LINEAR },
{ "nearest_mipmap_nearest", osg::Texture::NEAREST_MIPMAP_NEAREST },
} };
constexpr std::array<std::pair<std::string_view, osg::BlendFunc::BlendFuncMode>, 15> BlendFunc = {{
{"dst_alpha" , osg::BlendFunc::DST_ALPHA},
{"dst_color" , osg::BlendFunc::DST_COLOR},
{"one" , osg::BlendFunc::ONE},
{"one_minus_dst_alpha" , osg::BlendFunc::ONE_MINUS_DST_ALPHA},
{"one_minus_dst_color" , osg::BlendFunc::ONE_MINUS_DST_COLOR},
{"one_minus_src_alpha" , osg::BlendFunc::ONE_MINUS_SRC_ALPHA},
{"one_minus_src_color" , osg::BlendFunc::ONE_MINUS_SRC_COLOR},
{"src_alpha" , osg::BlendFunc::SRC_ALPHA},
{"src_alpha_saturate" , osg::BlendFunc::SRC_ALPHA_SATURATE},
{"src_color" , osg::BlendFunc::SRC_COLOR},
{"constant_color" , osg::BlendFunc::CONSTANT_COLOR},
{"one_minus_constant_color" , osg::BlendFunc::ONE_MINUS_CONSTANT_COLOR},
{"constant_alpha" , osg::BlendFunc::CONSTANT_ALPHA},
{"one_minus_constant_alpha" , osg::BlendFunc::ONE_MINUS_CONSTANT_ALPHA},
{"zero" , osg::BlendFunc::ZERO},
}};
constexpr std::array<std::pair<std::string_view, osg::BlendFunc::BlendFuncMode>, 15> BlendFunc = { {
{ "dst_alpha", osg::BlendFunc::DST_ALPHA },
{ "dst_color", osg::BlendFunc::DST_COLOR },
{ "one", osg::BlendFunc::ONE },
{ "one_minus_dst_alpha", osg::BlendFunc::ONE_MINUS_DST_ALPHA },
{ "one_minus_dst_color", osg::BlendFunc::ONE_MINUS_DST_COLOR },
{ "one_minus_src_alpha", osg::BlendFunc::ONE_MINUS_SRC_ALPHA },
{ "one_minus_src_color", osg::BlendFunc::ONE_MINUS_SRC_COLOR },
{ "src_alpha", osg::BlendFunc::SRC_ALPHA },
{ "src_alpha_saturate", osg::BlendFunc::SRC_ALPHA_SATURATE },
{ "src_color", osg::BlendFunc::SRC_COLOR },
{ "constant_color", osg::BlendFunc::CONSTANT_COLOR },
{ "one_minus_constant_color", osg::BlendFunc::ONE_MINUS_CONSTANT_COLOR },
{ "constant_alpha", osg::BlendFunc::CONSTANT_ALPHA },
{ "one_minus_constant_alpha", osg::BlendFunc::ONE_MINUS_CONSTANT_ALPHA },
{ "zero", osg::BlendFunc::ZERO },
} };
constexpr std::array<std::pair<std::string_view, osg::BlendEquation::Equation>, 8> BlendEquation = {{
{"rgba_min" , osg::BlendEquation::RGBA_MIN},
{"rgba_max" , osg::BlendEquation::RGBA_MAX},
{"alpha_min" , osg::BlendEquation::ALPHA_MIN},
{"alpha_max" , osg::BlendEquation::ALPHA_MAX},
{"logic_op" , osg::BlendEquation::LOGIC_OP},
{"add" , osg::BlendEquation::FUNC_ADD},
{"subtract" , osg::BlendEquation::FUNC_SUBTRACT},
{"reverse_subtract" , osg::BlendEquation::FUNC_REVERSE_SUBTRACT},
}};
constexpr std::array<std::pair<std::string_view, osg::BlendEquation::Equation>, 8> BlendEquation = { {
{ "rgba_min", osg::BlendEquation::RGBA_MIN },
{ "rgba_max", osg::BlendEquation::RGBA_MAX },
{ "alpha_min", osg::BlendEquation::ALPHA_MIN },
{ "alpha_max", osg::BlendEquation::ALPHA_MAX },
{ "logic_op", osg::BlendEquation::LOGIC_OP },
{ "add", osg::BlendEquation::FUNC_ADD },
{ "subtract", osg::BlendEquation::FUNC_SUBTRACT },
{ "reverse_subtract", osg::BlendEquation::FUNC_REVERSE_SUBTRACT },
} };
}
}

View file

@ -1,24 +1,24 @@
#include "pass.hpp"
#include <unordered_set>
#include <string>
#include <sstream>
#include <string>
#include <unordered_set>
#include <osg/BindImageTexture>
#include <osg/FrameBufferObject>
#include <osg/Program>
#include <osg/Shader>
#include <osg/State>
#include <osg/StateSet>
#include <osg/BindImageTexture>
#include <osg/FrameBufferObject>
#include <components/sceneutil/util.hpp>
#include <components/sceneutil/lightmanager.hpp>
#include <components/sceneutil/clearcolor.hpp>
#include <components/resource/scenemanager.hpp>
#include <components/sceneutil/clearcolor.hpp>
#include <components/sceneutil/lightmanager.hpp>
#include <components/sceneutil/util.hpp>
#include <components/stereo/multiview.hpp>
#include "technique.hpp"
#include "stateupdater.hpp"
#include "technique.hpp"
namespace
{
@ -249,35 +249,32 @@ float omw_EstimateFogCoverageFromUV(vec2 uv)
std::stringstream extBlock;
for (const auto& extension : technique.getGLSLExtensions())
extBlock << "#ifdef " << extension << '\n' << "\t#extension " << extension << ": enable" << '\n' << "#endif" << '\n';
extBlock << "#ifdef " << extension << '\n'
<< "\t#extension " << extension << ": enable" << '\n'
<< "#endif" << '\n';
const std::vector<std::pair<std::string,std::string>> defines = {
{"@pointLightCount", std::to_string(SceneUtil::PPLightBuffer::sMaxPPLightsArraySize)},
{"@version", std::to_string(technique.getGLSLVersion())},
{"@multiview", Stereo::getMultiview() ? "1" : "0"},
{"@builtinSampler", Stereo::getMultiview() ? "sampler2DArray" : "sampler2D"},
{"@profile", technique.getGLSLProfile()},
{"@extensions", extBlock.str()},
{"@uboStruct", StateUpdater::getStructDefinition()},
{"@ubo", mUBO ? "1" : "0"},
{"@normals", technique.getNormals() ? "1" : "0"},
{"@reverseZ", SceneUtil::AutoDepth::isReversed() ? "1" : "0"},
{"@radialFog", Settings::Manager::getBool("radial fog", "Fog") ? "1" : "0"},
{"@exponentialFog", Settings::Manager::getBool("exponential fog", "Fog") ? "1" : "0"},
{"@hdr", technique.getHDR() ? "1" : "0"},
{"@in", mLegacyGLSL ? "varying" : "in"},
{"@out", mLegacyGLSL ? "varying" : "out"},
{"@position", "gl_Position"},
{"@texture1D", mLegacyGLSL ? "texture1D" : "texture"},
{"@texture2D", mLegacyGLSL ? "texture2D" : "texture"},
{"@texture3D", mLegacyGLSL ? "texture3D" : "texture"},
{"@vertex", mLegacyGLSL ? "gl_Vertex" : "_omw_Vertex"},
{"@fragColor", mLegacyGLSL ? "gl_FragColor" : "_omw_FragColor"},
{"@useBindings", mLegacyGLSL ? "0" : "1"},
{"@fragBinding", mLegacyGLSL ? "" : "out vec4 omw_FragColor;"}
};
const std::vector<std::pair<std::string, std::string>> defines
= { { "@pointLightCount", std::to_string(SceneUtil::PPLightBuffer::sMaxPPLightsArraySize) },
{ "@version", std::to_string(technique.getGLSLVersion()) },
{ "@multiview", Stereo::getMultiview() ? "1" : "0" },
{ "@builtinSampler", Stereo::getMultiview() ? "sampler2DArray" : "sampler2D" },
{ "@profile", technique.getGLSLProfile() }, { "@extensions", extBlock.str() },
{ "@uboStruct", StateUpdater::getStructDefinition() }, { "@ubo", mUBO ? "1" : "0" },
{ "@normals", technique.getNormals() ? "1" : "0" },
{ "@reverseZ", SceneUtil::AutoDepth::isReversed() ? "1" : "0" },
{ "@radialFog", Settings::Manager::getBool("radial fog", "Fog") ? "1" : "0" },
{ "@exponentialFog", Settings::Manager::getBool("exponential fog", "Fog") ? "1" : "0" },
{ "@hdr", technique.getHDR() ? "1" : "0" }, { "@in", mLegacyGLSL ? "varying" : "in" },
{ "@out", mLegacyGLSL ? "varying" : "out" }, { "@position", "gl_Position" },
{ "@texture1D", mLegacyGLSL ? "texture1D" : "texture" },
{ "@texture2D", mLegacyGLSL ? "texture2D" : "texture" },
{ "@texture3D", mLegacyGLSL ? "texture3D" : "texture" },
{ "@vertex", mLegacyGLSL ? "gl_Vertex" : "_omw_Vertex" },
{ "@fragColor", mLegacyGLSL ? "gl_FragColor" : "_omw_FragColor" },
{ "@useBindings", mLegacyGLSL ? "0" : "1" },
{ "@fragBinding", mLegacyGLSL ? "" : "out vec4 omw_FragColor;" } };
for (const auto& [define, value]: defines)
for (const auto& [define, value] : defines)
for (size_t pos = header.find(define); pos != std::string::npos; pos = header.find(define))
header.replace(pos, define.size(), value);
@ -347,7 +344,8 @@ float omw_EstimateFogCoverageFromUV(vec2 uv)
if (mType == Type::Pixel)
{
if (!mVertex)
mVertex = new osg::Shader(osg::Shader::VERTEX, Stereo::getMultiview() ? s_DefaultVertexMultiview : s_DefaultVertex);
mVertex = new osg::Shader(
osg::Shader::VERTEX, Stereo::getMultiview() ? s_DefaultVertexMultiview : s_DefaultVertex);
mVertex->setShaderSource(getPassHeader(technique, preamble).append(mVertex->getShaderSource()));
mFragment->setShaderSource(getPassHeader(technique, preamble, true).append(mFragment->getShaderSource()));

View file

@ -2,18 +2,18 @@
#define OPENMW_COMPONENTS_FX_PASS_H
#include <array>
#include <string>
#include <cstdint>
#include <unordered_set>
#include <optional>
#include <string>
#include <unordered_set>
#include <osg/Timer>
#include <osg/BlendEquation>
#include <osg/BlendFunc>
#include <osg/Program>
#include <osg/Shader>
#include <osg/State>
#include <osg/Texture2D>
#include <osg/BlendEquation>
#include <osg/BlendFunc>
#include <osg/Timer>
namespace fx
{
@ -22,7 +22,6 @@ namespace fx
class Pass
{
public:
enum class Order
{
Forward,
@ -38,7 +37,7 @@ namespace fx
friend class Technique;
Pass(Type type=Type::Pixel, Order order=Order::Post, bool ubo = false);
Pass(Type type = Type::Pixel, Order order = Order::Post, bool ubo = false);
void compile(Technique& technique, std::string_view preamble);

View file

@ -1,14 +1,17 @@
#include "stateupdater.hpp"
#include <osg/BufferObject>
#include <osg/BufferIndexBinding>
#include <osg/BufferObject>
#include <components/resource/scenemanager.hpp>
#include <components/debug/debuglog.hpp>
#include <components/resource/scenemanager.hpp>
namespace fx
{
StateUpdater::StateUpdater(bool useUBO) : mUseUBO(useUBO) {}
StateUpdater::StateUpdater(bool useUBO)
: mUseUBO(useUBO)
{
}
void StateUpdater::setDefaults(osg::StateSet* stateset)
{
@ -16,22 +19,24 @@ namespace fx
{
osg::ref_ptr<osg::UniformBufferObject> ubo = new osg::UniformBufferObject;
osg::ref_ptr<osg::BufferTemplate<UniformData::BufferType>> data = new osg::BufferTemplate<UniformData::BufferType>();
osg::ref_ptr<osg::BufferTemplate<UniformData::BufferType>> data
= new osg::BufferTemplate<UniformData::BufferType>();
data->setBufferObject(ubo);
osg::ref_ptr<osg::UniformBufferBinding> ubb = new osg::UniformBufferBinding(static_cast<int>(Resource::SceneManager::UBOBinding::PostProcessor), data, 0, mData.getGPUSize());
osg::ref_ptr<osg::UniformBufferBinding> ubb = new osg::UniformBufferBinding(
static_cast<int>(Resource::SceneManager::UBOBinding::PostProcessor), data, 0, mData.getGPUSize());
stateset->setAttributeAndModes(ubb, osg::StateAttribute::ON);
}
else
{
const auto createUniform = [&] (const auto& v) {
const auto createUniform = [&](const auto& v) {
using T = std::decay_t<decltype(v)>;
std::string name = "omw." + std::string(T::sName);
stateset->addUniform(new osg::Uniform(name.c_str(), mData.get<T>()));
};
std::apply([&] (const auto& ... v) { (createUniform(v) , ...); }, mData.getData());
std::apply([&](const auto&... v) { (createUniform(v), ...); }, mData.getData());
}
}
@ -39,7 +44,9 @@ namespace fx
{
if (mUseUBO)
{
osg::UniformBufferBinding* ubb = dynamic_cast<osg::UniformBufferBinding*>(stateset->getAttribute(osg::StateAttribute::UNIFORMBUFFERBINDING, static_cast<int>(Resource::SceneManager::UBOBinding::PostProcessor)));
osg::UniformBufferBinding* ubb = dynamic_cast<osg::UniformBufferBinding*>(
stateset->getAttribute(osg::StateAttribute::UNIFORMBUFFERBINDING,
static_cast<int>(Resource::SceneManager::UBOBinding::PostProcessor)));
if (!ubb)
throw std::runtime_error("StateUpdater::apply: failed to get an UniformBufferBinding!");
@ -50,13 +57,13 @@ namespace fx
}
else
{
const auto setUniform = [&] (const auto& v) {
const auto setUniform = [&](const auto& v) {
using T = std::decay_t<decltype(v)>;
std::string name = "omw." + std::string(T::sName);
stateset->getUniform(name)->set(mData.get<T>());
};
std::apply([&] (const auto& ... v) { (setUniform(v) , ...); }, mData.getData());
std::apply([&](const auto&... v) { (setUniform(v), ...); }, mData.getData());
}
if (mPointLightBuffer)

View file

@ -20,13 +20,13 @@ namespace fx
mData.get<InvProjectionMatrix>() = osg::Matrixf::inverse(matrix);
}
void setViewMatrix(const osg::Matrixf& matrix)
{
void setViewMatrix(const osg::Matrixf& matrix)
{
mData.get<ViewMatrix>() = matrix;
mData.get<InvViewMatrix>() = osg::Matrixf::inverse(matrix);
}
void setPrevViewMatrix(const osg::Matrixf& matrix) { mData.get<PrevViewMatrix>() = matrix;}
void setPrevViewMatrix(const osg::Matrixf& matrix) { mData.get<PrevViewMatrix>() = matrix; }
void setEyePos(const osg::Vec3f& pos) { mData.get<EyePos>() = osg::Vec4f(pos, 0.f); }
@ -47,13 +47,10 @@ namespace fx
void setResolution(const osg::Vec2f& size)
{
mData.get<Resolution>() = size;
mData.get<RcpResolution>() = {1.f / size.x(), 1.f / size.y()};
mData.get<RcpResolution>() = { 1.f / size.x(), 1.f / size.y() };
}
void setSunVis(float vis)
{
mData.get<SunVis>() = vis;
}
void setSunVis(float vis) { mData.get<SunVis>() = vis; }
void setFogRange(float near, float far)
{
@ -89,13 +86,13 @@ namespace fx
void setWindSpeed(float speed) { mData.get<WindSpeed>() = speed; }
void setWeatherTransition(float transition) { mData.get<WeatherTransition>() = transition > 0 ? 1 - transition : 0; }
void bindPointLights(std::shared_ptr<SceneUtil::PPLightBuffer> buffer)
void setWeatherTransition(float transition)
{
mPointLightBuffer = buffer;
mData.get<WeatherTransition>() = transition > 0 ? 1 - transition : 0;
}
void bindPointLights(std::shared_ptr<SceneUtil::PPLightBuffer> buffer) { mPointLightBuffer = buffer; }
static std::string getStructDefinition()
{
static std::string definition = UniformData::getDefinition("_omw_data");
@ -107,95 +104,155 @@ namespace fx
void apply(osg::StateSet* stateset, osg::NodeVisitor* nv) override;
private:
struct ProjectionMatrix : std140::Mat4 { static constexpr std::string_view sName = "projectionMatrix"; };
struct ProjectionMatrix : std140::Mat4
{
static constexpr std::string_view sName = "projectionMatrix";
};
struct InvProjectionMatrix : std140::Mat4 { static constexpr std::string_view sName = "invProjectionMatrix"; };
struct InvProjectionMatrix : std140::Mat4
{
static constexpr std::string_view sName = "invProjectionMatrix";
};
struct ViewMatrix : std140::Mat4 { static constexpr std::string_view sName = "viewMatrix"; };
struct ViewMatrix : std140::Mat4
{
static constexpr std::string_view sName = "viewMatrix";
};
struct PrevViewMatrix : std140::Mat4 { static constexpr std::string_view sName = "prevViewMatrix"; };
struct PrevViewMatrix : std140::Mat4
{
static constexpr std::string_view sName = "prevViewMatrix";
};
struct InvViewMatrix : std140::Mat4 { static constexpr std::string_view sName = "invViewMatrix"; };
struct InvViewMatrix : std140::Mat4
{
static constexpr std::string_view sName = "invViewMatrix";
};
struct EyePos : std140::Vec4 { static constexpr std::string_view sName = "eyePos"; };
struct EyePos : std140::Vec4
{
static constexpr std::string_view sName = "eyePos";
};
struct EyeVec : std140::Vec4 { static constexpr std::string_view sName = "eyeVec"; };
struct EyeVec : std140::Vec4
{
static constexpr std::string_view sName = "eyeVec";
};
struct FogColor : std140::Vec4 { static constexpr std::string_view sName = "fogColor"; };
struct FogColor : std140::Vec4
{
static constexpr std::string_view sName = "fogColor";
};
struct SunColor : std140::Vec4 { static constexpr std::string_view sName = "sunColor"; };
struct SunColor : std140::Vec4
{
static constexpr std::string_view sName = "sunColor";
};
struct SunPos : std140::Vec4 { static constexpr std::string_view sName = "sunPos"; };
struct SunPos : std140::Vec4
{
static constexpr std::string_view sName = "sunPos";
};
struct Resolution : std140::Vec2 { static constexpr std::string_view sName = "resolution"; };
struct Resolution : std140::Vec2
{
static constexpr std::string_view sName = "resolution";
};
struct RcpResolution : std140::Vec2 { static constexpr std::string_view sName = "rcpResolution"; };
struct RcpResolution : std140::Vec2
{
static constexpr std::string_view sName = "rcpResolution";
};
struct FogNear : std140::Float { static constexpr std::string_view sName = "fogNear"; };
struct FogNear : std140::Float
{
static constexpr std::string_view sName = "fogNear";
};
struct FogFar : std140::Float { static constexpr std::string_view sName = "fogFar"; };
struct FogFar : std140::Float
{
static constexpr std::string_view sName = "fogFar";
};
struct Near : std140::Float { static constexpr std::string_view sName = "near"; };
struct Near : std140::Float
{
static constexpr std::string_view sName = "near";
};
struct Far : std140::Float { static constexpr std::string_view sName = "far"; };
struct Far : std140::Float
{
static constexpr std::string_view sName = "far";
};
struct Fov : std140::Float { static constexpr std::string_view sName = "fov"; };
struct Fov : std140::Float
{
static constexpr std::string_view sName = "fov";
};
struct GameHour : std140::Float { static constexpr std::string_view sName = "gameHour"; };
struct GameHour : std140::Float
{
static constexpr std::string_view sName = "gameHour";
};
struct SunVis : std140::Float { static constexpr std::string_view sName = "sunVis"; };
struct SunVis : std140::Float
{
static constexpr std::string_view sName = "sunVis";
};
struct WaterHeight : std140::Float { static constexpr std::string_view sName = "waterHeight"; };
struct WaterHeight : std140::Float
{
static constexpr std::string_view sName = "waterHeight";
};
struct IsWaterEnabled : std140::Bool { static constexpr std::string_view sName = "isWaterEnabled"; };
struct IsWaterEnabled : std140::Bool
{
static constexpr std::string_view sName = "isWaterEnabled";
};
struct SimulationTime : std140::Float { static constexpr std::string_view sName = "simulationTime"; };
struct SimulationTime : std140::Float
{
static constexpr std::string_view sName = "simulationTime";
};
struct DeltaSimulationTime : std140::Float { static constexpr std::string_view sName = "deltaSimulationTime"; };
struct DeltaSimulationTime : std140::Float
{
static constexpr std::string_view sName = "deltaSimulationTime";
};
struct WindSpeed : std140::Float { static constexpr std::string_view sName = "windSpeed"; };
struct WindSpeed : std140::Float
{
static constexpr std::string_view sName = "windSpeed";
};
struct WeatherTransition : std140::Float { static constexpr std::string_view sName = "weatherTransition"; };
struct WeatherTransition : std140::Float
{
static constexpr std::string_view sName = "weatherTransition";
};
struct WeatherID : std140::Int { static constexpr std::string_view sName = "weatherID"; };
struct WeatherID : std140::Int
{
static constexpr std::string_view sName = "weatherID";
};
struct NextWeatherID : std140::Int { static constexpr std::string_view sName = "nextWeatherID"; };
struct NextWeatherID : std140::Int
{
static constexpr std::string_view sName = "nextWeatherID";
};
struct IsUnderwater : std140::Bool { static constexpr std::string_view sName = "isUnderwater"; };
struct IsUnderwater : std140::Bool
{
static constexpr std::string_view sName = "isUnderwater";
};
struct IsInterior : std140::Bool { static constexpr std::string_view sName = "isInterior"; };
struct IsInterior : std140::Bool
{
static constexpr std::string_view sName = "isInterior";
};
using UniformData = std140::UBO<
ProjectionMatrix,
InvProjectionMatrix,
ViewMatrix,
PrevViewMatrix,
InvViewMatrix,
EyePos,
EyeVec,
FogColor,
SunColor,
SunPos,
Resolution,
RcpResolution,
FogNear,
FogFar,
Near,
Far,
Fov,
GameHour,
SunVis,
WaterHeight,
IsWaterEnabled,
SimulationTime,
DeltaSimulationTime,
WindSpeed,
WeatherTransition,
WeatherID,
NextWeatherID,
IsUnderwater,
IsInterior
>;
using UniformData = std140::UBO<ProjectionMatrix, InvProjectionMatrix, ViewMatrix, PrevViewMatrix,
InvViewMatrix, EyePos, EyeVec, FogColor, SunColor, SunPos, Resolution, RcpResolution, FogNear, FogFar, Near,
Far, Fov, GameHour, SunVis, WaterHeight, IsWaterEnabled, SimulationTime, DeltaSimulationTime, WindSpeed,
WeatherTransition, WeatherID, NextWeatherID, IsUnderwater, IsInterior>;
UniformData mData;
bool mUseUBO;

View file

@ -4,20 +4,20 @@
#include <string>
#include <utility>
#include <osg/CullStack>
#include <osg/Texture1D>
#include <osg/Texture2D>
#include <osg/Texture3D>
#include <osg/CullStack>
#include <SDL_opengl_glext.h>
#include <components/vfs/manager.hpp>
#include <components/stereo/multiview.hpp>
#include <components/misc/strings/algorithm.hpp>
#include <components/sceneutil/util.hpp>
#include <components/resource/imagemanager.hpp>
#include <components/debug/debuglog.hpp>
#include <components/files/conversion.hpp>
#include <components/misc/strings/algorithm.hpp>
#include <components/resource/imagemanager.hpp>
#include <components/sceneutil/util.hpp>
#include <components/stereo/multiview.hpp>
#include <components/vfs/manager.hpp>
#include "parse_constants.hpp"
@ -29,7 +29,7 @@ namespace
osg::Texture::WrapMode wrap_t = osg::Texture::CLAMP_TO_EDGE;
osg::Texture::WrapMode wrap_r = osg::Texture::CLAMP_TO_EDGE;
osg::Texture::FilterMode min_filter = osg::Texture::LINEAR_MIPMAP_LINEAR;
osg::Texture::FilterMode mag_filter =osg::Texture::LINEAR;
osg::Texture::FilterMode mag_filter = osg::Texture::LINEAR;
osg::Texture::InternalFormatMode compression = osg::Texture::USE_IMAGE_DATA_FORMAT;
std::optional<int> source_format;
std::optional<int> source_type;
@ -39,9 +39,11 @@ namespace
namespace fx
{
Technique::Technique(const VFS::Manager& vfs, Resource::ImageManager& imageManager, std::string name, int width, int height, bool ubo, bool supportsNormals)
Technique::Technique(const VFS::Manager& vfs, Resource::ImageManager& imageManager, std::string name, int width,
int height, bool ubo, bool supportsNormals)
: mName(std::move(name))
, mFileName(Files::pathToUnicodeString((Files::pathFromUnicodeString(Technique::sSubdir) / (mName + Technique::sExt))))
, mFileName(Files::pathToUnicodeString(
(Files::pathFromUnicodeString(Technique::sSubdir) / (mName + Technique::sExt))))
, mLastModificationTime(std::filesystem::file_time_type())
, mWidth(width)
, mHeight(height)
@ -84,16 +86,14 @@ namespace fx
auto block = mLexer->getLastJumpBlock();
std::string content = std::string(block.content);
content = "\n#line " + std::to_string(block.line + 1) + "\n" + std::string(block.content) + "\n";
content = "\n#line " + std::to_string(block.line + 1) + "\n" + std::string(block.content) + "\n";
return content;
}
Technique::UniformMap::iterator Technique::findUniform(const std::string& name)
{
return std::find_if(mDefinedUniforms.begin(), mDefinedUniforms.end(), [&name](const auto& uniform)
{
return uniform->mName == name;
});
return std::find_if(mDefinedUniforms.begin(), mDefinedUniforms.end(),
[&name](const auto& uniform) { return uniform->mName == name; });
}
bool Technique::compile()
@ -124,13 +124,17 @@ namespace fx
auto it = mPassMap.find(name);
if (it == mPassMap.end())
error(Misc::StringUtils::format("pass '%s' was found in the pass list, but there was no matching 'fragment', 'vertex' or 'compute' block", std::string(name)));
error(
Misc::StringUtils::format("pass '%s' was found in the pass list, but there was no matching "
"'fragment', 'vertex' or 'compute' block",
std::string(name)));
if (mLastAppliedType != Pass::Type::None && mLastAppliedType != it->second->mType)
{
swaps++;
if (swaps == 2)
Log(Debug::Warning) << "compute and pixel shaders are being swapped multiple times in shader chain, this can lead to serious performance drain.";
Log(Debug::Warning) << "compute and pixel shaders are being swapped multiple times in shader "
"chain, this can lead to serious performance drain.";
}
else
mLastAppliedType = it->second->mType;
@ -159,12 +163,13 @@ namespace fx
mValid = true;
}
catch(const std::runtime_error& e)
catch (const std::runtime_error& e)
{
clear();
mStatus = Status::Parse_Error;
mLastError = "Failed parsing technique '" + getName() + "' " + e.what();;
mLastError = "Failed parsing technique '" + getName() + "' " + e.what();
;
Log(Debug::Error) << mLastError;
}
@ -193,7 +198,7 @@ namespace fx
mLexer->error(msg);
}
template<>
template <>
void Technique::parseBlockImp<Lexer::Shared>()
{
if (!mLexer->jump())
@ -205,7 +210,7 @@ namespace fx
mShared = getBlockWithLineDirective();
}
template<>
template <>
void Technique::parseBlockImp<Lexer::Technique>()
{
if (!mPassKeys.empty())
@ -254,16 +259,16 @@ namespace fx
else if (key == "dynamic")
mDynamic = parseBool();
else
error(Misc::StringUtils::format("unexpected key '%s'", std::string{key}));
error(Misc::StringUtils::format("unexpected key '%s'", std::string{ key }));
expect<Lexer::SemiColon>();
}
}
if (mPassKeys.empty())
error("pass list in 'technique' block cannot be empty.");
}
template<>
template <>
void Technique::parseBlockImp<Lexer::Render_Target>()
{
if (mRenderTargets.count(mBlockName))
@ -316,7 +321,7 @@ namespace fx
mRenderTargets.emplace(mBlockName, std::move(rt));
}
template<>
template <>
void Technique::parseBlockImp<Lexer::Vertex>()
{
if (!mLexer->jump())
@ -339,7 +344,7 @@ namespace fx
pass->mType = Pass::Type::Pixel;
}
template<>
template <>
void Technique::parseBlockImp<Lexer::Fragment>()
{
if (!mLexer->jump())
@ -363,7 +368,7 @@ namespace fx
pass->mType = Pass::Type::Pixel;
}
template<>
template <>
void Technique::parseBlockImp<Lexer::Compute>()
{
if (!mLexer->jump())
@ -431,7 +436,7 @@ namespace fx
else if (key == "source")
{
expect<Lexer::String>();
auto image = mImageManager.getImage(std::string{std::get<Lexer::String>(mToken).value}, is3D);
auto image = mImageManager.getImage(std::string{ std::get<Lexer::String>(mToken).value }, is3D);
if constexpr (is1D)
{
type = Types::SamplerType::Texture_1D;
@ -449,12 +454,13 @@ namespace fx
}
}
else
error(Misc::StringUtils::format("unexpected key '%s'", std::string{key}));
error(Misc::StringUtils::format("unexpected key '%s'", std::string{ key }));
expect<Lexer::SemiColon>();
}
if (!sampler)
error(Misc::StringUtils::format("%s '%s' requires a filename", std::string(T::repr), std::string{mBlockName}));
error(Misc::StringUtils::format(
"%s '%s' requires a filename", std::string(T::repr), std::string{ mBlockName }));
if (!is1D)
{
@ -472,7 +478,7 @@ namespace fx
sampler->setSourceType(proxy.source_type.value());
if (proxy.internal_format.has_value())
sampler->setSourceFormat(proxy.internal_format.value());
sampler->setName(std::string{mBlockName});
sampler->setName(std::string{ mBlockName });
sampler->setResizeNonPowerOfTwoHint(false);
mTextures.emplace_back(sampler);
@ -500,7 +506,8 @@ namespace fx
expect<Lexer::Equal>("error parsing config for uniform block");
constexpr bool isVec = std::is_same_v<osg::Vec2f, SrcT> || std::is_same_v<osg::Vec3f, SrcT> || std::is_same_v<osg::Vec4f, SrcT>;
constexpr bool isVec = std::is_same_v<osg::Vec2f,
SrcT> || std::is_same_v<osg::Vec3f, SrcT> || std::is_same_v<osg::Vec4f, SrcT>;
constexpr bool isFloat = std::is_same_v<float, SrcT>;
constexpr bool isInt = std::is_same_v<int, SrcT>;
constexpr bool isBool = std::is_same_v<bool, SrcT>;
@ -569,7 +576,7 @@ namespace fx
uniform->mDisplayName = std::get<Lexer::String>(mToken).value;
}
else
error(Misc::StringUtils::format("unexpected key '%s'", std::string{key}));
error(Misc::StringUtils::format("unexpected key '%s'", std::string{ key }));
expect<Lexer::SemiColon>();
}
@ -597,61 +604,61 @@ namespace fx
mDefinedUniforms.emplace_back(std::move(uniform));
}
template<>
template <>
void Technique::parseBlockImp<Lexer::Sampler_1D>()
{
parseSampler<Lexer::Sampler_1D>();
}
template<>
template <>
void Technique::parseBlockImp<Lexer::Sampler_2D>()
{
parseSampler<Lexer::Sampler_2D>();
}
template<>
template <>
void Technique::parseBlockImp<Lexer::Sampler_3D>()
{
parseSampler<Lexer::Sampler_3D>();
}
template<>
template <>
void Technique::parseBlockImp<Lexer::Uniform_Bool>()
{
parseUniform<bool, bool>();
}
template<>
template <>
void Technique::parseBlockImp<Lexer::Uniform_Float>()
{
parseUniform<float, float>();
}
template<>
template <>
void Technique::parseBlockImp<Lexer::Uniform_Int>()
{
parseUniform<int, int>();
}
template<>
template <>
void Technique::parseBlockImp<Lexer::Uniform_Vec2>()
{
parseUniform<osg::Vec2f, Lexer::Vec2>();
}
template<>
template <>
void Technique::parseBlockImp<Lexer::Uniform_Vec3>()
{
parseUniform<osg::Vec3f, Lexer::Vec3>();
}
template<>
template <>
void Technique::parseBlockImp<Lexer::Uniform_Vec4>()
{
parseUniform<osg::Vec4f, Lexer::Vec4>();
}
template<class T>
template <class T>
void Technique::expect(const std::string& err)
{
mToken = mLexer->next();
@ -664,14 +671,15 @@ namespace fx
}
}
template<class T, class T2>
template <class T, class T2>
void Technique::expect(const std::string& err)
{
mToken = mLexer->next();
if (!std::holds_alternative<T>(mToken) && !std::holds_alternative<T2>(mToken))
{
if (err.empty())
error(Misc::StringUtils::format("%s. Expected %s or %s", err, std::string(T::repr), std::string(T2::repr)));
error(Misc::StringUtils::format(
"%s. Expected %s or %s", err, std::string(T::repr), std::string(T2::repr)));
else
error(Misc::StringUtils::format("Expected %s or %s", std::string(T::repr), std::string(T2::repr)));
}
@ -691,43 +699,44 @@ namespace fx
for (auto t = mLexer->next(); !std::holds_alternative<Lexer::Eof>(t); t = mLexer->next())
{
std::visit([this](auto&& arg) {
using T = std::decay_t<decltype(arg)>;
std::visit(
[this](auto&& arg) {
using T = std::decay_t<decltype(arg)>;
if constexpr (std::is_same_v<Lexer::Shared, T>)
parseBlock<Lexer::Shared>(false);
else if constexpr (std::is_same_v<Lexer::Technique, T>)
parseBlock<Lexer::Technique>(false);
else if constexpr (std::is_same_v<Lexer::Render_Target, T>)
parseBlock<Lexer::Render_Target>();
else if constexpr (std::is_same_v<Lexer::Vertex, T>)
parseBlock<Lexer::Vertex>();
else if constexpr (std::is_same_v<Lexer::Fragment, T>)
parseBlock<Lexer::Fragment>();
else if constexpr (std::is_same_v<Lexer::Compute, T>)
parseBlock<Lexer::Compute>();
else if constexpr (std::is_same_v<Lexer::Sampler_1D, T>)
parseBlock<Lexer::Sampler_1D>();
else if constexpr (std::is_same_v<Lexer::Sampler_2D, T>)
parseBlock<Lexer::Sampler_2D>();
else if constexpr (std::is_same_v<Lexer::Sampler_3D, T>)
parseBlock<Lexer::Sampler_3D>();
else if constexpr (std::is_same_v<Lexer::Uniform_Bool, T>)
parseBlock<Lexer::Uniform_Bool>();
else if constexpr (std::is_same_v<Lexer::Uniform_Float, T>)
parseBlock<Lexer::Uniform_Float>();
else if constexpr (std::is_same_v<Lexer::Uniform_Int, T>)
parseBlock<Lexer::Uniform_Int>();
else if constexpr (std::is_same_v<Lexer::Uniform_Vec2, T>)
parseBlock<Lexer::Uniform_Vec2>();
else if constexpr (std::is_same_v<Lexer::Uniform_Vec3, T>)
parseBlock<Lexer::Uniform_Vec3>();
else if constexpr (std::is_same_v<Lexer::Uniform_Vec4, T>)
parseBlock<Lexer::Uniform_Vec4>();
else
error("invalid top level block");
}
, t);
if constexpr (std::is_same_v<Lexer::Shared, T>)
parseBlock<Lexer::Shared>(false);
else if constexpr (std::is_same_v<Lexer::Technique, T>)
parseBlock<Lexer::Technique>(false);
else if constexpr (std::is_same_v<Lexer::Render_Target, T>)
parseBlock<Lexer::Render_Target>();
else if constexpr (std::is_same_v<Lexer::Vertex, T>)
parseBlock<Lexer::Vertex>();
else if constexpr (std::is_same_v<Lexer::Fragment, T>)
parseBlock<Lexer::Fragment>();
else if constexpr (std::is_same_v<Lexer::Compute, T>)
parseBlock<Lexer::Compute>();
else if constexpr (std::is_same_v<Lexer::Sampler_1D, T>)
parseBlock<Lexer::Sampler_1D>();
else if constexpr (std::is_same_v<Lexer::Sampler_2D, T>)
parseBlock<Lexer::Sampler_2D>();
else if constexpr (std::is_same_v<Lexer::Sampler_3D, T>)
parseBlock<Lexer::Sampler_3D>();
else if constexpr (std::is_same_v<Lexer::Uniform_Bool, T>)
parseBlock<Lexer::Uniform_Bool>();
else if constexpr (std::is_same_v<Lexer::Uniform_Float, T>)
parseBlock<Lexer::Uniform_Float>();
else if constexpr (std::is_same_v<Lexer::Uniform_Int, T>)
parseBlock<Lexer::Uniform_Int>();
else if constexpr (std::is_same_v<Lexer::Uniform_Vec2, T>)
parseBlock<Lexer::Uniform_Vec2>();
else if constexpr (std::is_same_v<Lexer::Uniform_Vec3, T>)
parseBlock<Lexer::Uniform_Vec3>();
else if constexpr (std::is_same_v<Lexer::Uniform_Vec4, T>)
parseBlock<Lexer::Uniform_Vec4>();
else
error("invalid top level block");
},
t);
}
}
@ -789,7 +798,7 @@ namespace fx
pass = std::make_shared<fx::Pass>();
bool clear = true;
osg::Vec4f clearColor = {1,1,1,1};
osg::Vec4f clearColor = { 1, 1, 1, 1 };
while (!isNext<Lexer::Eof>())
{
@ -817,7 +826,7 @@ namespace fx
else if (key == "rt3")
{
expect<Lexer::Literal>();
pass->mRenderTargets[2] =std::get<Lexer::Literal>(mToken).value;
pass->mRenderTargets[2] = std::get<Lexer::Literal>(mToken).value;
}
else if (key == "blend")
{
@ -868,8 +877,8 @@ namespace fx
FlagsType Technique::parseFlags()
{
auto parseBit = [this] (std::string_view term) {
for (const auto& [identifer, bit]: constants::TechniqueFlag)
auto parseBit = [this](std::string_view term) {
for (const auto& [identifer, bit] : constants::TechniqueFlag)
{
if (Misc::StringUtils::ciEqual(term, identifer))
return bit;
@ -888,104 +897,104 @@ namespace fx
{
expect<Lexer::Literal>();
for (const auto& [identifer, mode]: constants::FilterMode)
for (const auto& [identifer, mode] : constants::FilterMode)
{
if (asLiteral() == identifer)
return mode;
}
error(Misc::StringUtils::format("unrecognized filter mode '%s'", std::string{asLiteral()}));
error(Misc::StringUtils::format("unrecognized filter mode '%s'", std::string{ asLiteral() }));
}
osg::Texture::WrapMode Technique::parseWrapMode()
{
expect<Lexer::Literal>();
for (const auto& [identifer, mode]: constants::WrapMode)
for (const auto& [identifer, mode] : constants::WrapMode)
{
if (asLiteral() == identifer)
return mode;
}
error(Misc::StringUtils::format("unrecognized wrap mode '%s'", std::string{asLiteral()}));
error(Misc::StringUtils::format("unrecognized wrap mode '%s'", std::string{ asLiteral() }));
}
osg::Texture::InternalFormatMode Technique::parseCompression()
{
expect<Lexer::Literal>();
for (const auto& [identifer, mode]: constants::Compression)
for (const auto& [identifer, mode] : constants::Compression)
{
if (asLiteral() == identifer)
return mode;
}
error(Misc::StringUtils::format("unrecognized compression '%s'", std::string{asLiteral()}));
error(Misc::StringUtils::format("unrecognized compression '%s'", std::string{ asLiteral() }));
}
int Technique::parseInternalFormat()
{
expect<Lexer::Literal>();
for (const auto& [identifer, mode]: constants::InternalFormat)
for (const auto& [identifer, mode] : constants::InternalFormat)
{
if (asLiteral() == identifer)
return mode;
}
error(Misc::StringUtils::format("unrecognized internal format '%s'", std::string{asLiteral()}));
error(Misc::StringUtils::format("unrecognized internal format '%s'", std::string{ asLiteral() }));
}
int Technique::parseSourceType()
{
expect<Lexer::Literal>();
for (const auto& [identifer, mode]: constants::SourceType)
for (const auto& [identifer, mode] : constants::SourceType)
{
if (asLiteral() == identifer)
return mode;
}
error(Misc::StringUtils::format("unrecognized source type '%s'", std::string{asLiteral()}));
error(Misc::StringUtils::format("unrecognized source type '%s'", std::string{ asLiteral() }));
}
int Technique::parseSourceFormat()
{
expect<Lexer::Literal>();
for (const auto& [identifer, mode]: constants::SourceFormat)
for (const auto& [identifer, mode] : constants::SourceFormat)
{
if (asLiteral() == identifer)
return mode;
}
error(Misc::StringUtils::format("unrecognized source format '%s'", std::string{asLiteral()}));
error(Misc::StringUtils::format("unrecognized source format '%s'", std::string{ asLiteral() }));
}
osg::BlendEquation::Equation Technique::parseBlendEquation()
{
expect<Lexer::Literal>();
for (const auto& [identifer, mode]: constants::BlendEquation)
for (const auto& [identifer, mode] : constants::BlendEquation)
{
if (asLiteral() == identifer)
return mode;
}
error(Misc::StringUtils::format("unrecognized blend equation '%s'", std::string{asLiteral()}));
error(Misc::StringUtils::format("unrecognized blend equation '%s'", std::string{ asLiteral() }));
}
osg::BlendFunc::BlendFuncMode Technique::parseBlendFuncMode()
{
expect<Lexer::Literal>();
for (const auto& [identifer, mode]: constants::BlendFunc)
for (const auto& [identifer, mode] : constants::BlendFunc)
{
if (asLiteral() == identifer)
return mode;
}
error(Misc::StringUtils::format("unrecognized blend function '%s'", std::string{asLiteral()}));
error(Misc::StringUtils::format("unrecognized blend function '%s'", std::string{ asLiteral() }));
}
bool Technique::parseBool()

View file

@ -1,27 +1,27 @@
#ifndef OPENMW_COMPONENTS_FX_TECHNIQUE_H
#define OPENMW_COMPONENTS_FX_TECHNIQUE_H
#include <vector>
#include <string>
#include <variant>
#include <memory>
#include <unordered_map>
#include <filesystem>
#include <memory>
#include <string>
#include <unordered_map>
#include <variant>
#include <vector>
#include <osg/BlendEquation>
#include <osg/BlendFunc>
#include <osg/FrameBufferObject>
#include <osg/Node>
#include <osg/Program>
#include <osg/Shader>
#include <osg/Texture2D>
#include <osg/StateSet>
#include <osg/FrameBufferObject>
#include <osg/Texture2D>
#include <osg/Vec2f>
#include <osg/Vec3f>
#include <osg/Vec4f>
#include <osg/BlendFunc>
#include <osg/BlendEquation>
#include "pass.hpp"
#include "lexer.hpp"
#include "pass.hpp"
#include "types.hpp"
namespace Resource
@ -53,7 +53,8 @@ namespace fx
mPasses.emplace_back(subpass, copyOp);
}
struct SubPass {
struct SubPass
{
SubPass() = default;
osg::ref_ptr<osg::StateSet> mStateSet = new osg::StateSet;
@ -123,7 +124,8 @@ namespace fx
static constexpr FlagsType Flag_Disable_SunGlare = (1 << 4);
static constexpr FlagsType Flag_Hidden = (1 << 5);
Technique(const VFS::Manager& vfs, Resource::ImageManager& imageManager, std::string name, int width, int height, bool ubo, bool supportsNormals);
Technique(const VFS::Manager& vfs, Resource::ImageManager& imageManager, std::string name, int width,
int height, bool ubo, bool supportsNormals);
bool compile();
@ -183,11 +185,11 @@ namespace fx
std::string_view asLiteral() const;
template<class T>
void expect(const std::string& err="");
template <class T>
void expect(const std::string& err = "");
template<class T, class T2>
void expect(const std::string& err="");
template <class T, class T2>
void expect(const std::string& err = "");
template <class T>
bool isNext();
@ -201,10 +203,12 @@ namespace fx
void parseSampler();
template <class T>
void parseBlock(bool named=true);
void parseBlock(bool named = true);
template <class T>
void parseBlockImp() {}
void parseBlockImp()
{
}
void parseBlockHeader();
@ -296,21 +300,36 @@ namespace fx
bool mLocked = false;
};
template<> void Technique::parseBlockImp<Lexer::Shared>();
template<> void Technique::parseBlockImp<Lexer::Technique>();
template<> void Technique::parseBlockImp<Lexer::Render_Target>();
template<> void Technique::parseBlockImp<Lexer::Vertex>();
template<> void Technique::parseBlockImp<Lexer::Fragment>();
template<> void Technique::parseBlockImp<Lexer::Compute>();
template<> void Technique::parseBlockImp<Lexer::Sampler_1D>();
template<> void Technique::parseBlockImp<Lexer::Sampler_2D>();
template<> void Technique::parseBlockImp<Lexer::Sampler_3D>();
template<> void Technique::parseBlockImp<Lexer::Uniform_Bool>();
template<> void Technique::parseBlockImp<Lexer::Uniform_Float>();
template<> void Technique::parseBlockImp<Lexer::Uniform_Int>();
template<> void Technique::parseBlockImp<Lexer::Uniform_Vec2>();
template<> void Technique::parseBlockImp<Lexer::Uniform_Vec3>();
template<> void Technique::parseBlockImp<Lexer::Uniform_Vec4>();
template <>
void Technique::parseBlockImp<Lexer::Shared>();
template <>
void Technique::parseBlockImp<Lexer::Technique>();
template <>
void Technique::parseBlockImp<Lexer::Render_Target>();
template <>
void Technique::parseBlockImp<Lexer::Vertex>();
template <>
void Technique::parseBlockImp<Lexer::Fragment>();
template <>
void Technique::parseBlockImp<Lexer::Compute>();
template <>
void Technique::parseBlockImp<Lexer::Sampler_1D>();
template <>
void Technique::parseBlockImp<Lexer::Sampler_2D>();
template <>
void Technique::parseBlockImp<Lexer::Sampler_3D>();
template <>
void Technique::parseBlockImp<Lexer::Uniform_Bool>();
template <>
void Technique::parseBlockImp<Lexer::Uniform_Float>();
template <>
void Technique::parseBlockImp<Lexer::Uniform_Int>();
template <>
void Technique::parseBlockImp<Lexer::Uniform_Vec2>();
template <>
void Technique::parseBlockImp<Lexer::Uniform_Vec3>();
template <>
void Technique::parseBlockImp<Lexer::Uniform_Vec4>();
}
#endif

View file

@ -4,19 +4,19 @@
#include <optional>
#include <variant>
#include <osg/Camera>
#include <osg/Uniform>
#include <osg/Texture2D>
#include <osg/FrameBufferObject>
#include <osg/BlendFunc>
#include <osg/BlendEquation>
#include <osg/BlendFunc>
#include <osg/Camera>
#include <osg/FrameBufferObject>
#include <osg/Texture2D>
#include <osg/Uniform>
#include <MyGUI_Widget.h>
#include <components/debug/debuglog.hpp>
#include <components/misc/strings/format.hpp>
#include <components/sceneutil/depth.hpp>
#include <components/settings/shadermanager.hpp>
#include <components/misc/strings/format.hpp>
#include <components/debug/debuglog.hpp>
namespace fx
{
@ -29,7 +29,7 @@ namespace fx
std::optional<int> mWidth;
std::optional<int> mHeight;
std::tuple<int,int> get(int width, int height) const
std::tuple<int, int> get(int width, int height) const
{
int scaledWidth = width;
int scaledHeight = height;
@ -67,30 +67,15 @@ namespace fx
using value_type = T;
bool isArray() const
{
return mArray.has_value();
}
bool isArray() const { return mArray.has_value(); }
const std::vector<T>& getArray() const
{
return *mArray;
}
const std::vector<T>& getArray() const { return *mArray; }
T getValue() const
{
return mValue.value_or(mDefault);
}
T getValue() const { return mValue.value_or(mDefault); }
};
using Uniform_t = std::variant<
Uniform<osg::Vec2f>,
Uniform<osg::Vec3f>,
Uniform<osg::Vec4f>,
Uniform<bool>,
Uniform<float>,
Uniform<int>
>;
using Uniform_t = std::variant<Uniform<osg::Vec2f>, Uniform<osg::Vec3f>, Uniform<osg::Vec4f>, Uniform<bool>,
Uniform<float>, Uniform<int>>;
enum SamplerType
{
@ -123,7 +108,12 @@ namespace fx
size_t getNumElements() const
{
return std::visit([&](auto&& arg) { ;return arg.isArray() ? arg.getArray().size() : 1; }, mData);
return std::visit(
[&](auto&& arg) {
;
return arg.isArray() ? arg.getArray().size() : 1;
},
mData);
}
template <class T>
@ -147,42 +137,47 @@ namespace fx
template <class T>
void setValue(const T& value)
{
std::visit([&, value](auto&& arg){
using U = typename std::decay_t<decltype(arg)>::value_type;
std::visit(
[&, value](auto&& arg) {
using U = typename std::decay_t<decltype(arg)>::value_type;
if constexpr (std::is_same_v<T, U>)
{
arg.mValue = value;
if constexpr (std::is_same_v<T, U>)
{
arg.mValue = value;
Settings::ShaderManager::get().setValue(mTechniqueName, mName, value);
}
else
{
Log(Debug::Warning) << "Attempting to set uniform '" << mName << "' with wrong type";
}
}, mData);
Settings::ShaderManager::get().setValue(mTechniqueName, mName, value);
}
else
{
Log(Debug::Warning) << "Attempting to set uniform '" << mName << "' with wrong type";
}
},
mData);
}
template <class T, class A>
void setValue(const std::vector<T, A>& value)
{
std::visit([&, value](auto&& arg) {
using U = typename std::decay_t<decltype(arg)>::value_type;
std::visit(
[&, value](auto&& arg) {
using U = typename std::decay_t<decltype(arg)>::value_type;
if (!arg.isArray() || arg.getArray().size() != value.size())
{
Log(Debug::Error) << "Attempting to set uniform array '" << mName << "' with mismatching array sizes";
return;
}
if (!arg.isArray() || arg.getArray().size() != value.size())
{
Log(Debug::Error)
<< "Attempting to set uniform array '" << mName << "' with mismatching array sizes";
return;
}
if constexpr (std::is_same_v<T, U>)
{
arg.mArray = value;
Settings::ShaderManager::get().setValue(mTechniqueName, mName, value);
}
else
Log(Debug::Warning) << "Attempting to set uniform array '" << mName << "' with wrong type";
}, mData);
if constexpr (std::is_same_v<T, U>)
{
arg.mArray = value;
Settings::ShaderManager::get().setValue(mTechniqueName, mName, value);
}
else
Log(Debug::Warning) << "Attempting to set uniform array '" << mName << "' with wrong type";
},
mData);
}
void setUniform(osg::Uniform* uniform)
@ -191,39 +186,42 @@ namespace fx
if (!type || type.value() != uniform->getType())
return;
std::visit([&](auto&& arg)
{
if (arg.isArray())
{
for (size_t i = 0; i < arg.getArray().size(); ++i)
uniform->setElement(i, arg.getArray()[i]);
uniform->dirty();
}
else
uniform->set(arg.getValue());
}, mData);
std::visit(
[&](auto&& arg) {
if (arg.isArray())
{
for (size_t i = 0; i < arg.getArray().size(); ++i)
uniform->setElement(i, arg.getArray()[i]);
uniform->dirty();
}
else
uniform->set(arg.getValue());
},
mData);
}
std::optional<osg::Uniform::Type> getType() const
{
return std::visit([](auto&& arg) -> std::optional<osg::Uniform::Type> {
using T = typename std::decay_t<decltype(arg)>::value_type;
return std::visit(
[](auto&& arg) -> std::optional<osg::Uniform::Type> {
using T = typename std::decay_t<decltype(arg)>::value_type;
if constexpr (std::is_same_v<T, osg::Vec2f>)
return osg::Uniform::FLOAT_VEC2;
else if constexpr (std::is_same_v<T, osg::Vec3f>)
return osg::Uniform::FLOAT_VEC3;
else if constexpr (std::is_same_v<T, osg::Vec4f>)
return osg::Uniform::FLOAT_VEC4;
else if constexpr (std::is_same_v<T, float>)
return osg::Uniform::FLOAT;
else if constexpr (std::is_same_v<T, int>)
return osg::Uniform::INT;
else if constexpr (std::is_same_v<T, bool>)
return osg::Uniform::BOOL;
if constexpr (std::is_same_v<T, osg::Vec2f>)
return osg::Uniform::FLOAT_VEC2;
else if constexpr (std::is_same_v<T, osg::Vec3f>)
return osg::Uniform::FLOAT_VEC3;
else if constexpr (std::is_same_v<T, osg::Vec4f>)
return osg::Uniform::FLOAT_VEC4;
else if constexpr (std::is_same_v<T, float>)
return osg::Uniform::FLOAT;
else if constexpr (std::is_same_v<T, int>)
return osg::Uniform::INT;
else if constexpr (std::is_same_v<T, bool>)
return osg::Uniform::BOOL;
return std::nullopt;
}, mData);
return std::nullopt;
},
mData);
}
std::optional<std::string> getGLSL()
@ -241,62 +239,68 @@ namespace fx
}
}
return std::visit([&](auto&& arg) -> std::optional<std::string> {
using T = typename std::decay_t<decltype(arg)>::value_type;
return std::visit(
[&](auto&& arg) -> std::optional<std::string> {
using T = typename std::decay_t<decltype(arg)>::value_type;
auto value = arg.getValue();
auto value = arg.getValue();
const bool useUniform = arg.isArray() || (Settings::ShaderManager::get().getMode() == Settings::ShaderManager::Mode::Debug || mStatic == false);
const std::string uname = arg.isArray() ? Misc::StringUtils::format("%s[%zu]", mName, arg.getArray().size()) : mName;
const bool useUniform = arg.isArray()
|| (Settings::ShaderManager::get().getMode() == Settings::ShaderManager::Mode::Debug
|| mStatic == false);
const std::string uname = arg.isArray()
? Misc::StringUtils::format("%s[%zu]", mName, arg.getArray().size())
: mName;
if constexpr (std::is_same_v<T, osg::Vec2f>)
{
if (useUniform)
return Misc::StringUtils::format("uniform vec2 %s;", uname);
if constexpr (std::is_same_v<T, osg::Vec2f>)
{
if (useUniform)
return Misc::StringUtils::format("uniform vec2 %s;", uname);
return Misc::StringUtils::format("const vec2 %s=vec2(%f,%f);", mName, value[0], value[1]);
}
else if constexpr (std::is_same_v<T, osg::Vec3f>)
{
if (useUniform)
return Misc::StringUtils::format("uniform vec3 %s;", uname);
return Misc::StringUtils::format("const vec2 %s=vec2(%f,%f);", mName, value[0], value[1]);
}
else if constexpr (std::is_same_v<T, osg::Vec3f>)
{
if (useUniform)
return Misc::StringUtils::format("uniform vec3 %s;", uname);
return Misc::StringUtils::format("const vec3 %s=vec3(%f,%f,%f);", mName, value[0], value[1], value[2]);
}
else if constexpr (std::is_same_v<T, osg::Vec4f>)
{
if (useUniform)
return Misc::StringUtils::format("uniform vec4 %s;", uname);
return Misc::StringUtils::format(
"const vec3 %s=vec3(%f,%f,%f);", mName, value[0], value[1], value[2]);
}
else if constexpr (std::is_same_v<T, osg::Vec4f>)
{
if (useUniform)
return Misc::StringUtils::format("uniform vec4 %s;", uname);
return Misc::StringUtils::format("const vec4 %s=vec4(%f,%f,%f,%f);", mName, value[0], value[1], value[2], value[3]);
}
else if constexpr (std::is_same_v<T, float>)
{
if (useUniform)
return Misc::StringUtils::format("uniform float %s;", uname);
return Misc::StringUtils::format(
"const vec4 %s=vec4(%f,%f,%f,%f);", mName, value[0], value[1], value[2], value[3]);
}
else if constexpr (std::is_same_v<T, float>)
{
if (useUniform)
return Misc::StringUtils::format("uniform float %s;", uname);
return Misc::StringUtils::format("const float %s=%f;", mName, value);
}
else if constexpr (std::is_same_v<T, int>)
{
if (useUniform)
return Misc::StringUtils::format("uniform int %s;", uname);
return Misc::StringUtils::format("const float %s=%f;", mName, value);
}
else if constexpr (std::is_same_v<T, int>)
{
if (useUniform)
return Misc::StringUtils::format("uniform int %s;", uname);
return Misc::StringUtils::format("const int %s=%i;", mName, value);
}
else if constexpr (std::is_same_v<T, bool>)
{
if (useUniform)
return Misc::StringUtils::format("uniform bool %s;", uname);
return Misc::StringUtils::format("const int %s=%i;", mName, value);
}
else if constexpr (std::is_same_v<T, bool>)
{
if (useUniform)
return Misc::StringUtils::format("uniform bool %s;", uname);
return Misc::StringUtils::format("const bool %s=%s;", mName, value ? "true" : "false");
}
return Misc::StringUtils::format("const bool %s=%s;", mName, value ? "true" : "false");
}
return std::nullopt;
}, mData);
return std::nullopt;
},
mData);
}
};
}
}

View file

@ -5,7 +5,8 @@
namespace
{
template <class T, class WidgetT>
void createVectorWidget(const std::shared_ptr<fx::Types::UniformBase>& uniform, MyGUI::Widget* client, fx::Widgets::UniformBase* base)
void createVectorWidget(
const std::shared_ptr<fx::Types::UniformBase>& uniform, MyGUI::Widget* client, fx::Widgets::UniformBase* base)
{
int height = client->getHeight();
base->setSize(base->getSize().width, (base->getSize().height - height) + (height * T::num_components));
@ -13,7 +14,8 @@ namespace
for (int i = 0; i < T::num_components; ++i)
{
auto* widget = client->createWidget<WidgetT>("MW_ValueEditNumber", {0, height * i, client->getWidth(), height}, MyGUI::Align::Default);
auto* widget = client->createWidget<WidgetT>(
"MW_ValueEditNumber", { 0, height * i, client->getWidth(), height }, MyGUI::Align::Default);
widget->setData(uniform, static_cast<fx::Widgets::Index>(i));
base->addItem(widget);
}
@ -67,7 +69,6 @@ namespace fx
mCheckbutton->eventMouseButtonClick += MyGUI::newDelegate(this, &EditBool::notifyMouseButtonClick);
}
void EditBool::notifyMouseButtonClick(MyGUI::Widget* sender)
{
auto uniform = mUniform.lock();
@ -96,46 +97,50 @@ namespace fx
mLabel->setUserString("Caption_Text", uniform->mDescription);
}
std::visit([this, &uniform](auto&& arg) {
using T = typename std::decay_t<decltype(arg)>::value_type;
std::visit(
[this, &uniform](auto&& arg) {
using T = typename std::decay_t<decltype(arg)>::value_type;
if constexpr (std::is_same_v<osg::Vec4f, T>)
{
createVectorWidget<T, EditNumberFloat4>(uniform, mClient, this);
}
else if constexpr (std::is_same_v<osg::Vec3f, T>)
{
createVectorWidget<T, EditNumberFloat3>(uniform, mClient, this);
}
else if constexpr (std::is_same_v<osg::Vec2f, T>)
{
createVectorWidget<T, EditNumberFloat2>(uniform, mClient, this);
}
else if constexpr (std::is_same_v<T, float>)
{
auto* widget = mClient->createWidget<EditNumberFloat>("MW_ValueEditNumber", {0, 0, mClient->getWidth(), mClient->getHeight()}, MyGUI::Align::Stretch);
widget->setData(uniform);
mBases.emplace_back(widget);
}
else if constexpr (std::is_same_v<T, int>)
{
auto* widget = mClient->createWidget<EditNumberInt>("MW_ValueEditNumber", {0, 0, mClient->getWidth(), mClient->getHeight()}, MyGUI::Align::Stretch);
widget->setData(uniform);
mBases.emplace_back(widget);
}
else if constexpr (std::is_same_v<T, bool>)
{
auto* widget = mClient->createWidget<EditBool>("MW_ValueEditBool", {0, 0, mClient->getWidth(), mClient->getHeight()}, MyGUI::Align::Stretch);
widget->setData(uniform);
mBases.emplace_back(widget);
}
if constexpr (std::is_same_v<osg::Vec4f, T>)
{
createVectorWidget<T, EditNumberFloat4>(uniform, mClient, this);
}
else if constexpr (std::is_same_v<osg::Vec3f, T>)
{
createVectorWidget<T, EditNumberFloat3>(uniform, mClient, this);
}
else if constexpr (std::is_same_v<osg::Vec2f, T>)
{
createVectorWidget<T, EditNumberFloat2>(uniform, mClient, this);
}
else if constexpr (std::is_same_v<T, float>)
{
auto* widget = mClient->createWidget<EditNumberFloat>("MW_ValueEditNumber",
{ 0, 0, mClient->getWidth(), mClient->getHeight() }, MyGUI::Align::Stretch);
widget->setData(uniform);
mBases.emplace_back(widget);
}
else if constexpr (std::is_same_v<T, int>)
{
auto* widget = mClient->createWidget<EditNumberInt>("MW_ValueEditNumber",
{ 0, 0, mClient->getWidth(), mClient->getHeight() }, MyGUI::Align::Stretch);
widget->setData(uniform);
mBases.emplace_back(widget);
}
else if constexpr (std::is_same_v<T, bool>)
{
auto* widget = mClient->createWidget<EditBool>("MW_ValueEditBool",
{ 0, 0, mClient->getWidth(), mClient->getHeight() }, MyGUI::Align::Stretch);
widget->setData(uniform);
mBases.emplace_back(widget);
}
mReset->eventMouseButtonClick += MyGUI::newDelegate(this, &UniformBase::notifyResetClicked);
mReset->eventMouseButtonClick += MyGUI::newDelegate(this, &UniformBase::notifyResetClicked);
for (EditBase* base : mBases)
base->setValueFromUniform();
}, uniform->mData);
for (EditBase* base : mBases)
base->setValueFromUniform();
},
uniform->mData);
}
void UniformBase::addItem(EditBase* item)

View file

@ -1,8 +1,8 @@
#ifndef OPENMW_COMPONENTS_FX_WIDGETS_H
#define OPENMW_COMPONENTS_FX_WIDGETS_H
#include <MyGUI_Gui.h>
#include <MyGUI_Button.h>
#include <MyGUI_Gui.h>
#include <MyGUI_InputManager.h>
#include <osg/Vec2f>
@ -65,8 +65,8 @@ namespace fx
void initialiseOverride() override;
void notifyMouseButtonClick(MyGUI::Widget* sender);
MyGUI::Button* mCheckbutton{nullptr};
MyGUI::Widget* mFill{nullptr};
MyGUI::Button* mCheckbutton{ nullptr };
MyGUI::Widget* mFill{ nullptr };
};
template <class T, class UType>
@ -135,7 +135,6 @@ namespace fx
}
private:
void initialiseOverride() override
{
Base::initialiseOverride();
@ -181,7 +180,8 @@ namespace fx
// allow finer tuning when shift is pressed
constexpr double scaling = 20.0;
T step = MyGUI::InputManager::getInstance().isShiftPressed() ? uniform->mStep / scaling : uniform->mStep;
T step
= MyGUI::InputManager::getInstance().isShiftPressed() ? uniform->mStep / scaling : uniform->mStep;
if (step == 0)
{
@ -215,9 +215,11 @@ namespace fx
return;
if constexpr (std::is_fundamental_v<UType>)
setValue(std::clamp<T>(uniform->template getValue<UType>() + step, uniform->template getMin<UType>(), uniform->template getMax<T>()));
setValue(std::clamp<T>(uniform->template getValue<UType>() + step,
uniform->template getMin<UType>(), uniform->template getMax<T>()));
else
setValue(std::clamp<T>(uniform->template getValue<UType>()[mIndex] + step, uniform->template getMin<UType>()[mIndex], uniform->template getMax<UType>()[mIndex]));
setValue(std::clamp<T>(uniform->template getValue<UType>()[mIndex] + step,
uniform->template getMin<UType>()[mIndex], uniform->template getMax<UType>()[mIndex]));
}
void notifyButtonClicked(MyGUI::Widget* sender)
@ -233,21 +235,36 @@ namespace fx
increment(uniform->mStep);
}
MyGUI::Button* mButtonDecrease{nullptr};
MyGUI::Button* mButtonIncrease{nullptr};
MyGUI::Widget* mDragger{nullptr};
MyGUI::Widget* mFill{nullptr};
MyGUI::TextBox* mValueLabel{nullptr};
MyGUI::Button* mButtonDecrease{ nullptr };
MyGUI::Button* mButtonIncrease{ nullptr };
MyGUI::Widget* mDragger{ nullptr };
MyGUI::Widget* mFill{ nullptr };
MyGUI::TextBox* mValueLabel{ nullptr };
T mValue{};
int mLastPointerX{0};
int mLastPointerX{ 0 };
};
class EditNumberFloat4 : public EditNumber<float, osg::Vec4f> { MYGUI_RTTI_DERIVED(EditNumberFloat4) };
class EditNumberFloat3 : public EditNumber<float, osg::Vec3f> { MYGUI_RTTI_DERIVED(EditNumberFloat3) };
class EditNumberFloat2 : public EditNumber<float, osg::Vec2f> { MYGUI_RTTI_DERIVED(EditNumberFloat2) };
class EditNumberFloat : public EditNumber<float, float> { MYGUI_RTTI_DERIVED(EditNumberFloat) };
class EditNumberInt : public EditNumber<int, int> { MYGUI_RTTI_DERIVED(EditNumberInt) };
class EditNumberFloat4 : public EditNumber<float, osg::Vec4f>
{
MYGUI_RTTI_DERIVED(EditNumberFloat4)
};
class EditNumberFloat3 : public EditNumber<float, osg::Vec3f>
{
MYGUI_RTTI_DERIVED(EditNumberFloat3)
};
class EditNumberFloat2 : public EditNumber<float, osg::Vec2f>
{
MYGUI_RTTI_DERIVED(EditNumberFloat2)
};
class EditNumberFloat : public EditNumber<float, float>
{
MYGUI_RTTI_DERIVED(EditNumberFloat)
};
class EditNumberInt : public EditNumber<int, int>
{
MYGUI_RTTI_DERIVED(EditNumberInt)
};
class UniformBase final : public MyGUI::Widget
{
@ -263,14 +280,13 @@ namespace fx
Gui::AutoSizedTextBox* getLabel() { return mLabel; }
private:
void notifyResetClicked(MyGUI::Widget* sender);
void initialiseOverride() override;
Gui::AutoSizedButton* mReset{nullptr};
Gui::AutoSizedTextBox* mLabel{nullptr};
MyGUI::Widget* mClient{nullptr};
Gui::AutoSizedButton* mReset{ nullptr };
Gui::AutoSizedTextBox* mLabel{ nullptr };
MyGUI::Widget* mClient{ nullptr };
std::vector<EditBase*> mBases;
};
}