From 0ea5fc66924303d1bf73ba283a383e2aadee02f2 Mon Sep 17 00:00:00 2001 From: neodarz Date: Sat, 11 Aug 2018 20:21:34 +0200 Subject: Initial commit --- docs/doxygen/nel/driver__opengl_8h-source.html | 992 +++++++++++++++++++++++++ 1 file changed, 992 insertions(+) create mode 100644 docs/doxygen/nel/driver__opengl_8h-source.html (limited to 'docs/doxygen/nel/driver__opengl_8h-source.html') diff --git a/docs/doxygen/nel/driver__opengl_8h-source.html b/docs/doxygen/nel/driver__opengl_8h-source.html new file mode 100644 index 00000000..4c5c3ec5 --- /dev/null +++ b/docs/doxygen/nel/driver__opengl_8h-source.html @@ -0,0 +1,992 @@ + + + + nevrax.org : docs + + + + + + + + + + + + + + +
# Home   # nevrax.com   
+ + + + +
Nevrax
+ + + + + + + + + + +
+ + +
+ Nevrax.org
+ + + + + + + +
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
+
+ + +
+ + +
+Docs + +
+  + + + + + +
Documentation 
+ +
+Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  
+

driver_opengl.h

Go to the documentation of this file.
00001 
+00007 /* Copyright, 2000 Nevrax Ltd.
+00008  *
+00009  * This file is part of NEVRAX NEL.
+00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
+00011  * it under the terms of the GNU General Public License as published by
+00012  * the Free Software Foundation; either version 2, or (at your option)
+00013  * any later version.
+00014 
+00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
+00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
+00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+00018  * General Public License for more details.
+00019 
+00020  * You should have received a copy of the GNU General Public License
+00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
+00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+00023  * MA 02111-1307, USA.
+00024  */
+00025 
+00026 #ifndef NL_OPENGL_H
+00027 #define NL_OPENGL_H
+00028 
+00029 
+00030 #include "nel/misc/types_nl.h"
+00031 
+00032 #ifdef NL_OS_WINDOWS
+00033 
+00034 #define WIN32_LEAN_AND_MEAN
+00035 #include <windows.h>
+00036 #  ifdef min
+00037 #    undef min
+00038 #  endif
+00039 #  ifdef max
+00040 #    undef max
+00041 #  endif
+00042 
+00043 #else // NL_OS_UNIX
+00044 
+00045 #define GLX_GLXEXT_PROTOTYPES
+00046 
+00047 #include <GL/glx.h>
+00048 
+00049 #ifdef XF86VIDMODE
+00050 #include <X11/extensions/xf86vmode.h>
+00051 #endif //XF86VIDMODE
+00052 
+00053 #endif // NL_OS_UNIX
+00054 
+00055 #include <GL/gl.h>
+00056 #include "driver_opengl_extension.h"
+00057 
+00058 #include "3d/driver.h"
+00059 #include "3d/material.h"
+00060 #include "3d/shader.h"
+00061 #include "3d/vertex_buffer.h"
+00062 #include "nel/misc/matrix.h"
+00063 #include "nel/misc/smart_ptr.h"
+00064 #include "nel/misc/rgba.h"
+00065 #include "nel/misc/event_emitter.h"
+00066 #include "nel/misc/bit_set.h"
+00067 #include "3d/ptr_set.h"
+00068 #include "nel/misc/heap_memory.h"
+00069 #include "nel/misc/event_emitter_multi.h"
+00070 #include "driver_opengl_states.h"
+00071 #include "3d/texture_cube.h"
+00072 #include "3d/vertex_program_parse.h"
+00073 
+00074 
+00075 #ifdef NL_OS_WINDOWS
+00076 #include "nel/misc/win_event_emitter.h"
+00077 #elif defined (NL_OS_UNIX)
+00078 #include "unix_event_emitter.h"
+00079 #endif // NL_OS_UNIX
+00080 
+00081 
+00082 // For optimisation consideration, allow 256 lightmaps at max.
+00083 #define NL3D_DRV_MAX_LIGHTMAP           256
+00084 
+00085 
+00086 namespace NL3D {
+00087 
+00088 using NLMISC::CMatrix;
+00089 using NLMISC::CVector;
+00090 
+00091 
+00092 class   CDriverGL;
+00093 class   IVertexArrayRange;
+00094 class   IVertexBufferHardGL;
+00095 
+00096 
+00097 // ***************************************************************************
+00098 class CTextureDrvInfosGL : public ITextureDrvInfos
+00099 {
+00100 public:
+00101         /*
+00102                 ANY DATA ADDED HERE MUST BE SWAPPED IN swapTextureHandle() !!
+00103         */
+00104 
+00105         // The GL Id.
+00106         GLuint                                  ID;
+00107         // Is the internal format of the texture is a compressed one?
+00108         bool                                    Compressed;
+00109 
+00110         // This is the computed size of what memory this texture take.
+00111         uint32                                  TextureMemory;
+00112         // This is the owner driver.
+00113         CDriverGL                               *_Driver;
+00114 
+00115 
+00116         // The current wrap modes assigned to the texture.
+00117         ITexture::TWrapMode             WrapS;
+00118         ITexture::TWrapMode             WrapT;
+00119         ITexture::TMagFilter    MagFilter;
+00120         ITexture::TMinFilter    MinFilter;
+00121 
+00122         // The gl id is auto created here.
+00123         CTextureDrvInfosGL(IDriver *drv, ItTexDrvInfoPtrMap it, CDriverGL *drvGl);
+00124         // The gl id is auto deleted here.
+00125         ~CTextureDrvInfosGL();
+00126 };
+00127 
+00128 
+00129 // ***************************************************************************
+00130 class CVBDrvInfosGL : public IVBDrvInfos
+00131 {
+00132 public:
+00133         CVBDrvInfosGL(IDriver *drv, ItVBDrvInfoPtrList it) : IVBDrvInfos(drv, it) {}
+00134 };
+00135 
+00136 
+00137 // ***************************************************************************
+00138 class CShaderGL : public IShader
+00139 {
+00140 public:
+00141         GLenum          SrcBlend;
+00142         GLenum          DstBlend;
+00143         GLenum          ZComp;
+00144 
+00145         GLfloat         Emissive[4];
+00146         GLfloat         Ambient[4];
+00147         GLfloat         Diffuse[4];
+00148         GLfloat         Specular[4];
+00149         // For fast comp.
+00150         uint32          PackedEmissive;
+00151         uint32          PackedAmbient;
+00152         uint32          PackedDiffuse;
+00153         uint32          PackedSpecular;
+00154 
+00155         // The supported Shader type.
+00156         CMaterial::TShader      SupportedShader;
+00157 
+00158         CShaderGL(IDriver *drv, ItShaderPtrList it) : IShader(drv, it) {}
+00159 };
+00160 
+00161 
+00162 // ***************************************************************************
+00164 class   CVertexBufferInfo
+00165 {
+00166 public:
+00167         uint16                                  VertexFormat;
+00168         uint16                                  VertexSize;
+00169         uint32                                  NumVertices;
+00170         uint32                                  NumWeight;      
+00171         CVertexBuffer::TType    Type[CVertexBuffer::NumValue];
+00172 
+00173         // NB: ptrs are invalid if VertexFormat does not support the compoennt. must test VertexFormat, not the ptr.
+00174         void                                    *ValuePtr[CVertexBuffer::NumValue];
+00175 
+00176 
+00177         // ATI Special setup ?
+00178         bool                                    ATIVBHardMode;
+00179         // the handle of ATI memory
+00180         uint                                    ATIVertexObjectId;
+00181         // This is the offset relative to the ATIVertexObjectId start mem.
+00182         uint                                    ATIValueOffset[CVertexBuffer::NumValue];
+00183 
+00184 
+00185         void            setupVertexBuffer(CVertexBuffer &vb);
+00186         void            setupVertexBufferHard(IVertexBufferHardGL &vb);
+00187 };
+00188 
+00189 
+00190 
+00191 // ***************************************************************************
+00192 class CDriverGL : public IDriver
+00193 {
+00194 public:
+00195 
+00196         // Some constants
+00197         enum { MaxLight=8 };
+00198 
+00199         // Acces
+00200         uint32                                  getHwnd ()
+00201         {
+00202 #ifdef NL_OS_WINDOWS
+00203                 return (uint32)_hWnd;
+00204 #else // NL_OS_WINDOWS
+00205                 return 0;
+00206 #endif // NL_OS_WINDOWS
+00207         }
+00208 
+00209                                                         CDriverGL();
+00210         virtual                                 ~CDriverGL();
+00211 
+00212         virtual bool                    init();
+00213 
+00214         virtual ModeList                enumModes();
+00215 
+00216         virtual void                    disableHardwareVertexProgram();
+00217         virtual void                    disableHardwareVertexArrayAGP();
+00218         virtual void                    disableHardwareTextureShader();
+00219 
+00220         virtual bool                    setDisplay(void* wnd, const GfxMode& mode) throw(EBadDisplay);
+00221 
+00222         virtual void*                   getDisplay()
+00223         {
+00224 #ifdef NL_OS_WINDOWS
+00225                 return (void*)_hWnd;
+00226 #else // NL_OS_WINDOWS
+00227                 return NULL;
+00228 #endif // NL_OS_WINDOWS
+00229         }
+00230 
+00231         virtual emptyProc               getWindowProc();
+00232 
+00233         virtual bool                    activate();
+00234 
+00235         virtual sint                    getNbTextureStages() const;
+00236 
+00237         virtual bool                    isTextureExist(const ITexture&tex);
+00238 
+00239         virtual NLMISC::IEventEmitter   *getEventEmitter() { return&_EventEmitter; };
+00240 
+00241         virtual bool                    clear2D(CRGBA rgba);
+00242 
+00243         virtual bool                    clearZBuffer(float zval=1);
+00244         virtual void                    setColorMask (bool bRed, bool bGreen, bool bBlue, bool bAlpha);
+00245 
+00246         virtual bool                    setupTexture (ITexture& tex);
+00247 
+00248         virtual bool                    setupTextureEx (ITexture& tex, bool bUpload, bool &bAllUploaded, bool bMustRecreateSharedTexture= false);
+00249         virtual bool                    uploadTexture (ITexture& tex, NLMISC::CRect& rect, uint8 nNumMipMap);
+00250         virtual bool                    uploadTextureCube (ITexture& tex, NLMISC::CRect& rect, uint8 nNumMipMap, uint8 nNumFace);
+00251 
+00252         virtual void                    forceDXTCCompression(bool dxtcComp);
+00253 
+00254         virtual void                    forceTextureResize(uint divisor);
+00255 
+00257         void                            setTextureEnvFunction(uint stage, CMaterial& mat);
+00258 
+00260         void      setupUserTextureMatrix(uint numStages, CMaterial& mat);
+00261 
+00263         void      disableUserTextureMatrix();
+00264 
+00266         /*static inline void            setupCausticsFirstTex(const CMaterial &mat);
+00267 
+00269         static inline void              setupCausticsSecondTex(uint stage);*/
+00270 
+00271         virtual bool                    setupMaterial(CMaterial& mat);
+00272 
+00273         virtual void                    setFrustum(float left, float right, float bottom, float top, float znear, float zfar, bool perspective = true);
+00274 
+00275         virtual void                    setupViewMatrix(const CMatrix& mtx);
+00276 
+00277         virtual void                    setupViewMatrixEx(const CMatrix& mtx, const CVector &cameraPos);
+00278 
+00279         virtual void                    setupModelMatrix(const CMatrix& mtx);
+00280 
+00281         virtual void                    multiplyModelMatrix(const CMatrix& mtx);
+00282 
+00283         virtual CMatrix                 getViewMatrix() const;
+00284 
+00285         virtual void                    forceNormalize(bool normalize)
+00286         {
+00287                 _ForceNormalize= normalize;
+00288                 // if ForceNormalize, must enable GLNormalize now.
+00289                 if(normalize)
+00290                         enableGlNormalize(true);
+00291         }
+00292 
+00293         virtual bool                    isForceNormalize() const
+00294         {
+00295                 return _ForceNormalize;
+00296         }
+00297 
+00298 
+00299         virtual bool                    supportVertexBufferHard() const;
+00300 
+00301         virtual bool                    slowUnlockVertexBufferHard() const;
+00302 
+00303         virtual uint                    getMaxVerticesByVertexBufferHard() const;
+00304 
+00305         virtual bool                    initVertexArrayRange(uint agpMem, uint vramMem);
+00306 
+00307         virtual IVertexBufferHard       *createVertexBufferHard(uint16 vertexFormat, const uint8 *typeArray, uint32 numVertices, 
+00308                                                                                                                 IDriver::TVBHardType vbType);
+00309 
+00310         virtual void                    deleteVertexBufferHard(IVertexBufferHard *VB);
+00311 
+00312         virtual void                    activeVertexBufferHard(IVertexBufferHard *VB);
+00313 
+00314 
+00315         virtual bool                    activeVertexBuffer(CVertexBuffer& VB);
+00316 
+00317         virtual bool                    activeVertexBuffer(CVertexBuffer& VB, uint first, uint end);
+00318 
+00319         virtual void                    mapTextureStageToUV(uint stage, uint uv);
+00320 
+00321         virtual bool                    render(CPrimitiveBlock& PB, CMaterial& Mat);
+00322 
+00323         virtual void                    renderTriangles(CMaterial& Mat, uint32 *tri, uint32 ntris);
+00324 
+00325         virtual void                    renderSimpleTriangles(uint32 *tri, uint32 ntris);
+00326 
+00327         virtual void                    renderPoints(CMaterial& Mat, uint32 numPoints) ;
+00328         
+00329         virtual void                    renderQuads(CMaterial& Mat, uint32 startIndex, uint32 numQuads) ;
+00330 
+00331         virtual bool                    swapBuffers();
+00332 
+00333         virtual void                    profileRenderedPrimitives(CPrimitiveProfile &pIn, CPrimitiveProfile &pOut);
+00334 
+00335         virtual uint32                  profileAllocatedTextureMemory();
+00336 
+00337         virtual uint32                  profileSetupedMaterials() const;
+00338 
+00339         virtual uint32                  profileSetupedModelMatrix() const;
+00340 
+00341         void                                    enableUsedTextureMemorySum (bool enable);
+00342         
+00343         uint32                                  getUsedTextureMemory() const;
+00344 
+00345         virtual bool                    release();
+00346 
+00347         virtual TMessageBoxId   systemMessageBox (const char* message, const char* title, TMessageBoxType type=okType, TMessageBoxIcon icon=noIcon);
+00348 
+00349         virtual void                    setupScissor (const class CScissor& scissor);
+00350 
+00351         virtual void                    setupViewport (const class CViewport& viewport);
+00352 
+00353         virtual uint32                  getImplementationVersion () const
+00354         {
+00355                 return ReleaseVersion;
+00356         }
+00357 
+00358         virtual const char*             getDriverInformation ()
+00359         {
+00360                 return "Opengl 1.2 NeL Driver";
+00361         }
+00362 
+00363         virtual const char*             getVideocardInformation ();
+00364 
+00365         virtual bool                    isActive ();
+00366 
+00367         virtual uint8                   getBitPerPixel ();
+00368 
+00369         virtual void                    showCursor (bool b);
+00370 
+00371         // between 0.0 and 1.0
+00372         virtual void                    setMousePos(float x, float y);
+00373 
+00374         virtual void                    setCapture (bool b);
+00375 
+00376         virtual NLMISC::IMouseDevice                    *enableLowLevelMouse(bool enable);
+00377                 
+00378         virtual NLMISC::IKeyboardDevice                 *enableLowLevelKeyboard(bool enable);
+00379 
+00380         virtual NLMISC::IInputDeviceManager             *getLowLevelInputDeviceManager();
+00381 
+00382         virtual void                    getWindowSize (uint32 &width, uint32 &height);
+00383 
+00384         virtual void                    getBuffer (CBitmap &bitmap);
+00385 
+00386         virtual void                    getZBuffer (std::vector<float>  &zbuffer);
+00387 
+00388         virtual void                    getBufferPart (CBitmap &bitmap, NLMISC::CRect &rect);
+00389 
+00390         virtual void                    getZBufferPart (std::vector<float>  &zbuffer, NLMISC::CRect &rect);
+00391                 
+00392         virtual void                    copyFrameBufferToTexture(ITexture *tex,
+00393                                                              uint32 level,
+00394                                                                                                          uint32 offsetx,
+00395                                                                                                          uint32 offsety,
+00396                                                                                                          uint32 x,
+00397                                                                                                          uint32 y,
+00398                                                                                                          uint32 width,
+00399                                                                                                          uint32 height                                                                                                          
+00400                                                                                                         );
+00401 
+00402         virtual bool                    fillBuffer (CBitmap &bitmap);
+00403 
+00404         virtual void                    setPolygonMode (TPolygonMode mode);
+00405 
+00406         virtual uint                    getMaxLight () const;
+00407 
+00408         virtual void                    setLight (uint8 num, const CLight& light);
+00409 
+00410         virtual void                    enableLight (uint8 num, bool enable=true);
+00411 
+00412         virtual void                    setPerPixelLightingLight(CRGBA diffuse, CRGBA specular, float shininess);
+00413 
+00414         virtual void                    setAmbientColor (CRGBA color);
+00415 
+00417         // @{
+00418         virtual bool                    fogEnabled();
+00419         virtual void                    enableFog(bool enable);
+00421         virtual void                    setupFog(float start, float end, CRGBA color);
+00422         // @}
+00423 
+00425         // @{
+00426         virtual bool supportTextureShaders() const;
+00427 
+00428         virtual bool isTextureAddrModeSupported(CMaterial::TTexAddressingMode mode) const;
+00429 
+00430         virtual void setMatrix2DForTextureOffsetAddrMode(const uint stage, const float mat[4]);
+00431         // @}
+00432 
+00434         // @{
+00435                 virtual bool supportEMBM() const;               
+00436                 virtual bool isEMBMSupportedAtStage(uint stage) const;
+00437                 virtual void setEMBMMatrix(const uint stage, const float mat[4]);
+00438         // @}
+00439 
+00440         virtual bool supportPerPixelLighting(bool specular) const;
+00441 
+00442 
+00444         // @{
+00445         virtual bool                    supportBlendConstantColor() const;
+00446         virtual void                    setBlendConstantColor(NLMISC::CRGBA col);
+00447         virtual NLMISC::CRGBA   getBlendConstantColor() const;
+00448         virtual bool                    setMonitorColorProperties (const CMonitorColorProperties &properties);
+00449         // @}
+00450 
+00451 
+00452         virtual void                    swapTextureHandle(ITexture &tex0, ITexture &tex1);
+00453 
+00454 
+00455 private:
+00456         friend class                                    CTextureDrvInfosGL;
+00457         friend class                                    CVertexProgamDrvInfosGL;
+00458 
+00459 
+00460 private:
+00461         // Version of the driver. Not the interface version!! Increment when implementation of the driver change.
+00462         static const uint32             ReleaseVersion;
+00463 
+00464         bool                                    _FullScreen;
+00465         bool                                            _OffScreen;
+00466 
+00467 #ifdef NL_OS_WINDOWS
+00468 
+00469         friend static void GlWndProc(CDriverGL *driver, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
+00470         
+00471         HWND                                            _hWnd;
+00472         sint32                                          _WindowWidth, _WindowHeight;
+00473         HDC                                                     _hDC;
+00474         PIXELFORMATDESCRIPTOR           _pfd;
+00475     HGLRC                                               _hRC;
+00476         static uint                                     _Registered;
+00477         DEVMODE                                         _OldScreenMode;
+00478         NLMISC::CEventEmitterMulti      _EventEmitter; // this can contains a win emitter and eventually a direct input emitter 
+00479         bool                                            _DestroyWindow;
+00480 
+00481         // Off-screen rendering in Dib section
+00482         HPBUFFERARB                                     _PBuffer;
+00483 
+00484 #elif defined (NL_OS_UNIX)
+00485 
+00486         Display                                         *dpy;
+00487         GLXContext                                      ctx;
+00488         Window                                          win;
+00489         Cursor                                          cursor;
+00490         NLMISC::CUnixEventEmitter       _EventEmitter;
+00491 
+00492 #ifdef XF86VIDMODE
+00493         int                                             _OldDotClock;   // old dotclock
+00494         XF86VidModeModeLine             _OldScreenMode; // old modeline
+00495         int                                             _OldX, _OldY;   //Viewport settings
+00496 #endif //XF86VIDMODE
+00497 
+00498 #endif // NL_OS_UNIX
+00499 
+00500         bool                                    _Initialized;
+00501 
+00503         // @{
+00504         // OpenGL extensions Extensions.
+00505         CGlExtensions                   _Extensions;
+00506         // @}
+00507 
+00508 
+00509         // Depth of the driver in Bit Per Pixel
+00510         uint8                                   _Depth;
+00511 
+00512         // The forceNormalize() state.
+00513         bool                                    _ForceNormalize;
+00514 
+00515         // To know if light setup has been changed from last render() ( any call to setupViewMatrix() or setLight() ).
+00516         bool                                    _LightSetupDirty;
+00517 
+00518         // To know if the modelview matrix setup has been changed from last render() (any call to setupViewMatrix() / setupModelMatrix() ).
+00519         bool                                    _ModelViewMatrixDirty;
+00520 
+00521         // To know if the projection matrix has been changed
+00522         bool                                    _ProjMatDirty;
+00523 
+00524         // Mirror the gl projection matrix when _ProjMatDirty = false 
+00525         NLMISC::CMatrix                 _GLProjMat;
+00526 
+00527         // Ored of _LightSetupDirty and _ModelViewMatrixDirty
+00528         bool                                    _RenderSetupDirty;
+00529 
+00530         // Backup znear and zfar
+00531         float                                   _OODeltaZ;
+00532 
+00533         // Current View matrix, in NEL basis. This is the parameter passed in setupViewMatrix*().
+00534         CMatrix                                 _UserViewMtx;
+00535         // Current (OpenGL basis) View matrix.
+00536         // NB: if setuped with setupViewMatrixEx(), _ViewMtx.Pos()==(0,0,0)
+00537         CMatrix                                 _ViewMtx;
+00538         // Matrix used for specular
+00539         CMatrix                                 _TexMtx;
+00540         // Precision ZBuffer: The Current cameraPosition, to remove from each model Position.
+00541         CVector                                 _PZBCameraPos;
+00542 
+00543 
+00544         // Current computed (OpenGL basis) ModelView matrix.
+00545         // NB: This matrix have already substracted the _PZBCameraPos
+00546         // Hence this matrix represent the Exact eye-space basis (only _ViewMtx is a bit tricky).
+00547         CMatrix                                 _ModelViewMatrix;
+00548 
+00549         // Fog.
+00550         bool                                    _FogEnabled;
+00551         GLfloat                                 _CurrentFogColor[4];
+00552 
+00553 
+00554         // Num lights return by GL_MAX_LIGHTS
+00555         uint                                            _MaxDriverLight;
+00556         bool                                            _LightEnable[MaxLight];                         // Light enable.
+00557         uint                                            _LightMode[MaxLight];                           // Light mode.
+00558         CVector                                         _WorldLightPos[MaxLight];                       // World position of the lights.
+00559         CVector                                         _WorldLightDirection[MaxLight];         // World direction of the lights.
+00560 
+00561         //\name description of the per pixel light
+00562         // @{
+00563                 void checkForPerPixelLightingSupport();
+00564                 bool                                            _SupportPerPixelShader;
+00565                 bool                                            _SupportPerPixelShaderNoSpec;
+00566                 float                                           _PPLExponent;
+00567                 NLMISC::CRGBA                           _PPLightDiffuseColor;
+00568                 NLMISC::CRGBA                           _PPLightSpecularColor;
+00569         // @}
+00570 
+00571         
+00572 
+00574         // @{
+00575 
+00576         // Special Texture environnements.
+00577         enum    CTexEnvSpecial {
+00578                 TexEnvSpecialDisabled= 0, 
+00579                 TexEnvSpecialLightMap, 
+00580                 TexEnvSpecialSpecularStage0,
+00581                 TexEnvSpecialSpecularStage1,
+00582                 TexEnvSpecialSpecularStage1NoText,
+00583                 TexEnvSpecialPPLStage0,
+00584                 TexEnvSpecialPPLStage2,
+00585                 TexEnvSpecialCloudStage0,
+00586                 TexEnvSpecialCloudStage1,
+00587         };
+00588 
+00589         // NB: CRefPtr are not used for mem/spped optimisation. setupMaterial() and setupTexture() reset those states.
+00590         CMaterial*                              _CurrentMaterial;
+00591         CMaterial::TShader              _CurrentMaterialSupportedShader;
+00592         ITexture*                               _CurrentTexture[IDRV_MAT_MAXTEXTURES];
+00593         CTextureDrvInfosGL*             _CurrentTextureInfoGL[IDRV_MAT_MAXTEXTURES];
+00594         CMaterial::CTexEnv              _CurrentTexEnv[IDRV_MAT_MAXTEXTURES];
+00595         // Special Texture Environnement.
+00596         CTexEnvSpecial                  _CurrentTexEnvSpecial[IDRV_MAT_MAXTEXTURES];
+00597         // Texture addressing mode
+00598         GLenum                                  _CurrentTexAddrMode[IDRV_MAT_MAXTEXTURES];
+00599         // Reset texture shaders to their initial state if they are used
+00600         void                                    resetTextureShaders();
+00601         // activation of texture shaders
+00602         bool                                    _NVTextureShaderEnabled;
+00603         // Which stages support EMBM
+00604         bool                                    _StageSupportEMBM[IDRV_MAT_MAXTEXTURES];
+00605 
+00606         // Prec settings for material.
+00607         CDriverGLStates                 _DriverGLStates;
+00608         // Optim: To not test change in Materials states if just texture has changed. Very usefull for landscape.
+00609         uint32                                  _MaterialAllTextureTouchedFlag;
+00610 
+00611         // @}
+00612 
+00613         bool                                    _CurrentGlNormalize;
+00614 
+00615 private:        
+00616         // Get the proj matrix setupped in GL
+00617         void                                    refreshProjMatrixFromGL();
+00618 
+00619         bool                                    setupVertexBuffer(CVertexBuffer& VB);
+00620         // Activate Texture Environnement. Do it with caching.
+00621         bool                                    activateTexture(uint stage, ITexture *tex);
+00622         // NB: this test _CurrentTexEnv[] and _CurrentTexEnvSpecial[].
+00623         void                                    activateTexEnvMode(uint stage, const CMaterial::CTexEnv  &env);
+00624         void                                    activateTexEnvColor(uint stage, const CMaterial::CTexEnv  &env);
+00625         // Force Activate Texture Environnement. no caching here. TexEnvSpecial is disabled.
+00626         void                                    forceActivateTexEnvMode(uint stage, const CMaterial::CTexEnv  &env);
+00627         void                                    activateTexEnvColor(uint stage, NLMISC::CRGBA col);
+00628         void                                    forceActivateTexEnvColor(uint stage, NLMISC::CRGBA col)
+00629         {
+00630                 static  const float     OO255= 1.0f/255;        
+00631                 _CurrentTexEnv[stage].ConstantColor= col;
+00632                 // Setup the gl cte color.
+00633                 _DriverGLStates.activeTextureARB(stage);
+00634                 GLfloat         glcol[4];
+00635                 glcol[0]= col.R*OO255;
+00636                 glcol[1]= col.G*OO255;
+00637                 glcol[2]= col.B*OO255;
+00638                 glcol[3]= col.A*OO255;
+00639                 glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, glcol);        
+00640         }
+00641         void                                    forceActivateTexEnvColor(uint stage, const CMaterial::CTexEnv  &env)
+00642         {       
+00643                 forceActivateTexEnvColor(stage, env.ConstantColor);     
+00644         }
+00645 
+00646 
+00648         void                                    enableNVTextureShader(bool enabled);
+00649         // check nv texture shader consistency
+00650         void                    verifyNVTextureShaderConfig();
+00651 
+00652         // Called by doRefreshRenderSetup(). set _LightSetupDirty to false
+00653         void                                    cleanLightSetup ();
+00654 
+00655         // According to extensions, retrieve GL tex format of the texture.
+00656         GLint                                   getGlTextureFormat(ITexture& tex, bool &compressed);
+00657 
+00658 
+00659         // Clip the wanted rectangle with window. return true if rect is not NULL.
+00660         bool                                    clipRect(NLMISC::CRect &rect);
+00661 
+00662 
+00664 
+00666         // @{
+00668         sint                    beginMultiPass();
+00670         void                    setupPass(uint pass);
+00672         void                    endMultiPass();
+00674         CVertexBufferInfo       _LastVB;
+00675         // @}
+00676 
+00677 
+00679         void                    setupUVPtr(uint stage, CVertexBufferInfo &VB, uint uvId);
+00680 
+00681 
+00683         // @{
+00684         void                    computeLightMapInfos(const CMaterial &mat);
+00685         sint                    beginLightMapMultiPass();
+00686         void                    setupLightMapPass(uint pass);
+00687         void                    endLightMapMultiPass();
+00688 
+00690         uint                    _NLightMaps;
+00691         uint                    _NLightMapPerPass;
+00692         uint                    _NLightMapPass;
+00693         // This array is the LUT from lmapId in [0, _NLightMaps[, to original lightmap id in material.
+00694         std::vector<uint>               _LightMapLUT;
+00695 
+00696         // last stage env.
+00697         CMaterial::CTexEnv      _LightMapLastStageEnv;
+00698 
+00699         // Caching
+00700         bool                    _LastVertexSetupIsLightMap;
+00701         sint8                   _LightMapUVMap[IDRV_MAT_MAXTEXTURES];
+00702 
+00703         // restore std vertex Setup.
+00704         void                    resetLightMapVertexSetup();
+00705 
+00706         // @}
+00707 
+00709         // @{
+00710         sint                    beginSpecularMultiPass();
+00711         void                    setupSpecularPass(uint pass);
+00712         void                    endSpecularMultiPass();
+00713         // @}
+00714                 
+00716         // @{
+00717         // per pixel lighting with specular
+00718         sint                    beginPPLMultiPass();
+00719         void                    setupPPLPass(uint pass);
+00720         void                    endPPLMultiPass();
+00721 
+00722         // per pixel lighting, no specular
+00723         sint                    beginPPLNoSpecMultiPass();
+00724         void                    setupPPLNoSpecPass(uint pass);
+00725         void                    endPPLNoSpecMultiPass();
+00726 
+00727         typedef NLMISC::CSmartPtr<CTextureCube> TSPTextureCube; 
+00728         typedef std::vector<TSPTextureCube> TTexCubeVect;       
+00729         TTexCubeVect   _SpecularTextureCubes; // the cube maps used to compute the specular lighting.
+00730                 
+00731 
+00733         CTextureCube   *getSpecularCubeMap(uint exp);
+00734 
+00735         // get (and if necessary, build) the cube map used for diffuse lighting
+00736         CTextureCube   *getDiffuseCubeMap() { return getSpecularCubeMap(1); }
+00737 
+00738 
+00739 
+00740         // @}
+00741 
+00743         // @{
+00744         /*sint                  beginCausticsMultiPass(const CMaterial &mat);
+00745         void                    setupCausticsPass(const CMaterial &mat, uint pass);
+00746         void                    endCausticsMultiPass(const CMaterial &mat);*/
+00747         // @}
+00748 
+00750         sint                    beginCloudMultiPass ();
+00751         void                    setupCloudPass (uint pass);
+00752         void                    endCloudMultiPass ();
+00753         // @}
+00754 
+00755 
+00757         void                    setupGlArrays(CVertexBufferInfo &vb);
+00758 
+00760         void                    setupGlArraysStd(CVertexBufferInfo &vb);
+00761         void                    setupGlArraysForNVVertexProgram(CVertexBufferInfo &vb);
+00762         void                    setupGlArraysForEXTVertexShader(CVertexBufferInfo &vb);
+00763         void                    toggleGlArraysForNVVertexProgram();
+00764         void                    toggleGlArraysForEXTVertexShader();
+00765 
+00767         void                    enableGlNormalize(bool normalize)
+00768         {
+00769                 if(_CurrentGlNormalize!=normalize)
+00770                 {
+00771                         _CurrentGlNormalize= normalize;
+00772                         if(normalize)
+00773                                 glEnable(GL_NORMALIZE);
+00774                         else
+00775                                 glDisable(GL_NORMALIZE);
+00776                 }
+00777         }
+00778 
+00779         // refresh matrixes and lights.
+00780         void                    refreshRenderSetup()
+00781         {
+00782                 // check if something to change.
+00783                 if(_RenderSetupDirty)
+00784                 {
+00785                         doRefreshRenderSetup();
+00786                 }
+00787         }
+00788         void                    doRefreshRenderSetup();
+00789 
+00790 
+00792         // @{
+00793         CPtrSet<IVertexBufferHardGL>    _VertexBufferHardSet;
+00794         friend class                                    CVertexArrayRangeNVidia;
+00795         friend class                                    CVertexBufferHardGLNVidia;
+00796         friend class                                    CVertexArrayRangeATI;
+00797         friend class                                    CVertexBufferHardGLATI;
+00798         // The VertexArrayRange activated.
+00799         IVertexArrayRange                               *_CurrentVertexArrayRange;
+00800         // The VertexBufferHardGL activated.
+00801         IVertexBufferHardGL                             *_CurrentVertexBufferHard;
+00802         // current setup passed to nglVertexArrayRangeNV()
+00803         void                                                    *_NVCurrentVARPtr;
+00804         uint32                                                  _NVCurrentVARSize;
+00805 
+00806         // Info got from ATI or NVidia extension.
+00807         bool                                                    _SupportVBHard;
+00808         bool                                                    _SlowUnlockVBHard;
+00809         uint32                                                  _MaxVerticesByVBHard;
+00810 
+00811         // The AGP VertexArrayRange.
+00812         IVertexArrayRange                               *_AGPVertexArrayRange;
+00813         // The VRAM VertexArrayRange.
+00814         IVertexArrayRange                               *_VRAMVertexArrayRange;
+00815 
+00816 
+00817         void                                                    resetVertexArrayRange();
+00818 
+00819         void                                                    fenceOnCurVBHardIfNeeded(IVertexBufferHardGL *newVBHard);
+00820 
+00821 
+00822         // @}
+00823 
+00824 
+00826         // @{
+00827         CPrimitiveProfile                                                                       _PrimitiveProfileIn;
+00828         CPrimitiveProfile                                                                       _PrimitiveProfileOut;
+00829         uint32                                                                                          _AllocatedTextureMemory;
+00830         uint32                                                                                          _NbSetupMaterialCall;
+00831         uint32                                                                                          _NbSetupModelMatrixCall;
+00832         bool                                                                                            _SumTextureMemoryUsed;
+00833         std::set<CTextureDrvInfosGL*>                                           _TextureUsed;
+00834         uint                                                    computeMipMapMemoryUsage(uint w, uint h, GLint glfmt) const;
+00835         // @}
+00836 
+00838         // @{
+00839 
+00840         bool                    isVertexProgramSupported () const;
+00841         bool                    isVertexProgramEmulated () const;
+00842         bool                    activeVertexProgram (CVertexProgram *program);
+00843         void                    setConstant (uint index, float, float, float, float);
+00844         void                    setConstant (uint index, double, double, double, double);
+00845         void                    setConstant (uint indexStart, const NLMISC::CVector& value);
+00846         void                    setConstant (uint indexStart, const NLMISC::CVectorD& value);   
+00847         void                    setConstant (uint index, uint num, const float *src);   
+00848         void                    setConstant (uint index, uint num, const double *src);
+00849         void                    setConstantMatrix (uint index, IDriver::TMatrix matrix, IDriver::TTransform transform); 
+00850         void                    enableVertexProgramDoubleSidedColor(bool doubleSided);
+00851         bool                supportVertexProgramDoubleSidedColor() const;
+00852 
+00853         
+00854         // @}
+00855 
+00857         // @{
+00858                 bool activeNVVertexProgram (CVertexProgram *program);
+00859                 bool activeEXTVertexShader (CVertexProgram *program);           
+00861 
+00862 
+00863 
+00865         // @{
+00867                 CMaterial::TShader      getSupportedShader(CMaterial::TShader shader);
+00868         // @}
+00869 
+00870         bool                    isVertexProgramEnabled () const
+00871         {
+00872                 // Don't use glIsEnabled, too slow.
+00873                 return _VertexProgramEnabled;
+00874         }
+00875 
+00876         // Track state of activeVertexProgram()
+00877         bool                                                    _VertexProgramEnabled;
+00878         // Say if last setupGlArrays() was a VertexProgram setup.
+00879         bool                                                    _LastSetupGLArrayVertexProgram;
+00880 
+00881         // The last vertex program that was setupped
+00882         NLMISC::CRefPtr<CVertexProgram> _LastSetuppedVP;
+00883 
+00884         bool                                                    _ForceDXTCCompression;
+00886         uint                                                    _ForceTextureResizePower;
+00887 
+00888 
+00889         // user texture matrix
+00890         NLMISC::CMatrix         _UserTexMat[IDRV_MAT_MAXTEXTURES];
+00891         uint                            _UserTexMatEnabled; // bitm ask for user texture coords
+00892         //NLMISC::CMatrix               _UserTexMat[IDRV_MAT_MAXTEXTURES];
+00893 
+00894         // Static const
+00895         static const uint NumCoordinatesType[CVertexBuffer::NumType];
+00896         static const uint GLType[CVertexBuffer::NumType];
+00897         static const uint GLVertexAttribIndex[CVertexBuffer::NumValue];
+00898         static const uint GLMatrix[IDriver::NumMatrix];
+00899         static const uint GLTransform[IDriver::NumTransform];
+00900 
+00902         // @{
+00903                 NLMISC::CSmartPtr<CTextureCube> _CausticCubeMap; // a cube map used for the rendering of caustics
+00904                 static void initCausticCubeMap();
+00905         // @}
+00906 
+00908         sint                    inlGetNumTextStages() const {return _Extensions.NbTextureStages;}
+00909 
+00910 
+00911         NLMISC::CRGBA                                   _CurrentBlendConstantColor;
+00912 
+00914         // @{
+00915                         // Variants offset used for : 
+00916                         // Secondary color
+00917                         // Fog Coords
+00918                         // Skin Weight
+00919                         // Palette Skin
+00920                         // This mean that they must have 4 components
+00921                         public:
+00922                                 enum EEVSVariants { EVSSecondaryColorVariant = 0, EVSFogCoordsVariant = 1, EVSSkinWeightVariant = 2, EVSPaletteSkinVariant = 3, EVSNumVariants };
+00923                         private:
+00924                         // Handle for standard gl arrays
+00925                         GLuint _EVSPositionHandle;
+00926                         GLuint _EVSNormalHandle;
+00927                         GLuint _EVSColorHandle;                 
+00928                         GLuint _EVSTexHandle[8];
+00929                         // Handle of the first constant c[0]. In vertex program wa have 96 constant c[0] .. c[95]
+00930                         GLuint _EVSConstantHandle;
+00931                         // 
+00932                         bool   setupEXTVertexShader(const CVPParser::TProgram &program, GLuint id, uint variants[EVSNumVariants], uint16 &usedInputRegisters);
+00933                         //                      
+00934         // @}
+00935 
+00936         // init EMBM settings (set each stage to modify the next)
+00937         void    initEMBM();
+00938 
+00939         // Monitor color parameters backup
+00940 #ifdef WIN32
+00941         bool                                                    _NeedToRestaureGammaRamp;
+00942         uint16                                                  _GammaRampBackuped[3*256];
+00943 #endif
+00944 };
+00945 
+00946 
+00947 // ***************************************************************************
+00948 class CVertexProgamDrvInfosGL : public IVertexProgramDrvInfos
+00949 {
+00950 public:
+00951         // The GL Id.
+00952         GLuint                                  ID;
+00953 
+00957         GLuint                                  Variants[CDriverGL::EVSNumVariants];
+00962         uint16                                  UsedVertexComponents;
+00963 
+00964 
+00965         // The gl id is auto created here.
+00966         CVertexProgamDrvInfosGL (CDriverGL *drv, ItVtxPrgDrvInfoPtrList it);
+00967 };
+00968 
+00969 
+00970 } // NL3D
+00971 
+00972 #endif // NL_OPENGL_H
+
+ + +
                                                                                                                                                                    +
+ + -- cgit v1.2.1