OGRE  1.8
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreGLRenderSystem.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4  (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org
6 
7 Copyright (c) 2000-2013 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef __GLRenderSystem_H__
29 #define __GLRenderSystem_H__
30 
31 #include "OgreGLPrerequisites.h"
32 #include "OgrePlatform.h"
33 #include "OgreRenderSystem.h"
36 #include "OgreVector4.h"
37 
38 
39 namespace Ogre {
40 
41  class GLSLProgramFactory;
42 
47  {
48  private:
51 
55  #define MAX_LIGHTS 8
56  Light* mLights[MAX_LIGHTS];
57 
62 
66 
68  size_t mTextureCoordIndex[OGRE_MAX_TEXTURE_LAYERS];
69 
71  GLenum mTextureTypes[OGRE_MAX_TEXTURE_LAYERS];
72 
75 
76  void initConfigOptions(void);
77  void initInputDevices(void);
78  void processInputDevices(void);
79 
80  void setGLLight(size_t index, Light* lt);
81  void makeGLMatrix(GLfloat gl_matrix[16], const Matrix4& m);
82 
83  GLint getBlendMode(SceneBlendFactor ogreBlend) const;
84  GLint getTextureAddressingMode(TextureUnitState::TextureAddressingMode tam) const;
85  void initialiseContext(RenderWindow* primary);
86 
87  void setLights();
88 
94  bool mColourWrite[4];
95 
96  GLint convertCompareFunction(CompareFunction func) const;
97  GLint convertStencilOp(StencilOperation op, bool invert = false) const;
98 
100  GLfloat _getCurrentAnisotropy(size_t unit);
101 
104 
106  void setGLLightPositionDirection(Light* lt, GLenum lightindex);
107 
109  GLfloat mAutoTextureMatrix[16];
110 
113 
117 
118  unsigned short mCurrentLights;
119 
120  GLuint getCombinedMinMipFilter(void) const;
121 
125 
126  /* The main GL context - main thread only */
128  /* The current GL context - main thread only */
133 
140 
142 
143  // local data members of _render that were moved here to improve performance
144  // (save allocations)
147 
148 
149  protected:
150  void setClipPlanesImpl(const PlaneList& clipPlanes);
151  bool activateGLTextureUnit(size_t unit);
152  void bindVertexElementToGpu( const VertexElement &elem, HardwareVertexBufferSharedPtr vertexBuffer,
153  const size_t vertexStart,
154  vector<GLuint>::type &attribsBound, vector<GLuint>::type &instanceAttribsBound );
155  public:
156  // Default constructor / destructor
157  GLRenderSystem();
158  ~GLRenderSystem();
159 
160  // ----------------------------------
161  // Overridden RenderSystem functions
162  // ----------------------------------
166  const String& getName(void) const;
170  ConfigOptionMap& getConfigOptions(void);
174  void setConfigOption(const String &name, const String &value);
178  String validateConfigOptions(void);
182  RenderWindow* _initialise(bool autoCreateWindow, const String& windowTitle = "OGRE Render Window");
186  virtual RenderSystemCapabilities* createRenderSystemCapabilities() const;
190  void initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps, RenderTarget* primary);
194  void reinitialise(void); // Used if settings changed mid-rendering
198  void shutdown(void);
199 
203  void setAmbientLight(float r, float g, float b);
207  void setShadingType(ShadeOptions so);
211  void setLightingEnabled(bool enabled);
212 
214  RenderWindow* _createRenderWindow(const String &name, unsigned int width, unsigned int height,
215  bool fullScreen, const NameValuePairList *miscParams = 0);
216 
218  bool _createRenderWindows(const RenderWindowDescriptionList& renderWindowDescriptions,
219  RenderWindowList& createdWindows);
220 
222  DepthBuffer* _createDepthBufferFor( RenderTarget *renderTarget );
223 
225  void _getDepthStencilFormatFor( GLenum internalColourFormat, GLenum *depthFormat,
226  GLenum *stencilFormat );
227 
229  virtual MultiRenderTarget * createMultiRenderTarget(const String & name);
230 
234  void destroyRenderWindow(RenderWindow* pWin);
238  String getErrorDescription(long errorNumber) const;
239 
243  VertexElementType getColourVertexElementType(void) const;
247  void setNormaliseNormals(bool normalise);
248 
249  // -----------------------------
250  // Low-level overridden members
251  // -----------------------------
255  void _useLights(const LightList& lights, unsigned short limit);
259  bool areFixedFunctionLightsInViewSpace() const { return true; }
263  void _setWorldMatrix(const Matrix4 &m);
267  void _setViewMatrix(const Matrix4 &m);
271  void _setProjectionMatrix(const Matrix4 &m);
275  void _setSurfaceParams(const ColourValue &ambient,
276  const ColourValue &diffuse, const ColourValue &specular,
277  const ColourValue &emissive, Real shininess,
278  TrackVertexColourType tracking);
282  void _setPointParameters(Real size, bool attenuationEnabled,
283  Real constant, Real linear, Real quadratic, Real minSize, Real maxSize);
287  void _setPointSpritesEnabled(bool enabled);
291  void _setTexture(size_t unit, bool enabled, const TexturePtr &tex);
295  void _setTextureCoordSet(size_t stage, size_t index);
299  void _setTextureCoordCalculation(size_t stage, TexCoordCalcMethod m,
300  const Frustum* frustum = 0);
304  void _setTextureBlendMode(size_t stage, const LayerBlendModeEx& bm);
308  void _setTextureAddressingMode(size_t stage, const TextureUnitState::UVWAddressingMode& uvw);
312  void _setTextureBorderColour(size_t stage, const ColourValue& colour);
316  void _setTextureMipmapBias(size_t unit, float bias);
320  void _setTextureMatrix(size_t stage, const Matrix4& xform);
324  void _setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op );
328  void _setSeparateSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, SceneBlendFactor destFactorAlpha, SceneBlendOperation op, SceneBlendOperation alphaOp );
332  void _setSceneBlendingOperation(SceneBlendOperation op);
336  void _setSeparateSceneBlendingOperation(SceneBlendOperation op, SceneBlendOperation alphaOp);
340  void _setAlphaRejectSettings(CompareFunction func, unsigned char value, bool alphaToCoverage);
344  void _setViewport(Viewport *vp);
348  void _beginFrame(void);
352  void _endFrame(void);
356  void _setCullingMode(CullingMode mode);
360  void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL);
364  void _setDepthBufferCheckEnabled(bool enabled = true);
368  void _setDepthBufferWriteEnabled(bool enabled = true);
372  void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL);
376  void _setDepthBias(float constantBias, float slopeScaleBias);
380  void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha);
384  void _setFog(FogMode mode, const ColourValue& colour, Real density, Real start, Real end);
388  void _convertProjectionMatrix(const Matrix4& matrix,
389  Matrix4& dest, bool forGpuProgram = false);
393  void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
394  Matrix4& dest, bool forGpuProgram = false);
398  void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top,
399  Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false);
403  void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
404  Matrix4& dest, bool forGpuProgram = false);
408  void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane,
409  bool forGpuProgram);
413  void setClipPlane (ushort index, Real A, Real B, Real C, Real D);
417  void enableClipPlane (ushort index, bool enable);
421  void _setPolygonMode(PolygonMode level);
425  void setStencilCheckEnabled(bool enabled);
429  void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS,
430  uint32 refValue = 0, uint32 mask = 0xFFFFFFFF,
431  StencilOperation stencilFailOp = SOP_KEEP,
432  StencilOperation depthFailOp = SOP_KEEP,
433  StencilOperation passOp = SOP_KEEP,
434  bool twoSidedOperation = false);
438  void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter);
442  void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy);
446  void setVertexDeclaration(VertexDeclaration* decl);
450  void setVertexBufferBinding(VertexBufferBinding* binding);
454  void _render(const RenderOperation& op);
455 
459  void bindGpuProgram(GpuProgram* prg);
463  void unbindGpuProgram(GpuProgramType gptype);
467  void bindGpuProgramParameters(GpuProgramType gptype,
468  GpuProgramParametersSharedPtr params, uint16 variabilityMask);
472  void bindGpuProgramPassIterationParameters(GpuProgramType gptype);
476  void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600) ;
477  void clearFrameBuffer(unsigned int buffers,
478  const ColourValue& colour = ColourValue::Black,
479  Real depth = 1.0f, unsigned short stencil = 0);
480  HardwareOcclusionQuery* createHardwareOcclusionQuery(void);
481  Real getHorizontalTexelOffset(void);
482  Real getVerticalTexelOffset(void);
483  Real getMinimumDepthInputValue(void);
484  Real getMaximumDepthInputValue(void);
485  OGRE_MUTEX(mThreadInitMutex)
486  void registerThread();
487  void unregisterThread();
488  void preExtraThreadsStarted();
489  void postExtraThreadsStarted();
490 
491  // ----------------------------------
492  // GLRenderSystem specific members
493  // ----------------------------------
497  void _oneTimeContextInitialization();
500  void _switchContext(GLContext *context);
504  void _setRenderTarget(RenderTarget *target);
512  void _unregisterContext(GLContext *context);
514  GLContext* _getMainContext() {return mMainContext;}
515 
517  unsigned int getDisplayMonitorCount() const;
518 
520  virtual void beginProfileEvent( const String &eventName );
521 
523  virtual void endProfileEvent( void );
524 
526  virtual void markProfileEvent( const String &eventName );
527 };
528 }
529 #endif
530 
Manages the target rendering window.
A 'canvas' which can receive the results of a rendering operation.
#define MAX_LIGHTS
Array of up to 8 lights, indexed as per API Note that a null value indicates a free slot...
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:78
float Real
Software floating point type.
unsigned int uint32
Definition: OgrePlatform.h:270
GLGpuProgramManager * mGpuProgramManager
Singleton wrapper for hardware buffer manager.
Records the state of all the vertex buffer bindings required to provide a vertex declaration with the...
map< String, String >::type NameValuePairList
Name / value parameter pair (first = name, second = value)
Definition: OgreCommon.h:553
Defines a plane in 3D space.
Definition: OgrePlane.h:61
FogMode
Fog modes.
Definition: OgreCommon.h:124
Leave the stencil buffer unchanged.
Matrix4 mViewMatrix
View matrix to set world against.
Class representing colour.
GpuProgramType
Enumerates the types of programs which can run on the GPU.
A frustum represents a pyramid, capped at the near and far end which is used to represent either a vi...
Definition: OgreFrustum.h:85
Defines a program which runs on the GPU such as a vertex or fragment program.
GLSLProgramFactory * mGLSLProgramFactory
TexCoordCalcMethod
Enum describing the ways to generate texture coordinates.
#define OGRE_MUTEX(name)
Shared pointer implementation used to share index buffers.
Generalised low-level GL program, can be applied to multiple types (eg ARB and NV) ...
FilterType
Definition: OgreCommon.h:93
vector< GLuint >::type mRenderInstanceAttribsBound
SceneBlendFactor
Blending factors for manually blending objects with the scene.
#define _OgreGLExport
uint32 mStencilMask
Store last stencil mask state.
GLGpuProgram * mCurrentFragmentProgram
CullingMode
Hardware culling modes based on vertex winding.
Definition: OgreCommon.h:138
This class represents a render target that renders to multiple RenderTextures at once.
This is a abstract class that that provides the interface for the query class for hardware occlusion...
This class declares the usage of a single vertex buffer as a component of a complete VertexDeclaratio...
vector< RenderWindow * >::type RenderWindowList
Render window container.
Definition: OgreCommon.h:767
Representation of a dynamic light source in the scene.
Definition: OgreLight.h:73
bool areFixedFunctionLightsInViewSpace() const
See RenderSystem.
vector< Plane >::type PlaneList
Definition: OgrePlane.h:160
GLGpuProgram * mCurrentVertexProgram
#define OGRE_MAX_TEXTURE_LAYERS
Define max number of texture layers allowed per pass on any card.
Definition: OgreConfig.h:70
GLGpuProgram * mCurrentGeometryProgram
GLSupport * mGLSupport
GL support class, used for creating windows etc.
An abstract class that contains a depth/stencil buffer.
unsigned short mFixedFunctionTextureUnits
Number of fixed-function texture units.
bool mStopRendering
Rendering loop control.
ShadeOptions
Light shading modes.
Definition: OgreCommon.h:116
GLContextList mBackgroundContextList
List of background thread contexts.
Texture addressing mode for each texture coordinate.
map< String, ConfigOption >::type ConfigOptionMap
TextureAddressingMode
Texture addressing modes - default is TAM_WRAP.
unsigned short mCurrentLights
FilterOptions mMinFilter
Last min & mip filtering options, so we can combine them.
bool mDepthWrite
Store last depth write state.
Specialisation of SharedPtr to allow SharedPtr to be assigned to TexturePtr.
Definition: OgreTexture.h:443
VertexElementType
Vertex element type, used to identify the base types of the vertex contents.
unsigned short ushort
An abstraction of a viewport, i.e.
Definition: OgreViewport.h:56
'New' rendering operation using vertex buffers.
This class declares the format of a set of vertex inputs, which can be issued to the rendering API th...
Class that encapsulates an GL context.
Definition: OgreGLContext.h:41
Wrapper class which indicates a given angle value is in Radians.
Definition: OgreMath.h:46
PolygonMode
The polygon mode to use when rasterising.
Definition: OgreCommon.h:182
static const ColourValue Black
vector< GLuint >::type mRenderAttribsBound
SceneBlendOperation
Blending operations controls how objects are blended into the scene.
list< GLContext * >::type GLContextList
HardwareBufferManager * mHardwareBufferManager
singleton class for storing the capabilities of the graphics card.
_StringBase String
Manager/factory for RenderTextures.
vector< RenderWindowDescription >::type RenderWindowDescriptionList
Render window creation parameters container.
Definition: OgreCommon.h:764
unsigned short uint16
Definition: OgrePlatform.h:271
Factory class for GLSL programs.
StencilOperation
Enum describing the various actions which can be taken onthe stencil buffer.
FilterOptions
Filtering options for textures / mipmaps.
Definition: OgreCommon.h:103
GLRTTManager * mRTTManager
Manager object for creating render textures.
Defines the functionality of a 3D API.
CompareFunction
Comparison functions used for the depth/stencil buffer operations and others.
Definition: OgreCommon.h:67
int TrackVertexColourType
An enumeration describing which material properties should track the vertex colours.
Definition: OgreCommon.h:279
Class which manages blending of both colour and alpha components.
bool mGLInitialised
Check if the GL system has already been initialised.
Implementation of GL as a rendering system.