Stellarium 0.12.3
List of all members | Classes | Public Member Functions | Protected Member Functions | Protected Attributes
StelQGLRenderer Class Referenceabstract

Base class for renderer based on OpenGL and at the same time Qt's QGL. More...

#include <StelQGLRenderer.hpp>

Public Member Functions

 StelQGLRenderer (QGraphicsView *const parent, const bool pvrSupported)
 Construct a StelQGLRenderer. More...
 
virtual bool init ()
 Initialize the renderer. More...
 
virtual QImage screenshot ()
 Take a screenshot and return it. More...
 
virtual void renderFrame (StelRenderClient &renderClient)
 Render a frame. More...
 
virtual void viewportHasBeenResized (const QSize size)
 Must be called once at startup and on every GL viewport resize, specifying new size. More...
 
virtual QSize getViewportSize () const
 Get size of the viewport in pixels. More...
 
StelIndexBuffercreateIndexBuffer (const IndexType type)
 Create an empty index buffer and return a pointer to it. More...
 
virtual void drawText (const TextParams &params)
 Draw text with specified parameters. More...
 
virtual void setFont (const QFont &font)
 Set font to use for drawing text. More...
 
virtual void bindTextureBackend (StelTextureBackend *const textureBackend, const int textureUnit)
 Bind a texture (following draw calls will use this texture on specified texture unit). More...
 
void ensureTextureNotBound (StelTextureBackend *const textureBackend)
 Must be called by texture backend destructor to ensure we don't keep any pointers to it. More...
 
virtual void destroyTextureBackend (StelTextureBackend *const textureBackend)
 Destroy a StelTextureBackend. More...
 
virtual void setGlobalColor (const Vec4f &color)
 Set the global vertex color. More...
 
virtual void setCulledFaces (const CullFace cullFace)
 Set which faces (triangles) should be culled. More...
 
virtual void setBlendMode (const BlendMode mode)
 Set blend mode. More...
 
virtual void setDepthTest (const DepthTest test)
 Set depth test mode. More...
 
virtual void clearDepthBuffer ()
 Clear the depth buffer to zeroes, removing any depth information. More...
 
virtual void setStencilTest (const StencilTest test)
 Set stencil test mode. More...
 
virtual void clearStencilBuffer ()
 Clear the stencil buffer to zeroes, removing any stencil information. More...
 
virtual void swapBuffers ()
 Swap front and back buffers. More...
 
virtual void drawRect (const float x, const float y, const float width, const float height, const float angle=0.0f)
 Draw a rectangle to the screen. More...
 
virtual void drawTexturedRect (const float x, const float y, const float width, const float height, const float angle=0.0f)
 Draw a textured rectangle to the screen. More...
 
virtual StelRendererStatisticsgetStatistics ()
 Access statistics data. More...
 
virtual void makeGLContextCurrent ()
 Make Stellarium GL context the currently used GL context. Call this before GL calls. More...
 
QGLContext * getGLContext ()
 Used to access the GL context. More...
 
QGLFunctions & getGLFunctions ()
 Used for GL/GLES-compatible function wrappers and to determine which GL features are available. More...
 
QThread * getLoaderThread ()
 Get a pointer to the thread used for loading graphics data (e.g. textures). More...
 
const Vec4fgetGlobalColor () const
 Get global vertex color (used for drawing). More...
 
virtual bool areNonPowerOfTwoTexturesSupported () const =0
 Returns true if non-power-of-two textures are supported, false otherwise. More...
 
QPaintEngine::Type qtPaintEngineType () const
 Get the paint engine type used for Qt drawing. More...
 
- Public Member Functions inherited from StelRenderer
virtual ~StelRenderer ()
 Destructor. More...
 
template<class V >
StelVertexBuffer< V > * createVertexBuffer (const PrimitiveType primitiveType)
 Create an empty vertex buffer and return a pointer to it. More...
 
template<class V >
void drawVertexBuffer (StelVertexBuffer< V > *vertexBuffer, class StelIndexBuffer *indexBuffer=NULL, StelProjectorP projector=StelProjectorP(NULL), bool dontProject=false)
 Draw contents of a vertex buffer. More...
 
template<class V >
void drawVertexBuffer (StelVertexBuffer< V > *vertexBuffer, class StelIndexBuffer *indexBuffer, StelProjector *projector, bool dontProject=false)
 Draw contents of a vertex buffer. More...
 
virtual void drawLine (const float startX, const float startY, const float endX, const float endY)
 Draw a line with current global color to the screen. More...
 
StelTextureNewcreateTexture (const QString &filename, const TextureParams &params=TextureParams(), const TextureLoadingMode loadingMode=TextureLoadingMode_Normal)
 Create a texture from specified file or URL. More...
 
StelTextureNewcreateTexture (QImage &image, const TextureParams &params=TextureParams())
 Create a texture from an image. More...
 
StelTextureNewcreateTexture (const void *const data, const QSize size, const TextureDataFormat format, const TextureParams &params=TextureParams())
 Create a texture from raw data. More...
 
virtual bool areFloatTexturesSupported () const =0
 Returns true if floating point textures are supported, false otherwise. More...
 
StelTextureNewgetViewportTexture ()
 Get a texture of the viewport, with everything drawn to the viewport so far. More...
 
virtual StelGLSLShadercreateGLSLShader ()
 Create a GLSL shader. More...
 
virtual bool isGLSLSupported () const =0
 Are GLSL shaders supported? More...
 
void setGlobalColor (const float r, const float g, const float b, const float a=1.0f)
 setGlobalColor overload specifying color channels directly instead of through Vec4f. More...
 

Protected Member Functions

virtual StelTextureBackendcreateTextureBackend (const QString &filename, const TextureParams &params, const TextureLoadingMode loadingMode)
 Implementation of createTexture. More...
 
virtual StelTextureBackendcreateTextureBackend (QImage &image, const TextureParams &params)
 Implementation of createTexture loading from image. More...
 
virtual StelTextureBackendcreateTextureBackend (const void *data, const QSize size, const TextureDataFormat format, const TextureParams &params)
 Implementation of createTexture loading from raw data. More...
 
virtual StelTextureBackendgetViewportTextureBackend ()
 Implementation of getViewportTexture. More...
 
virtual int getTextureUnitCountBackend ()=0
 Return the number of texture units (implementation). More...
 
virtual void invariant () const
 Asserts that we're in a valid state. More...
 
void setupGLState (StelProjector *projector)
 Set up GL state common between the GL1 and GL2 backends before drawing. More...
 
void restoreGLState (StelProjector *projector)
 Reset GL state after drawing. More...
 
template<class VBufferBackend >
void updateDrawStatistics (VBufferBackend *vertexBuffer, StelQGLIndexBuffer *indexBuffer)
 Update statistics in a drawVertexBufferBackend() call. More...
 
- Protected Member Functions inherited from StelRenderer
virtual StelVertexBufferBackendcreateVertexBufferBackend (const PrimitiveType primitiveType, const QVector< StelVertexAttribute > &attributes)=0
 Create a vertex buffer backend. More...
 
virtual void drawVertexBufferBackend (StelVertexBufferBackend *vertexBuffer, class StelIndexBuffer *indexBuffer, StelProjector *projector, const bool dontProject)=0
 Draw contents of a vertex buffer (backend). More...
 

Protected Attributes

QString glVendorString
 OpenGL vendor string (used to enable/disable features based on driver). More...
 
QString glRendererString
 OpenGL renderer (usually GPU) string (can be used to enable/disable features based on GPU). More...
 
StelRendererStatistics statistics
 Statistics collected during program run (such as estimated texture memory usage, etc.). More...
 
QGLFunctions gl
 Wraps some GL functions for compatibility across GL and GLES. More...
 

Detailed Description

Base class for renderer based on OpenGL and at the same time Qt's QGL.

Note
This is an internal class of the Renderer subsystem and should not be used elsewhere.

Definition at line 83 of file StelQGLRenderer.hpp.

Constructor & Destructor Documentation

StelQGLRenderer::StelQGLRenderer ( QGraphicsView *const  parent,
const bool  pvrSupported 
)
inline

Construct a StelQGLRenderer.

Parameters
parentParent widget for the renderer's GL widget.
pvrSupportedAre .pvr (PVRTC - PowerVR hardware) textures supported on this platform? This should be true for mobile platforms with PowerVR GPUs.

Definition at line 91 of file StelQGLRenderer.hpp.

Member Function Documentation

virtual bool StelQGLRenderer::areNonPowerOfTwoTexturesSupported ( ) const
pure virtual

Returns true if non-power-of-two textures are supported, false otherwise.

Implemented in StelQGL2Renderer, and StelQGL1Renderer.

virtual void StelQGLRenderer::bindTextureBackend ( StelTextureBackend *const  textureBackend,
const int  textureUnit 
)
virtual

Bind a texture (following draw calls will use this texture on specified texture unit).

Parameters
textureBackendTexture to bind.
textureUnitTexture unit to use. If multitexturing is not supported, binds to texture units other than 0 are ignored.

Implements StelRenderer.

virtual void StelQGLRenderer::clearDepthBuffer ( )
inlinevirtual

Clear the depth buffer to zeroes, removing any depth information.

Implements StelRenderer.

Definition at line 256 of file StelQGLRenderer.hpp.

virtual void StelQGLRenderer::clearStencilBuffer ( )
inlinevirtual

Clear the stencil buffer to zeroes, removing any stencil information.

Implements StelRenderer.

Definition at line 273 of file StelQGLRenderer.hpp.

StelIndexBuffer* StelQGLRenderer::createIndexBuffer ( const IndexType  type)
inlinevirtual

Create an empty index buffer and return a pointer to it.

Implements StelRenderer.

Definition at line 199 of file StelQGLRenderer.hpp.

virtual StelTextureBackend* StelQGLRenderer::createTextureBackend ( const QString &  filename,
const TextureParams params,
const TextureLoadingMode  loadingMode 
)
protectedvirtual

Implementation of createTexture.

Returns texture backend to be wrapped in a StelTextureNew. Must not fail, but can return a backend in error state.

See Also
createTexture

Implements StelRenderer.

virtual StelTextureBackend* StelQGLRenderer::createTextureBackend ( QImage &  image,
const TextureParams params 
)
protectedvirtual

Implementation of createTexture loading from image.

Returns texture backend to be wrapped in a StelTextureNew. Must not fail, but can return a backend in error state.

See Also
createTexture

Implements StelRenderer.

virtual StelTextureBackend* StelQGLRenderer::createTextureBackend ( const void *  data,
const QSize  size,
const TextureDataFormat  format,
const TextureParams params 
)
protectedvirtual

Implementation of createTexture loading from raw data.

Returns texture backend to be wrapped in a StelTextureNew. Must not fail, but can return a backend in error state.

See Also
createTexture

Implements StelRenderer.

virtual void StelQGLRenderer::destroyTextureBackend ( StelTextureBackend *const  backend)
virtual

Destroy a StelTextureBackend.

The backend might be destroyed, but the implementation might also cache the texture, not destroying it if it has muliple users.

Implements StelRenderer.

virtual void StelQGLRenderer::drawRect ( const float  x,
const float  y,
const float  width,
const float  height,
const float  angle = 0.0f 
)
virtual

Draw a rectangle to the screen.

The rectangle will be colored by the global color (which can be specified by setGlobalColor()).

The rectangle can be rotated around its center by an angle specified in degrees.

Parameters
xX position of the top left corner on the screen in pixels.
yY position of the top left corner on the screen in pixels.
widthWidth in pixels.
heightHeight in pixels.
angleAngle to rotate the rectangle around its center in degrees.

Implements StelRenderer.

virtual void StelQGLRenderer::drawText ( const TextParams params)
virtual

Draw text with specified parameters.

Parameters are specified by a builder-style struct.

Examples:

// Note that text position and string must be always specified, so they
// are in the constructor.
// Draw with default parameters (no rotation, no shift, no gravity, 2D projection).
renderer->drawText(TextParams(16, 16, "Hello World"));
// Rotate by 30 degrees.
renderer->drawText(TextParams(16, 16 "Hello World!").angleDegrees(30.0f));
// Rotate by 30 degrees and shift by (8, 4) in rotated direction.
renderer->drawText(TextParams(16, 16 "Hello World!").angleDegrees(30.0f).shift(8.0f, 4.0f));
Parameters
paramsParameters of the text to draw.
See Also
TextParams

Implements StelRenderer.

virtual void StelQGLRenderer::drawTexturedRect ( const float  x,
const float  y,
const float  width,
const float  height,
const float  angle = 0.0f 
)
virtual

Draw a textured rectangle to the screen.

The rectangle will be textured by the currently bound texture.

The rectangle can be rotated around its center by an angle specified in degrees.

Parameters
xX position of the top left corner on the screen in pixels.
yY position of the top left corner on the screen in pixels.
widthWidth in pixels.
heightHeight in pixels.
angleAngle to rotate the rectangle around its center in degrees.

Implements StelRenderer.

