summaryrefslogtreecommitdiff
path: root/src/cubeaddon.h
blob: 45933a0ac7f2f60c7f02b4bf69d85e7dd7bd9802 (plain)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
 * Compiz cube reflection and cylinder deformation plugin
 *
 * cubeaddon.h
 *
 * Copyright : (C) 2009 by Dennis Kasprzyk
 * E-mail    : onestone@opencompositing.org
 *
 * includes code from cubecaps.c
 *
 * Copyright : (C) 2007 Guillaume Seguin
 * E-mail    : guillaume@segu.in
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <math.h>

#include <core/core.h>
#include <core/pluginclasshandler.h>

#include <composite/composite.h>
#include <opengl/opengl.h>
#include <cube/cube.h>

#include "cubeaddon_options.h"

#define CUBEADDON_GRID_SIZE    100
#define CAP_ELEMENTS 15
#define CAP_NVERTEX (((CAP_ELEMENTS * (CAP_ELEMENTS + 1)) + 2) * 3)
#define CAP_NIDX (CAP_ELEMENTS * (CAP_ELEMENTS - 1) * 4)

#define CAP_NIMGVERTEX (((CAP_ELEMENTS + 1) * (CAP_ELEMENTS + 1)) * 5)
#define CAP_NIMGIDX (CAP_ELEMENTS * CAP_ELEMENTS * 4)

#define RAD2I1024 162.9746617

class CubeaddonScreen :
    public CompositeScreenInterface,
    public GLScreenInterface,
    public CubeScreenInterface,
    public PluginClassHandler<CubeaddonScreen, CompScreen>,
    public CubeaddonOptions
{
    public:
	CubeaddonScreen (CompScreen *);
	~CubeaddonScreen ();
	
	bool setOption (const CompString &name, CompOption::Value &value);

	void donePaint ();

	bool glPaintOutput (const GLScreenPaintAttrib&, const GLMatrix&,
			    const CompRegion&, CompOutput *, unsigned int);
	void glPaintTransformedOutput (const GLScreenPaintAttrib&,
				       const GLMatrix&, const CompRegion&,
				       CompOutput *, unsigned int);


	void cubeGetRotation (float &x, float &v, float &progress);
	void cubeClearTargetOutput (float xRotate, float vRotate);
	void cubePaintTop (const GLScreenPaintAttrib &sAttrib,
			   const GLMatrix            &transform,
			   CompOutput                *output,
			   int                       size);
	void cubePaintBottom (const GLScreenPaintAttrib &sAttrib,
			      const GLMatrix            &transform,
			      CompOutput                *output,
			      int                       size);
	bool cubeCheckOrientation (const GLScreenPaintAttrib &sAttrib,
				   const GLMatrix            &transform,
				   CompOutput                *output,
				   std::vector<GLVector>     &points);
	bool cubeShouldPaintViewport (const GLScreenPaintAttrib &sAttrib,
				      const GLMatrix            &transform,
				      CompOutput                *output,
				      PaintOrder                order);
	
	bool cubeShouldPaintAllViewports ();

	class CubeCap
	{
	    public:
		CubeCap ();
		
		void load (bool scale, bool aspect, bool clamp);
		
		int                        mCurrent;
		CompOption::Value::Vector  mFiles;

		bool                       mLoaded;

		GLTexture::List            mTexture;
		GLMatrix                   mTexMat;
	};
	
	friend class CubeaddonWindow;
	
    private:
	bool changeCap (bool top, int change);
	void drawBasicGround ();
	void paintCap (const GLScreenPaintAttrib &sAttrib,
		       const GLMatrix            &transform,
		       CompOutput                *output,
		       int                       size,
		       bool                      top,
		       bool                      adjust,
		       unsigned short            *color);

    private:
	
	CompositeScreen *cScreen;
	GLScreen        *gScreen;
	CubeScreen      *cubeScreen;


	bool mReflection;
	bool mFirst;

	CompOutput *mLast;

	float mYTrans;
	float mZTrans;

	float mBackVRotate;
	float mVRot;

	float mDeform;
	bool  mWasDeformed;

	GLfloat      *mWinNormals;
	unsigned int mWinNormSize;

	GLfloat  mCapFill[CAP_NVERTEX];
	GLfloat  mCapFillNorm[CAP_NVERTEX];
	GLushort mCapFillIdx[CAP_NIDX];
	float    mCapDeform;
	float    mCapDistance;
	int      mCapDeformType;

	CubeCap mTopCap;
	CubeCap mBottomCap;
	
	float mSinT[1024];
	float mCosT[1024];
};

class CubeaddonWindow :
    public GLWindowInterface,
    public PluginClassHandler<CubeaddonWindow, CompWindow>
{
    public:
	CubeaddonWindow (CompWindow *);

	bool glDraw (const GLMatrix&, GLFragment::Attrib&,
		     const CompRegion&, unsigned int);
	void glAddGeometry (const GLTexture::MatrixList&,
			    const CompRegion&, const CompRegion&,
			    unsigned int, unsigned int);
	void glDrawTexture (GLTexture *, GLFragment::Attrib& attrib,
			    unsigned int);

	CompWindow      *window;
	GLWindow        *gWindow;
	CubeaddonScreen *caScreen;
	CubeScreen      *cubeScreen;
};

class CubeaddonPluginVTable :
    public CompPlugin::VTableForScreenAndWindow<CubeaddonScreen, CubeaddonWindow>
{
    public:
	bool init ();
};