mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2025-04-24 08:38:47 +00:00
Updated shaderuniforms.h to allow for non buffered uniforms
This commit is contained in:
parent
ddd9cb41f5
commit
9cea1e1c48
1 changed files with 39 additions and 22 deletions
|
@ -40,33 +40,47 @@ public:
|
|||
const char *Name;
|
||||
UniformType Type;
|
||||
std::size_t Offset;
|
||||
int UniformLocation = -1; // Only used when uniform buffers aren't used
|
||||
};
|
||||
|
||||
class UniformBlockDecl
|
||||
{
|
||||
public:
|
||||
static FString Create(const char *name, const std::vector<UniformFieldDesc> &fields, int bindingpoint)
|
||||
static FString Create(const char *name, const std::vector<UniformFieldDesc> &fields, int bindingpoint, bool noUniformBuffer = false)
|
||||
{
|
||||
FString decl;
|
||||
FString layout;
|
||||
if (bindingpoint == -1)
|
||||
|
||||
if (noUniformBuffer == false)
|
||||
{
|
||||
layout = "push_constant";
|
||||
FString layout;
|
||||
if (bindingpoint == -1)
|
||||
{
|
||||
layout = "push_constant";
|
||||
}
|
||||
else if (screen->glslversion < 4.20)
|
||||
{
|
||||
layout = "std140";
|
||||
}
|
||||
else
|
||||
{
|
||||
layout.Format("std140, binding = %d", bindingpoint);
|
||||
}
|
||||
decl.Format("layout(%s) uniform %s\n{\n", layout.GetChars(), name);
|
||||
for (size_t i = 0; i < fields.size(); i++)
|
||||
{
|
||||
decl.AppendFormat("\t%s %s;\n", GetTypeStr(fields[i].Type), fields[i].Name);
|
||||
}
|
||||
decl += "};\n";
|
||||
}
|
||||
else if (screen->glslversion < 4.20)
|
||||
else // Not using buffer
|
||||
{
|
||||
layout = "std140";
|
||||
decl += "\n";
|
||||
for (size_t i = 0; i < fields.size(); i++)
|
||||
{
|
||||
decl.AppendFormat("\tuniform %s %s;\n", GetTypeStr(fields[i].Type), fields[i].Name);
|
||||
}
|
||||
decl += "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
layout.Format("std140, binding = %d", bindingpoint);
|
||||
}
|
||||
decl.Format("layout(%s) uniform %s\n{\n", layout.GetChars(), name);
|
||||
for (size_t i = 0; i < fields.size(); i++)
|
||||
{
|
||||
decl.AppendFormat("\t%s %s;\n", GetTypeStr(fields[i].Type), fields[i].Name);
|
||||
}
|
||||
decl += "};\n";
|
||||
|
||||
return decl;
|
||||
}
|
||||
|
@ -114,12 +128,12 @@ public:
|
|||
return bindingpoint;
|
||||
}
|
||||
|
||||
FString CreateDeclaration(const char *name, const std::vector<UniformFieldDesc> &fields)
|
||||
FString CreateDeclaration(const char *name, const std::vector<UniformFieldDesc> &fields, bool noUniformBuffer = false)
|
||||
{
|
||||
mFields = fields;
|
||||
return UniformBlockDecl::Create(name, fields, bindingpoint);
|
||||
return UniformBlockDecl::Create(name, fields, bindingpoint, noUniformBuffer);
|
||||
}
|
||||
|
||||
|
||||
void Init()
|
||||
{
|
||||
if (mBuffer == nullptr)
|
||||
|
@ -131,24 +145,27 @@ public:
|
|||
if (mBuffer != nullptr)
|
||||
mBuffer->SetData(sizeof(T), &Values);
|
||||
}
|
||||
|
||||
|
||||
IDataBuffer* GetBuffer() const
|
||||
{
|
||||
// OpenGL needs to mess around with this in ways that should not be part of the interface.
|
||||
return mBuffer;
|
||||
}
|
||||
|
||||
|
||||
T *operator->() { return &Values; }
|
||||
const T *operator->() const { return &Values; }
|
||||
|
||||
T Values;
|
||||
|
||||
std::vector<UniformFieldDesc> mFields;
|
||||
|
||||
private:
|
||||
ShaderUniforms(const ShaderUniforms &) = delete;
|
||||
ShaderUniforms &operator=(const ShaderUniforms &) = delete;
|
||||
|
||||
IDataBuffer *mBuffer = nullptr;
|
||||
std::vector<UniformFieldDesc> mFields;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue