1 | // |
---|
2 | // Lol Engine |
---|
3 | // |
---|
4 | // Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net> |
---|
5 | // This program is free software; you can redistribute it and/or |
---|
6 | // modify it under the terms of the Do What The Fuck You Want To |
---|
7 | // Public License, Version 2, as published by Sam Hocevar. See |
---|
8 | // http://sam.zoy.org/projects/COPYING.WTFPL for more details. |
---|
9 | // |
---|
10 | |
---|
11 | // |
---|
12 | // The Shader class |
---|
13 | // ---------------- |
---|
14 | // |
---|
15 | |
---|
16 | #if !defined __LOL_SHADER_H__ |
---|
17 | #define __LOL_SHADER_H__ |
---|
18 | |
---|
19 | #include <stdint.h> |
---|
20 | |
---|
21 | namespace lol |
---|
22 | { |
---|
23 | |
---|
24 | struct ShaderUniform |
---|
25 | { |
---|
26 | friend class Shader; |
---|
27 | |
---|
28 | public: |
---|
29 | inline ShaderUniform() : flags(0) {} |
---|
30 | |
---|
31 | private: |
---|
32 | uintptr_t frag, vert; |
---|
33 | /* FIXME: do we really need this to indicate which locations are valid? */ |
---|
34 | uint32_t flags; |
---|
35 | }; |
---|
36 | |
---|
37 | struct ShaderAttrib |
---|
38 | { |
---|
39 | friend class Shader; |
---|
40 | friend class VertexDeclaration; |
---|
41 | |
---|
42 | public: |
---|
43 | inline ShaderAttrib() : m_flags((uint64_t)0 - 1) {} |
---|
44 | |
---|
45 | private: |
---|
46 | uint64_t m_flags; |
---|
47 | }; |
---|
48 | |
---|
49 | class ShaderData; |
---|
50 | |
---|
51 | class Shader |
---|
52 | { |
---|
53 | public: |
---|
54 | static Shader *Create(char const *lolfx); |
---|
55 | static Shader *Create(char const *vert, char const *frag); |
---|
56 | static void Destroy(Shader *shader); |
---|
57 | |
---|
58 | ShaderAttrib GetAttribLocation(char const *attr, struct VertexUsage usage, |
---|
59 | int index) const; |
---|
60 | |
---|
61 | ShaderUniform GetUniformLocation(char const *uni) const; |
---|
62 | void SetUniform(ShaderUniform const &uni, int i); |
---|
63 | void SetUniform(ShaderUniform const &uni, ivec2 const &v); |
---|
64 | void SetUniform(ShaderUniform const &uni, ivec3 const &v); |
---|
65 | void SetUniform(ShaderUniform const &uni, ivec4 const &v); |
---|
66 | void SetUniform(ShaderUniform const &uni, float f); |
---|
67 | void SetUniform(ShaderUniform const &uni, vec2 const &v); |
---|
68 | void SetUniform(ShaderUniform const &uni, vec3 const &v); |
---|
69 | void SetUniform(ShaderUniform const &uni, vec4 const &v); |
---|
70 | void SetUniform(ShaderUniform const &uni, mat2 const &m); |
---|
71 | void SetUniform(ShaderUniform const &uni, mat3 const &m); |
---|
72 | void SetUniform(ShaderUniform const &uni, mat4 const &m); |
---|
73 | |
---|
74 | /* FIXME: this should be called SetUniform, too, but we need a new |
---|
75 | * type to represent textures. */ |
---|
76 | void SetTexture(ShaderUniform const &uni, int id, int index); |
---|
77 | |
---|
78 | void Bind() const; |
---|
79 | void Unbind() const; |
---|
80 | |
---|
81 | protected: |
---|
82 | Shader(char const *vert, char const *frag); |
---|
83 | ~Shader(); |
---|
84 | |
---|
85 | private: |
---|
86 | ShaderData *data; |
---|
87 | }; |
---|
88 | |
---|
89 | } /* namespace lol */ |
---|
90 | |
---|
91 | #endif // __LOL_SHADER_H__ |
---|
92 | |
---|