OGRE  2.0
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 const * 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, const 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(const 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 _setVertexTexture(size_t unit, const TexturePtr &tex);
308  void _setGeometryTexture(size_t unit, const TexturePtr &tex);
312  void _setComputeTexture(size_t unit, const TexturePtr &tex);
316  void _setTessellationHullTexture(size_t unit, const TexturePtr &tex);
320  void _setTessellationDomainTexture(size_t unit, const TexturePtr &tex);
324  void _setTextureCoordSet(size_t stage, size_t index);
328  void _setTextureCoordCalculation(size_t stage, TexCoordCalcMethod m,
329  const Frustum* frustum = 0);
333  void _setTextureBlendMode(size_t stage, const LayerBlendModeEx& bm);
337  void _setTextureAddressingMode(size_t stage, const TextureUnitState::UVWAddressingMode& uvw);
341  void _setTextureBorderColour(size_t stage, const ColourValue& colour);
345  void _setTextureMipmapBias(size_t unit, float bias);
349  void _setTextureMatrix(size_t stage, const Matrix4& xform);
353  void _setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op );
357  void _setSeparateSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, SceneBlendFactor destFactorAlpha, SceneBlendOperation op, SceneBlendOperation alphaOp );
361  void _setSceneBlendingOperation(SceneBlendOperation op);
365  void _setSeparateSceneBlendingOperation(SceneBlendOperation op, SceneBlendOperation alphaOp);
369  void _setAlphaRejectSettings(CompareFunction func, unsigned char value, bool alphaToCoverage);
373  void _setViewport(Viewport *vp);
377  void _beginFrame(void);
381  void _endFrame(void);
385  void _setCullingMode(CullingMode mode);
389  void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL);
393  void _setDepthBufferCheckEnabled(bool enabled = true);
397  void _setDepthBufferWriteEnabled(bool enabled = true);
401  void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL);
405  void _setDepthBias(float constantBias, float slopeScaleBias);
409  void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha);
413  void _setFog(FogMode mode, const ColourValue& colour, Real density, Real start, Real end);
417  void _convertProjectionMatrix(const Matrix4& matrix,
418  Matrix4& dest, bool forGpuProgram = false);
422  void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
423  Matrix4& dest, bool forGpuProgram = false);
427  void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top,
428  Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false);
432  void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
433  Matrix4& dest, bool forGpuProgram = false);
437  void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane,
438  bool forGpuProgram);
442  void setClipPlane (ushort index, Real A, Real B, Real C, Real D);
446  void enableClipPlane (ushort index, bool enable);
450  void _setPolygonMode(PolygonMode level);
454  void setStencilCheckEnabled(bool enabled);
458  void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS,
459  uint32 refValue = 0, uint32 compareMask = 0xFFFFFFFF, uint32 writeMask = 0xFFFFFFFF,
460  StencilOperation stencilFailOp = SOP_KEEP,
461  StencilOperation depthFailOp = SOP_KEEP,
462  StencilOperation passOp = SOP_KEEP,
463  bool twoSidedOperation = false,
464  bool readBackAsTexture = false);
468  void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter);
472  void _setTextureUnitCompareFunction(size_t unit, CompareFunction function);
476  void _setTextureUnitCompareEnabled(size_t unit, bool compare);
480  void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy);
484  void setVertexDeclaration(VertexDeclaration* decl);
488  void setVertexBufferBinding(VertexBufferBinding* binding);
492  void _render(const RenderOperation& op);
493 
497  void bindGpuProgram(GpuProgram* prg);
501  void unbindGpuProgram(GpuProgramType gptype);
505  void bindGpuProgramParameters(GpuProgramType gptype,
506  GpuProgramParametersSharedPtr params, uint16 variabilityMask);
510  void bindGpuProgramPassIterationParameters(GpuProgramType gptype);
514  void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600) ;
515  void clearFrameBuffer(unsigned int buffers,
516  const ColourValue& colour = ColourValue::Black,
517  Real depth = 1.0f, unsigned short stencil = 0);
518  HardwareOcclusionQuery* createHardwareOcclusionQuery(void);
519  Real getHorizontalTexelOffset(void);
520  Real getVerticalTexelOffset(void);
521  Real getMinimumDepthInputValue(void);
522  Real getMaximumDepthInputValue(void);
523  OGRE_MUTEX(mThreadInitMutex);
524  void registerThread();
525  void unregisterThread();
526  void preExtraThreadsStarted();
527  void postExtraThreadsStarted();
528  GLSupport* getGLSupportRef() { return mGLSupport; }
529 
530  // ----------------------------------
531  // GLRenderSystem specific members
532  // ----------------------------------
536  void _oneTimeContextInitialization();
539  void _switchContext(GLContext *context);
543  void _setRenderTarget(RenderTarget *target);
551  void _unregisterContext(GLContext *context);
553  GLContext* _getMainContext() {return mMainContext;}
554 
556  unsigned int getDisplayMonitorCount() const;
557 
559  virtual bool hasAnisotropicMipMapFilter() const { return false; }
560 
562  virtual void beginProfileEvent( const String &eventName );
563 
565  virtual void endProfileEvent( void );
566 
568  virtual void markProfileEvent( const String &eventName );
569  };
570 }
571 #endif
572 
Leave the stencil buffer unchanged.
Definition: OgreCommon.h:90
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:79
float Real
Software floating point type.
unsigned int uint32
Definition: OgrePlatform.h:420
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:580
Defines a plane in 3D space.
Definition: OgrePlane.h:61
FogMode
Fog modes.
Definition: OgreCommon.h:152
#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:84
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:121
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:166
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:794
Representation of a dynamic light source in the scene.
Definition: OgreLight.h:70
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:144
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
StencilOperation
Enum describing the various actions which can be taken on the stencil buffer.
Definition: OgreCommon.h:87
An abstraction of a viewport, i.e.
Definition: OgreViewport.h:56
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:49
PolygonMode
The polygon mode to use when rasterising.
Definition: OgreCommon.h:210
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
Definition: OgreCommon.h:53
Manager/factory for RenderTextures.
vector< RenderWindowDescription >::type RenderWindowDescriptionList
Render window creation parameters container.
Definition: OgreCommon.h:791
unsigned short uint16
Definition: OgrePlatform.h:421
FilterOptions
Filtering options for textures / mipmaps.
Definition: OgreCommon.h:131
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:74
int TrackVertexColourType
An enumeration describing which material properties should track the vertex colours.
Definition: OgreCommon.h:221
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.