Last active
March 28, 2016 16:00
-
-
Save yorung/63d1bbe45c4b52762293 to your computer and use it in GitHub Desktop.
Share same vertex layout across multiple vertex shaders
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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