void StelQGLRenderer::ensureTextureNotBound ( StelTextureBackend *const  textureBackend)
inline

Must be called by texture backend destructor to ensure we don't keep any pointers to it.

Not called by destroyTextureBackend as texture backends are sometimes constructed and destroyed internally (e.g. by drawText).

Definition at line 221 of file StelQGLRenderer.hpp.

QGLContext* StelQGLRenderer::getGLContext ( )
inline

Used to access the GL context.

Safer than making glContext protected as derived classes can't overwrite it.

Definition at line 315 of file StelQGLRenderer.hpp.

QGLFunctions& StelQGLRenderer::getGLFunctions ( )
inline

Used for GL/GLES-compatible function wrappers and to determine which GL features are available.

Definition at line 321 of file StelQGLRenderer.hpp.

const Vec4f& StelQGLRenderer::getGlobalColor ( ) const
inline

Get global vertex color (used for drawing).

Definition at line 333 of file StelQGLRenderer.hpp.

QThread* StelQGLRenderer::getLoaderThread ( )
inline

Get a pointer to the thread used for loading graphics data (e.g. textures).

Definition at line 327 of file StelQGLRenderer.hpp.

virtual StelRendererStatistics& StelQGLRenderer::getStatistics ( )
inlinevirtual

Access statistics data.

Contents are backend specific - might include thing like vertices per frame, estimated texture memory, etc. .

User code might add its own statistics as well (e.g. StelSkyDrawer).

Implements StelRenderer.

Definition at line 294 of file StelQGLRenderer.hpp.

virtual int StelQGLRenderer::getTextureUnitCountBackend ( )
protectedpure virtual

Return the number of texture units (implementation).

Implemented in StelQGL2Renderer, and StelQGL1Renderer.

virtual QSize StelQGLRenderer::getViewportSize ( ) const
inlinevirtual

Get size of the viewport in pixels.

Implements StelRenderer.

Definition at line 193 of file StelQGLRenderer.hpp.

virtual StelTextureBackend* StelQGLRenderer::getViewportTextureBackend ( )
inlineprotectedvirtual

Implementation of getViewportTexture.

See Also
getViewportTexture.

Implements StelRenderer.

Definition at line 367 of file StelQGLRenderer.hpp.

virtual bool StelQGLRenderer::init ( )
inlinevirtual

Initialize the renderer.

Must be called before any other methods.

Returns
true on success, false if there was an error.

Implements StelRenderer.

Reimplemented in StelQGL2Renderer, and StelQGL1Renderer.

Definition at line 163 of file StelQGLRenderer.hpp.

virtual void StelQGLRenderer::invariant ( ) const
inlineprotectedvirtual

Asserts that we're in a valid state.

Overriding methods should also call StelQGLRenderer::invariant().

Reimplemented in StelQGL2Renderer, and StelQGL1Renderer.

Definition at line 380 of file StelQGLRenderer.hpp.

virtual void StelQGLRenderer::makeGLContextCurrent ( )
inlinevirtual

Make Stellarium GL context the currently used GL context. Call this before GL calls.

Definition at line 300 of file StelQGLRenderer.hpp.

QPaintEngine::Type StelQGLRenderer::qtPaintEngineType ( ) const
inline

Get the paint engine type used for Qt drawing.

Definition at line 342 of file StelQGLRenderer.hpp.

virtual void StelQGLRenderer::renderFrame ( StelRenderClient renderClient)
virtual

Render a frame.

This might not render the entire frame - if rendering takes too long, the backend may (or may not) suspend the rendering to finish it next time renderFrame is called.

Parameters
renderClientAllows the renderer to draw the scene in parts.
See Also
StelRenderClient

Implements StelRenderer.

void StelQGLRenderer::restoreGLState ( StelProjector projector)
inlineprotected

Reset GL state after drawing.

Definition at line 485 of file StelQGLRenderer.hpp.

virtual QImage StelQGLRenderer::screenshot ( )
inlinevirtual

Take a screenshot and return it.

Implements StelRenderer.

Definition at line 178 of file StelQGLRenderer.hpp.

virtual void StelQGLRenderer::setBlendMode ( const BlendMode  blendMode)
inlinevirtual

Set blend mode.

Used to enable/disable transparency and similar effects.

On startup, the blend mode is BlendMode_None.

Implements StelRenderer.

Definition at line 246 of file StelQGLRenderer.hpp.

