StelPainter.hpp   StelPainter.hpp 
skipping to change at line 23 skipping to change at line 23
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA.
*/ */
#ifndef _STELPAINTER_HPP_ #ifndef _STELPAINTER_HPP_
#define _STELPAINTER_HPP_ #define _STELPAINTER_HPP_
#include "GLee.h"
#include "fixx11h.h"
#include "VecMath.hpp" #include "VecMath.hpp"
#include "StelSphereGeometry.hpp" #include "StelSphereGeometry.hpp"
#include "StelProjectorType.hpp" #include "StelProjectorType.hpp"
#include "StelProjector.hpp" #include "StelProjector.hpp"
#include <QString> #include <QString>
#include <QVarLengthArray>
#include <QFontMetrics>
class StelFont; #ifdef USE_OPENGL_ES2
#define STELPAINTER_GL2 1
#endif
#ifdef STELPAINTER_GL2
class QGLShaderProgram;
#endif
class QPainter;
class StelPainterLight
{
public:
StelPainterLight(int alight=0) : light(alight), enabled(false) {}
void setPosition(const Vec4f& v);
Vec4f& getPosition() {return position;}
void setDiffuse(const Vec4f& v);
Vec4f& getDiffuse() {return diffuse;}
void setSpecular(const Vec4f& v);
Vec4f& getSpecular() {return specular;}
void setAmbient(const Vec4f& v);
Vec4f& getAmbient() {return ambient;}
void setEnable(bool v);
void enable();
void disable();
bool isEnabled() const {return enabled;}
private:
int light;
Vec4f position;
Vec4f diffuse;
Vec4f specular;
Vec4f ambient;
bool enabled;
};
class StelPainterMaterial
{
public:
StelPainterMaterial();
void setSpecular(const Vec4f& v);
Vec4f& getSpecular() {return specular;}
void setAmbient(const Vec4f& v);
Vec4f& getAmbient() {return ambient;}
void setEmission(const Vec4f& v);
Vec4f& getEmission() {return emission;}
void setShininess(float v);
float getShininess() {return shininess;}
private:
Vec4f specular;
Vec4f ambient;
Vec4f emission;
float shininess;
};
//! @class StelPainter //! @class StelPainter
//! Provides functions for performing openGL drawing operations. //! Provides functions for performing openGL drawing operations.
//! All coordinates are converted using the StelProjector instance passed a t construction. //! All coordinates are converted using the StelProjector instance passed a t construction.
//! Because openGL is not thread safe, only one instance of StelPainter can exist at a time, enforcing thread safety. //! Because openGL is not thread safe, only one instance of StelPainter can exist at a time, enforcing thread safety.
//! As a coding rule, no openGL calls should be performed when no instance of StelPainter exist. //! As a coding rule, no openGL calls should be performed when no instance of StelPainter exist.
//! Typical usage is to create a local instance of StelPainter where drawin g operations are needed. //! Typical usage is to create a local instance of StelPainter where drawin g operations are needed.
class StelPainter class StelPainter
{ {
public: public:
friend class VertexArrayProjector;
//! Define the drawing mode when drawing polygons
enum SphericalPolygonDrawMode
{
SphericalPolygonDrawModeFill=0, //!< Draw th
e interior of the polygon
SphericalPolygonDrawModeBoundary=1, //!< Draw th
e boundary of the polygon
SphericalPolygonDrawModeTextureFill=2 //!< Draw the interi
or of the polygon filled with the current texture
};
//! Define the shade model when interpolating polygons
enum ShadeModel
{
ShadeModelFlat=0x1D00, //!< GL_FLAT
ShadeModelSmooth=0x1D01 //!< GL_SMOOTH
};
//! Define the drawing mode when drawing vertex
enum DrawingMode
{
Points = 0x0000, //!< GL_POINTS
Lines = 0x0001, //!< GL_LINES
LineLoop = 0x0002, //!< GL_LINE_LOOP
LineStrip = 0x0003, //!< GL_LINE_STRIP
Triangles = 0x0004, //!< GL_TRIANGLES
TriangleStrip = 0x0005, //!< GL_TRIANGLE_STRIP
TriangleFan = 0x0006 //!< GL_TRIANGLE_FAN
};
explicit StelPainter(const StelProjectorP& prj); explicit StelPainter(const StelProjectorP& prj);
~StelPainter(); ~StelPainter();
//! Return the instance of projector associated to this painter //! Return the instance of projector associated to this painter
const StelProjectorP getProjector() const {return prj;} const StelProjectorP& getProjector() const {return prj;}
void setProjector(const StelProjectorP& p);
//! Fill with black around the viewport. //! Fill with black around the viewport.
void drawViewportShape(void) const; void drawViewportShape(void);
//! Generalisation of glVertex3v for non-linear projections.
//! This method does not manage the lighting operations properly.
void drawVertex3v(const Vec3d& v) const
{
Vec3d win;
prj->project(v, win);
glVertex3dv(win);
}
//! Convenience function.
//! @sa drawVertex3v
void drawVertex3(double x, double y, double z) const {drawVertex3v(V
ec3d(x, y, z));}
//! Draw the string at the given position and angle with the given f ont. //! Draw the string at the given position and angle with the given f ont.
//! If the gravity label flag is set, uses drawTextGravity180. //! If the gravity label flag is set, uses drawTextGravity180.
//! @param font the font to use for display //! @param font the font to use for display
//! @param x horizontal position of the lower left corner of the fir st character of the text in pixel. //! @param x horizontal position of the lower left corner of the fir st character of the text in pixel.
//! @param y horizontal position of the lower left corner of the fir st character of the text in pixel. //! @param y horizontal position of the lower left corner of the fir st character of the text in pixel.
//! @param str the text to print. //! @param str the text to print.
//! @param angleDeg rotation angle in degree. Rotation is around x,y . //! @param angleDeg rotation angle in degree. Rotation is around x,y .
//! @param xshift shift in pixel in the rotated x direction. //! @param xshift shift in pixel in the rotated x direction.
//! @param yshift shift in pixel in the rotated y direction. //! @param yshift shift in pixel in the rotated y direction.
//! @param noGravity don't take into account the fact that the text should be written with gravity. //! @param noGravity don't take into account the fact that the text should be written with gravity.
void drawText(const StelFont* font, float x, float y, const QString& void drawText(float x, float y, const QString& str, float angleDeg=0
str, float angleDeg=0.f, .f,
float xshift=0.f, float yshift=0.f, bool noGravity=tru float xshift=0.f, float yshift=0.f, bool noGravity
e) const; =true) const;
void drawText(const Vec3d& v, const QString& str, float angleDeg=0.f
,
float xshift=0.f, float yshift=0.f, bool noGravity
=true) const;
//! Draw the given SphericalRegion.
//! @param region The SphericalRegion to draw.
//! @param drawMode define whether to draw the outline or the fill o
r both.
//! @param boundaryColor use this color for drawing the boundary onl
y if the drawMode is SphericalPolygonDrawModeFillAndBoundary.
//! @param clippingCap if not set to NULL, tells the painter to try
to clip part of the region outside the cap.
//! Typically set that to false if you think that the region is full
y contained in the viewport.
void drawSphericalRegion(const SphericalRegion* region, SphericalPol
ygonDrawMode drawMode=SphericalPolygonDrawModeFill, const SphericalCap* cli
ppingCap=NULL, bool doSubDivise=true);
void drawGreatCircleArcs(const StelVertexArray& va, const SphericalC
ap* clippingCap=NULL, bool doSubDivide=true);
//! Draw the given polygon void drawSphericalTriangles(const StelVertexArray& va, bool textured
//! @param poly The polygon to draw , const SphericalCap* clippingCap=NULL, bool doSubDivide=true);
void drawPolygon(const StelGeom::Polygon& poly) const;
//! Draw a small circle arc between points start and stop with rotat ion point in rotCenter. //! Draw a small circle arc between points start and stop with rotat ion point in rotCenter.
//! The angle between start and stop must be < 180 deg. //! The angle between start and stop must be < 180 deg.
//! The algorithm ensures that the line will look smooth, even for n on linear distortion.
//! Each time the small circle crosses the edge of the viewport, the viewportEdgeIntersectCallback is called with the //! Each time the small circle crosses the edge of the viewport, the viewportEdgeIntersectCallback is called with the
//! screen 2d position, direction of the currently drawn arc toward the inside of the viewport. //! screen 2d position, direction of the currently drawn arc toward the inside of the viewport.
//! If rotCenter is equal to 0,0,0, the method draws a great circle. //! If rotCenter is equal to 0,0,0, the method draws a great circle.
void drawSmallCircleArc(const Vec3d& start, const Vec3d& stop, const void drawSmallCircleArc(const Vec3d& start, const Vec3d& stop, const
Vec3d& rotCenter, void (*viewportEdgeIntersectCallback)(const Vec3d& scree Vec3d& rotCenter, void (*viewportEdgeIntersectCallback)(const Vec3d& scree
nPos, const Vec3d& direction, const void* userData)=NULL, const void* userD nPos, const Vec3d& direction, void* userData)=NULL, void* userData=NULL);
ata=NULL) const;
//! Draw a great circle arc between points start and stop.
//! The angle between start and stop must be < 180 deg.
//! The algorithm ensures that the line will look smooth, even for n
on linear distortion.
//! Each time the small circle crosses the edge of the viewport, the
viewportEdgeIntersectCallback is called with the
//! screen 2d position, direction of the currently drawn arc toward
the inside of the viewport.
//! @param clippingCap if not set to NULL, tells the painter to try
to clip part of the region outside the cap.
void drawGreatCircleArc(const Vec3d& start, const Vec3d& stop, const
SphericalCap* clippingCap=NULL, void (*viewportEdgeIntersectCallback)(cons
t Vec3d& screenPos, const Vec3d& direction, void* userData)=NULL, void* use
rData=NULL);
//! Draw a simple circle, 2d viewport coordinates in pixel //! Draw a simple circle, 2d viewport coordinates in pixel
void drawCircle(double x,double y,double r) const; void drawCircle(double x,double y,double r);
//! Draw a square using the current texture at the given projected 2 d position. //! Draw a square using the current texture at the given projected 2 d position.
//! This method is not thread safe.
//! @param x x position in the viewport in pixel. //! @param x x position in the viewport in pixel.
//! @param y y position in the viewport in pixel. //! @param y y position in the viewport in pixel.
//! @param size the size of a square side in pixel. //! @param radius the half size of a square side in pixel.
void drawSprite2dMode(double x, double y, double size) const; void drawSprite2dMode(double x, double y, float radius);
void drawSprite2dMode(const Vec3d& v, float radius);
//! Draw a rotated square using the current texture at the given pro jected 2d position. //! Draw a rotated square using the current texture at the given pro jected 2d position.
//! This method is not thread safe.
//! @param x x position in the viewport in pixel. //! @param x x position in the viewport in pixel.
//! @param y y position in the viewport in pixel. //! @param y y position in the viewport in pixel.
//! @param size the size of a square side in pixel. //! @param radius the half size of a square side in pixel.
//! @param rotation rotation angle in degree.
void drawSprite2dMode(double x, double y, double size, double rotati
on) const;
//! Draw a rotated rectangle using the current texture at the given
projected 2d position.
//! @param x x position in the viewport in pixel.
//! @param y y position in the viewport in pixel.
//! @param sizex the size of the rectangle x side in pixel.
//! @param sizey the size of the rectangle y side in pixel.
//! @param rotation rotation angle in degree. //! @param rotation rotation angle in degree.
void drawRectSprite2dMode(double x, double y, double sizex, double s izey, double rotation) const; void drawSprite2dMode(double x, double y, float radius, float rotati on);
//! Draw a GL_POINT at the given position. //! Draw a GL_POINT at the given position.
//! @param x x position in the viewport in pixels. //! @param x x position in the viewport in pixels.
//! @param y y position in the viewport in pixels. //! @param y y position in the viewport in pixels.
void drawPoint2d(double x, double y) const; void drawPoint2d(double x, double y);
//! Draw a line between the 2 points.
//! @param x1 x position of point 1 in the viewport in pixels.
//! @param y1 y position of point 1 in the viewport in pixels.
//! @param x2 x position of point 2 in the viewport in pixels.
//! @param y2 y position of point 2 in the viewport in pixels.
void drawLine2d(double x1, double y1, double x2, double y2);
//! Draw a rectangle using the current texture at the given projecte
d 2d position.
//! This method is not thread safe.
//! @param x x position of the top left corner in the viewport in pi
xel.
//! @param y y position of the tope left corner in the viewport in p
ixel.
//! @param width width in pixel.
//! @param height height in pixel.
void drawRect2d(float x, float y, float width, float height, bool te
xtured=true);
//! Re-implementation of gluSphere : glu is overridden for non-stand ard projection. //! Re-implementation of gluSphere : glu is overridden for non-stand ard projection.
void sSphere(GLdouble radius, GLdouble oneMinusOblateness, void sSphere(double radius, double oneMinusOblateness, int slices, i
GLint slices, GLint stacks, int orientInside = 0) const nt stacks, int orientInside = 0, bool flipTexture = false);
;
//! Re-implementation of gluCylinder : glu is overridden for non-sta ndard projection. //! Re-implementation of gluCylinder : glu is overridden for non-sta ndard projection.
void sCylinder(GLdouble radius, GLdouble height, GLint slices, GLint stacks, int orientInside = 0) const; void sCylinder(double radius, double height, int slices, int orientI nside = 0);
//! Draw a disk with a special texturing mode having texture center at center of disk. //! Draw a disk with a special texturing mode having texture center at center of disk.
//! The disk is made up of concentric circles with increasing refine ment. //! The disk is made up of concentric circles with increasing refine ment.
//! The number of slices of the outmost circle is (innerFanSlices<<l evel). //! The number of slices of the outmost circle is (innerFanSlices<<l evel).
//! @param radius the radius of the disk. //! @param radius the radius of the disk.
//! @param innerFanSlices the number of slices. //! @param innerFanSlices the number of slices.
//! @param level the numbe of concentric circles. //! @param level the numbe of concentric circles.
void sFanDisk(double radius,int innerFanSlices,int level) const; void sFanDisk(double radius,int innerFanSlices,int level);
//! Draw a disk with a special texturing mode having texture center
at center.
//! @param radius the radius of the disk.
//! @param slices the number of slices.
//! @param stacks ???
//! @param orientInside ???
void sDisk(GLdouble radius, GLint slices, GLint stacks, int orientIn
side = 0) const;
//! Draw a ring with a radial texturing. //! Draw a ring with a radial texturing.
void sRing(GLdouble rMin, GLdouble rMax, GLint slices, GLint stacks, int orientInside) const; void sRing(double rMin, double rMax, int slices, int stacks, int ori entInside);
//! Draw a fisheye texture in a sphere. //! Draw a fisheye texture in a sphere.
void sSphereMap(GLdouble radius, GLint slices, GLint stacks, void sSphereMap(double radius, int slices, int stacks, double textur
double textureFov = 2.*M_PI, int orientInside = 0) eFov = 2.*M_PI, int orientInside = 0);
const;
//! Set the font to use for subsequent text drawing.
void setFont(const QFont& font);
//! Set the color to use for subsequent drawing.
void setColor(float r, float g, float b, float a=1.f);
//! Get the color currently used for drawing.
Vec4f getColor() const;
//! Get the light
StelPainterLight& getLight() {return light;}
//! Get the material
StelPainterMaterial& getMaterial() {return material;}
//! Get the font metrics for the current font.
QFontMetrics getFontMetrics() const;
//! Get some informations about the OS openGL capacities. //! Get some informations about the OS openGL capacities.
//! This method needs to be called once at init //! This method needs to be called once at init.
static void initSystemGLInfo(); static void initSystemGLInfo();
private: //! Set the QPainter to use for performing some drawing operations.
static void setQPainter(QPainter* qPainter);
//! Switch to native OpenGL painting, i.e not using QPainter. // The following methods try to reflect the API of the incoming QGLP
//! After this call revertToQtPainting() MUST be called. ainter class
void switchToNativeOpenGLPainting();
//! Revert openGL state so that Qt painting works again. //! Sets the point size to use with draw().
void revertToQtPainting(); //! This function has no effect if a shader program is in use, or on
OpenGL/ES 2.0. Shader programs must set the
//! point size in the vertex shader.
void setPointSize(qreal size);
//! Define the current shade model used when interpolating between v
ertex.
void setShadeModel(ShadeModel m);
//! Set whether texturing is enabled.
void enableTexture2d(bool b);
// Thoses methods should eventually be replaced by a single setVerte
xArray
//! use instead of glVertexPointer
void setVertexPointer(int size, int type, const void* pointer) {
vertexArray.size = size; vertexArray.type = type; vertexArra
y.pointer = pointer;
}
//! use instead of glTexCoordPointer
void setTexCoordPointer(int size, int type, const void* pointer)
{
texCoordArray.size = size; texCoordArray.type = type; texCoo
rdArray.pointer = pointer;
}
//! use instead of glColorPointer
void setColorPointer(int size, int type, const void* pointer)
{
colorArray.size = size; colorArray.type = type; colorArray.p
ointer = pointer;
}
//! use instead of glNormalPointer
void setNormalPointer(int type, const void* pointer)
{
normalArray.size = 3; normalArray.type = type; normalArray.p
ointer = pointer;
}
void drawTextGravity180(const StelFont* font, float x, float y, cons //! use instead of glEnableClient
t QString& str, void enableClientStates(bool vertex, bool texture=false, bool color=
bool speedOptimize = 1, float xshift = 0, floa false, bool normal=false);
t yshift = 0) const;
//! Init the real openGL Matrices to a 2d orthographic projection //! convenience method that enable and set all the given arrays.
void initGlMatrixOrtho2d(void) const; //! It is equivalent to calling enableClientState and set the array
pointer for each arrays.
void setArrays(const Vec3d* vertice, const Vec2f* texCoords=NULL, co
nst Vec3f* colorArray=NULL, const Vec3f* normalArray=NULL);
//! Draws primitives using vertices from the arrays specified by set
VertexArray().
//! The type of primitive to draw is specified by mode.
//! If indices is NULL, this operation will consume count values fro
m the enabled arrays, starting at offset.
//! Else it will consume count elements of indices, starting at offs
et, which are used to index into the
//! enabled arrays.
void drawFromArray(DrawingMode mode, int count, int offset=0, bool d
oProj=true, const unsigned int* indices=NULL);
//! The assoaciated instance of projector private:
const StelProjectorP prj; //! Struct describing one opengl array
typedef struct
{
int size; // The number of coo
rdinates per vertex.
int type; // The data type of
each coordinate (GL_SHORT, GL_INT, GL_FLOAT, or GL_DOUBLE).
const void* pointer; // Pointer to the first coordinate o
f the first vertex in the array.
bool enabled; // Define whether the array
is enabled or not.
} ArrayDesc;
//! Project an array using the current projection.
//! @return a descriptor of the new array
ArrayDesc projectArray(const ArrayDesc& array, int offset, int count
, const unsigned int* indices=NULL);
//! Project the passed triangle on the screen ensuring that it will
look smooth, even for non linear distortion
//! by splitting it into subtriangles. The resulting vertex arrays a
re appended to the passed out* ones.
//! The size of each edge must be < 180 deg.
//! @param vertices a pointer to an array of 3 vertices.
//! @param edgeFlags a pointer to an array of 3 flags indicating whe
ther the next segment is an edge.
//! @param texturePos a pointer to an array of 3 texture coordinates
, or NULL if the triangle should not be textured.
void projectSphericalTriangle(const SphericalCap* clippingCap, const
Vec3d* vertices, QVarLengthArray<Vec3f, 4096>* outVertices,
const Vec2f* texturePos=NULL, QVarLengthArray<Vec2f,
4096>* outTexturePos=NULL,int nbI=0,
bool checkDisc1=true, bool checkDisc2=true, bool che
ckDisc3=true) const;
void drawTextGravity180(float x, float y, const QString& str, float
xshift = 0, float yshift = 0) const;
// Used by the method below
static QVector<Vec2f> smallCircleVertexArray;
void drawSmallCircleVertexArray();
//! Whether the GL_POINT_SPRITE extension is available and activated //! The associated instance of projector
static bool flagGlPointSprite; StelProjectorP prj;
#ifndef NDEBUG
//! Mutex allowing thread safety //! Mutex allowing thread safety
static class QMutex* globalMutex; static class QMutex* globalMutex;
#endif
//! The QPainter to use for some drawing operations.
static QPainter* qPainter;
#ifdef STELPAINTER_GL2
Vec4f currentColor;
bool texture2dEnabled;
static QGLShaderProgram* basicShaderProgram;
struct BasicShaderVars {
int projectionMatrix;
int color;
int vertex;
};
static BasicShaderVars basicShaderVars;
static QGLShaderProgram* colorShaderProgram;
static QGLShaderProgram* texturesShaderProgram;
struct TexturesShaderVars {
int projectionMatrix;
int texCoord;
int vertex;
int texColor;
};
static TexturesShaderVars texturesShaderVars;
static QGLShaderProgram* texturesColorShaderProgram;
struct TexturesColorShaderVars {
int projectionMatrix;
int texCoord;
int vertex;
int color;
};
static TexturesColorShaderVars texturesColorShaderVars;
#endif
//! The descriptor for the current opengl vertex array
ArrayDesc vertexArray;
//! The descriptor for the current opengl texture coordinate array
ArrayDesc texCoordArray;
//! The descriptor for the current opengl normal array
ArrayDesc normalArray;
//! The descriptor for the current opengl color array
ArrayDesc colorArray;
//! the single light used by the painter
StelPainterLight light;
//! The material used by the painter
StelPainterMaterial material;
}; };
#endif // _STELPAINTER_HPP_ #endif // _STELPAINTER_HPP_
 End of changes. 32 change blocks. 
80 lines changed or deleted 356 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/