source: trunk/src/gpu/shader.h @ 2001

Last change on this file since 2001 was 2001, checked in by sam, 7 years ago

tutorial: add a new texture generation example.

  • Property svn:keywords set to Id
File size: 2.3 KB
Line 
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
21namespace lol
22{
23
24struct ShaderUniform
25{
26    friend class Shader;
27
28public:
29    inline ShaderUniform() : flags(0) {}
30
31private:
32    uintptr_t frag, vert;
33    /* FIXME: do we really need this to indicate which locations are valid? */
34    uint32_t flags;
35};
36
37struct ShaderAttrib
38{
39    friend class Shader;
40    friend class VertexDeclaration;
41
42public:
43    inline ShaderAttrib() : m_flags((uint64_t)0 - 1) {}
44
45private:
46    uint64_t m_flags;
47};
48
49struct ShaderTexture
50{
51    friend class Shader;
52    friend class FrameBuffer;
53    friend class Texture;
54
55public:
56    inline ShaderTexture() : m_flags(0) {}
57
58private:
59    uint64_t m_flags;
60};
61
62class ShaderData;
63
64class Shader
65{
66public:
67    static Shader *Create(char const *lolfx);
68    static void Destroy(Shader *shader);
69
70    ShaderAttrib GetAttribLocation(char const *attr, struct VertexUsage usage,
71                                   int index) const;
72
73    ShaderUniform GetUniformLocation(char const *uni) const;
74    void SetUniform(ShaderUniform const &uni, int i);
75    void SetUniform(ShaderUniform const &uni, ivec2 const &v);
76    void SetUniform(ShaderUniform const &uni, ivec3 const &v);
77    void SetUniform(ShaderUniform const &uni, ivec4 const &v);
78    void SetUniform(ShaderUniform const &uni, float f);
79    void SetUniform(ShaderUniform const &uni, vec2 const &v);
80    void SetUniform(ShaderUniform const &uni, vec3 const &v);
81    void SetUniform(ShaderUniform const &uni, vec4 const &v);
82    void SetUniform(ShaderUniform const &uni, mat2 const &m);
83    void SetUniform(ShaderUniform const &uni, mat3 const &m);
84    void SetUniform(ShaderUniform const &uni, mat4 const &m);
85    void SetUniform(ShaderUniform const &uni, ShaderTexture tex, int index);
86
87    void Bind() const;
88    void Unbind() const;
89
90protected:
91    Shader(char const *vert, char const *frag);
92    ~Shader();
93
94private:
95    ShaderData *data;
96};
97
98} /* namespace lol */
99
100#endif // __LOL_SHADER_H__
101
Note: See TracBrowser for help on using the repository browser.