~compiz-team/compiz/0.9.12

« back to all changes in this revision

Viewing changes to plugins/water/src/water.h

MergeĀ GLESĀ support

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
22
 *
23
23
 * Author: David Reveman <davidr@novell.com>
 
24
 *         Frederic Plourde <frederic.plourde@collabora.co.uk>
24
25
 */
25
26
 
26
27
#include "water_options.h"
29
30
 
30
31
#include <composite/composite.h>
31
32
#include <opengl/opengl.h>
 
33
#include <opengl/framebufferobject.h>
 
34
#include "shaders.h"
32
35
 
33
36
 
34
37
#define WATER_SCREEN(s) \
39
42
#define K 0.1964f
40
43
 
41
44
#define TEXTURE_NUM 3
42
 
 
43
 
#define TINDEX(ws, i) (((ws)->tIndex + (i)) % TEXTURE_NUM)
44
 
 
45
 
#define WATER_INITIATE_MODIFIERS_DEFAULT (ControlMask | CompSuperMask)
46
 
 
47
 
struct WaterFunction {
48
 
    GLFragment::FunctionId id;
49
 
 
50
 
    int target;
51
 
    int param;
52
 
    int unit;
53
 
};
 
45
#define PROG_NUM 3
 
46
 
 
47
#define INDEX(ws, i) (((ws)->fboIndex + (i)) % TEXTURE_NUM)
 
48
 
 
49
enum programTypes { SET, UPDATE, PAINT};
54
50
 
55
51
class WaterScreen :
56
52
    public ScreenInterface,
 
53
    public GLScreenInterface,
57
54
    public CompositeScreenInterface,
58
55
    public PluginClassHandler<WaterScreen,CompScreen>,
59
56
    public WaterOptions
60
57
{
61
58
    public:
 
59
 
62
60
        WaterScreen (CompScreen *screen);
63
61
        ~WaterScreen ();
64
62
 
66
64
 
67
65
        void handleEvent (XEvent *);
68
66
 
 
67
        void glPaintCompositedOutput (const CompRegion    &region,
 
68
                                      GLFramebufferObject *fbo,
 
69
                                      unsigned int         mask);
69
70
        void preparePaint (int);
70
71
        void donePaint ();
71
72
 
72
 
        GLFragment::FunctionId
73
 
        getBumpMapFragmentFunction (GLTexture *texture,
74
 
                                    int       unit,
75
 
                                    int       param);
76
 
 
77
 
        void allocTexture (int index);
78
 
 
79
 
        bool fboPrologue (int tIndex);
 
73
        bool fboPrologue (int fboIndex);
80
74
        void fboEpilogue ();
81
75
        bool fboUpdate (float dt, float fade);
82
 
        bool fboVertices (GLenum type, XPoint *p, int n, float v);
83
 
 
84
 
        void softwareUpdate (float dt, float fade);
85
 
        void softwarePoints (XPoint *p, int n, float add);
86
 
        void softwareLines (XPoint *p, int n, float v);
87
 
        void softwareVertices (GLenum type, XPoint *p, int n, float v);
88
76
 
89
77
        void waterUpdate (float dt);
90
 
        void scaleVertices (XPoint *p, int n);
91
78
        void waterVertices (GLenum type, XPoint *p, int n, float v);
92
79
 
93
80
        bool rainTimeout ();
94
81
        bool wiperTimeout ();
95
82
 
96
 
        void waterReset ();
 
83
        void waterSetup ();
97
84
 
98
85
        void handleMotionEvent ();
99
86
 
104
91
 
105
92
        CompScreen::GrabHandle grabIndex;
106
93
 
107
 
        int width, height;
108
 
 
109
 
        GLuint program;
110
 
        GLuint texture[TEXTURE_NUM];
111
 
 
112
 
        int     tIndex;
 
94
        GLProgram      *program[PROG_NUM];
 
95
        GLVertexBuffer *vertexBuffer[PROG_NUM];
 
96
 
 
97
        static GLfloat vertexData[18];
 
98
 
 
99
        static GLfloat textureData[12];
 
100
 
 
101
        GLFramebufferObject *waterFbo[TEXTURE_NUM];
 
102
 
 
103
        GLFramebufferObject *oldFbo;
 
104
        GLint oldViewport[4];
 
105
        int    fboIndex;
 
106
        bool   useFbo;
 
107
 
 
108
        int texWidth, texHeight;
113
109
        GLenum  target;
114
110
        GLfloat tx, ty;
115
111
 
116
112
        int count;
117
113
 
118
 
        GLuint fbo;
119
 
        GLint  fboStatus;
120
 
 
121
114
        void          *data;
122
115
        float         *d0;
123
116
        float         *d1;
129
122
        float wiperAngle;
130
123
        float wiperSpeed;
131
124
 
132
 
        std::vector<WaterFunction> bumpMapFunctions;
133
 
};
134
 
 
135
 
class WaterWindow :
136
 
    public GLWindowInterface,
137
 
    public PluginClassHandler<WaterWindow,CompWindow>
138
 
{
139
 
    public:
140
 
        WaterWindow (CompWindow *window) :
141
 
            PluginClassHandler<WaterWindow,CompWindow> (window),
142
 
            window (window),
143
 
            gWindow (GLWindow::get (window)),
144
 
            wScreen (WaterScreen::get (screen)),
145
 
            gScreen (GLScreen::get (screen))
146
 
        {
147
 
            GLWindowInterface::setHandler (gWindow, false);
148
 
        }
149
 
 
150
 
        void glDrawTexture (GLTexture *texture, GLFragment::Attrib &,
151
 
                            unsigned int);
152
 
 
153
 
        CompWindow  *window;
154
 
        GLWindow    *gWindow;
155
 
        WaterScreen *wScreen;
156
 
        GLScreen    *gScreen;
 
125
        GLVector lightVec;
157
126
};
158
127
 
159
128
class WaterPluginVTable :
160
 
    public CompPlugin::VTableForScreenAndWindow<WaterScreen,WaterWindow>
 
129
    public CompPlugin::VTableForScreen<WaterScreen>
161
130
{
162
131
    public:
163
132
 
164
133
        bool init ();
165
134
};
 
135