2
* effect.h - opengl 3D effects header
3
* Copyright (C) 2011, D Haley
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24
#undef ATTRIBUTE_PRINTF
25
#include <libxml/xmlreader.h>
26
#undef ATTRIBUTE_PRINTF
29
//MacOS is "special" and puts it elsewhere
31
#include <OpenGL/glu.h>
39
//opengl allows up to 6 clipping planes
40
const unsigned int MAX_OPENGL_CLIPPLANES=6;
58
ANAGLYPH_GREENMAGENTA,
59
//Colour matrix +accumulation buffer methods
62
ANAGLYPH_ENUM_END //Not a method. end of enum
68
static Camera *curCam;
70
unsigned int effectType;
74
virtual void enable(unsigned int pass=0) const =0;
75
virtual void disable() const=0;
76
std::string getName() const;
79
//Write the effect's state information to file
80
virtual bool writeState(std::ofstream &f,
81
unsigned int format, unsigned int depth) const=0;
82
//read the effects state information from an XML file
83
virtual bool readState(xmlNodePtr n)=0;
85
virtual bool needCamUpdate() const { return false;}
87
//!Returns true if the effect has any influence on the output
88
virtual bool willDoSomething() const=0;
90
virtual unsigned int numPassesNeeded() const { return 1;}
92
virtual unsigned int getType() const { return effectType;};
93
static void setCurCam(Camera *c) {curCam=c;}
94
static void setBoundingCube(const BoundCube &c) {bc=c;}
99
class BoxCropEffect : public Effect
102
//controlling ID values for gl plane. No more than MAX_OPENGL_CLIPPLANES allowed
103
unsigned int openGLIdStart,openGLIdEnd;
104
//Cropping margins (Fraction from edge towards opposite edge (complete)). 0->1.
105
//Opposing edges must sum to 0->1. (xLo,xHi,yLo...)
106
float cropFractions[6];
107
//!True if we should transform to camera coordinates before applying crop
108
bool useCamCoordinates;
110
//!Aspect ratio of output image
113
void doClip(const Point3D &origin, const Point3D & normal,unsigned int glOffset) const;
115
BoxCropEffect(){useCamCoordinates=false;effectType=EFFECT_BOX_CROP;openGLIdStart=0; }
116
virtual ~BoxCropEffect(){};
118
//!Enable the clipping plane. Values *must* be set before calling
119
void enable(unsigned int pass) const;
121
//!DIsable the clipping plane
122
void disable() const;
126
//Write the effect's state information to file
127
bool writeState(std::ofstream &f, unsigned int format,
128
unsigned int depth) const;
129
//read the effects state information from an XML file
130
bool readState(xmlNodePtr n);
132
//!Returns true if the effect has any influence on the output
133
bool willDoSomething() const;
135
//!Set the fractions of cube from margin
136
//-- there should be 6 floats (x,y,z)_(low,high) (x_lo, x_hi....)
137
// each low/hi should form a sum between 0 and 1.
138
void setFractions(const float *fractionArray);
140
void useCamCoords(bool enable){useCamCoordinates=enable;};
142
//!Alters the input box to generate cropping bounding box
143
//note the box may be inside out if the cropping limits
144
//exceed themselves..
145
void getCroppedBounds(BoundCube &b) const;
147
float getCropValue(unsigned int pos) const {ASSERT(pos<6); return cropFractions[pos];}
150
class AnaglyphEffect : public Effect
153
unsigned int colourMode;
156
mutable Camera *oldCam;
160
AnaglyphEffect(){effectType=EFFECT_ANAGLYPH;colourMode=ANAGLYPH_REDBLUE;oldCam=0;baseShift=0.01f; eyeFlip=false;}
163
//!Enable the clipping plane. Values *must* be set before calling
164
void enable(unsigned int pass) const;
166
//!DIsable the clipping plane
167
void disable() const;
169
//Write the effect's state information to file
170
bool writeState(std::ofstream &f, unsigned int format,
171
unsigned int depth) const;
172
//read the effects state information from an XML file
173
bool readState(xmlNodePtr n);
175
//!Whether we should be flipping the lens from its hard-coded left-right
176
void setFlip(bool shouldFlip) {eyeFlip=shouldFlip;};
178
void setMode(unsigned int mode){ASSERT(colourMode<ANAGLYPH_ENUM_END);colourMode=mode;};
179
void setBaseShift(float shift) { baseShift=shift;};
181
bool needCamUpdate() const { return true;}
182
//!Returns true if the effect has any influence on the output
183
bool willDoSomething() const {return true;};
185
virtual unsigned int numPassesNeeded() const { return 2;}
188
float getBaseShift() const { return baseShift;};
189
unsigned int getMode() const { return colourMode;};
195
Effect *makeEffect(unsigned int effectID);
197
Effect *makeEffect(const std::string &s);