1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
// Gawain shader interface (C --> GLSL)
//
// This code is part of the Gawain library, with modifications
// specific to integration with Blender.
//
// Copyright 2017 Mike Erwin
//
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of
// the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
#pragma once
#include "gwn_common.h"
typedef enum {
GWN_UNIFORM_NONE = 0, // uninitialized/unknown
GWN_UNIFORM_MODELVIEW, // mat4 ModelViewMatrix
GWN_UNIFORM_PROJECTION, // mat4 ProjectionMatrix
GWN_UNIFORM_MVP, // mat4 ModelViewProjectionMatrix
GWN_UNIFORM_MODELVIEW_INV, // mat4 ModelViewInverseMatrix
GWN_UNIFORM_PROJECTION_INV, // mat4 ProjectionInverseMatrix
GWN_UNIFORM_NORMAL, // mat3 NormalMatrix
GWN_UNIFORM_COLOR, // vec4 color
GWN_UNIFORM_CUSTOM, // custom uniform, not one of the above built-ins
GWN_NUM_UNIFORMS, // Special value, denotes number of builtin uniforms.
} Gwn_UniformBuiltin;
typedef struct Gwn_ShaderInput {
struct Gwn_ShaderInput* next;
uint32_t name_offset;
unsigned name_hash;
Gwn_UniformBuiltin builtin_type; // only for uniform inputs
GLenum gl_type; // only for attrib inputs
GLint size; // only for attrib inputs
GLint location;
} Gwn_ShaderInput;
#define GWN_NUM_SHADERINTERFACE_BUCKETS 1009
typedef struct Gwn_ShaderInterface {
GLint program;
uint32_t name_buffer_offset;
Gwn_ShaderInput* attrib_buckets[GWN_NUM_SHADERINTERFACE_BUCKETS];
Gwn_ShaderInput* uniform_buckets[GWN_NUM_SHADERINTERFACE_BUCKETS];
Gwn_ShaderInput* builtin_uniforms[GWN_NUM_UNIFORMS];
char* name_buffer;
} Gwn_ShaderInterface;
Gwn_ShaderInterface* GWN_shaderinterface_create(GLint program_id);
void GWN_shaderinterface_discard(Gwn_ShaderInterface*);
const Gwn_ShaderInput* GWN_shaderinterface_uniform(const Gwn_ShaderInterface*, const char* name);
const Gwn_ShaderInput* GWN_shaderinterface_uniform_builtin(const Gwn_ShaderInterface*, Gwn_UniformBuiltin);
const Gwn_ShaderInput* GWN_shaderinterface_attr(const Gwn_ShaderInterface*, const char* name);
|