Merge remote-tracking branch 'origin/custom_postprocess'

This commit is contained in:
Rachael Alexanderson 2017-07-03 17:17:17 -04:00
commit 2bfd7859e4
4 changed files with 67 additions and 0 deletions

View File

@ -183,6 +183,40 @@ void FGLRenderer::PostProcessScene(int fixedcm)
RunCustomPostProcessShaders("scene");
}
#include "vm.h"
DEFINE_ACTION_FUNCTION(_Shader, SetUniform1f)
{
PARAM_PROLOGUE;
PARAM_STRING(shaderName);
PARAM_STRING(uniformName);
PARAM_FLOAT_DEF(value);
for (unsigned int i = 0; i < PostProcessShaders.Size(); i++)
{
PostProcessShader &shader = PostProcessShaders[i];
if (shader.Name == shaderName)
shader.Uniform1f[uniformName] = value;
}
return 0;
}
DEFINE_ACTION_FUNCTION(_Shader, SetUniform1i)
{
PARAM_PROLOGUE;
PARAM_STRING(shaderName);
PARAM_STRING(uniformName);
PARAM_INT_DEF(value);
for (unsigned int i = 0; i < PostProcessShaders.Size(); i++)
{
PostProcessShader &shader = PostProcessShaders[i];
if (shader.Name == shaderName)
shader.Uniform1i[uniformName] = value;
}
return 0;
}
void FGLRenderer::RunCustomPostProcessShaders(FString target)
{
if (!gl_custompost)
@ -230,6 +264,24 @@ void FGLRenderer::RunCustomPostProcessShaders(FString target)
shader.Instance->Program.Bind();
TMap<FString, float>::Iterator it1f(shader.Uniform1f);
TMap<FString, float>::Pair *pair1f;
while (it1f.NextPair(pair1f))
{
int location = glGetUniformLocation(shader.Instance->Program, pair1f->Key.GetChars());
if (location != -1)
glUniform1f(location, pair1f->Value);
}
TMap<FString, int>::Iterator it1i(shader.Uniform1i);
TMap<FString, int>::Pair *pair1i;
while (it1i.NextPair(pair1i))
{
int location = glGetUniformLocation(shader.Instance->Program, pair1i->Key.GetChars());
if (location != -1)
glUniform1i(location, pair1i->Value);
}
shader.Instance->InputTexture.Set(0);
if (shader.Instance->HWTexture)

View File

@ -92,6 +92,11 @@ struct PostProcessShader
FString ShaderLumpName;
int ShaderVersion = 0;
FTexture *Texture = nullptr;
FString Name;
TMap<FString, int> Uniform1i;
TMap<FString, float> Uniform1f;
std::shared_ptr<PostProcessShaderInstance> Instance;
};

View File

@ -693,6 +693,11 @@ void gl_ParseHardwareShader(FScanner &sc, int deflump)
sc.MustGetNumber();
shaderdesc.ShaderVersion = sc.Number;
}
else if (sc.Compare("name"))
{
sc.MustGetString();
shaderdesc.Name = sc.String;
}
else if (sc.Compare("texture"))
{
sc.MustGetString();

View File

@ -775,3 +775,8 @@ class Lighting : SectorEffect native
{
}
struct Shader native
{
native static void SetUniform1f(string shaderName, string uniformName, float value);
native static void SetUniform1i(string shaderName, string uniformName, int value);
}