OGRE  1.7
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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-2011 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 "OgreGLSLProgramFactory.h"
37 #include "OgreVector4.h"
38 
39 namespace Ogre {
44  {
45  private:
48 
52  #define MAX_LIGHTS 8
53  Light* mLights[MAX_LIGHTS];
54 
59 
63 
65  size_t mTextureCoordIndex[OGRE_MAX_TEXTURE_LAYERS];
66 
68  GLenum mTextureTypes[OGRE_MAX_TEXTURE_LAYERS];
69 
72 
73  void initConfigOptions(void);
74  void initInputDevices(void);
75  void processInputDevices(void);
76 
77  void setGLLight(size_t index, Light* lt);
78  void makeGLMatrix(GLfloat gl_matrix[16], const Matrix4& m);
79 
80  GLint getBlendMode(SceneBlendFactor ogreBlend) const;
81  GLint getTextureAddressingMode(TextureUnitState::TextureAddressingMode tam) const;
82  void initialiseContext(RenderWindow* primary);
83 
84  void setLights();
85 
91  bool mColourWrite[4];
92 
93  GLint convertCompareFunction(CompareFunction func) const;
94  GLint convertStencilOp(StencilOperation op, bool invert = false) const;
95 
97  GLfloat _getCurrentAnisotropy(size_t unit);
98 
101 
103  void setGLLightPositionDirection(Light* lt, GLenum lightindex);
104 
106  GLfloat mAutoTextureMatrix[16];
107 
110 
114 
115  unsigned short mCurrentLights;
116 
117  GLuint getCombinedMinMipFilter(void) const;
118 
122 
123  /* The main GL context - main thread only */
125  /* The current GL context - main thread only */
130 
137 
139 
140  protected:
141  void setClipPlanesImpl(const PlaneList& clipPlanes);
142  bool activateGLTextureUnit(size_t unit);
143  public:
144  // Default constructor / destructor
145  GLRenderSystem();
146  ~GLRenderSystem();
147 
148  // ----------------------------------
149  // Overridden RenderSystem functions
150  // ----------------------------------
154  const String& getName(void) const;
158  ConfigOptionMap& getConfigOptions(void);
162  void setConfigOption(const String &name, const String &value);
166  String validateConfigOptions(void);
170  RenderWindow* _initialise(bool autoCreateWindow, const String& windowTitle = "OGRE Render Window");
174  virtual RenderSystemCapabilities* createRenderSystemCapabilities() const;
178  void initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps, RenderTarget* primary);
182  void reinitialise(void); // Used if settings changed mid-rendering
186  void shutdown(void);
187 
191  void setAmbientLight(float r, float g, float b);
195  void setShadingType(ShadeOptions so);
199  void setLightingEnabled(bool enabled);
200 
202  RenderWindow* _createRenderWindow(const String &name, unsigned int width, unsigned int height,
203  bool fullScreen, const NameValuePairList *miscParams = 0);
204 
206  bool _createRenderWindows(const RenderWindowDescriptionList& renderWindowDescriptions,
207  RenderWindowList& createdWindows);
208 
209 
211  virtual MultiRenderTarget * createMultiRenderTarget(const String & name);
212 
216  void destroyRenderWindow(RenderWindow* pWin);
220  String getErrorDescription(long errorNumber) const;
221 
225  VertexElementType getColourVertexElementType(void) const;
229  void setNormaliseNormals(bool normalise);
230 
231  // -----------------------------
232  // Low-level overridden members
233  // -----------------------------
237  void _useLights(const LightList& lights, unsigned short limit);
241  bool areFixedFunctionLightsInViewSpace() const { return true; }
245  void _setWorldMatrix(const Matrix4 &m);
249  void _setViewMatrix(const Matrix4 &m);
253  void _setProjectionMatrix(const Matrix4 &m);
257  void _setSurfaceParams(const ColourValue &ambient,
258  const ColourValue &diffuse, const ColourValue &specular,
259  const ColourValue &emissive, Real shininess,
260  TrackVertexColourType tracking);
264  void _setPointParameters(Real size, bool attenuationEnabled,
265  Real constant, Real linear, Real quadratic, Real minSize, Real maxSize);
269  void _setPointSpritesEnabled(bool enabled);
273  void _setTexture(size_t unit, bool enabled, const TexturePtr &tex);
277  void _setTextureCoordSet(size_t stage, size_t index);
281  void _setTextureCoordCalculation(size_t stage, TexCoordCalcMethod m,
282  const Frustum* frustum = 0);
286  void _setTextureBlendMode(size_t stage, const LayerBlendModeEx& bm);
290  void _setTextureAddressingMode(size_t stage, const TextureUnitState::UVWAddressingMode& uvw);
294  void _setTextureBorderColour(size_t stage, const ColourValue& colour);
298  void _setTextureMipmapBias(size_t unit, float bias);
302  void _setTextureMatrix(size_t stage, const Matrix4& xform);
306  void _setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op );
310  void _setSeparateSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, SceneBlendFactor destFactorAlpha, SceneBlendOperation op, SceneBlendOperation alphaOp );
314  void _setSceneBlendingOperation(SceneBlendOperation op);
318  void _setSeparateSceneBlendingOperation(SceneBlendOperation op, SceneBlendOperation alphaOp);
322  void _setAlphaRejectSettings(CompareFunction func, unsigned char value, bool alphaToCoverage);
326  void _setViewport(Viewport *vp);
330  void _beginFrame(void);
334  void _endFrame(void);
338  void _setCullingMode(CullingMode mode);
342  void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL);
346  void _setDepthBufferCheckEnabled(bool enabled = true);
350  void _setDepthBufferWriteEnabled(bool enabled = true);
354  void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL);
358  void _setDepthBias(float constantBias, float slopeScaleBias);
362  void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha);
366  void _setFog(FogMode mode, const ColourValue& colour, Real density, Real start, Real end);
370  void _convertProjectionMatrix(const Matrix4& matrix,
371  Matrix4& dest, bool forGpuProgram = false);
375  void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
376  Matrix4& dest, bool forGpuProgram = false);
380  void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top,
381  Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false);
385  void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
386  Matrix4& dest, bool forGpuProgram = false);
390  void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane,
391  bool forGpuProgram);
395  void setClipPlane (ushort index, Real A, Real B, Real C, Real D);
399  void enableClipPlane (ushort index, bool enable);
403  void _setPolygonMode(PolygonMode level);
407  void setStencilCheckEnabled(bool enabled);
411  void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS,
412  uint32 refValue = 0, uint32 mask = 0xFFFFFFFF,
413  StencilOperation stencilFailOp = SOP_KEEP,
414  StencilOperation depthFailOp = SOP_KEEP,
415  StencilOperation passOp = SOP_KEEP,
416  bool twoSidedOperation = false);
420  void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter);
424  void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy);
428  void setVertexDeclaration(VertexDeclaration* decl);
432  void setVertexBufferBinding(VertexBufferBinding* binding);
436  void _render(const RenderOperation& op);
440  void bindGpuProgram(GpuProgram* prg);
444  void unbindGpuProgram(GpuProgramType gptype);
448  void bindGpuProgramParameters(GpuProgramType gptype,
449  GpuProgramParametersSharedPtr params, uint16 variabilityMask);
453  void bindGpuProgramPassIterationParameters(GpuProgramType gptype);
457  void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600) ;
458  void clearFrameBuffer(unsigned int buffers,
459  const ColourValue& colour = ColourValue::Black,
460  Real depth = 1.0f, unsigned short stencil = 0);
461  HardwareOcclusionQuery* createHardwareOcclusionQuery(void);
462  Real getHorizontalTexelOffset(void);
463  Real getVerticalTexelOffset(void);
464  Real getMinimumDepthInputValue(void);
465  Real getMaximumDepthInputValue(void);
466  OGRE_MUTEX(mThreadInitMutex)
467  void registerThread();
468  void unregisterThread();
469  void preExtraThreadsStarted();
470  void postExtraThreadsStarted();
471 
472  // ----------------------------------
473  // GLRenderSystem specific members
474  // ----------------------------------
478  void _oneTimeContextInitialization();
481  void _switchContext(GLContext *context);
485  void _setRenderTarget(RenderTarget *target);
493  void _unregisterContext(GLContext *context);
495  GLContext* _getMainContext() {return mMainContext;}
496 
498  unsigned int getDisplayMonitorCount() const;
499  };
500 }
501 #endif
502 
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:246
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:524
Defines a plane in 3D space.
Definition: OgrePlane.h:61
FogMode
Fog modes.
Definition: OgreCommon.h:122
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:84
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)
Generalised low-level GL program, can be applied to multiple types (eg ARB and NV) ...
FilterType
Definition: OgreCommon.h:91
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:136
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...
vector< RenderWindow * >::type RenderWindowList
Render window container.
Definition: OgreCommon.h:738
Representation of a dynamic light source in the scene.
Definition: OgreLight.h:72
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.
unsigned short mFixedFunctionTextureUnits
Number of fixed-function texture units.
bool mStopRendering
Rendering loop control.
ShadeOptions
Light shading modes.
Definition: OgreCommon.h:114
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:440
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:180
static const ColourValue Black
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:735
unsigned short uint16
Definition: OgrePlatform.h:247
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:101
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:65
int TrackVertexColourType
An enumeration describing which material properties should track the vertex colours.
Definition: OgreCommon.h:277
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.