virtual void StelQGLRenderer::setCulledFaces ( const CullFace  cullFace)
inlinevirtual

Set which faces (triangles) should be culled.

Front faces are usually those whose vertices are in counter-clockwise order, but a StelProjector might flip this order after projection. If such a StelProjector is used with StelRenderer::drawVertexBuffer(), front faces will be clock wise. This doesn't affect the user in any way as the projection is done inside renderer.

However, if doing manual projection and sending the already projected vertices for drawing, this order will be flipped, so previously counter-clockwise(front) faces will be clock-wise (back) faces, so if culling is used, opposite face should be used with setCulledFaces().

Whether a StelProjector changes clockwise-counterclockwise winding can be determined by StelProjector::flipFrontBackFace().

Implements StelRenderer.

Definition at line 241 of file StelQGLRenderer.hpp.

virtual void StelQGLRenderer::setDepthTest ( const DepthTest  test)
inlinevirtual

Set depth test mode.

Depth test is implemented to be as specific as possible, only supporting what Stellarium needs. This might be counterintuitive, as much of the power of OpenGL is removed. However, this makes it easier to implement different Renderer backends that might not necessarily be based on OpenGL.

Implements StelRenderer.

Definition at line 251 of file StelQGLRenderer.hpp.

virtual void StelQGLRenderer::setFont ( const QFont &  font)
inlinevirtual

Set font to use for drawing text.

Implements StelRenderer.

Definition at line 207 of file StelQGLRenderer.hpp.

virtual void StelQGLRenderer::setGlobalColor ( const Vec4f color)
inlinevirtual

Set the global vertex color.

Default color is white.

This color is used when rendering vertex formats that have no vertex color attribute, lines, non-textured rectangles, etc. .

Per-vertex color completely overrides this (this is to keep behavior from before the GL refactor unchanged).

Note
Color channel values can be outside of the 0-1 range.

Implements StelRenderer.

Definition at line 236 of file StelQGLRenderer.hpp.

virtual void StelQGLRenderer::setStencilTest ( const StencilTest  test)
inlinevirtual

Set stencil test mode.

Stencil test is implemented to be as specific as possible, only supporting what Stellarium needs. This might be counterintuitive, as much of the power of OpenGL is removed. However, this makes it easier to implement different Renderer backends that might not necessarily be based on OpenGL.

Implements StelRenderer.

Definition at line 268 of file StelQGLRenderer.hpp.

void StelQGLRenderer::setupGLState ( StelProjector projector)
inlineprotected

Set up GL state common between the GL1 and GL2 backends before drawing.

Definition at line 392 of file StelQGLRenderer.hpp.

virtual void StelQGLRenderer::swapBuffers ( )
inlinevirtual

Swap front and back buffers.

This is only needed before the Renderer takes control of frame start/end, e.g. during loading at startup.

Implements StelRenderer.

Definition at line 279 of file StelQGLRenderer.hpp.

template<class VBufferBackend >
void StelQGLRenderer::updateDrawStatistics ( VBufferBackend *  vertexBuffer,
StelQGLIndexBuffer indexBuffer 
)
inlineprotected

Update statistics in a drawVertexBufferBackend() call.

Parameters
vertexBufferVertex buffer drawn.
indexBufferIndex buffer (if any), specifying which vertices to draw.

Definition at line 506 of file StelQGLRenderer.hpp.

virtual void StelQGLRenderer::viewportHasBeenResized ( const QSize  size)
inlinevirtual

Must be called once at startup and on every GL viewport resize, specifying new size.

Implements StelRenderer.

Definition at line 186 of file StelQGLRenderer.hpp.

Member Data Documentation

QGLFunctions StelQGLRenderer::gl
protected

Wraps some GL functions for compatibility across GL and GLES.

Definition at line 795 of file StelQGLRenderer.hpp.

QString StelQGLRenderer::glRendererString
protected

OpenGL renderer (usually GPU) string (can be used to enable/disable features based on GPU).

Definition at line 352 of file StelQGLRenderer.hpp.

QString StelQGLRenderer::glVendorString
protected

OpenGL vendor string (used to enable/disable features based on driver).

Definition at line 349 of file StelQGLRenderer.hpp.

StelRendererStatistics StelQGLRenderer::statistics
protected

Statistics collected during program run (such as estimated texture memory usage, etc.).

Definition at line 355 of file StelQGLRenderer.hpp.


The documentation for this class was generated from the following file: