Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/RenderSystems/GL/include/OgreGLRenderSystem.h @ 3

Last change on this file since 3 was 3, checked in by anonymous, 17 years ago

=update

File size: 15.3 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org
6
7Copyright (c) 2000-2006 Torus Knot Software Ltd
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23
24You may alternatively use this source under the terms of a specific version of
25the OGRE Unrestricted License provided you have obtained such a license from
26Torus Knot Software Ltd.
27-----------------------------------------------------------------------------
28*/
29#ifndef __GLRenderSystem_H__
30#define __GLRenderSystem_H__
31
32#include "OgreGLPrerequisites.h"
33#include "OgrePlatform.h"
34#include "OgreRenderSystem.h"
35#include "OgreGLHardwareBufferManager.h"
36#include "OgreGLGpuProgramManager.h"
37#include "OgreGLSLProgramFactory.h"
38#include "OgreVector4.h"
39
40
41namespace Ogre {
42    /**
43      Implementation of GL as a rendering system.
44     */
45    class _OgrePrivate GLRenderSystem : public RenderSystem
46    {
47    private:
48        // Rendering loop control
49        bool mStopRendering;
50
51        // Array of up to 8 lights, indexed as per API
52        // Note that a null value indicates a free slot
53        #define MAX_LIGHTS 8
54        Light* mLights[MAX_LIGHTS];
55
56        // clip planes
57        typedef std::vector<Vector4> PlaneList2;
58        PlaneList2 mClipPlanes;
59        void setGLClipPlanes() const;
60
61
62        // view matrix to set world against
63        Matrix4 mViewMatrix;
64        Matrix4 mWorldMatrix;
65        Matrix4 mTextureMatrix;
66
67        // Last min & mip filtering options, so we can combine them
68        FilterOptions mMinFilter;
69        FilterOptions mMipFilter;
70
71        // What texture coord set each texture unit is using
72        size_t mTextureCoordIndex[OGRE_MAX_TEXTURE_LAYERS];
73
74        /// holds texture type settings for every stage
75        GLenum mTextureTypes[OGRE_MAX_TEXTURE_LAYERS];
76
77                /// Number of fixed-function texture units
78                unsigned short mFixedFunctionTextureUnits;
79
80        void initConfigOptions(void);
81        void initInputDevices(void);
82        void processInputDevices(void);
83
84        void setGLLight(size_t index, Light* lt);
85        void makeGLMatrix(GLfloat gl_matrix[16], const Matrix4& m);
86 
87        GLint getBlendMode(SceneBlendFactor ogreBlend) const;
88                GLint getTextureAddressingMode(TextureUnitState::TextureAddressingMode tam) const;
89
90        void setLights();
91
92        // Store last depth write state
93        bool mDepthWrite;
94                // Store last stencil mask state
95                uint32 mStencilMask;
96                // Store last colour write state
97                bool mColourWrite[4];
98
99        GLint convertCompareFunction(CompareFunction func) const;
100        GLint convertStencilOp(StencilOperation op, bool invert = false) const;
101
102                // internal method for anisotrophy validation
103                GLfloat _getCurrentAnisotropy(size_t unit);
104               
105        /// GL support class, used for creating windows etc
106        GLSupport* mGLSupport;
107       
108        /// Internal method to set pos / direction of a light
109        void setGLLightPositionDirection(Light* lt, GLenum lightindex);
110
111        bool mUseAutoTextureMatrix;
112        GLfloat mAutoTextureMatrix[16];
113
114        // check if the GL system has already been initialized
115        bool mGLInitialized;
116        // Initialise GL system and capabilities
117        void initGL(RenderTarget *primary);
118
119        HardwareBufferManager* mHardwareBufferManager;
120        GLGpuProgramManager* mGpuProgramManager;
121                GLSLProgramFactory* mGLSLProgramFactory;
122
123        unsigned short mCurrentLights;
124
125        GLuint getCombinedMinMipFilter(void) const;
126
127        GLGpuProgram* mCurrentVertexProgram;
128        GLGpuProgram* mCurrentFragmentProgram;
129
130                /* The main GL context - main thread only */
131        GLContext *mMainContext;
132        /* The current GL context  - main thread only*/
133        GLContext *mCurrentContext;
134                typedef std::list<GLContext*> GLContextList;
135                /// List of background thread contexts
136                GLContextList mBackgroundContextList;
137
138        /** Manager object for creating render textures.
139            Direct render to texture via GL_EXT_framebuffer_object is preferable
140                        to pbuffers, which depend on the GL support used and are generally
141                        unwieldy and slow. However, FBO support for stencil buffers is poor.
142        */
143        GLRTTManager *mRTTManager;
144    public:
145        // Default constructor / destructor
146        GLRenderSystem();
147        ~GLRenderSystem();
148
149        // ----------------------------------
150        // Overridden RenderSystem functions
151        // ----------------------------------
152        /** See
153          RenderSystem
154         */
155        const String& getName(void) const;
156        /** See
157          RenderSystem
158         */
159        ConfigOptionMap& getConfigOptions(void);
160        /** See
161          RenderSystem
162         */
163        void setConfigOption(const String &name, const String &value);
164        /** See
165          RenderSystem
166         */
167        String validateConfigOptions(void);
168        /** See
169          RenderSystem
170         */
171        RenderWindow* initialise(bool autoCreateWindow, const String& windowTitle = "OGRE Render Window");
172        /** See
173          RenderSystem
174         */
175        void reinitialise(void); // Used if settings changed mid-rendering
176        /** See
177          RenderSystem
178         */
179        void shutdown(void);
180
181        /** See
182          RenderSystem
183         */
184        void setAmbientLight(float r, float g, float b);
185        /** See
186          RenderSystem
187         */
188        void setShadingType(ShadeOptions so);
189        /** See
190          RenderSystem
191         */
192        void setLightingEnabled(bool enabled);
193       
194                /// @copydoc RenderSystem::createRenderWindow
195                RenderWindow* createRenderWindow(const String &name, unsigned int width, unsigned int height, 
196                        bool fullScreen, const NameValuePairList *miscParams = 0);
197
198                /// @copydoc RenderSystem::createMultiRenderTarget
199                virtual MultiRenderTarget * createMultiRenderTarget(const String & name); 
200               
201        /** See
202          RenderSystem
203         */
204        void destroyRenderWindow(RenderWindow* pWin);
205        /** See
206          RenderSystem
207         */
208        String getErrorDescription(long errorNumber) const;
209
210        /** See
211          RenderSystem
212         */
213        VertexElementType getColourVertexElementType(void) const;
214        /** See
215          RenderSystem
216         */
217        void setNormaliseNormals(bool normalise);
218
219        // -----------------------------
220        // Low-level overridden members
221        // -----------------------------
222        /** See
223          RenderSystem
224         */
225        void _useLights(const LightList& lights, unsigned short limit);
226        /** See
227          RenderSystem
228         */
229        void _setWorldMatrix(const Matrix4 &m);
230        /** See
231          RenderSystem
232         */
233        void _setViewMatrix(const Matrix4 &m);
234        /** See
235          RenderSystem
236         */
237        void _setProjectionMatrix(const Matrix4 &m);
238        /** See
239          RenderSystem
240         */
241        void _setSurfaceParams(const ColourValue &ambient,
242            const ColourValue &diffuse, const ColourValue &specular,
243            const ColourValue &emissive, Real shininess,
244            TrackVertexColourType tracking);
245        /** See
246          RenderSystem
247         */
248                void _setPointParameters(Real size, bool attenuationEnabled, 
249                        Real constant, Real linear, Real quadratic, Real minSize, Real maxSize);
250        /** See
251          RenderSystem
252         */
253                void _setPointSpritesEnabled(bool enabled);
254                /** See
255          RenderSystem
256         */
257        void _setTexture(size_t unit, bool enabled, const TexturePtr &tex);
258        /** See
259          RenderSystem
260         */
261        void _setTextureCoordSet(size_t stage, size_t index);
262        /** See
263          RenderSystem
264         */
265        void _setTextureCoordCalculation(size_t stage, TexCoordCalcMethod m, 
266            const Frustum* frustum = 0);
267        /** See
268          RenderSystem
269         */
270        void _setTextureBlendMode(size_t stage, const LayerBlendModeEx& bm);
271        /** See
272          RenderSystem
273         */
274        void _setTextureAddressingMode(size_t stage, const TextureUnitState::UVWAddressingMode& uvw);
275        /** See
276          RenderSystem
277         */
278        void _setTextureBorderColour(size_t stage, const ColourValue& colour);
279                /** See
280                RenderSystem
281                */
282                void _setTextureMipmapBias(size_t unit, float bias);
283        /** See
284          RenderSystem
285         */
286        void _setTextureMatrix(size_t stage, const Matrix4& xform);
287        /** See
288          RenderSystem
289         */
290        void _setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor);
291        /** See
292          RenderSystem
293         */
294        void _setAlphaRejectSettings(CompareFunction func, unsigned char value);
295        /** See
296          RenderSystem
297         */
298        void _setViewport(Viewport *vp);
299        /** See
300          RenderSystem
301         */
302        void _beginFrame(void);
303        /** See
304          RenderSystem
305         */
306        void _endFrame(void);
307        /** See
308          RenderSystem
309         */
310        void _setCullingMode(CullingMode mode);
311        /** See
312          RenderSystem
313         */
314        void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL);
315        /** See
316          RenderSystem
317         */
318        void _setDepthBufferCheckEnabled(bool enabled = true);
319        /** See
320          RenderSystem
321         */
322        void _setDepthBufferWriteEnabled(bool enabled = true);
323        /** See
324          RenderSystem
325         */
326        void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL);
327        /** See
328          RenderSystem
329         */
330        void _setDepthBias(float constantBias, float slopeScaleBias);
331        /** See
332          RenderSystem
333         */
334        void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha);
335                /** See
336          RenderSystem
337         */
338        void _setFog(FogMode mode, const ColourValue& colour, Real density, Real start, Real end);
339        /** See
340          RenderSystem
341         */
342        void _convertProjectionMatrix(const Matrix4& matrix,
343            Matrix4& dest, bool forGpuProgram = false);
344        /** See
345          RenderSystem
346         */
347        void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane, 
348            Matrix4& dest, bool forGpuProgram = false);
349        /** See
350        RenderSystem
351        */
352        void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top, 
353            Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false);
354        /** See
355          RenderSystem
356         */
357                void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane, 
358            Matrix4& dest, bool forGpuProgram = false);
359        /** See
360        RenderSystem
361        */
362        void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane, 
363            bool forGpuProgram);
364        /** See
365        RenderSystem
366        */
367        void setClipPlane (ushort index, Real A, Real B, Real C, Real D);
368        /** See
369        RenderSystem
370        */
371        void enableClipPlane (ushort index, bool enable);
372        /** See
373          RenderSystem
374         */
375        void _setPolygonMode(PolygonMode level);
376        /** See
377          RenderSystem
378         */
379        void setStencilCheckEnabled(bool enabled);
380        /** See RenderSystem.
381         */
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);
388        /** See
389          RenderSystem
390         */
391        void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter);
392        /** See
393          RenderSystem
394         */
395                void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy);
396        /** See
397          RenderSystem
398         */
399                void setVertexDeclaration(VertexDeclaration* decl);
400        /** See
401          RenderSystem
402         */
403                void setVertexBufferBinding(VertexBufferBinding* binding);
404        /** See
405          RenderSystem
406         */
407        void _render(const RenderOperation& op);
408        /** See
409          RenderSystem
410         */
411        void bindGpuProgram(GpuProgram* prg);
412        /** See
413          RenderSystem
414         */
415        void unbindGpuProgram(GpuProgramType gptype);
416        /** See
417          RenderSystem
418         */
419        void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params);
420                /** See
421                RenderSystem
422                */
423                void bindGpuProgramPassIterationParameters(GpuProgramType gptype);
424        /** See
425          RenderSystem
426         */
427        void setClipPlanes(const PlaneList& clipPlanes);
428        /** See
429          RenderSystem
430         */
431        void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600) ;
432        void clearFrameBuffer(unsigned int buffers, 
433            const ColourValue& colour = ColourValue::Black, 
434            Real depth = 1.0f, unsigned short stencil = 0);
435        HardwareOcclusionQuery* createHardwareOcclusionQuery(void);
436        Real getHorizontalTexelOffset(void);
437        Real getVerticalTexelOffset(void);
438        Real getMinimumDepthInputValue(void);
439        Real getMaximumDepthInputValue(void);
440                void registerThread();
441                void unregisterThread();
442                void preExtraThreadsStarted();
443                void postExtraThreadsStarted();
444
445        // ----------------------------------
446        // GLRenderSystem specific members
447        // ----------------------------------
448        /** One time initialization for the RenderState of a context. Things that
449            only need to be set once, like the LightingModel can be defined here.
450         */
451        void _oneTimeContextInitialization();
452        /** Switch GL context, dealing with involved internal cached states too
453        */
454        void _switchContext(GLContext *context);
455        /**
456         * Set current render target to target, enabling its GL context if needed
457         */
458        void _setRenderTarget(RenderTarget *target);
459        /** Unregister a render target->context mapping. If the context of target
460            is the current context, change the context to the main context so it
461            can be destroyed safely.
462           
463            @note This is automatically called by the destructor of
464            GLContext.
465         */
466        void _unregisterContext(GLContext *context);
467                /** Returns the main context */
468                GLContext* _getMainContext() {return mMainContext;} 
469    };
470}
471#endif
472
Note: See TracBrowser for help on using the repository browser.