OGRE  1.7
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OgreGLESRenderSystem.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) 2008 Renato Araujo Oliveira Filho <renatox@gmail.com>
8 Copyright (c) 2000-2011 Torus Knot Software Ltd
9 
10 Permission is hereby granted, free of charge, to any person obtaining a copy
11 of this software and associated documentation files (the "Software"), to deal
12 in the Software without restriction, including without limitation the rights
13 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 copies of the Software, and to permit persons to whom the Software is
15 furnished to do so, subject to the following conditions:
16 
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19 
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 THE SOFTWARE.
27 -----------------------------------------------------------------------------
28 */
29 
30 #ifndef __GLESRenderSystem_H__
31 #define __GLESRenderSystem_H__
32 
33 #include "OgreGLESPrerequisites.h"
34 
35 #include "OgreRenderSystem.h"
36 
37 
38 namespace Ogre {
39  class GLESContext;
40  class GLESSupport;
41  class GLESRTTManager;
42  class GLESGpuProgramManager;
43  class HardwareBufferManager;
44 
49  {
50  private:
51 
55  #define MAX_LIGHTS 8
56  Light* mLights[MAX_LIGHTS];
57  unsigned short mCurrentLights;
58 
63 
67 
74 
76  size_t mTextureCoordIndex[OGRE_MAX_TEXTURE_LAYERS];
77 
80 
82  bool mColourWrite[4];
83 
86 
89 
90  GLfloat mAutoTextureMatrix[16];
91 
93  size_t mTextureCount;
95 
98 
99  /* The main GL context - main thread only */
101 
102  /* The current GL context - main thread only */
106 
113 
119 
122 
126  GLenum mPolygonMode;
127 
128  GLuint getCombinedMinMipFilter(void) const;
129 
130  GLint getTextureAddressingMode(TextureUnitState::TextureAddressingMode tam) const;
131  GLint getBlendMode(SceneBlendFactor ogreBlend) const;
132  void makeGLMatrix(GLfloat gl_matrix[16], const Matrix4& m);
133  void setGLLight(size_t index, Light* lt);
134 
136  void setGLLightPositionDirection(Light* lt, GLenum lightindex);
137  void setLights();
138 
139  bool activateGLTextureUnit(size_t unit);
140 
141  public:
142  // Default constructor / destructor
144  virtual ~GLESRenderSystem();
145 
146  // ----------------------------------
147  // Overridden RenderSystem functions
148  // ----------------------------------
152  const String& getName(void) const;
156  ConfigOptionMap& getConfigOptions(void);
160  void setConfigOption(const String &name, const String &value);
164  String validateConfigOptions(void);
168  RenderWindow* _initialise(bool autoCreateWindow, const String& windowTitle = "OGRE Render NativeWindowType");
172  virtual RenderSystemCapabilities* createRenderSystemCapabilities() const;
176  void initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps, RenderTarget* primary);
180  void reinitialise(void); // Used if settings changed mid-rendering
184  void shutdown(void);
188  void setAmbientLight(float r, float g, float b);
192  void setShadingType(ShadeOptions so);
196  void setLightingEnabled(bool enabled);
197 
199  RenderWindow* _createRenderWindow(const String &name, unsigned int width, unsigned int height,
200  bool fullScreen, const NameValuePairList *miscParams = 0);
201 
203  virtual MultiRenderTarget * createMultiRenderTarget(const String & name);
204 
208  void destroyRenderWindow(RenderWindow* pWin);
212  String getErrorDescription(long errorNumber) const;
216  VertexElementType getColourVertexElementType(void) const;
220  void setNormaliseNormals(bool normalise);
221 
222  // -----------------------------
223  // Low-level overridden members
224  // -----------------------------
228  void _useLights(const LightList& lights, unsigned short limit);
232  bool areFixedFunctionLightsInViewSpace() const { return true; }
236  void _setWorldMatrix(const Matrix4 &m);
240  void _setViewMatrix(const Matrix4 &m);
244  void _setProjectionMatrix(const Matrix4 &m);
248  void _setSurfaceParams(const ColourValue &ambient,
249  const ColourValue &diffuse, const ColourValue &specular,
250  const ColourValue &emissive, Real shininess,
251  TrackVertexColourType tracking);
255  void _setPointParameters(Real size, bool attenuationEnabled,
256  Real constant, Real linear, Real quadratic, Real minSize, Real maxSize);
260  void _setPointSpritesEnabled(bool enabled);
264  void _setTexture(size_t unit, bool enabled, const TexturePtr &tex);
268  void _setTextureCoordSet(size_t stage, size_t index);
272  void _setTextureCoordCalculation(size_t stage, TexCoordCalcMethod m,
273  const Frustum* frustum = 0);
277  void _setTextureBlendMode(size_t stage, const LayerBlendModeEx& bm);
281  void _setTextureAddressingMode(size_t stage, const TextureUnitState::UVWAddressingMode& uvw);
285  void _setTextureBorderColour(size_t stage, const ColourValue& colour);
289  void _setTextureMipmapBias(size_t unit, float bias);
293  void _setTextureMatrix(size_t stage, const Matrix4& xform);
297  void _setViewport(Viewport *vp);
301  void _beginFrame(void);
305  void _endFrame(void);
309  void _setCullingMode(CullingMode mode);
313  void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL);
317  void _setDepthBufferCheckEnabled(bool enabled = true);
321  void _setDepthBufferWriteEnabled(bool enabled = true);
325  void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL);
329  void _setDepthBias(float constantBias, float slopeScaleBias);
333  void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha);
337  void _setFog(FogMode mode, const ColourValue& colour, Real density, Real start, Real end);
341  void _convertProjectionMatrix(const Matrix4& matrix,
342  Matrix4& dest, bool forGpuProgram = false);
346  void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
347  Matrix4& dest, bool forGpuProgram = false);
351  void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top,
352  Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false);
356  void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
357  Matrix4& dest, bool forGpuProgram = false);
361  void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane,
362  bool forGpuProgram);
366  void setClipPlane (ushort index, Real A, Real B, Real C, Real D);
370  void enableClipPlane (ushort index, bool enable);
374  void _setPolygonMode(PolygonMode level);
378  void setStencilCheckEnabled(bool enabled);
382  void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS,
383  uint32 refValue = 0, uint32 mask = 0xFFFFFFFF,
384  StencilOperation stencilFailOp = SOP_KEEP,
385  StencilOperation depthFailOp = SOP_KEEP,
386  StencilOperation passOp = SOP_KEEP,
387  bool twoSidedOperation = false);
391  void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter);
395  void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy);
399  void setVertexDeclaration(VertexDeclaration* decl);
403  void setVertexBufferBinding(VertexBufferBinding* binding);
407  void _render(const RenderOperation& op);
411  void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600);
412 
413 
414  void clearFrameBuffer(unsigned int buffers,
415  const ColourValue& colour = ColourValue::Black,
416  Real depth = 1.0f, unsigned short stencil = 0);
417  HardwareOcclusionQuery* createHardwareOcclusionQuery(void);
418  Real getHorizontalTexelOffset(void);
419  Real getVerticalTexelOffset(void);
420  Real getMinimumDepthInputValue(void);
421  Real getMaximumDepthInputValue(void);
422  void registerThread();
423  void unregisterThread();
424  void preExtraThreadsStarted();
425  void postExtraThreadsStarted();
426  void setClipPlanesImpl(const Ogre::PlaneList& planeList);
427 
428  // ----------------------------------
429  // GLESRenderSystem specific members
430  // ----------------------------------
432  GLESContext* _getMainContext() { return mMainContext; }
440  void _unregisterContext(GLESContext *context);
443  void _switchContext(GLESContext *context);
447  void _oneTimeContextInitialization();
448  void initialiseContext(RenderWindow* primary);
452  void _setRenderTarget(RenderTarget *target);
453 
454  GLint convertCompareFunction(CompareFunction func) const;
455  GLint convertStencilOp(StencilOperation op, bool invert = false) const;
456 
457  void bindGpuProgram(GpuProgram* prg);
458  void unbindGpuProgram(GpuProgramType gptype);
459  void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params, uint16 mask);
460  void bindGpuProgramPassIterationParameters(GpuProgramType gptype);
461 
463  void _setSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op );
465  void _setSeparateSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, SceneBlendFactor destFactorAlpha, SceneBlendOperation op, SceneBlendOperation alphaOp );
467  void _setAlphaRejectSettings( CompareFunction func, unsigned char value, bool alphaToCoverage );
469  unsigned int getDisplayMonitorCount() const;
470 
471  GLenum _getPolygonMode(void) { return mPolygonMode; }
472 
474  GLfloat _getCurrentAnisotropy(size_t unit);
475 
476  void _setSceneBlendingOperation(SceneBlendOperation op);
477  void _setSeparateSceneBlendingOperation(SceneBlendOperation op, SceneBlendOperation alphaOp);
478  };
479 }
480 
481 #endif
Manages the target rendering window.
A 'canvas' which can receive the results of a rendering operation.
GLenum mPolygonMode
OpenGL ES doesn't support setting the PolygonMode like desktop GL So we will cache the value and set ...
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:78
float Real
Software floating point type.
bool areFixedFunctionLightsInViewSpace() const
See RenderSystem.
unsigned int uint32
Definition: OgrePlatform.h:246
Singleton wrapper for hardware buffer manager.
GLESRTTManager * mRTTManager
Manager object for creating render textures.
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.
GLESContext * _getMainContext()
Returns the main context.
unsigned short mFixedFunctionTextureUnits
Number of fixed-function texture units.
Class representing colour.
GpuProgramType
Enumerates the types of programs which can run on the GPU.
size_t mTextureMipmapCount
Used to store the number of mipmaps in the currently bound texture.
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.
ushort mActiveTextureUnit
These variables are used for caching RenderSystem state.
bool mGLInitialised
Check if the GL system has already been initialised.
FilterType
Definition: OgreCommon.h:91
bool mDepthWrite
Store last depth write state.
GLESGpuProgramManager * mGpuProgramManager
#define _OgreGLESExport
SceneBlendFactor
Blending factors for manually blending objects with the scene.
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...
Matrix4 mViewMatrix
View matrix to set world against.
Representation of a dynamic light source in the scene.
Definition: OgreLight.h:72
vector< Plane >::type PlaneList
Definition: OgrePlane.h:160
#define OGRE_MAX_TEXTURE_LAYERS
Define max number of texture layers allowed per pass on any card.
Definition: OgreConfig.h:70
Manager/factory for RenderTextures.
ShadeOptions
Light shading modes.
Definition: OgreCommon.h:114
Class that encapsulates an GL context.
Texture addressing mode for each texture coordinate.
map< String, ConfigOption >::type ConfigOptionMap
TextureAddressingMode
Texture addressing modes - default is TAM_WRAP.
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.
GLESSupport * mGLSupport
GL support class, used for creating windows etc.
uint32 mStencilMask
Store last stencil mask state.
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...
Implementation of GL as a rendering system.
#define MAX_LIGHTS
Array of up to 8 lights, indexed as per API Note that a null value indicates a free slot...
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.
singleton class for storing the capabilities of the graphics card.
_StringBase String
unsigned short uint16
Definition: OgrePlatform.h:247
HardwareBufferManager * mHardwareBufferManager
StencilOperation
Enum describing the various actions which can be taken onthe stencil buffer.
FilterOptions
Filtering options for textures / mipmaps.
Definition: OgreCommon.h:101
Defines the functionality of a 3D API.
CompareFunction
Comparison functions used for the depth/stencil buffer operations and others.
Definition: OgreCommon.h:65
FilterOptions mMinFilter
Last min & mip filtering options, so we can combine them.
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.