|
|
|
@ -17,6 +17,8 @@
|
|
|
|
|
#include "driver_opengl.h"
|
|
|
|
|
#include "driver_opengl_uniform_buffer.h"
|
|
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
|
|
#include <nel/misc/debug.h>
|
|
|
|
|
|
|
|
|
|
namespace NL3D {
|
|
|
|
@ -32,6 +34,71 @@ const char *GLSLHeaderUniformBuffer =
|
|
|
|
|
"#define NL_USER_PIXEL_PROGRAM_BIND " NL_MACRO_TO_STR(NL_USER_PIXEL_PROGRAM_BIND) "\n"
|
|
|
|
|
"#define NL_USER_MATERIAL_BIND " NL_MACRO_TO_STR(NL_USER_MATERIAL_BIND) "\n";
|
|
|
|
|
|
|
|
|
|
static const char *s_UniformBufferBindDefine[] = {
|
|
|
|
|
"NL_BUILTIN_CAMERA_BIND",
|
|
|
|
|
"NL_BUILTIN_MODEL_BIND",
|
|
|
|
|
"NL_BUILTIN_MATERIAL_BIND",
|
|
|
|
|
"NL_USER_ENV_BIND",
|
|
|
|
|
"NL_USER_VERTEX_PROGRAM_BIND",
|
|
|
|
|
"NL_USER_GEOMETRY_PROGRAM_BIND",
|
|
|
|
|
"NL_USER_PIXEL_PROGRAM_BIND",
|
|
|
|
|
"NL_USER_MATERIAL_BIND",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const char *s_UniformBufferName[] = {
|
|
|
|
|
"BuiltinCamera",
|
|
|
|
|
"BuiltinModel",
|
|
|
|
|
"BuiltinMaterial",
|
|
|
|
|
"UserEnv",
|
|
|
|
|
"UserLocal", // Yes, there can only be one per stage here, as these are bound to the stage
|
|
|
|
|
"UserLocal",
|
|
|
|
|
"UserLocal",
|
|
|
|
|
"UserMaterial",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const char *s_TypeKeyword[] = {
|
|
|
|
|
"float", // float
|
|
|
|
|
"vec2", // CVector2D
|
|
|
|
|
"vec3",
|
|
|
|
|
"vec4", // CVector
|
|
|
|
|
"int", // sint32
|
|
|
|
|
"ivec2",
|
|
|
|
|
"ivec3",
|
|
|
|
|
"ivec3",
|
|
|
|
|
"unsigned int", // uint32
|
|
|
|
|
"uvec2",
|
|
|
|
|
"uvec3",
|
|
|
|
|
"uvec4",
|
|
|
|
|
"bool",
|
|
|
|
|
"bvec2",
|
|
|
|
|
"bvec3",
|
|
|
|
|
"bvec4",
|
|
|
|
|
"mat2",
|
|
|
|
|
"mat3",
|
|
|
|
|
"mat4", // CMatrix
|
|
|
|
|
"mat2x3",
|
|
|
|
|
"mat2x4",
|
|
|
|
|
"mat3x2",
|
|
|
|
|
"mat3x4",
|
|
|
|
|
"mat4x2",
|
|
|
|
|
"mat4x3",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void generateUniformBufferGLSL(std::stringstream &ss, const CUniformBufferFormat &ubf, sint binding)
|
|
|
|
|
{
|
|
|
|
|
ss << "layout(std140, binding = " << s_UniformBufferBindDefine[binding] << ") uniform " << s_UniformBufferName[binding] << "\n";
|
|
|
|
|
ss << "{\n";
|
|
|
|
|
for (sint i = 0; i < ubf.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
const CUniformBufferFormat::CEntry &entry = ubf.get(i);
|
|
|
|
|
ss << "\t" << s_TypeKeyword[entry.Type] << " " << NLMISC::CStringMapper::unmap(entry.Name);
|
|
|
|
|
if (entry.Count != 1)
|
|
|
|
|
ss << "[" << entry.Count << "]";
|
|
|
|
|
ss << ";\n";
|
|
|
|
|
}
|
|
|
|
|
ss << "}\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // NLDRIVERGL3
|
|
|
|
|
} // NL3D
|
|
|
|
|
|
|
|
|
|