OGRE  1.9
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-2014 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 
42  namespace GLSL {
43  class GLSLProgramFactory;
44  }
45 
46  class GLStateCacheManager;
47 
52  {
53  private:
56 
60  #define MAX_LIGHTS 8
61  Light* mLights[MAX_LIGHTS];
62 
67 
71 
73  size_t mTextureCoordIndex[OGRE_MAX_TEXTURE_LAYERS];
74 
76  GLenum mTextureTypes[OGRE_MAX_TEXTURE_LAYERS];
77 
80 
81  void initConfigOptions(void);
82  void initInputDevices(void);
83  void processInputDevices(void);
84 
85  void setGLLight(size_t index, Light* lt);
86  void makeGLMatrix(GLfloat gl_matrix[16], const Matrix4& m);
87 
88  GLint getBlendMode(SceneBlendFactor ogreBlend) const;
89  GLint getTextureAddressingMode(TextureUnitState::TextureAddressingMode tam) const;
90  void initialiseContext(RenderWindow* primary);
91 
92  void setLights();
93 
99  bool mColourWrite[4];
100 
102  int mScissorBox[4];
103 
104  GLint convertCompareFunction(CompareFunction func) const;
105  GLint convertStencilOp(StencilOperation op, bool invert = false) const;
106 
108  GLfloat _getCurrentAnisotropy(size_t unit);
109 
112 
114  void setGLLightPositionDirection(Light* lt, GLenum lightindex);
115 
117  GLfloat mAutoTextureMatrix[16];
118 
121 
125 
126  unsigned short mCurrentLights;
127 
128  GLuint getCombinedMinMipFilter(void) const;
129 
133 
134  /* The main GL context - main thread only */
136  /* The current GL context - main thread only */
141 
143 
150 
152 
153  // local data members of _render that were moved here to improve performance
154  // (save allocations)
157 
158 
159  protected:
160  void setClipPlanesImpl(const PlaneList& clipPlanes);
161  void bindVertexElementToGpu( const VertexElement &elem, HardwareVertexBufferSharedPtr vertexBuffer,
162  const size_t vertexStart,
163  vector<GLuint>::type &attribsBound, vector<GLuint>::type &instanceAttribsBound );
164  public:
165  // Default constructor / destructor
166  GLRenderSystem();
167  ~GLRenderSystem();
168 
169  // ----------------------------------
170  // Overridden RenderSystem functions
171  // ----------------------------------
175  const String& getName(void) const;
179  ConfigOptionMap& getConfigOptions(void);
183  void setConfigOption(const String &name, const String &value);
187  String validateConfigOptions(void);
191  RenderWindow* _initialise(bool autoCreateWindow, const String& windowTitle = "OGRE Render Window");
195  virtual RenderSystemCapabilities* createRenderSystemCapabilities() const;
199  void initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps, RenderTarget* primary);
203  void reinitialise(void); // Used if settings changed mid-rendering
207  void shutdown(void);
208 
212  void setAmbientLight(float r, float g, float b);
216  void setShadingType(ShadeOptions so);
220  void setLightingEnabled(bool enabled);
221 
223  RenderWindow* _createRenderWindow(const String &name, unsigned int width, unsigned int height,
224  bool fullScreen, const NameValuePairList *miscParams = 0);
225 
227  bool _createRenderWindows(const RenderWindowDescriptionList& renderWindowDescriptions,
228  RenderWindowList& createdWindows);
229 
231  DepthBuffer* _createDepthBufferFor( RenderTarget *renderTarget );
232 
234  void _getDepthStencilFormatFor( GLenum internalColourFormat, GLenum *depthFormat,
235  GLenum *stencilFormat );
236 
238  virtual MultiRenderTarget * createMultiRenderTarget(const String & name);
239 
243  void destroyRenderWindow(RenderWindow* pWin);
247  String getErrorDescription(long errorNumber) const;
248 
252  VertexElementType getColourVertexElementType(void) const;
256  void setNormaliseNormals(bool normalise);
257 
258  // -----------------------------
259  // Low-level overridden members
260  // -----------------------------
264  void _useLights(const LightList& lights, unsigned short limit);
268  bool areFixedFunctionLightsInViewSpace() const { return true; }
272  void _setWorldMatrix(const Matrix4 &m);
276  void _setViewMatrix(const Matrix4 &m);
280  void _setProjectionMatrix(const Matrix4 &m);
284  void _setSurfaceParams(const ColourValue &ambient,
285  const ColourValue &diffuse, const ColourValue &specular,
286  const ColourValue &emissive, Real shininess,
287  TrackVertexColourType tracking);
291  void _setPointParameters(Real size, bool attenuationEnabled,
292  Real constant, Real linear, Real quadratic, Real minSize, Real maxSize);
296  void _setPointSpritesEnabled(bool enabled);
300  void _setTexture(size_t unit, bool enabled, const TexturePtr &tex);
304  void _setTextureCoordSet(size_t stage, size_t index);
308  void _setTextureCoordCalculation(size_t stage, TexCoordCalcMethod m,
309  const Frustum* frustum = 0);
313  void _setTextureBlendMode(size_t stage, const LayerBlendModeEx& bm);
317  void _setTextureAddressingMode(size_t stage, const TextureUnitState::UVWAddressingMode& uvw);
321  void _setTextureBorderColour(size_t stage, const ColourValue& colour);
325  void _setTextureMipmapBias(size_t unit, float bias);
329  void _setTextureMatrix(size_t stage, const Matrix4& xform);
333  void _setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op );
337  void _setSeparateSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, SceneBlendFactor destFactorAlpha, SceneBlendOperation op, SceneBlendOperation alphaOp );
341  void _setSceneBlendingOperation(SceneBlendOperation op);
345  void _setSeparateSceneBlendingOperation(SceneBlendOperation op, SceneBlendOperation alphaOp);
349  void _setAlphaRejectSettings(CompareFunction func, unsigned char value, bool alphaToCoverage);
353  void _setViewport(Viewport *vp);
357  void _beginFrame(void);
361  void _endFrame(void);
365  void _setCullingMode(CullingMode mode);
369  void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL);
373  void _setDepthBufferCheckEnabled(bool enabled = true);
377  void _setDepthBufferWriteEnabled(bool enabled = true);
381  void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL);
385  void _setDepthBias(float constantBias, float slopeScaleBias);
389  void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha);
393  void _setFog(FogMode mode, const ColourValue& colour, Real density, Real start, Real end);
397  void _convertProjectionMatrix(const Matrix4& matrix,
398  Matrix4& dest, bool forGpuProgram = false);
402  void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
403  Matrix4& dest, bool forGpuProgram = false);
407  void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top,
408  Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false);
412  void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
413  Matrix4& dest, bool forGpuProgram = false);
417  void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane,
418  bool forGpuProgram);
422  void setClipPlane (ushort index, Real A, Real B, Real C, Real D);
426  void enableClipPlane (ushort index, bool enable);
430  void _setPolygonMode(PolygonMode level);
434  void setStencilCheckEnabled(bool enabled);
438  void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS,
439  uint32 refValue = 0, uint32 compareMask = 0xFFFFFFFF, uint32 writeMask = 0xFFFFFFFF,
440  StencilOperation stencilFailOp = SOP_KEEP,
441  StencilOperation depthFailOp = SOP_KEEP,
442  StencilOperation passOp = SOP_KEEP,
443  bool twoSidedOperation = false);
447  void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter);
451  void _setTextureUnitCompareFunction(size_t unit, CompareFunction function);
455  void _setTextureUnitCompareEnabled(size_t unit, bool compare);
459  void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy);
463  void setVertexDeclaration(VertexDeclaration* decl);
467  void setVertexBufferBinding(VertexBufferBinding* binding);
471  void _render(const RenderOperation& op);
472 
476  void bindGpuProgram(GpuProgram* prg);
480  void unbindGpuProgram(GpuProgramType gptype);
484  void bindGpuProgramParameters(GpuProgramType gptype,
485  GpuProgramParametersSharedPtr params, uint16 variabilityMask);
489  void bindGpuProgramPassIterationParameters(GpuProgramType gptype);
493  void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600) ;
494  void clearFrameBuffer(unsigned int buffers,
495  const ColourValue& colour = ColourValue::Black,
496  Real depth = 1.0f, unsigned short stencil = 0);
497  HardwareOcclusionQuery* createHardwareOcclusionQuery(void);
498  Real getHorizontalTexelOffset(void);
499  Real getVerticalTexelOffset(void);
500  Real getMinimumDepthInputValue(void);
501  Real getMaximumDepthInputValue(void);
502  OGRE_MUTEX(mThreadInitMutex);
503  void registerThread();
504  void unregisterThread();
505  void preExtraThreadsStarted();
506  void postExtraThreadsStarted();
507  GLSupport* getGLSupportRef() { return mGLSupport; }
508 
509  // ----------------------------------
510  // GLRenderSystem specific members
511  // ----------------------------------
515  void _oneTimeContextInitialization();
518  void _switchContext(GLContext *context);
522  void _setRenderTarget(RenderTarget *target);
530  void _unregisterContext(GLContext *context);
532  GLContext* _getMainContext() {return mMainContext;}
533 
535  unsigned int getDisplayMonitorCount() const;
536 
538  virtual bool hasAnisotropicMipMapFilter() const { return false; }
539 
541  virtual void beginProfileEvent( const String &eventName );
542 
544  virtual void endProfileEvent( void );
545 
547  virtual void markProfileEvent( const String &eventName );
548  };
549 }
550 #endif
551 
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:344
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:550
Defines a plane in 3D space.
Definition: OgrePlane.h:61
FogMode
Fog modes.
Definition: OgreCommon.h:121
Leave the stencil buffer unchanged.
#define OGRE_MUTEX(name)
virtual bool hasAnisotropicMipMapFilter() const
Determines if the system has anisotropic mip map filter support.
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.
TexCoordCalcMethod
Enum describing the ways to generate texture coordinates.
Shared pointer implementation used to share vertex buffers.
Generalised low-level GL program, can be applied to multiple types (eg ARB and NV) ...
FilterType
Definition: OgreCommon.h:90
vector< GLuint >::type mRenderInstanceAttribsBound
GLSL::GLSLProgramFactory * mGLSLProgramFactory
SceneBlendFactor
Blending factors for manually blending objects with the scene.
#define _OgreGLExport
GLGpuProgram * mCurrentFragmentProgram
CullingMode
Hardware culling modes based on vertex winding.
Definition: OgreCommon.h:135
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:764
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:72
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:113
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.
VertexElementType
Vertex element type, used to identify the base types of the vertex contents.
GLStateCacheManager * mStateCacheManager
unsigned short ushort
An abstraction of a viewport, i.e.
Definition: OgreViewport.h:57
uint32 mStencilWriteMask
Store last stencil mask state.
'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:47
PolygonMode
The polygon mode to use when rasterising.
Definition: OgreCommon.h:179
static const ColourValue Black
vector< GLuint >::type mRenderAttribsBound
SceneBlendOperation
Blending operations controls how objects are blended into the scene.
list< GLContext * >::type GLContextList
GLContext * _getMainContext()
Returns the main context.
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:761
unsigned short uint16
Definition: OgrePlatform.h:345
StencilOperation
Enum describing the various actions which can be taken on the stencil buffer.
FilterOptions
Filtering options for textures / mipmaps.
Definition: OgreCommon.h:100
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:64
int TrackVertexColourType
An enumeration describing which material properties should track the vertex colours.
Definition: OgreCommon.h:276
GLSupport * getGLSupportRef()
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.
An in memory cache of the OpenGL state.