Skip to content

Instantly share code, notes, and snippets.

@yorung
Last active March 28, 2016 16:00
Show Gist options
  • Select an option

  • Save yorung/63d1bbe45c4b52762293 to your computer and use it in GitHub Desktop.

Select an option

Save yorung/63d1bbe45c4b52762293 to your computer and use it in GitHub Desktop.
Share same vertex layout across multiple vertex shaders
struct InputElement {
const char* name;
ShaderFormat format;
int offset;
int inputSlot;
bool perInstance;
};
static InputElement elements[] = {
{"POSITION", SF_R32G32B32_FLOAT, 0, 0, false},
{"COLOR", SF_R8G8B8A8_UNORM, 12, 0, false},
{"TEXCOORD", SF_R32G32_FLOAT, 16, 0, false},
};
GLuint CreateProgramWithElements()
{
GLuint program = glCreateProgram();
for (int i = 0; i < numElements; i++) {
glBindAttribLocation(program, i, elements[i].name);
}
return program;
}
void CreatePrograms()
{
GLuint a = CreateProgramWithElements();
GLuint b = CreateProgramWithElements();
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment