rpcsx/rpcs3/Emu/GS/GL/GLShaderParam.h

143 lines
2.6 KiB
C
Raw Normal View History

#pragma once
#include "OpenGL.h"
2013-11-09 22:29:49 +01:00
enum GLParamFlag
{
PARAM_IN,
PARAM_OUT,
PARAM_UNIFORM,
PARAM_CONST,
PARAM_NONE,
};
2013-11-09 22:29:49 +01:00
struct GLParamItem
{
2013-11-27 20:16:19 +01:00
std::string name;
std::string location;
std::string value;
2013-11-27 20:16:19 +01:00
GLParamItem(const std::string& _name, int _location, const std::string& _value = "")
: name(_name)
, value(_value)
{
2013-11-27 20:16:19 +01:00
if (_location > -1)
location = "layout (location = " + std::to_string(_location) + ") ";
else
location = "";
}
};
2013-11-09 22:29:49 +01:00
struct GLParamType
{
2013-11-09 22:29:49 +01:00
const GLParamFlag flag;
2013-11-27 20:16:19 +01:00
std::string type;
std::vector<GLParamItem> items;
2013-11-27 20:16:19 +01:00
GLParamType(const GLParamFlag _flag, const std::string& _type)
: flag(_flag)
, type(_type)
{
}
2013-11-27 20:16:19 +01:00
bool SearchName(const std::string& name)
{
for(u32 i=0; i<items.size(); ++i)
{
2013-11-27 20:16:19 +01:00
if(items[i].name.compare(name) == 0) return true;
}
return false;
}
2013-11-27 20:16:19 +01:00
std::string Format()
{
2013-11-27 20:16:19 +01:00
std::string ret = "";
for(u32 n=0; n<items.size(); ++n)
{
2013-11-27 20:16:19 +01:00
ret += items[n].location + type + " " + items[n].name;
if(!items[n].value.empty())
{
2013-11-27 20:16:19 +01:00
ret += " = " + items[n].value;
}
ret += ";\n";
}
return ret;
}
};
2013-11-09 22:29:49 +01:00
struct GLParamArray
{
std::vector<GLParamType> params;
2013-11-27 20:16:19 +01:00
GLParamType* SearchParam(const std::string& type)
{
for(u32 i=0; i<params.size(); ++i)
{
2013-11-27 20:16:19 +01:00
if (params[i].type.compare(type) == 0)
return &params[i];
}
return nullptr;
}
2013-11-27 20:16:19 +01:00
std::string GetParamFlag(const GLParamFlag flag)
{
switch(flag)
{
2014-04-04 15:25:38 +02:00
case PARAM_OUT: return "out ";
case PARAM_IN: return "in ";
case PARAM_UNIFORM: return "uniform ";
case PARAM_CONST: return "const ";
}
2013-11-27 20:16:19 +01:00
return "";
}
2013-11-27 20:16:19 +01:00
bool HasParam(const GLParamFlag flag, std::string type, const std::string& name)
{
type = GetParamFlag(flag) + type;
2013-11-09 22:29:49 +01:00
GLParamType* t = SearchParam(type);
return t && t->SearchName(name);
}
2013-11-27 20:16:19 +01:00
std::string AddParam(const GLParamFlag flag, std::string type, const std::string& name, const std::string& value)
{
type = GetParamFlag(flag) + type;
2013-11-09 22:29:49 +01:00
GLParamType* t = SearchParam(type);
if(t)
{
if(!t->SearchName(name)) t->items.emplace_back(name, -1, value);
}
else
{
const u32 num = params.size();
params.emplace_back(flag, type);
params[num].items.emplace_back(name, -1, value);
}
return name;
}
2013-11-27 20:16:19 +01:00
std::string AddParam(const GLParamFlag flag, std::string type, const std::string& name, int location = -1)
{
type = GetParamFlag(flag) + type;
2013-11-09 22:29:49 +01:00
GLParamType* t = SearchParam(type);
if(t)
{
if(!t->SearchName(name)) t->items.emplace_back(name, location);
}
else
{
const u32 num = params.size();
params.emplace_back(flag, type);
params[num].items.emplace_back(name, location);
}
return name;
}
};