StelPainter.hpp   StelPainter.hpp 
/* /*
* Stellarium * Stellarium
* Copyright (C) 2008 Fabien Chereau * Copyright (C) 2008 Fabien Chereau
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. * of the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
skipping to change at line 40 skipping to change at line 40
#include <QFontMetrics> #include <QFontMetrics>
class QOpenGLShaderProgram; class QOpenGLShaderProgram;
//! @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 : protected QOpenGLFunctions
{ {
public: public:
friend class VertexArrayProjector; friend class VertexArrayProjector;
//! Define the drawing mode when drawing polygons //! Define the drawing mode when drawing polygons
enum SphericalPolygonDrawMode enum SphericalPolygonDrawMode
{ {
SphericalPolygonDrawModeFill=0, //!< Draw the interior of the polygon SphericalPolygonDrawModeFill=0, //!< Draw the interior of the polygon
SphericalPolygonDrawModeBoundary=1, //!< Draw the boundary of the polygon SphericalPolygonDrawModeBoundary=1, //!< Draw the boundary of the polygon
SphericalPolygonDrawModeTextureFill=2, //!< Draw the interior of the polygon filled with the current texture SphericalPolygonDrawModeTextureFill=2, //!< Draw the interior of the polygon filled with the current texture
skipping to change at line 69 skipping to change at line 69
LineLoop = 0x0002, //!< GL_LINE_LOOP LineLoop = 0x0002, //!< GL_LINE_LOOP
LineStrip = 0x0003, //!< GL_LINE_STRIP LineStrip = 0x0003, //!< GL_LINE_STRIP
Triangles = 0x0004, //!< GL_TRIANGLES Triangles = 0x0004, //!< GL_TRIANGLES
TriangleStrip = 0x0005, //!< GL_TRIANGLE_STRIP TriangleStrip = 0x0005, //!< GL_TRIANGLE_STRIP
TriangleFan = 0x0006 //!< GL_TRIANGLE_FAN TriangleFan = 0x0006 //!< GL_TRIANGLE_FAN
}; };
explicit StelPainter(const StelProjectorP& prj); explicit StelPainter(const StelProjectorP& prj);
~StelPainter(); ~StelPainter();
//! Returns a QOpenGLFunctions object suitable for drawing directly
with OpenGL while this StelPainter is active.
//! This is recommended to be used instead of QOpenGLContext::curren
tContext()->functions() when a StelPainter is available,
//! and you only need to call a few GL functions directly.
inline QOpenGLFunctions* glFuncs() { return this; }
//! 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); void setProjector(const StelProjectorP& p);
//! Fill with black around the viewport. //! Fill with black around the viewport.
void drawViewportShape(void); void drawViewportShape(void);
//! 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 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.
skipping to change at line 230 skipping to change at line 235
//! Set the color to use for subsequent drawing. //! Set the color to use for subsequent drawing.
void setColor(float r, float g, float b, float a=1.f); void setColor(float r, float g, float b, float a=1.f);
//! Get the color currently used for drawing. //! Get the color currently used for drawing.
Vec4f getColor() const; Vec4f getColor() const;
//! Get the font metrics for the current font. //! Get the font metrics for the current font.
QFontMetrics getFontMetrics() const; QFontMetrics getFontMetrics() const;
//! Enable OpenGL blending. By default, blending is disabled.
//! The additional parameters specify the blending mode, the default
parameters are suitable for
//! "normal" blending operations that you want in most cases. Blendi
ng will be automatically disabled when
//! the StelPainter is destroyed.
void setBlending(bool enableBlending, GLenum blendSrc = GL_SRC_ALPHA
, GLenum blendDst = GL_ONE_MINUS_SRC_ALPHA);
void setDepthTest(bool enable);
void setDepthMask(bool enable);
//! Set the OpenGL GL_CULL_FACE state, by default face culling is di
sabled
void setCullFace(bool enable);
//! Enables/disables line smoothing. By default, smoothing is disabl
ed.
void setLineSmooth(bool enable);
//! Sets the line width. Default is 1.0f.
void setLineWidth(float width);
//! Create the OpenGL shaders programs used by the StelPainter. //! Create the OpenGL shaders programs used by the StelPainter.
//! This method needs to be called once at init. //! This method needs to be called once at init.
static void initGLShaders(); static void initGLShaders();
//! Delete the OpenGL shaders objects. //! Delete the OpenGL shaders objects.
//! This method needs to be called once before exit. //! This method needs to be called once before exit.
static void deinitGLShaders(); static void deinitGLShaders();
//! Set whether texturing is enabled.
void enableTexture2d(bool b);
// Thoses methods should eventually be replaced by a single setVerte xArray // Thoses methods should eventually be replaced by a single setVerte xArray
//! use instead of glVertexPointer //! use instead of glVertexPointer
void setVertexPointer(int size, int type, const void* pointer) { void setVertexPointer(int size, int type, const void* pointer) {
vertexArray.size = size; vertexArray.type = type; vertexArra y.pointer = pointer; vertexArray.size = size; vertexArray.type = type; vertexArra y.pointer = pointer;
} }
//! use instead of glTexCoordPointer //! use instead of glTexCoordPointer
void setTexCoordPointer(int size, int type, const void* pointer) void setTexCoordPointer(int size, int type, const void* pointer)
{ {
texCoordArray.size = size; texCoordArray.type = type; texCoo rdArray.pointer = pointer; texCoordArray.size = size; texCoordArray.type = type; texCoo rdArray.pointer = pointer;
skipping to change at line 265 skipping to change at line 286
{ {
colorArray.size = size; colorArray.type = type; colorArray.p ointer = pointer; colorArray.size = size; colorArray.type = type; colorArray.p ointer = pointer;
} }
//! use instead of glNormalPointer //! use instead of glNormalPointer
void setNormalPointer(int type, const void* pointer) void setNormalPointer(int type, const void* pointer)
{ {
normalArray.size = 3; normalArray.type = type; normalArray.p ointer = pointer; normalArray.size = 3; normalArray.type = type; normalArray.p ointer = pointer;
} }
//! use instead of glEnableClient //! Simulates glEnableClientState, basically you describe what data the ::drawFromArray call has available
void enableClientStates(bool vertex, bool texture=false, bool color= false, bool normal=false); void enableClientStates(bool vertex, bool texture=false, bool color= false, bool normal=false);
//! convenience method that enable and set all the given arrays. //! convenience method that enable and set all the given arrays.
//! It is equivalent to calling enableClientState and set the array pointer for each arrays. //! It is equivalent to calling enableClientState and set the array pointer for each arrays.
void setArrays(const Vec3d* vertices, const Vec2f* texCoords=NULL, c onst Vec3f* colorArray=NULL, const Vec3f* normalArray=NULL); void setArrays(const Vec3d* vertices, const Vec2f* texCoords=NULL, c onst Vec3f* colorArray=NULL, const Vec3f* normalArray=NULL);
void setArrays(const Vec3f* vertices, const Vec2f* texCoords=NULL, c onst Vec3f* colorArray=NULL, const Vec3f* normalArray=NULL); void setArrays(const Vec3f* vertices, const Vec2f* texCoords=NULL, c onst Vec3f* colorArray=NULL, const Vec3f* normalArray=NULL);
//! Draws primitives using vertices from the arrays specified by set VertexArray(). //! Draws primitives using vertices from the arrays specified by set VertexArray().
//! @param mode The type of primitive to draw. //! @param mode The type of primitive to draw.
//! If @param indices is NULL, this operation will consume @param co unt values from the enabled arrays, starting at @param offset. //! If @param indices is NULL, this operation will consume @param co unt values from the enabled arrays, starting at @param offset.
skipping to change at line 293 skipping to change at line 314
//! Link an opengl program and show a message in case of error or wa rnings. //! Link an opengl program and show a message in case of error or wa rnings.
//! @return true if the link was successful. //! @return true if the link was successful.
static bool linkProg(class QOpenGLShaderProgram* prog, const QString & name); static bool linkProg(class QOpenGLShaderProgram* prog, const QString & name);
private: private:
friend class StelTextureMgr; friend class StelTextureMgr;
friend class StelTexture; friend class StelTexture;
//! RAII class used to store and restore the opengl state. //! Helper struct to track the GL state and restore it to canonical
//! to use it we just need to instanciate it at the beginning of a m values on StelPainter creation/destruction
ethod that might change the state. struct GLState
class GLState
{ {
public: GLState(QOpenGLFunctions *gl);
GLState();
~GLState();
private:
bool blend; bool blend;
int blendSrcRGB, blendDstRGB, blendSrcAlpha, blendDstAlpha; GLenum blendSrc, blendDst;
}; bool depthTest;
bool depthMask;
bool cullFace;
bool lineSmooth;
GLfloat lineWidth;
//! Applies the values stored here to set the GL state
void apply();
//! Resets the state to the default values (like a GLState w
as newly constructed)
//! and calls apply()
void reset();
private:
QOpenGLFunctions* gl;
} glState;
// From text-use-opengl-buffer // From text-use-opengl-buffer
static QCache<QByteArray, struct StringTexture> texCache; static QCache<QByteArray, struct StringTexture> texCache;
struct StringTexture* getTexTexture(const QString& str, int pixelSiz e); struct StringTexture* getTexTexture(const QString& str, int pixelSiz e);
//! Struct describing one opengl array //! Struct describing one opengl array
typedef struct ArrayDesc typedef struct ArrayDesc
{ {
ArrayDesc() : size(0), type(0), pointer(NULL), enabled(false ) {} ArrayDesc() : size(0), type(0), pointer(NULL), enabled(false ) {}
int size; // The number of coo rdinates per vertex. int size; // The number of coo rdinates per vertex.
skipping to change at line 355 skipping to change at line 386
#ifndef NDEBUG #ifndef NDEBUG
//! Mutex allowing thread safety //! Mutex allowing thread safety
static class QMutex* globalMutex; static class QMutex* globalMutex;
#endif #endif
//! The used for text drawing //! The used for text drawing
QFont currentFont; QFont currentFont;
Vec4f currentColor; Vec4f currentColor;
bool texture2dEnabled;
static QOpenGLShaderProgram* basicShaderProgram; static QOpenGLShaderProgram* basicShaderProgram;
struct BasicShaderVars { struct BasicShaderVars {
int projectionMatrix; int projectionMatrix;
int color; int color;
int vertex; int vertex;
}; };
static BasicShaderVars basicShaderVars; static BasicShaderVars basicShaderVars;
static QOpenGLShaderProgram* colorShaderProgram; static QOpenGLShaderProgram* colorShaderProgram;
 End of changes. 10 change blocks. 
17 lines changed or deleted 55 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/