OGRE  1.8
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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-2013 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 namespace Ogre {
38  class GLESContext;
39  class GLESSupport;
40  class GLESRTTManager;
41  class GLESGpuProgramManager;
42  class HardwareBufferManager;
43 
48  {
49  private:
50  typedef HashMap<GLenum, GLint> TexEnviMap;
51  typedef HashMap<GLenum, GLfloat> TexEnvfMap;
52  typedef HashMap<GLenum, const GLfloat *> TexEnvfvMap;
53  typedef HashMap<GLenum, GLfloat> PointParamfMap;
54  typedef HashMap<GLenum, const GLfloat *> PointParamfvMap;
55  typedef HashMap<GLenum, const GLfloat *> MaterialfvMap;
56  typedef HashMap<GLenum, GLfloat> LightfMap;
57  typedef HashMap<GLenum, const GLfloat *> LightfvMap;
58 
62  #define MAX_LIGHTS 8
63  Light* mLights[MAX_LIGHTS];
64  unsigned short mCurrentLights;
65 
70 
74 
76  size_t mTextureCoordIndex[OGRE_MAX_TEXTURE_LAYERS];
77 
80 
82  bool mColourWrite[4];
83 
85  GLboolean mDepthWrite;
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 
141 
144 
146  unsigned int mDiscardBuffers;
147 
151  GLenum mPolygonMode;
152 
153  GLuint getCombinedMinMipFilter(void) const;
154 
155  GLint getTextureAddressingMode(TextureUnitState::TextureAddressingMode tam) const;
156  GLint getBlendMode(SceneBlendFactor ogreBlend) const;
157  void makeGLMatrix(GLfloat gl_matrix[16], const Matrix4& m);
158  void setGLLight(size_t index, Light* lt);
159 
161  void setGLLightPositionDirection(Light* lt, GLenum lightindex);
162  void setLights();
163 
164  bool activateGLTextureUnit(size_t unit);
165  bool activateGLClientTextureUnit(size_t unit);
166  void setGLTexEnvi(GLenum target, GLenum name, GLint param);
167  void setGLTexEnvf(GLenum target, GLenum name, GLfloat param);
168  void setGLTexEnvfv(GLenum target, GLenum name, const GLfloat *param);
169  void setGLPointParamf(GLenum name, GLfloat param);
170  void setGLPointParamfv(GLenum name, const GLfloat *param);
171  void setGLMaterialfv(GLenum face, GLenum name, const GLfloat *param);
172  void setGLMatrixMode(GLenum mode);
173  void setGLDepthMask(GLboolean flag);
174  void setGLClearDepthf(GLclampf depth);
175  void setGLColorMask(bool red, bool green, bool blue, bool alpha);
176  void setGLLightf(GLenum light, GLenum name, GLfloat param);
177  void setGLLightfv(GLenum light, GLenum name, const GLfloat *param);
178 
179  public:
180  // Default constructor / destructor
182  virtual ~GLESRenderSystem();
183 
184  // ----------------------------------
185  // Overridden RenderSystem functions
186  // ----------------------------------
190  const String& getName(void) const;
194  ConfigOptionMap& getConfigOptions(void);
198  void setConfigOption(const String &name, const String &value);
202  String validateConfigOptions(void);
206  RenderWindow* _initialise(bool autoCreateWindow, const String& windowTitle = "OGRE Render NativeWindowType");
210  virtual RenderSystemCapabilities* createRenderSystemCapabilities() const;
214  void initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps, RenderTarget* primary);
218  void reinitialise(void); // Used if settings changed mid-rendering
222  void shutdown(void);
226  void setAmbientLight(float r, float g, float b);
230  void setShadingType(ShadeOptions so);
234  void setLightingEnabled(bool enabled);
235 
237  RenderWindow* _createRenderWindow(const String &name, unsigned int width, unsigned int height,
238  bool fullScreen, const NameValuePairList *miscParams = 0);
239 
241  DepthBuffer* _createDepthBufferFor( RenderTarget *renderTarget );
242 
244  void _getDepthStencilFormatFor( GLenum internalColourFormat, GLenum *depthFormat,
245  GLenum *stencilFormat );
246 
248  virtual MultiRenderTarget * createMultiRenderTarget(const String & name);
249 
253  void destroyRenderWindow(RenderWindow* pWin);
257  String getErrorDescription(long errorNumber) const;
261  VertexElementType getColourVertexElementType(void) const;
265  void setNormaliseNormals(bool normalise);
266 
267  // -----------------------------
268  // Low-level overridden members
269  // -----------------------------
273  void _useLights(const LightList& lights, unsigned short limit);
277  bool areFixedFunctionLightsInViewSpace() const { return true; }
281  void _setWorldMatrix(const Matrix4 &m);
285  void _setViewMatrix(const Matrix4 &m);
289  void _setProjectionMatrix(const Matrix4 &m);
293  void _setSurfaceParams(const ColourValue &ambient,
294  const ColourValue &diffuse, const ColourValue &specular,
295  const ColourValue &emissive, Real shininess,
296  TrackVertexColourType tracking);
300  void _setPointParameters(Real size, bool attenuationEnabled,
301  Real constant, Real linear, Real quadratic, Real minSize, Real maxSize);
305  void _setPointSpritesEnabled(bool enabled);
309  void _setTexture(size_t unit, bool enabled, const TexturePtr &tex);
313  void _setTextureCoordSet(size_t stage, size_t index);
317  void _setTextureCoordCalculation(size_t stage, TexCoordCalcMethod m,
318  const Frustum* frustum = 0);
322  void _setTextureBlendMode(size_t stage, const LayerBlendModeEx& bm);
326  void _setTextureAddressingMode(size_t stage, const TextureUnitState::UVWAddressingMode& uvw);
330  void _setTextureBorderColour(size_t stage, const ColourValue& colour);
334  void _setTextureMipmapBias(size_t unit, float bias);
338  void _setTextureMatrix(size_t stage, const Matrix4& xform);
342  void _setViewport(Viewport *vp);
346  void _beginFrame(void);
350  void _endFrame(void);
354  void _setCullingMode(CullingMode mode);
358  void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL);
362  void _setDepthBufferCheckEnabled(bool enabled = true);
366  void _setDepthBufferWriteEnabled(bool enabled = true);
370  void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL);
374  void _setDepthBias(float constantBias, float slopeScaleBias);
378  void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha);
382  void _setFog(FogMode mode, const ColourValue& colour, Real density, Real start, Real end);
386  void _convertProjectionMatrix(const Matrix4& matrix,
387  Matrix4& dest, bool forGpuProgram = false);
391  void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
392  Matrix4& dest, bool forGpuProgram = false);
396  void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top,
397  Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false);
401  void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
402  Matrix4& dest, bool forGpuProgram = false);
406  void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane,
407  bool forGpuProgram);
411  void setClipPlane (ushort index, Real A, Real B, Real C, Real D);
415  void enableClipPlane (ushort index, bool enable);
419  void _setPolygonMode(PolygonMode level);
423  void setStencilCheckEnabled(bool enabled);
427  void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS,
428  uint32 refValue = 0, uint32 mask = 0xFFFFFFFF,
429  StencilOperation stencilFailOp = SOP_KEEP,
430  StencilOperation depthFailOp = SOP_KEEP,
431  StencilOperation passOp = SOP_KEEP,
432  bool twoSidedOperation = false);
436  void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter);
440  void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy);
444  void setVertexDeclaration(VertexDeclaration* decl);
448  void setVertexBufferBinding(VertexBufferBinding* binding);
452  void _render(const RenderOperation& op);
456  void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600);
457 
458  void _setDiscardBuffers(unsigned int flags) { mDiscardBuffers = flags; }
459  unsigned int getDiscardBuffers(void) { return mDiscardBuffers; }
460 
461  void clearFrameBuffer(unsigned int buffers,
462  const ColourValue& colour = ColourValue::Black,
463  Real depth = 1.0f, unsigned short stencil = 0);
464  HardwareOcclusionQuery* createHardwareOcclusionQuery(void);
465  Real getHorizontalTexelOffset(void);
466  Real getVerticalTexelOffset(void);
467  Real getMinimumDepthInputValue(void);
468  Real getMaximumDepthInputValue(void);
469  void registerThread();
470  void unregisterThread();
471  void preExtraThreadsStarted();
472  void postExtraThreadsStarted();
473  void setClipPlanesImpl(const Ogre::PlaneList& planeList);
474 
475  // ----------------------------------
476  // GLESRenderSystem specific members
477  // ----------------------------------
479  GLESContext* _getMainContext() { return mMainContext; }
487  void _unregisterContext(GLESContext *context);
490  void _switchContext(GLESContext *context);
494  void _oneTimeContextInitialization();
495  void initialiseContext(RenderWindow* primary);
499  void _setRenderTarget(RenderTarget *target);
500 
501  GLint convertCompareFunction(CompareFunction func) const;
502  GLint convertStencilOp(StencilOperation op, bool invert = false) const;
503 
504  void bindGpuProgram(GpuProgram* prg);
505  void unbindGpuProgram(GpuProgramType gptype);
506  void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params, uint16 mask);
507  void bindGpuProgramPassIterationParameters(GpuProgramType gptype);
508 
510  void _setSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op );
512  void _setSeparateSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, SceneBlendFactor destFactorAlpha, SceneBlendOperation op, SceneBlendOperation alphaOp );
514  void _setAlphaRejectSettings( CompareFunction func, unsigned char value, bool alphaToCoverage );
516  unsigned int getDisplayMonitorCount() const;
517 
518  GLenum _getPolygonMode(void) { return mPolygonMode; }
519 
521  GLfloat _getCurrentAnisotropy(size_t unit);
522 
523  void _setSceneBlendingOperation(SceneBlendOperation op);
524  void _setSeparateSceneBlendingOperation(SceneBlendOperation op, SceneBlendOperation alphaOp);
525 
527  virtual void beginProfileEvent( const String &eventName ) {}
528 
530  virtual void endProfileEvent( void ) {}
531 
533  virtual void markProfileEvent( const String &eventName ) {}
534  };
535 }
536 
537 #endif
virtual void markProfileEvent(const String &eventName)
Marks an instantaneous event for graphics profilers.
Manages the target rendering window.
A 'canvas' which can receive the results of a rendering operation.
virtual void beginProfileEvent(const String &eventName)
This marks the beginning of an event for GPU profiling.
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
HashMap< GLenum, const GLfloat * > MaterialfvMap
float Real
Software floating point type.
bool areFixedFunctionLightsInViewSpace() const
See RenderSystem.
HashMap< GLenum, GLint > TexEnviMap
unsigned int uint32
Definition: OgrePlatform.h:270
Singleton wrapper for hardware buffer manager.
GLESRTTManager * mRTTManager
Manager object for creating render textures.
PointParamfMap mActivePointParamfMap
Records the state of all the vertex buffer bindings required to provide a vertex declaration with the...
unsigned int getDiscardBuffers(void)
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.
GLESContext * _getMainContext()
Returns the main context.
HashMap< GLenum, const GLfloat * > PointParamfvMap
GLboolean mDepthWrite
Store last depth write state.
unsigned short mFixedFunctionTextureUnits
Number of fixed-function texture units.
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.
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:93
GLESGpuProgramManager * mGpuProgramManager
#define _OgreGLESExport
SceneBlendFactor
Blending factors for manually blending objects with the scene.
HashMap< GLenum, GLfloat > PointParamfMap
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...
Matrix4 mViewMatrix
View matrix to set world against.
Representation of a dynamic light source in the scene.
Definition: OgreLight.h:73
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.
An abstract class that contains a depth/stencil buffer.
ShadeOptions
Light shading modes.
Definition: OgreCommon.h:116
Class that encapsulates an GL context.
void _setDiscardBuffers(unsigned int flags)
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:443
unsigned int mDiscardBuffers
Mask of buffers who contents can be discarded if GL_EXT_discard_framebuffer is supported.
VertexElementType
Vertex element type, used to identify the base types of the vertex contents.
PointParamfvMap mActivePointParamfvMap
HashMap< GLenum, const GLfloat * > LightfvMap
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:182
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
virtual void endProfileEvent(void)
Ends the currently active GPU profiling event.
unsigned short uint16
Definition: OgrePlatform.h:271
HardwareBufferManager * mHardwareBufferManager
StencilOperation
Enum describing the various actions which can be taken onthe stencil buffer.
FilterOptions
Filtering options for textures / mipmaps.
Definition: OgreCommon.h:103
Defines the functionality of a 3D API.
CompareFunction
Comparison functions used for the depth/stencil buffer operations and others.
Definition: OgreCommon.h:67
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:279
Class which manages blending of both colour and alpha components.
HashMap< GLenum, GLfloat > TexEnvfMap
HashMap< GLenum, const GLfloat * > TexEnvfvMap
HashMap< GLenum, GLfloat > LightfMap