Skip to content

Instantly share code, notes, and snippets.

@Themaister
Created November 14, 2015 20:33
Show Gist options
  • Save Themaister/80dadf408d15eec9ec2c to your computer and use it in GitHub Desktop.
Save Themaister/80dadf408d15eec9ec2c to your computer and use it in GitHub Desktop.
// GLSL source
#version 450
layout(location = 0) uniform mat4 uMVP;
layout(location = 0) in vec4 aPosition;
void main()
{
gl_Position = uMVP * aPosition;
}
// This C++ shader is autogenerated by TBDProjectName.
#include "TBDProjectName/internal_interface.hpp"
#include "TBDProjectName/external_interface.h"
#include <stdint.h>
#include <stdio.h>
using namespace TBDProjectName;
using namespace glm;
namespace Implementation
{
struct Shader : VertexShader<Shader>
{
internal::StageInput<vec4> aPosition__;
#define aPosition aPosition__.get()
internal::UniformConstant<mat4> uMVP__;
#define uMVP uMVP__.get()
inline void entry_point()
{
gl_Position = (uMVP * aPosition);
}
Shader()
{
register_stage_input(aPosition__, 0);
register_uniform_constant(uMVP__, 0);
}
};
}
TBDProjectName_shader_t* TBDProjectName_construct(void)
{
return new Implementation::Shader();
}
void TBDProjectName_destruct(TBDProjectName_shader_t *shader)
{
delete static_cast<Implementation::Shader*>(shader);
}
void TBDProjectName_invoke(TBDProjectName_shader_t *shader)
{
static_cast<Implementation::Shader*>(shader)->invoke();
}
static const struct TBDProjectName_interface vtable =
{
TBDProjectName_construct,
TBDProjectName_destruct,
TBDProjectName_invoke,
};
const struct TBDProjectName_interface* TBDProjectName_get_interface(void)
{
return &vtable;
}
// Test code ...
int main()
{
auto *iface = TBDProjectName_get_interface();
auto *shader = iface->construct();
vec4 pos = vec4(0.0f);
vec4 inPos = vec4(1.0f);
mat4 mvp = mat4(4.0f);
TBDProjectName_set_builtin(shader, TBDPROJECTNAME_BUILTIN_POSITION, &pos, sizeof(pos));
TBDProjectName_set_stage_input(shader, 0, &inPos, sizeof(inPos));
TBDProjectName_set_uniform_constant(shader, 0, &mvp, sizeof(mvp));
iface->invoke(shader);
iface->destruct(shader);
printf("%f %f %f %f\n", pos.x, pos.y, pos.z, pos.w);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment