From 7be6891bd71ce22e6d82bcfe50e6249f421d3642 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Sun, 8 Sep 2013 21:57:27 +0200 Subject: [PATCH] Cleanup driver interface --- code/nel/include/nel/3d/driver.h | 1016 ++++++++++------- code/nel/include/nel/3d/driver_user.h | 1 - code/nel/include/nel/3d/gpu_program_params.h | 67 +- code/nel/include/nel/3d/u_driver.h | 7 - code/nel/src/3d/driver.cpp | 19 +- .../src/3d/driver/direct3d/driver_direct3d.h | 1 - .../src/3d/driver/opengl/driver_opengl.cpp | 6 - code/nel/src/3d/driver/opengl/driver_opengl.h | 2 - code/nel/src/3d/driver_user.cpp | 6 - code/nel/src/3d/gpu_program_params.cpp | 36 +- code/nel/src/3d/stereo_ovr.cpp | 18 +- 11 files changed, 661 insertions(+), 518 deletions(-) diff --git a/code/nel/include/nel/3d/driver.h b/code/nel/include/nel/3d/driver.h index 2d10c5653..2414d3df5 100644 --- a/code/nel/include/nel/3d/driver.h +++ b/code/nel/include/nel/3d/driver.h @@ -31,6 +31,7 @@ #include "nel/3d/vertex_program.h" #include "nel/3d/pixel_program.h" #include "nel/3d/geometry_program.h" +#include "nel/3d/gpu_program_params.h" #include "nel/3d/material.h" #include "nel/misc/mutex.h" #include "nel/3d/primitive_profile.h" @@ -120,9 +121,9 @@ public: static const uint32 InterfaceVersion; public: - enum TMessageBoxId { okId=0, yesId, noId, abortId, retryId, cancelId, ignoreId, idCount }; - enum TMessageBoxType { okType=0, okCancelType, yesNoType, abortRetryIgnoreType, yesNoCancelType, retryCancelType, typeCount }; - enum TMessageBoxIcon { noIcon=0, handIcon, questionIcon, exclamationIcon, asteriskIcon, warningIcon, errorIcon, informationIcon, stopIcon, iconCount }; + enum TMessageBoxId { okId = 0, yesId, noId, abortId, retryId, cancelId, ignoreId, idCount }; + enum TMessageBoxType { okType = 0, okCancelType, yesNoType, abortRetryIgnoreType, yesNoCancelType, retryCancelType, typeCount }; + enum TMessageBoxIcon { noIcon = 0, handIcon, questionIcon, exclamationIcon, asteriskIcon, warningIcon, errorIcon, informationIcon, stopIcon, iconCount }; enum TCullMode { CCW = 0, CW }; enum TStencilOp { keep = 0, zero, replace, incr, decr, invert }; enum TStencilFunc { never = 0, less, lessequal, equal, notequal, greaterequal, greater, always}; @@ -132,116 +133,218 @@ public: * * \see setPolygonMode, getPolygonMode */ - enum TPolygonMode { Filled=0, Line, Point }; - + enum TPolygonMode { Filled = 0, Line, Point }; /** * Driver Max matrix count. * Kept for backward compatibility. Suppose any Hardware VertexProgram can handle only 16 matrix * */ - enum TMatrixCount { MaxModelMatrix= 16 }; + enum TMatrixCount { MaxModelMatrix = 16 }; + + enum TMatrix + { + ModelView= 0, + Projection, + ModelViewProjection, + NumMatrix + }; + + enum TTransform + { + Identity=0, + Inverse, + Transpose, + InverseTranspose, + NumTransform + }; protected: + CSynchronized _SyncTexDrvInfos; + TTexDrvSharePtrList _TexDrvShares; + TMatDrvInfoPtrList _MatDrvInfos; + TVBDrvInfoPtrList _VBDrvInfos; + TIBDrvInfoPtrList _IBDrvInfos; + TGPUPrgDrvInfoPtrList _GPUPrgDrvInfos; - CSynchronized _SyncTexDrvInfos; - - TTexDrvSharePtrList _TexDrvShares; - TMatDrvInfoPtrList _MatDrvInfos; - TVBDrvInfoPtrList _VBDrvInfos; - TIBDrvInfoPtrList _IBDrvInfos; TPolygonMode _PolygonMode; - TGPUPrgDrvInfoPtrList _GPUPrgDrvInfos; uint _ResetCounter; public: - IDriver(void); - virtual ~IDriver(void); + IDriver(); + virtual ~IDriver(); - virtual bool init (uint windowIcon = 0, emptyProc exitFunc = 0)=0; + virtual bool init(uint windowIcon = 0, emptyProc exitFunc = 0) = 0; + + /// Deriver should calls IDriver::release() first, to destroy all driver components (textures, shaders, VBuffers). + virtual bool release(); + + /// Before rendering via a driver in a thread, must activate() (per thread). + virtual bool activate() = 0; // Test if the device is lost. Can only happen with D3D. // The calling application may skip some part of its rendering when it is the case (this is not a requirement, but may save cpu for other applications) virtual bool isLost() const = 0; + /// Return true if driver is still active. Return false else. If he user close the window, must return false. + virtual bool isActive() = 0; + + + + /** Return the driver reset counter. + * The reset counter is incremented at each driver reset. + */ + uint getResetCounter() const { return _ResetCounter; } + + // get the number of call to swapBuffer since the driver was created + virtual uint64 getSwapBufferCounter() const = 0; + + + /// \name Disable Hardware Feature /** Disable some Feature that may be supported by the Hardware * Call before setDisplay() to work properly */ // @{ - virtual void disableHardwareVertexProgram()=0; - virtual void disableHardwarePixelProgram()=0; - virtual void disableHardwareVertexArrayAGP()=0; - virtual void disableHardwareTextureShader()=0; + virtual void disableHardwareVertexProgram() = 0; + virtual void disableHardwarePixelProgram() = 0; + virtual void disableHardwareVertexArrayAGP() = 0; + virtual void disableHardwareTextureShader() = 0; // @} + + + /// \name Windowing + // @{ // first param is the associated window. // Must be a HWND for Windows (WIN32). - virtual bool setDisplay(nlWindow wnd, const GfxMode& mode, bool show = true, bool resizeable = true) throw(EBadDisplay)=0; + virtual bool setDisplay(nlWindow wnd, const GfxMode& mode, bool show = true, bool resizeable = true) throw(EBadDisplay) = 0; // Must be called after a setDisplay that initialize the mode - virtual bool setMode(const GfxMode& mode)=0; - virtual bool getModes(std::vector &modes)=0; + virtual bool setMode(const GfxMode &mode) = 0; + virtual bool getModes(std::vector &modes) = 0; /// Set the title of the NeL window - virtual void setWindowTitle(const ucstring &title)=0; - + virtual void setWindowTitle(const ucstring &title) = 0; /// Set icon(s) of the NeL window - virtual void setWindowIcon(const std::vector &bitmaps)=0; - + virtual void setWindowIcon(const std::vector &bitmaps) = 0; /// Set the position of the NeL window - virtual void setWindowPos(sint32 x, sint32 y)=0; - + virtual void setWindowPos(sint32 x, sint32 y) = 0; /// Show or hide the NeL window - virtual void showWindow(bool show)=0; + virtual void showWindow(bool show) = 0; /// return the current screen mode (if we are in windowed, return the screen mode behind the window) - virtual bool getCurrentScreenMode(GfxMode &mode)=0; + virtual bool getCurrentScreenMode(GfxMode &mode) = 0; /// enter/leave the dialog mode - virtual void beginDialogMode() =0; - virtual void endDialogMode() =0; + virtual void beginDialogMode() = 0; + virtual void endDialogMode() = 0; // Return is the associated window information. (Implementation dependent) // Must be a HWND for Windows (WIN32). - virtual nlWindow getDisplay() =0; + virtual nlWindow getDisplay() = 0; - /** - * Setup monitor color properties. - * - * Return false if setup failed. - */ - virtual bool setMonitorColorProperties (const CMonitorColorProperties &properties) = 0; + /// Setup monitor color properties. Return false if setup failed + virtual bool setMonitorColorProperties(const CMonitorColorProperties &properties) = 0; // Return is the associated default window proc for the driver. (Implementation dependent) // Must be a void GlWndProc(IDriver *driver, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) for Windows (WIN32). virtual emptyProc getWindowProc() = 0; - /// Before rendering via a driver in a thread, must activate() (per thread). - virtual bool activate(void) = 0; + virtual NLMISC::IEventEmitter *getEventEmitter() = 0; + + /// Copy a string to system clipboard. + virtual bool copyTextToClipboard(const ucstring &text) = 0; - /// Get the number of texture stage available, for multi texturing (Normal material shaders). Valid only after setDisplay(). - virtual uint getNbTextureStages() const = 0; + /// Paste a string from system clipboard. + virtual bool pasteTextFromClipboard(ucstring &text) = 0;/// Return the depth of the driver after init(). - /** is the texture is set up in the driver - * NB: this method is thread safe. - */ - virtual bool isTextureExist(const ITexture&tex)=0; + virtual uint8 getBitPerPixel() = 0; - virtual NLMISC::IEventEmitter* getEventEmitter(void) = 0; + /** Output a system message box and print a message with an icon. This method can be call even if the driver is not initialized. + * This method is used to return internal driver problem when string can't be displayed in the driver window. + * If the driver can't open a messageBox, it should not override this method and let the IDriver class manage it with the ASCII console. + * + * \param message This is the message to display in the message box. + * \param title This is the title of the message box. + * \param type This is the type of the message box, ie number of button and label of buttons. + * \param icon This is the icon of the message box should use like warning, error etc... + */ + virtual TMessageBoxId systemMessageBox(const char *message, const char *title, TMessageBoxType type = okType, TMessageBoxIcon icon = noIcon); - /* Clear the current target surface pixels. The function ignores the viewport settings but uses the scissor. */ + /// Get the width and the height of the window + virtual void getWindowSize(uint32 &width, uint32 &height) = 0; + + /// Get the position of the window always (0,0) in fullscreen + virtual void getWindowPos(sint32 &x, sint32 &y) = 0; + // @} + + + + /// \name Framebuffer operations + // @{ + /// Clear the current target surface pixels. The function ignores the viewport settings but uses the scissor. virtual bool clear2D(CRGBA rgba) = 0; - /* Clear the current target surface zbuffer. The function ignores the viewport settings but uses the scissor. */ + /// Clear the current target surface zbuffer. The function ignores the viewport settings but uses the scissor. virtual bool clearZBuffer(float zval=1) = 0; - /* Clear the current target surface stencil buffer. The function ignores the viewport settings but uses the scissor. */ + /// Clear the current target surface stencil buffer. The function ignores the viewport settings but uses the scissor. virtual bool clearStencilBuffer(float stencilval=0) = 0; /// Set the color mask filter through where the operation done will pass - virtual void setColorMask (bool bRed, bool bGreen, bool bBlue, bool bAlpha) = 0; + virtual void setColorMask(bool bRed, bool bGreen, bool bBlue, bool bAlpha) = 0; + // @} + + + /// \name Copy framebuffer to memory + // @{ + /** get the RGBA back buffer. After swapBuffers(), the content of the back buffer is undefined. + * + * \param bitmap the buffer will be written in this bitmap + */ + virtual void getBuffer(CBitmap &bitmap) = 0; + + /** get the ZBuffer (back buffer). + * + * \param zbuffer the returned array of Z. size of getWindowSize() . + */ + virtual void getZBuffer(std::vector &zbuffer) = 0; + + /** get a part of the RGBA back buffer. After swapBuffers(), the content of the back buffer is undefined. + * NB: 0,0 is the bottom left corner of the screen. + * + * \param bitmap the buffer will be written in this bitmap + * \param rect the in/out (wanted/clipped) part of Color buffer to retrieve. + */ + virtual void getBufferPart(CBitmap &bitmap, NLMISC::CRect &rect) = 0; + + /** get a part of the ZBuffer (back buffer). + * NB: 0,0 is the bottom left corner of the screen. + * + * \param zbuffer the returned array of Z. size of rec.Width*rec.Height. + * \param rect the in/out (wanted/clipped) part of ZBuffer to retrieve. + */ + virtual void getZBufferPart(std::vector &zbuffer, NLMISC::CRect &rect) = 0; + // @} + + + + /// \name Copy memory to framebuffer + // @{ + /** fill the RGBA back buffer + * + * \param bitmap will be written in the buffer. no-op if bad size. + * \return true if success + */ + virtual bool fillBuffer(CBitmap &bitmap) = 0; + // @} + + + + /// \name Viewport depth clipping + // @{ /** Set depth range. Depth range specify a linear mapping from device z coordinates (in the [-1, 1] range) to window coordinates (in the [0, 1] range) * This mapping occurs after clipping of primitives and division by w of vertices coordinates. * Default depth range is [0, 1]. @@ -250,11 +353,20 @@ public: virtual void setDepthRange(float znear, float zfar) = 0; // Get the current depth range virtual void getDepthRange(float &znear, float &zfar) const = 0; + // @} + + + /// \name Textures + // @{ + /** is the texture is set up in the driver + * NB: this method is thread safe. + */ + virtual bool isTextureExist(const ITexture &tex) = 0; /** setup a texture, generate and upload if needed. same as setupTextureEx(tex, true, dummy); */ - virtual bool setupTexture(ITexture& tex) = 0; + virtual bool setupTexture(ITexture &tex) = 0; /** setup a texture in the driver. * \param bUpload if true the texture is created and uploaded to VRAM, if false the texture is only created @@ -267,59 +379,81 @@ public: * is only bound to tex (thus creating and uploading nothing) * NB: the texture must be at least touch()-ed for the recreate to work. */ - virtual bool setupTextureEx (ITexture& tex, bool bUpload, bool& bAllUploaded, - bool bMustRecreateSharedTexture= false) = 0; + virtual bool setupTextureEx( ITexture &tex, bool bUpload, bool &bAllUploaded, + bool bMustRecreateSharedTexture = false) = 0; /** The texture must be created or uploadTexture do nothing. * These function can be used to upload piece by piece a texture. Use it in conjunction with setupTextureEx(..., false); * For compressed textures, the rect must aligned on pixel block. (a block of pixel size is 4x4 pixels). */ - virtual bool uploadTexture (ITexture& tex, NLMISC::CRect& rect, uint8 nNumMipMap) = 0; - virtual bool uploadTextureCube (ITexture& tex, NLMISC::CRect& rect, uint8 nNumMipMap, uint8 nNumFace) = 0; + virtual bool uploadTexture(ITexture &tex, NLMISC::CRect &rect, uint8 nNumMipMap) = 0; + virtual bool uploadTextureCube(ITexture &tex, NLMISC::CRect &rect, uint8 nNumMipMap, uint8 nNumFace) = 0; /** * Invalidate shared texture */ - bool invalidateShareTexture (ITexture &); + bool invalidateShareTexture(ITexture &); /** * Get the driver share texture name */ - static void getTextureShareName (const ITexture& tex, std::string &output); + static void getTextureShareName(const ITexture &tex, std::string &output); /** if true force all the uncompressed RGBA 32 bits and RGBA 24 bits texture to be DXTC5 compressed. * Do this only during upload if ITexture::allowDegradation() is true and if ITexture::UploadFormat is "Automatic" * and if bitmap format is RGBA. */ - virtual void forceDXTCCompression(bool dxtcComp)=0; + virtual void forceDXTCCompression(bool dxtcComp) = 0; /** if different from 0, enable anisotropic filter on textures. -1 enables max value. * Default is 0. */ - virtual void setAnisotropicFilter(sint filter)=0; + virtual void setAnisotropicFilter(sint filter) = 0; /** if !=1, force mostly all the textures (but TextureFonts lightmaps, interfaces etc..) * to be divided by Divisor (2, 4, 8...) * Default is 1. * NB: this is done only on TextureFile */ - virtual void forceTextureResize(uint divisor)=0; + virtual void forceTextureResize(uint divisor) = 0; - /** Sets enforcement of native fragment programs. This is by default enabled. - * - * \param nativeOnly If set to false, fragment programs don't need to be native to stay loaded, - * otherwise (aka if true) they will be purged. + /** Get the number of texture stage available, for multi texturing (Normal material shaders). Valid only after setDisplay(). */ - virtual void forceNativeFragmentPrograms(bool nativeOnly) = 0; + virtual uint getNbTextureStages() const = 0; + + /** Get max number of per stage constant that can be used simultaneously. + * This will usually match the number of texture stages, but with a D3D driver, this feature is not available most of the time + * so it is emulated. If pixel shaders are available this will be fully supported. + * Under OpenGL this simply returns the maximum number of texture stages (getNbTextureStages) in both return values. + */ + virtual void getNumPerStageConstant(uint &lightedMaterial, uint &unlightedMaterial) const = 0; + + // [DEPRECATED] Return if this texture is a rectangle texture that requires RECT sampler (OpenGL specific pre-NPOT functionality) + virtual bool isTextureRectangle(ITexture *tex) const = 0; + + // Return true if driver support non-power of two textures + virtual bool supportNonPowerOfTwoTextures() const = 0; + // @} + + + + /// \name Texture operations + // @{ + // copy the first texture in a second one of different dimensions + virtual bool stretchRect(ITexture *srcText, NLMISC::CRect &srcRect, ITexture *destText, NLMISC::CRect &destRect) = 0; + // @} - virtual bool setupMaterial(CMaterial& mat)=0; + + /// \name Material + // @{ + virtual bool setupMaterial(CMaterial &mat) = 0; /** Special for Faster Specular Setup. Call this between lot of primitives rendered with Specular Materials. * Visual Errors may arise if you don't correctly call endSpecularBatch(). */ - virtual void startSpecularBatch()=0; - virtual void endSpecularBatch()=0; + virtual void startSpecularBatch() = 0; + virtual void endSpecularBatch() = 0; /// \name Material multipass. /** NB: setupMaterial() must be called before those methods. @@ -327,18 +461,26 @@ public: * NB: Other render calls performs the needed setup automatically */ // @{ - /// init multipass for _CurrentMaterial. return number of pass required to render this material. - virtual sint beginMaterialMultiPass() = 0; - /// active the ith pass of this material. - virtual void setupMaterialPass(uint pass) = 0; - /// end multipass for this material. - virtual void endMaterialMultiPass() = 0; + /// init multipass for _CurrentMaterial. return number of pass required to render this material. + virtual sint beginMaterialMultiPass() = 0; + /// active the ith pass of this material. + virtual void setupMaterialPass(uint pass) = 0; + /// end multipass for this material. + virtual void endMaterialMultiPass() = 0; // @} + // Does the driver support the per-pixel lighting shader ? + virtual bool supportPerPixelLighting(bool specular) const = 0; + // @} + + + + /// \name Camera + // @{ // Setup the camera mode as a perspective/ortho camera. NB: znear and zfar must be >0 (if perspective). - virtual void setFrustum(float left, float right, float bottom, float top, float znear, float zfar, bool perspective=true)=0; - virtual void setFrustumMatrix(CMatrix &frust)=0; - virtual CMatrix getFrustumMatrix()=0; + virtual void setFrustum(float left, float right, float bottom, float top, float znear, float zfar, bool perspective = true) = 0; + virtual void setFrustumMatrix(CMatrix &frust) = 0; + virtual CMatrix getFrustumMatrix() = 0; virtual float getClipSpaceZMin() const = 0; @@ -346,7 +488,7 @@ public: * * NB: you must setupViewMatrix() BEFORE setupModelMatrix(), or else undefined results. */ - virtual void setupViewMatrix(const CMatrix& mtx)=0; + virtual void setupViewMatrix(const CMatrix &mtx)=0; /** setup the view matrix (inverse of camera matrix). * Extended: give a cameraPos (mtx.Pos() is not taken into account but for getViewMatrix()), @@ -360,38 +502,40 @@ public: * \param mtx the same view matrix (still with correct "inversed" camera position) as if passed in setupViewMatrix() * \param cameraPos position of the camera (before inversion, ie mtx.getPos()!=cameraPos ). */ - virtual void setupViewMatrixEx(const CMatrix& mtx, const CVector &cameraPos)=0; + virtual void setupViewMatrixEx(const CMatrix &mtx, const CVector &cameraPos) = 0; /** setup the model matrix. * * NB: you must setupModelMatrix() AFTER setupViewMatrix(), or else undefined results. */ - virtual void setupModelMatrix(const CMatrix& mtx)=0; + virtual void setupModelMatrix(const CMatrix &mtx) = 0; - virtual CMatrix getViewMatrix(void)const=0; + virtual CMatrix getViewMatrix() const = 0; + // @} + + /// \name Fixed pipeline vertex program + // @{ /** Force input normal to be normalized by the driver. default is false. * NB: driver force the normalization himself if: * - current Model matrix has a scale. */ - virtual void forceNormalize(bool normalize)=0; + virtual void forceNormalize(bool normalize) = 0; /** return the forceNormalize() state. */ - virtual bool isForceNormalize() const =0; + virtual bool isForceNormalize() const = 0; + // @} + - /** Get max number of per stage constant that can be used simultaneously. - * This will usually match the number of texture stages, but with a D3D driver, this feature is not available most of the time - * so it is emulated. If pixel shaders are available this will be fully supported. - */ - virtual void getNumPerStageConstant(uint &lightedMaterial, uint &unlightedMaterial) const = 0; - + /// \name Vertex Buffer Hard: Features + // @{ /** return true if driver support VertexBufferHard. */ - virtual bool supportVertexBufferHard() const =0; + virtual bool supportVertexBufferHard() const = 0; /** return true if volatile vertex buffer are supported. (e.g a vertex buffer which can be created with the flag CVertexBuffer::AGPVolatile or CVertexBuffer::RAMVolatile) * If these are not supported, a RAM vb is created instead (transparent to user) @@ -405,9 +549,13 @@ public: /** return true if driver support VertexBufferHard, but vbHard->unlock() are slow (ATI-openGL). */ - virtual bool slowUnlockVertexBufferHard() const =0; + virtual bool slowUnlockVertexBufferHard() const = 0; + // @} + + /// \name Vertex Buffer Hard: Settings + // @{ /* Returns true if static vertex and index buffers must by allocated in VRAM, false in AGP. * Default is false. */ @@ -418,16 +566,15 @@ public: */ void setStaticMemoryToVRAM(bool staticMemoryToVRAM); - /** Return the driver reset counter. - * The reset counter is incremented at each driver reset. - */ - uint getResetCounter () const { return _ResetCounter; } - /** return How many vertices VertexBufferHard support */ - virtual uint getMaxVerticesByVertexBufferHard() const =0; + virtual uint getMaxVerticesByVertexBufferHard() const = 0; + // @} + + /// \name Vertex Buffer Hard + // @{ /** Allocate the initial VertexArray Memory. (no-op if !supportVertexBufferHard()). * VertexArrayRange is first reseted, so any VBhard created before will be deleted. * NB: call it after setDisplay(). But setDisplay() by default call initVertexBufferHard(16Mo, 0); @@ -437,17 +584,21 @@ public: * \param vramMem amount of VRAM Memory required. if 0, reseted. * \return false if one the Buffer has not been allocated (at least at 500K). */ - virtual bool initVertexBufferHard(uint agpMem, uint vramMem=0) =0; + virtual bool initVertexBufferHard(uint agpMem, uint vramMem = 0) = 0; /** Return the amount of AGP memory allocated by initVertexBufferHard() to store vertices. */ - virtual uint32 getAvailableVertexAGPMemory () =0; + virtual uint32 getAvailableVertexAGPMemory() = 0; /** Return the amount of video memory allocated by initVertexBufferHard() to store vertices. */ - virtual uint32 getAvailableVertexVRAMMemory () =0; + virtual uint32 getAvailableVertexVRAMMemory() = 0; + // @} + + /// \name Vertex Buffer Objects + // @{ /** active a current VB, for future render(). * This method suppose that all vertices in the VB will be used. * @@ -457,30 +608,33 @@ public: * * \see activeVertexProgram */ - virtual bool activeVertexBuffer(CVertexBuffer& VB)=0; - + virtual bool activeVertexBuffer(CVertexBuffer &VB) = 0; /** active a current IB, for future render(). * * Don't change the index buffer format/size after having activated it. * Don't lock the index buffer after having activated it. */ - virtual bool activeIndexBuffer(CIndexBuffer& IB)=0; + virtual bool activeIndexBuffer(CIndexBuffer &IB) = 0; + // @} + + /// \name Rendering + // @{ /** Render a list of indexed lines with previously setuped VertexBuffer / IndexBuffer / Matrixes. * \param mat is the material to use during this rendering * \param firstIndex is the first index in the index buffer to use as first line. * \param nlines is the number of line to render. */ - virtual bool renderLines(CMaterial& mat, uint32 firstIndex, uint32 nlines)=0; + virtual bool renderLines(CMaterial &mat, uint32 firstIndex, uint32 nlines) = 0; /** Render a list of indexed triangles with previously setuped VertexBuffer / IndexBuffer / Matrixes. * \param mat is the material to use during this rendering * \param firstIndex is the first index in the index buffer to use as first triangle. * \param ntris is the number of triangle to render. */ - virtual bool renderTriangles(CMaterial& mat, uint32 firstIndex, uint32 ntris)=0; + virtual bool renderTriangles(CMaterial &mat, uint32 firstIndex, uint32 ntris) = 0; /** Render a list of triangles with previously setuped VertexBuffer / IndexBuffer / Matrixes, AND previously setuped MATERIAL!! * This use the last material setuped. It should be a "Normal shader" material, because no multi-pass is allowed @@ -491,7 +645,7 @@ public: * \param firstIndex is the first index in the index buffer to use as first triangle. * \param ntris is the number of triangle to render. */ - virtual bool renderSimpleTriangles(uint32 firstIndex, uint32 ntris)=0; + virtual bool renderSimpleTriangles(uint32 firstIndex, uint32 ntris) = 0; /** Render points with previously setuped VertexBuffer / Matrixes. * Points are stored as a sequence in the vertex buffer. @@ -499,7 +653,7 @@ public: * \param startVertex is the first vertex to use during this rendering. * \param numPoints is the number of point to render. */ - virtual bool renderRawPoints(CMaterial& mat, uint32 startVertex, uint32 numPoints)=0; + virtual bool renderRawPoints(CMaterial &mat, uint32 startVertex, uint32 numPoints) = 0; /** Render lines with previously setuped VertexBuffer / Matrixes. * Lines are stored as a sequence in the vertex buffer. @@ -507,7 +661,7 @@ public: * \param startVertex is the first vertex to use during this rendering. * \param numLine is the number of line to render. */ - virtual bool renderRawLines(CMaterial& mat, uint32 startVertex, uint32 numTri)=0; + virtual bool renderRawLines(CMaterial &mat, uint32 startVertex, uint32 numTri) = 0; /** Render triangles with previously setuped VertexBuffer / Matrixes. * Triangles are stored as a sequence in the vertex buffer. @@ -515,15 +669,15 @@ public: * \param startVertex is the first vertex to use during this rendering. * \param numTri is the number of triangle to render. */ - virtual bool renderRawTriangles(CMaterial& mat, uint32 startVertex, uint32 numTri)=0; + virtual bool renderRawTriangles(CMaterial &mat, uint32 startVertex, uint32 numTri) = 0; /** If the driver support it, primitive can be rendered with an offset added to each index * These are the offseted version of the 'render' functions * \see supportIndexOffset */ - virtual bool renderLinesWithIndexOffset(CMaterial& mat, uint32 firstIndex, uint32 nlines, uint indexOffset)=0; - virtual bool renderTrianglesWithIndexOffset(CMaterial& mat, uint32 firstIndex, uint32 ntris, uint indexOffset)=0; - virtual bool renderSimpleTrianglesWithIndexOffset(uint32 firstIndex, uint32 ntris, uint indexOffset)=0; + virtual bool renderLinesWithIndexOffset(CMaterial &mat, uint32 firstIndex, uint32 nlines, uint indexOffset) = 0; + virtual bool renderTrianglesWithIndexOffset(CMaterial &mat, uint32 firstIndex, uint32 ntris, uint indexOffset) = 0; + virtual bool renderSimpleTrianglesWithIndexOffset(uint32 firstIndex, uint32 ntris, uint indexOffset) = 0; /** render quads with previously setuped VertexBuffer / Matrixes. @@ -540,8 +694,13 @@ public: * \param startVertex is the first vertex to use during this rendering. * \param numQuad is the number of quad to render. */ - virtual bool renderRawQuads(CMaterial& mat, uint32 startVertex, uint32 numQuads)=0; + virtual bool renderRawQuads(CMaterial &mat, uint32 startVertex, uint32 numQuads) = 0; + // @} + + + /// \name Texture coordinates fixed pipeline + // @{ /** Say what Texture Stage use what UV coord. * by default activeVertexBuffer*() methods map all stage i to UV i. You can change this behavior, * after calling activeVertexBuffer*(), by using this method. @@ -553,63 +712,58 @@ public: * Warning!: some CMaterial Shader may change automatically this behavior too when setupMaterial() * (and so render*()) is called. But Normal shader doesn't do it. */ - virtual void mapTextureStageToUV(uint stage, uint uv)=0; + virtual void mapTextureStageToUV(uint stage, uint uv) = 0; + // @} + + + /// \name Buffer swapping + // @{ /// Swap the back and front buffers. - virtual bool swapBuffers(void)=0; - - /// Copy a string to system clipboard. - virtual bool copyTextToClipboard(const ucstring &text) =0; - - /// Paste a string from system clipboard. - virtual bool pasteTextFromClipboard(ucstring &text) =0; + virtual bool swapBuffers() = 0; /** set the number of VBL wait when a swapBuffers() is issued. 0 means no synchronisation to the VBL * Default is 1. Values >1 may be clamped to 1 by the driver. */ - virtual void setSwapVBLInterval(uint interval)=0; + virtual void setSwapVBLInterval(uint interval) = 0; /// get the number of VBL wait when a swapBuffers() is issued. 0 means no synchronisation to the VBL - virtual uint getSwapVBLInterval()=0; + virtual uint getSwapVBLInterval() = 0; + // @} + + + /// \name Profiling. // @{ - - /** Get the number of primitives rendered from the last swapBuffers() call. * \param pIn the number of requested rendered primitive. * \param pOut the number of effective rendered primitive. pOut==pIn if no multi-pass material is used * (Lightmap, Specular ...). */ - virtual void profileRenderedPrimitives(CPrimitiveProfile &pIn, CPrimitiveProfile &pOut) =0; - + virtual void profileRenderedPrimitives(CPrimitiveProfile &pIn, CPrimitiveProfile &pOut) = 0; /** Return the amount of Texture memory requested. taking mipmap, compression, texture format, etc... into account. * NB: because of GeForce*, RGB888 is considered to be 32 bits. So it may be false for others cards :). */ - virtual uint32 profileAllocatedTextureMemory() =0; - + virtual uint32 profileAllocatedTextureMemory() = 0; /** Get the number of material setuped from the last swapBuffers() call. */ - virtual uint32 profileSetupedMaterials() const =0; - + virtual uint32 profileSetupedMaterials() const = 0; /** Get the number of matrix setuped from the last swapBuffers() call. */ - virtual uint32 profileSetupedModelMatrix() const =0; - + virtual uint32 profileSetupedModelMatrix() const = 0; /** Enable the sum of texture memory used since last swapBuffers() call. To retrieve the memory used call getUsedTextureMemory(). */ - virtual void enableUsedTextureMemorySum (bool enable=true) =0; - + virtual void enableUsedTextureMemorySum (bool enable = true) = 0; /** Return the amount of texture video memory used since last swapBuffers() call. Before use this method, you should enable * the sum with enableUsedTextureMemorySum(). */ - virtual uint32 getUsedTextureMemory() const =0; - + virtual uint32 getUsedTextureMemory() const = 0; /** If the driver support it, enable profile VBHard locks. * No-Op if already profiling @@ -638,179 +792,126 @@ public: /** For each texture setuped in the driver, "print" result: type, shareName, format and size (mipmap included) */ void profileTextureUsage(std::vector &result); - // @} + /// \name Fog support. // @{ - virtual bool fogEnabled()=0; - virtual void enableFog(bool enable)=0; + virtual bool fogEnabled() = 0; + virtual void enableFog(bool enable = true) = 0; /// setup fog parameters. fog must enabled to see result. start and end are distance values. - virtual void setupFog(float start, float end, CRGBA color)=0; + virtual void setupFog(float start, float end, NLMISC::CRGBA color) = 0; /// Get. - virtual float getFogStart() const =0; - virtual float getFogEnd() const =0; - virtual CRGBA getFogColor() const =0; + virtual float getFogStart() const = 0; + virtual float getFogEnd() const = 0; + virtual NLMISC::CRGBA getFogColor() const = 0; // @} - /// Deriver should calls IDriver::release() first, to destroy all driver components (textures, shaders, VBuffers). - virtual bool release(void); - /// Return true if driver is still active. Return false else. If he user close the window, must return false. - virtual bool isActive()=0; - - /// Return the depth of the driver after init(). - virtual uint8 getBitPerPixel ()=0; - - /** Output a system message box and print a message with an icon. This method can be call even if the driver is not initialized. - * This method is used to return internal driver problem when string can't be displayed in the driver window. - * If the driver can't open a messageBox, it should not override this method and let the IDriver class manage it with the ASCII console. - * - * \param message This is the message to display in the message box. - * \param title This is the title of the message box. - * \param type This is the type of the message box, ie number of button and label of buttons. - * \param icon This is the icon of the message box should use like warning, error etc... - */ - virtual TMessageBoxId systemMessageBox (const char* message, const char* title, TMessageBoxType type=okType, TMessageBoxIcon icon=noIcon); + /// \name Viewport + // @{ /** Set the current viewport * * \param viewport is a viewport to setup as current viewport. */ - virtual void setupViewport (const class CViewport& viewport)=0; + virtual void setupViewport(const class CViewport &viewport) = 0; /** Get the current viewport */ virtual void getViewport(CViewport &viewport) = 0; - /** Set the current Scissor. * \param scissor is a scissor to setup the current Scissor, in Window relative coordinate (0,1). */ - virtual void setupScissor (const class CScissor& scissor)=0; + virtual void setupScissor(const class CScissor &scissor) = 0; + // @} + + /// \name Driver information + // @{ /** * Get the driver version. Not the same than interface version. Incremented at each implementation change. * * \see InterfaceVersion */ - virtual uint32 getImplementationVersion () const = 0; + virtual uint32 getImplementationVersion() const = 0; /** * Get driver information. * get the nel name of the driver (ex: "Opengl 1.2 NeL Driver") */ - virtual const char* getDriverInformation () = 0; + virtual const char *getDriverInformation() = 0; /** * Get videocard information. * get the official name of the driver */ - virtual const char* getVideocardInformation () = 0; + virtual const char *getVideocardInformation () = 0; + // @} + + /// \name Mouse / Keyboard / Game devices // @{ - /// show cursor if b is true, or hide it if b is false - virtual void showCursor (bool b) = 0; + /// show cursor if b is true, or hide it if b is false + virtual void showCursor(bool b) = 0; - /// x and y must be between 0.0 and 1.0 - virtual void setMousePos (float x, float y) = 0; + /// x and y must be between 0.0 and 1.0 + virtual void setMousePos(float x, float y) = 0; - /** Enable / disable low level mouse. This allow to take advantage of some options (speed of the mouse, automatic wrapping) - * It returns a interface to these parameters when it is supported, or NULL otherwise - * The interface pointer is valid as long as the low level mouse is enabled. - * A call to disable the mouse returns NULL, and restore the default mouse behavior - * NB : - In this mode the mouse cursor isn't drawn. - * - Calls to showCursor have no effects - * - Calls to setCapture have no effects - */ - virtual NLMISC::IMouseDevice *enableLowLevelMouse(bool enable, bool exclusive) = 0; + /** Enable / disable low level mouse. This allow to take advantage of some options (speed of the mouse, automatic wrapping) + * It returns a interface to these parameters when it is supported, or NULL otherwise + * The interface pointer is valid as long as the low level mouse is enabled. + * A call to disable the mouse returns NULL, and restore the default mouse behavior + * NB : - In this mode the mouse cursor isn't drawn. + * - Calls to showCursor have no effects + * - Calls to setCapture have no effects + */ + virtual NLMISC::IMouseDevice *enableLowLevelMouse(bool enable, bool exclusive) = 0; - /** Enable / disable a low level keyboard. - * Such a keyboard can only send KeyDown and KeyUp event. It just consider the keyboard as a - * gamepad with lots of buttons... - * This returns a interface to some parameters when it is supported, or NULL otherwise. - * The interface pointer is valid as long as the low level keyboard is enabled. - * A call to disable the keyboard returns NULL, and restore the default keyboard behavior - */ - virtual NLMISC::IKeyboardDevice *enableLowLevelKeyboard(bool enable) = 0; + /** Enable / disable a low level keyboard. + * Such a keyboard can only send KeyDown and KeyUp event. It just consider the keyboard as a + * gamepad with lots of buttons... + * This returns a interface to some parameters when it is supported, or NULL otherwise. + * The interface pointer is valid as long as the low level keyboard is enabled. + * A call to disable the keyboard returns NULL, and restore the default keyboard behavior + */ + virtual NLMISC::IKeyboardDevice *enableLowLevelKeyboard(bool enable) = 0; - /** Get the delay in ms for mouse double clicks. - */ - virtual uint getDoubleClickDelay(bool hardwareMouse) = 0; + /** Get the delay in ms for mouse double clicks. + */ + virtual uint getDoubleClickDelay(bool hardwareMouse) = 0; - /** If true, capture the mouse to force it to stay under the window. - * NB : this has no effects if a low level mouse is used - */ - virtual void setCapture (bool b) = 0; + /** If true, capture the mouse to force it to stay under the window. + * NB : this has no effects if a low level mouse is used + */ + virtual void setCapture(bool b) = 0; - // see if system cursor is currently captured - virtual bool isSystemCursorCaptured() = 0; + // see if system cursor is currently captured + virtual bool isSystemCursorCaptured() = 0; - // Add a new cursor (name is case unsensitive) - virtual void addCursor(const std::string &name, const NLMISC::CBitmap &bitmap) = 0; + // Add a new cursor (name is case unsensitive) + virtual void addCursor(const std::string &name, const NLMISC::CBitmap &bitmap) = 0; - // Display a cursor from its name (case unsensitive) - virtual void setCursor(const std::string &name, NLMISC::CRGBA col, uint8 rot, sint hotSpotX, sint hotSpotY, bool forceRebuild = false) = 0; + // Display a cursor from its name (case unsensitive) + virtual void setCursor(const std::string &name, NLMISC::CRGBA col, uint8 rot, sint hotSpotX, sint hotSpotY, bool forceRebuild = false) = 0; - // Change default scale for all cursors - virtual void setCursorScale(float scale) = 0; + // Change default scale for all cursors + virtual void setCursorScale(float scale) = 0; - /** Check whether there is a low level device manager available, and get its interface. Return NULL if not available - * From this interface you can deal with mouse and keyboard as above, but you can also manage game device (joysticks, joypads ...) - */ - virtual NLMISC::IInputDeviceManager *getLowLevelInputDeviceManager() = 0; + /** Check whether there is a low level device manager available, and get its interface. Return NULL if not available + * From this interface you can deal with mouse and keyboard as above, but you can also manage game device (joysticks, joypads ...) + */ + virtual NLMISC::IInputDeviceManager *getLowLevelInputDeviceManager() = 0; // @} - /// Get the width and the height of the window - virtual void getWindowSize (uint32 &width, uint32 &height) = 0; - - /// Get the position of the window always (0,0) in fullscreen - virtual void getWindowPos (sint32 &x, sint32 &y) = 0; - - /** get the RGBA back buffer. After swapBuffers(), the content of the back buffer is undefined. - * - * \param bitmap the buffer will be written in this bitmap - */ - virtual void getBuffer (CBitmap &bitmap) = 0; - - /** get the ZBuffer (back buffer). - * - * \param zbuffer the returned array of Z. size of getWindowSize() . - */ - virtual void getZBuffer (std::vector &zbuffer) = 0; - - /** get a part of the RGBA back buffer. After swapBuffers(), the content of the back buffer is undefined. - * NB: 0,0 is the bottom left corner of the screen. - * - * \param bitmap the buffer will be written in this bitmap - * \param rect the in/out (wanted/clipped) part of Color buffer to retrieve. - */ - virtual void getBufferPart (CBitmap &bitmap, NLMISC::CRect &rect) = 0; - - // copy the first texture in a second one of different dimensions - virtual bool stretchRect (ITexture * srcText, NLMISC::CRect &srcRect, ITexture * destText, NLMISC::CRect &destRect) = 0; - - // is this texture a rectangle texture ? - virtual bool isTextureRectangle(ITexture * tex) const = 0; - - // return true if driver support Bloom effect. - virtual bool supportBloomEffect() const =0; - - // return true if driver support non-power of two textures - virtual bool supportNonPowerOfTwoTextures() const =0; - - /** get a part of the ZBuffer (back buffer). - * NB: 0,0 is the bottom left corner of the screen. - * - * \param zbuffer the returned array of Z. size of rec.Width*rec.Height. - * \param rect the in/out (wanted/clipped) part of ZBuffer to retrieve. - */ - virtual void getZBufferPart (std::vector &zbuffer, NLMISC::CRect &rect) = 0; + /// \name Render target // TODO: Handle Color/ZBuffer/Stencil consistently + // @{ /** Set the current render target. * * The render target can be a texture (tex pointer) or the back buffer (tex = NULL). @@ -843,17 +944,23 @@ public: * \param cubaFace the face of the cube to copy texture to. * \return true if the render target has been changed */ - virtual bool setRenderTarget (ITexture *tex, - uint32 x = 0, - uint32 y = 0, - uint32 width = 0, - uint32 height = 0, - uint32 mipmapLevel = 0, - uint32 cubeFace = 0 - ) = 0 ; + virtual bool setRenderTarget( ITexture *tex, + uint32 x = 0, + uint32 y = 0, + uint32 width = 0, + uint32 height = 0, + uint32 mipmapLevel = 0, + uint32 cubeFace = 0 + ) = 0; virtual ITexture *getRenderTarget() const = 0; + /** Retrieve the render target size. + * If the render target is the frame buffer, it returns the size of the frame buffer. + * It the render target is a texture, it returns the size of the texture mipmap selected as render target. + */ + virtual bool getRenderTargetSize (uint32 &width, uint32 &height) = 0; + /** Trick method : copy the current texture target into another texture without updating the current texture. * * This method copies the current texture into another texture. @@ -880,30 +987,21 @@ public: * \param height height of the renderable area to copy, if 0, use the whole size. * \param mipmapLevel the mipmap to copy texture to. */ - virtual bool copyTargetToTexture (ITexture *tex, - uint32 offsetx = 0, - uint32 offsety = 0, - uint32 x = 0, - uint32 y = 0, - uint32 width = 0, - uint32 height = 0, - uint32 mipmapLevel = 0 + virtual bool copyTargetToTexture( ITexture *tex, + uint32 offsetx = 0, + uint32 offsety = 0, + uint32 x = 0, + uint32 y = 0, + uint32 width = 0, + uint32 height = 0, + uint32 mipmapLevel = 0 ) = 0; - - /** Retrieve the render target size. - * If the render target is the frame buffer, it returns the size of the frame buffer. - * It the render target is a texture, it returns the size of the texture mipmap selected as render target. - */ - virtual bool getRenderTargetSize (uint32 &width, uint32 &height) = 0; - - /** fill the RGBA back buffer - * - * \param bitmap will be written in the buffer. no-op if bad size. - * \return true if success - */ - virtual bool fillBuffer (CBitmap &bitmap) = 0; + // @} + + /// \name Render state: Polygon mode + // @{ /** Set the global polygon mode. Can be filled, line or point. The implementation driver must * call IDriver::setPolygonMode and active this mode. * @@ -915,13 +1013,27 @@ public: _PolygonMode=mode; } + /** Get the global polygon mode. + * + * \param polygon mode choose in this driver. + * \see setPolygonMode(), TPolygonMode + */ + TPolygonMode getPolygonMode () + { + return _PolygonMode; + } + // @} + + + /// \name Fixed pipeline lights + // @{ /** * return the number of light supported by driver. typically 8. * * \see enableLight() setLight() */ - virtual uint getMaxLight () const = 0; + virtual uint getMaxLight() const = 0; /** * Setup a light. @@ -932,7 +1044,7 @@ public: * \param light is a light to set in this slot. * \see enableLight() */ - virtual void setLight (uint8 num, const CLight& light) = 0; + virtual void setLight(uint8 num, const CLight &light) = 0; /** * Enable / disable light. @@ -943,7 +1055,7 @@ public: * \param enable is true to enable the light, false to disable it. * \see setLight() */ - virtual void enableLight (uint8 num, bool enable=true) = 0; + virtual void enableLight(uint8 num, bool enable = true) = 0; /** * Set ambient. @@ -951,112 +1063,134 @@ public: * \param color is the new global ambient color for the scene. * \see setLight(), enableLight() */ - virtual void setAmbientColor (CRGBA color) = 0; + virtual void setAmbientColor(NLMISC::CRGBA color) = 0; /** Setup the light used for per pixel lighting. The given values should have been modulated by the material diffuse and specular. * This is only useful for material that have their shader set as 'PerPixelLighting' * \param the light used for per pixel lighting */ - virtual void setPerPixelLightingLight(CRGBA diffuse, CRGBA specular, float shininess) = 0; + virtual void setPerPixelLightingLight(NLMISC::CRGBA diffuse, NLMISC::CRGBA specular, float shininess) = 0; /** Setup the unique light used for Lightmap Shader. * Lightmaped primitives are lit per vertex with this light (should be local attenuated for maximum efficiency) * This is only useful for material that have their shader set as 'LightMap' * \param the light used for per pixel lighting */ - virtual void setLightMapDynamicLight (bool enable, const CLight& light) = 0; + virtual void setLightMapDynamicLight(bool enable, const CLight &light) = 0; + // @} - /** Get the global polygon mode. - * - * \param polygon mode choose in this driver. - * \see setPolygonMode(), TPolygonMode - */ - TPolygonMode getPolygonMode () - { - return _PolygonMode; - } - /// \name Vertex program interface + + /// \name Vertex Program // @{ - enum TMatrix - { - ModelView= 0, - Projection, - ModelViewProjection, - NumMatrix - }; - - enum TTransform - { - Identity=0, - Inverse, - Transpose, - InverseTranspose, - NumTransform - }; - - /** - * Does the driver supports vertex programs ? - */ - virtual bool supportVertexProgram () const =0; + // Order of preference + // - activeVertexProgram + // - CMaterial pass[n] VP (uses activeVertexProgram, but does not override if one already set by code) + // - default generic VP that mimics fixed pipeline / no VP with fixed pipeline /** * Does the driver supports vertex program, but emulated by CPU ? */ - virtual bool isVertexProgramEmulated () const =0; + virtual bool isVertexProgramEmulated() const = 0; - /** - * Does the driver supports pixel programs ? + /** Return true if the driver supports the specified vertex program profile. */ - virtual bool supportPixelProgram() const =0; - virtual bool supportPixelProgram(CPixelProgram::TProfile profile) const =0; + virtual bool supportVertexProgram(CVertexProgram::TProfile profile = CVertexProgram::nelvp) const = 0; - - - /** - * Activate / disactivate a vertex program - * - * \param program is a pointer on a vertex program. Can be NULL to disable the current vertex program. - * - * \return true if setup/unsetup succeeded, false else. + /** Compile the given vertex program, return if successful. Error information is returned as a string. */ - virtual bool activeVertexProgram (CVertexProgram *program) =0; + virtual bool compileVertexProgram(CVertexProgram *program, std::string &error) const = 0; - /** - * Activate / disactivate a pixel program - * - * \param program is a pointer on a pixel program. Can be NULL to disable the current pixel program. - * - * \return true if setup/unsetup successed, false else. - */ - virtual bool activePixelProgram (CPixelProgram *program) =0; - - /** - * Setup vertex program constant (uniform) values. + /** Set the active vertex program. This will override vertex programs specified in CMaterial render calls. + * Also used internally by setupMaterial(CMaterial) when getVertexProgram returns NULL. + * The vertex program is activated immediately. */ - virtual void setConstant (uint index, float, float, float, float) =0; - virtual void setConstant (uint index, double, double, double, double) =0; - virtual void setConstant (uint index, const NLMISC::CVector& value) =0; - virtual void setConstant (uint index, const NLMISC::CVectorD& value) =0; + virtual bool activeVertexProgram(CVertexProgram *program) = 0; + + /** Get the currently active vertex program. + */ + virtual CVertexProgram *getActiveVertexProgram() const = 0; + + // Set parameters + virtual void setVertexProgram1f(uint index, float f0) = 0; + virtual void setVertexProgram2f(uint index, float f0, float f1) = 0; + virtual void setVertexProgram3f(uint index, float f0, float f1, float f2) = 0; + virtual void setVertexProgram4f(uint index, float f0, float f1, float f2, float f3) = 0; + virtual void setVertexProgram1i(uint index, sint32 i0) = 0; + virtual void setVertexProgram2i(uint index, sint32 i0, sint32 i1) = 0; + virtual void setVertexProgram3i(uint index, sint32 i0, sint32 i1, sint32 i2) = 0; + virtual void setVertexProgram4i(uint index, sint32 i0, sint32 i1, sint32 i2, sint32 i3) = 0; + virtual void setVertexProgram3f(uint index, const NLMISC::CVector& v) = 0; + virtual void setVertexProgram4f(uint index, const NLMISC::CVector& v, float f3) = 0; + virtual void setVertexProgram4x4f(uint index, const NLMISC::CMatrix& m) = 0; + virtual void setVertexProgram1fv(uint index, size_t num, const float *src) = 0; + virtual void setVertexProgram2fv(uint index, size_t num, const float *src) = 0; + virtual void setVertexProgram3fv(uint index, size_t num, const float *src) = 0; + virtual void setVertexProgram4fv(uint index, size_t num, const float *src) = 0; + // @} + + + + /// \name Pixel Program + // @{ + + // Order of preference + // - activePixelProgram + // - CMaterial pass[n] PP (uses activePixelProgram, but does not override if one already set by code) + // - PP generated from CMaterial (uses activePixelProgram, but does not override if one already set by code) + + /** Return true if the driver supports the specified pixel program profile. + */ + virtual bool supportPixelProgram(CPixelProgram::TProfile profile = CPixelProgram::nelvp) const = 0; + + /** Compile the given pixel program, return if successful. Error information is returned as a string. + */ + virtual bool compilePixelProgram(CPixelProgram *program, std::string &error) const = 0; + + /** Set the active pixel program. This will override pixel programs specified in CMaterial render calls. + * Also used internally by setupMaterial(CMaterial) when getPixelProgram returns NULL. + * The pixel program is activated immediately. + */ + virtual bool activePixelProgram(CPixelProgram *program) = 0; + + /** Get the currently active pixel program. + */ + virtual CPixelProgram *getActivePixelProgram() const = 0; + + // Set parameters + virtual void setPixelProgram1f(uint index, float f0) = 0; + virtual void setPixelProgram2f(uint index, float f0, float f1) = 0; + virtual void setPixelProgram3f(uint index, float f0, float f1, float f2) = 0; + virtual void setPixelProgram4f(uint index, float f0, float f1, float f2, float f3) = 0; + virtual void setPixelProgram1i(uint index, sint32 i0) = 0; + virtual void setPixelProgram2i(uint index, sint32 i0, sint32 i1) = 0; + virtual void setPixelProgram3i(uint index, sint32 i0, sint32 i1, sint32 i2) = 0; + virtual void setPixelProgram4i(uint index, sint32 i0, sint32 i1, sint32 i2, sint32 i3) = 0; + virtual void setPixelProgram3f(uint index, const NLMISC::CVector& v) = 0; + virtual void setPixelProgram4f(uint index, const NLMISC::CVector& v, float f3) = 0; + virtual void setPixelProgram4x4f(uint index, const NLMISC::CMatrix& m) = 0; + virtual void setPixelProgram1fv(uint index, size_t num, const float *src) = 0; + virtual void setPixelProgram2fv(uint index, size_t num, const float *src) = 0; + virtual void setPixelProgram3fv(uint index, size_t num, const float *src) = 0; + virtual void setPixelProgram4fv(uint index, size_t num, const float *src) = 0; + // @} + + + + /// \name Legacy vertex program parameter setters + // @{ + /** + * Setup constant values. + */ + inline void setConstant(uint index, float f0, float f1, float f2, float f3) { setVertexProgram4f(index, f0, f1, f2, f3); } + inline void setConstant(uint index, double d0, double d1, double d2, double d3) { setVertexProgram4f(index, (float)d0, (float)d1, (float)d2, (float)d3); } + inline void setConstant(uint index, const NLMISC::CVector &value) { setVertexProgram4f(index, value, 0.f); } + inline void setConstant(uint index, const NLMISC::CVectorD &value) { setVertexProgram4f(index, (float)value.x, (float)value.y, (float)value.z, 0.f); } /// setup several 4 float csts taken from the given tab - virtual void setConstant (uint index, uint num, const float *src) =0; - /// setup several 4 double csts taken from the given tab - virtual void setConstant (uint index, uint num, const double *src) =0; - // TODO: rename to setVertexProgramConstant - - /** - * Setup pixel program constant (uniform) values. - */ - virtual void setPixelProgramConstant (uint index, float, float, float, float) =0; - virtual void setPixelProgramConstant (uint index, double, double, double, double) =0; - virtual void setPixelProgramConstant (uint index, const NLMISC::CVector& value) =0; - virtual void setPixelProgramConstant (uint index, const NLMISC::CVectorD& value) =0; - /// setup several 4 float csts taken from the given tab - virtual void setPixelProgramConstant (uint index, uint num, const float *src) =0; - /// setup several 4 double csts taken from the given tab - virtual void setPixelProgramConstant (uint index, uint num, const double *src) =0; - // TODO: uint32 and sint32 uniform types supported in opengl from gp4fp and gp5fp and sint32 in d3d + inline void setConstant(uint index, uint num, const float *src) { setVertexProgram4fv(index, num, src); } + /// setup several 4 double csts taken from the given tab (convert to float) + virtual void setConstant(uint index, uint num, const double *src) = 0; /** * Setup constants with a current matrix. @@ -1069,20 +1203,7 @@ public: * \param transform is the transformation to apply to the matrix before store it in the constants. * */ - virtual void setPixelProgramConstantMatrix (uint index, TMatrix matrix, TTransform transform) =0; - - /** - * Setup constants with a current matrix. - * - * This call must be done after setFrustum(), setupViewMatrix() or setupModelMatrix() to get correct - * results. - * - * \param index is the base constant index where to store the matrix. This index must be a multiple of 4. - * \param matrix is the matrix id to store in the constants - * \param transform is the transformation to apply to the matrix before store it in the constants. - * - */ - virtual void setConstantMatrix (uint index, TMatrix matrix, TTransform transform) =0; + virtual void setConstantMatrix(uint index, TMatrix matrix, TTransform transform) = 0; /** * Setup the constant with the fog vector. This vector must be used to get the final fog value in a vertex shader. @@ -1096,14 +1217,26 @@ public: * \param index is the index where to store the vector. * */ - virtual void setConstantFog (uint index) =0; + virtual void setConstantFog(uint index) = 0; + // @} - /// Check if the driver support double sided colors vertex programs - virtual bool supportVertexProgramDoubleSidedColor() const = 0; + + /// \name Legacy effects + // @{ // test if support for cloud render in a single pass virtual bool supportCloudRenderSinglePass() const = 0; + // [FIXME] Return true if driver support Bloom effect // FIXME: This is terrible + virtual bool supportBloomEffect() const = 0; + // @} + + + + /// \name Backface color + // @{ + /// Check if the driver support double sided colors vertex programs + virtual bool supportVertexProgramDoubleSidedColor() const = 0; /** * Activate VertexProgram 2Sided Color mode. In 2Sided mode, the BackFace (if material 2Sided enabled) read the * result from o[BFC0], and not o[COL0]. @@ -1111,27 +1244,29 @@ public: * NB: no-op if not supported by driver */ virtual void enableVertexProgramDoubleSidedColor(bool doubleSided) =0; - // @} + + /// \name Texture addressing modes aka textures/pixels shaders // @{ - /// test whether the device supports some form of texture shader. (could be limited to DX6 EMBM for example) - virtual bool supportTextureShaders() const = 0; - // Is the shader water supported ? If not, the driver caller should implement its own version - virtual bool supportWaterShader() const = 0; - // - /// test whether a texture addressing mode is supported - virtual bool supportTextureAddrMode(CMaterial::TTexAddressingMode mode) const = 0; - /** setup the 2D matrix for the OffsetTexture, OffsetTextureScale and OffsetTexture addressing mode - * It should be stored as the following - * [a0 a1] - * [a2 a3] - */ - virtual void setMatrix2DForTextureOffsetAddrMode(const uint stage, const float mat[4]) = 0; + /// test whether the device supports some form of texture shader. (could be limited to DX6 EMBM for example) + virtual bool supportTextureShaders() const = 0; + // Is the shader water supported ? If not, the driver caller should implement its own version + virtual bool supportWaterShader() const = 0; + // + /// test whether a texture addressing mode is supported + virtual bool supportTextureAddrMode(CMaterial::TTexAddressingMode mode) const = 0; + /** setup the 2D matrix for the OffsetTexture, OffsetTextureScale and OffsetTexture addressing mode + * It should be stored as the following + * [a0 a1] + * [a2 a3] + */ + virtual void setMatrix2DForTextureOffsetAddrMode(const uint stage, const float mat[4]) = 0; //@} + /** \name EMBM support. If texture shaders are present, this is not available, must use them instead. * EMBM is a color op of CMaterial. * NB : EMBM is the equivalent of the CMaterial::OffsetTexture addressing mode. However, it is both a texture @@ -1143,38 +1278,35 @@ public: */ // @{ - // Test if EMBM is supported. - virtual bool supportEMBM() const = 0; - // Test if EMBM is supported for the given stage - virtual bool isEMBMSupportedAtStage(uint stage) const = 0; - // set the matrix used for EMBM addressing - virtual void setEMBMMatrix(const uint stage, const float mat[4]) = 0; + // Test if EMBM is supported. + virtual bool supportEMBM() const = 0; + // Test if EMBM is supported for the given stage + virtual bool isEMBMSupportedAtStage(uint stage) const = 0; + // set the matrix used for EMBM addressing + virtual void setEMBMMatrix(const uint stage, const float mat[4]) = 0; // @} - // Does the driver support the per-pixel lighting shader ? - virtual bool supportPerPixelLighting(bool specular) const = 0; /// \name Misc // @{ - /** Does the driver support Blend Constant Color ??? If yes CMaterial::blendConstant* enum can be used * for blend Src ord Dst factor. If no, using these enum will have undefined results. */ - virtual bool supportBlendConstantColor() const =0; + virtual bool supportBlendConstantColor() const = 0; /** see supportBlendConstantColor(). Set the current Blend Constant Color. */ - virtual void setBlendConstantColor(NLMISC::CRGBA col)=0; + virtual void setBlendConstantColor(NLMISC::CRGBA col) = 0; /** see supportBlendConstantColor(). Get the current Blend Constant Color. */ - virtual NLMISC::CRGBA getBlendConstantColor() const =0; + virtual NLMISC::CRGBA getBlendConstantColor() const = 0; /** force the driver to flush all command. glFinish() in opengl. * Interesting only for debug and profiling purpose. */ - virtual void finish() =0; + virtual void finish() = 0; // Flush command queue an immediately returns virtual void flush() = 0; @@ -1183,27 +1315,27 @@ public: * See GL_POLYGON_SMOOTH help, and GL_SRC_ALPHA_SATURATE OpenGL doc (not yet implemented now since * used only for alpha part in ShadowMap gen) */ - virtual void enablePolygonSmoothing(bool smooth) =0; + virtual void enablePolygonSmoothing(bool smooth) = 0; /// see enablePolygonSmoothing() - virtual bool isPolygonSmoothingEnabled() const =0; - + virtual bool isPolygonSmoothingEnabled() const = 0; // @} + /** Special method to internally swap the Driver handle of 2 textures. * USE IT WITH CARE (eg: may have Size problems, mipmap problems, format problems ...) * Actually, it is used only by CAsyncTextureManager, to manage Lods of DXTC CTextureFile. * NB: internally, all textures slots are disabled. */ - virtual void swapTextureHandle(ITexture &tex0, ITexture &tex1) =0; + virtual void swapTextureHandle(ITexture &tex0, ITexture &tex1) = 0; /** Advanced usage. Get the texture Handle.Useful for texture sorting for instance * NB: if the texture is not setuped in the driver, 0 is returned. * NB: if implementation does not support it, 0 may be returned. OpenGL ones return the Texture ID. * NB: unlike isTextureExist(), this method is not thread safe. */ - virtual uint getTextureHandle(const ITexture&tex)=0; + virtual uint getTextureHandle(const ITexture&tex) = 0; // see if the Multiply-Add Tex Env operator is supported (see CMaterial::Mad) virtual bool supportMADOperator() const = 0; @@ -1224,16 +1356,16 @@ public: }; // Get the number of hardware renderer available on the client platform. - virtual uint getNumAdapter() const=0; + virtual uint getNumAdapter() const = 0; // Get a hardware renderer description. - virtual bool getAdapter(uint adapter, CAdapter &desc) const=0; + virtual bool getAdapter(uint adapter, CAdapter &desc) const = 0; /** Choose the hardware renderer. * Call it before the setDisplay and enumModes methods * Choose adapter = 0xffffffff for the default one. */ - virtual bool setAdapter(uint adapter)=0; + virtual bool setAdapter(uint adapter) = 0; /** Tell if the vertex color memory format is RGBA (openGL) or BGRA (directx) * BGRA : @@ -1247,20 +1379,22 @@ public: */ virtual CVertexBuffer::TVertexColorType getVertexColorFormat() const =0; + + /// \name Bench // @{ - // Start the bench. See CHTimer::startBench(); - virtual void startBench (bool wantStandardDeviation = false, bool quick = false, bool reset = true) =0; + virtual void startBench(bool wantStandardDeviation = false, bool quick = false, bool reset = true) =0; // End the bench. See CHTimer::endBench(); - virtual void endBench () =0; + virtual void endBench () =0; // Display the bench result - virtual void displayBench (class NLMISC::CLog *log) =0; - + virtual void displayBench (class NLMISC::CLog *log) =0; // @} + + /// \name Occlusion query mechanism // @{ // Test whether this device supports the occlusion query mechanism @@ -1273,8 +1407,8 @@ public: virtual void deleteOcclusionQuery(IOcclusionQuery *oq) = 0; // @} - // get the number of call to swapBuffer since the driver was created - virtual uint64 getSwapBufferCounter() const = 0; + + /** Set cull mode * Useful for mirrors / cube map rendering or when the scene must be rendered upside down @@ -1291,23 +1425,25 @@ public: virtual void stencilMask(uint mask) = 0; protected: - friend class IVBDrvInfos; - friend class IIBDrvInfos; - friend class CTextureDrvShare; - friend class ITextureDrvInfos; - friend class IMaterialDrvInfos; - friend class IGPUProgramDrvInfos; + friend class IVBDrvInfos; + friend class IIBDrvInfos; + friend class CTextureDrvShare; + friend class ITextureDrvInfos; + friend class IMaterialDrvInfos; + friend class IGPUProgramDrvInfos; + friend class IGPUProgramParamsDrvInfos; /// remove ptr from the lists in the driver. - void removeVBDrvInfoPtr(ItVBDrvInfoPtrList vbDrvInfoIt); - void removeIBDrvInfoPtr(ItIBDrvInfoPtrList ibDrvInfoIt); - void removeTextureDrvInfoPtr(ItTexDrvInfoPtrMap texDrvInfoIt); - void removeTextureDrvSharePtr(ItTexDrvSharePtrList texDrvShareIt); - void removeMatDrvInfoPtr(ItMatDrvInfoPtrList shaderIt); - void removeGPUPrgDrvInfoPtr(ItGPUPrgDrvInfoPtrList gpuPrgDrvInfoIt); + void removeVBDrvInfoPtr(ItVBDrvInfoPtrList vbDrvInfoIt); + void removeIBDrvInfoPtr(ItIBDrvInfoPtrList ibDrvInfoIt); + void removeTextureDrvInfoPtr(ItTexDrvInfoPtrMap texDrvInfoIt); + void removeTextureDrvSharePtr(ItTexDrvSharePtrList texDrvShareIt); + void removeMatDrvInfoPtr(ItMatDrvInfoPtrList shaderIt); + void removeGPUPrgDrvInfoPtr(ItGPUPrgDrvInfoPtrList gpuPrgDrvInfoIt); private: - bool _StaticMemoryToVRAM; + bool _StaticMemoryToVRAM; + }; // -------------------------------------------------- diff --git a/code/nel/include/nel/3d/driver_user.h b/code/nel/include/nel/3d/driver_user.h index fff83d6d5..30ea98c65 100644 --- a/code/nel/include/nel/3d/driver_user.h +++ b/code/nel/include/nel/3d/driver_user.h @@ -474,7 +474,6 @@ public: virtual void forceDXTCCompression(bool dxtcComp); virtual void setAnisotropicFilter(sint filter); virtual void forceTextureResize(uint divisor); - virtual void forceNativeFragmentPrograms(bool nativeOnly); virtual bool setMonitorColorProperties (const CMonitorColorProperties &properties); // @} diff --git a/code/nel/include/nel/3d/gpu_program_params.h b/code/nel/include/nel/3d/gpu_program_params.h index d1a3125a2..08d8010d4 100644 --- a/code/nel/include/nel/3d/gpu_program_params.h +++ b/code/nel/include/nel/3d/gpu_program_params.h @@ -48,10 +48,10 @@ namespace NL3D { * \brief CGPUProgramParams * \date 2013-09-07 22:17GMT * \author Jan Boon (Kaetemi) - * A storage for user-provided parameters for GPU programs. + * A storage for USERCODE-PROVIDED parameters for GPU programs. * Allows for fast updating and iteration of parameters. * NOTE TO DRIVER IMPLEMENTORS: DO NOT USE FOR STORING COPIES - * OF HARDCODED MATERIAL PARAMETERS OR DRIVER PARAMETERS!!! + * OF HARDCODED DRIVER MATERIAL PARAMETERS OR DRIVER PARAMETERS!!! */ class CGPUProgramParams { @@ -66,36 +66,70 @@ public: CGPUProgramParams(); virtual ~CGPUProgramParams(); - void setF(uint index, float f0); - void setF(uint index, float f0, float f1); - void setF(uint index, float f0, float f1, float f2); - void setF(uint index, float f0, float f1, float f2, float f3); - void setI(uint index, int i0); - void setI(uint index, int i0, int i1); - void setI(uint index, int i0, int i1, int i2); - void setI(uint index, int i0, int i1, int i2, int i3); - void setF(uint index, const NLMISC::CVector& v); - void setF(uint index, const NLMISC::CMatrix& m); - void setF(uint index, uint num, const float *src); + // Copy from another params storage + void copy(CGPUProgramParams *params); + + // Set by index, available only when the associated program has been compiled + void set1f(uint index, float f0); + void set2f(uint index, float f0, float f1); + void set3f(uint index, float f0, float f1, float f2); + void set4f(uint index, float f0, float f1, float f2, float f3); + void set1i(uint index, sint32 i0); + void set2i(uint index, sint32 i0, sint32 i1); + void set3i(uint index, sint32 i0, sint32 i1, sint32 i2); + void set4i(uint index, sint32 i0, sint32 i1, sint32 i2, sint32 i3); + void set3f(uint index, const NLMISC::CVector& v); + void set4f(uint index, const NLMISC::CVector& v, float f3); + void set4x4f(uint index, const NLMISC::CMatrix& m); + void set1fv(uint index, size_t num, const float *src); + void set2fv(uint index, size_t num, const float *src); + void set3fv(uint index, size_t num, const float *src); + void set4fv(uint index, size_t num, const float *src); + void unset(uint index); + + // Set by name, it is recommended to use index when repeatedly setting an element + void set1f(const std::string &name, float f0); + void set2f(const std::string &name, float f0, float f1); + void set3f(const std::string &name, float f0, float f1, float f2); + void set4f(const std::string &name, float f0, float f1, float f2, float f3); + void set1i(const std::string &name, sint32 i0); + void set2i(const std::string &name, sint32 i0, sint32 i1); + void set3i(const std::string &name, sint32 i0, sint32 i1, sint32 i2); + void set4i(const std::string &name, sint32 i0, sint32 i1, sint32 i2, sint32 i3); + void set3f(const std::string &name, const NLMISC::CVector& v); + void set4f(const std::string &name, const NLMISC::CVector& v, float f3); + void set4x4f(const std::string &name, const NLMISC::CMatrix& m); + void set1fv(const std::string &name, size_t num, const float *src); + void set2fv(const std::string &name, size_t num, const float *src); + void set3fv(const std::string &name, size_t num, const float *src); + void set4fv(const std::string &name, size_t num, const float *src); + void unset(const std::string &name); + + /// Maps the given name to the given index, on duplicate entry the data set by name will be prefered as it can be assumed to have been set after the data set by index + void map(uint index, const std::string &name); // Internal /// Allocate specified number of components if necessary size_t allocOffset(uint index, uint count, TType type); + size_t allocOffset(const std::string &name, uint count, TType type); /// Return offset for specified index size_t getOffset(uint index) const; + size_t getOffset(const std::string &name) const; /// Remove by offset void freeOffset(size_t offset); - // Iteration + // Iteration (returns the offsets for access using getFooByOffset) size_t getBegin() const { return m_Meta.size() ? m_First : s_End; } size_t getNext(size_t offset) const { return m_Meta[offset].Next; } size_t getEnd() const { return s_End; } // Data access - uint getCountByOffset(size_t offset) { return m_Meta[offset].Count; } + uint getCountByOffset(size_t offset) { return m_Meta[offset].Count; } // component count (number of floats or ints) float *getPtrFByOffset(size_t offset) { return m_Vec[offset].F; } int *getPtrIByOffset(size_t offset) { return m_Vec[offset].I; } TType getTypeByOffset(size_t offset) { return m_Meta[offset].Type; } + uint getIndexByOffset(size_t offset) { return m_Meta[offset].Index; } + const std::string *getNameByOffset(size_t offset); // non-optimized for dev tools only, may return NULL if name unknown // Utility static inline uint getNbRegistersByComponents(uint count) { return (count + 3) >> 2; } // vector register per 4 components @@ -103,7 +137,8 @@ public: private: std::vector m_Vec; std::vector m_Meta; - std::vector m_Map; // map from index to buffer index + std::vector m_Map; // map from index to offset + std::map m_MapName; // map from name to offset size_t m_First; size_t m_Last; static const size_t s_End = -1; diff --git a/code/nel/include/nel/3d/u_driver.h b/code/nel/include/nel/3d/u_driver.h index 1397c9c6e..2e74ae3fe 100644 --- a/code/nel/include/nel/3d/u_driver.h +++ b/code/nel/include/nel/3d/u_driver.h @@ -673,13 +673,6 @@ public: */ virtual void forceTextureResize(uint divisor)=0; - /** Sets enforcement of native fragment programs. This is by default enabled. - * - * \param nativeOnly If set to false, fragment programs don't need to be native to stay loaded, - * otherwise (aka if true) they will be purged. - */ - virtual void forceNativeFragmentPrograms(bool nativeOnly) = 0; - /** Setup monitor color properties. * * Return false if setup failed. diff --git a/code/nel/src/3d/driver.cpp b/code/nel/src/3d/driver.cpp index 31dd4d2ec..2bfb0ea1f 100644 --- a/code/nel/src/3d/driver.cpp +++ b/code/nel/src/3d/driver.cpp @@ -240,24 +240,9 @@ void IDriver::removeMatDrvInfoPtr(ItMatDrvInfoPtrList shaderIt) _MatDrvInfos.erase(shaderIt); } // *************************************************************************** -/*void IDriver::removeShaderDrvInfoPtr(ItShaderDrvInfoPtrList shaderIt) +void IDriver::removeGPUPrgDrvInfoPtr(ItGPUPrgDrvInfoPtrList gpuPrgDrvInfoIt) { - _ShaderDrvInfos.erase(shaderIt); -} -// *************************************************************************** -void IDriver::removeVtxPrgDrvInfoPtr(ItVtxPrgDrvInfoPtrList vtxPrgDrvInfoIt) -{ - _VtxPrgDrvInfos.erase(vtxPrgDrvInfoIt); -} -// *************************************************************************** -void IDriver::removePixelPrgDrvInfoPtr(ItPixelPrgDrvInfoPtrList pixelPrgDrvInfoIt) -{ - _PixelPrgDrvInfos.erase(pixelPrgDrvInfoIt); -}*/ -// *************************************************************************** -void IDriver::removeGPUPrgDrvInfoPtr(ItGPUPrgDrvInfoPtrList vtxPrgDrvInfoIt) -{ - _GPUPrgDrvInfos.erase(vtxPrgDrvInfoIt); + _GPUPrgDrvInfos.erase(gpuPrgDrvInfoIt); } // *************************************************************************** diff --git a/code/nel/src/3d/driver/direct3d/driver_direct3d.h b/code/nel/src/3d/driver/direct3d/driver_direct3d.h index d329a6f56..3494812cc 100644 --- a/code/nel/src/3d/driver/direct3d/driver_direct3d.h +++ b/code/nel/src/3d/driver/direct3d/driver_direct3d.h @@ -880,7 +880,6 @@ public: virtual void forceDXTCCompression(bool dxtcComp); virtual void setAnisotropicFilter(sint filter); virtual void forceTextureResize(uint divisor); - virtual void forceNativeFragmentPrograms(bool /* nativeOnly */) {} // ignored // Driver information virtual uint getNumAdapter() const; diff --git a/code/nel/src/3d/driver/opengl/driver_opengl.cpp b/code/nel/src/3d/driver/opengl/driver_opengl.cpp index a93c05338..3eff7eebf 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl.cpp @@ -1993,12 +1993,6 @@ static void fetchPerturbedEnvMapR200() #endif } -// *************************************************************************** -void CDriverGL::forceNativeFragmentPrograms(bool nativeOnly) -{ - _ForceNativeFragmentPrograms = nativeOnly; -} - // *************************************************************************** void CDriverGL::initFragmentShaders() { diff --git a/code/nel/src/3d/driver/opengl/driver_opengl.h b/code/nel/src/3d/driver/opengl/driver_opengl.h index 29fd59957..89b71c931 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl.h +++ b/code/nel/src/3d/driver/opengl/driver_opengl.h @@ -370,8 +370,6 @@ public: virtual void forceTextureResize(uint divisor); - virtual void forceNativeFragmentPrograms(bool nativeOnly); - /// Setup texture env functions. Used by setupMaterial void setTextureEnvFunction(uint stage, CMaterial& mat); diff --git a/code/nel/src/3d/driver_user.cpp b/code/nel/src/3d/driver_user.cpp index 83c7343ec..e5d814755 100644 --- a/code/nel/src/3d/driver_user.cpp +++ b/code/nel/src/3d/driver_user.cpp @@ -1496,12 +1496,6 @@ void CDriverUser::forceTextureResize(uint divisor) _Driver->forceTextureResize(divisor); } -void CDriverUser::forceNativeFragmentPrograms(bool nativeOnly) -{ - NL3D_HAUTO_UI_DRIVER; - - _Driver->forceNativeFragmentPrograms(nativeOnly); -} bool CDriverUser::setMonitorColorProperties (const CMonitorColorProperties &properties) { NL3D_HAUTO_UI_DRIVER; diff --git a/code/nel/src/3d/gpu_program_params.cpp b/code/nel/src/3d/gpu_program_params.cpp index 0a03500ea..217a9683e 100644 --- a/code/nel/src/3d/gpu_program_params.cpp +++ b/code/nel/src/3d/gpu_program_params.cpp @@ -36,6 +36,7 @@ #include // Project includes +#include using namespace std; // using namespace NLMISC; @@ -52,20 +53,20 @@ CGPUProgramParams::~CGPUProgramParams() } -void CGPUProgramParams::setF(uint index, float f0) +void CGPUProgramParams::set(uint index, float f0) { float *f = getPtrFByOffset(allocOffset(index, 1, Float)); f[0] = f0; } -void CGPUProgramParams::setF(uint index, float f0, float f1) +void CGPUProgramParams::set(uint index, float f0, float f1) { float *f = getPtrFByOffset(allocOffset(index, 2, Float)); f[0] = f0; f[1] = f1; } -void CGPUProgramParams::setF(uint index, float f0, float f1, float f2) +void CGPUProgramParams::set(uint index, float f0, float f1, float f2) { float *f = getPtrFByOffset(allocOffset(index, 3, Float)); f[0] = f0; @@ -73,7 +74,7 @@ void CGPUProgramParams::setF(uint index, float f0, float f1, float f2) f[2] = f2; } -void CGPUProgramParams::setF(uint index, float f0, float f1, float f2, float f3) +void CGPUProgramParams::set(uint index, float f0, float f1, float f2, float f3) { float *f = getPtrFByOffset(allocOffset(index, 4, Float)); f[0] = f0; @@ -82,20 +83,20 @@ void CGPUProgramParams::setF(uint index, float f0, float f1, float f2, float f3) f[3] = f3; } -void CGPUProgramParams::setI(uint index, int i0) +void CGPUProgramParams::set(uint index, int i0) { int *i = getPtrIByOffset(allocOffset(index, 1, Int)); i[0] = i0; } -void CGPUProgramParams::setI(uint index, int i0, int i1) +void CGPUProgramParams::set(uint index, int i0, int i1) { int *i = getPtrIByOffset(allocOffset(index, 2, Int)); i[0] = i0; i[1] = i1; } -void CGPUProgramParams::setI(uint index, int i0, int i1, int i2) +void CGPUProgramParams::set(uint index, int i0, int i1, int i2) { int *i = getPtrIByOffset(allocOffset(index, 3, Int)); i[0] = i0; @@ -103,7 +104,7 @@ void CGPUProgramParams::setI(uint index, int i0, int i1, int i2) i[2] = i2; } -void CGPUProgramParams::setI(uint index, int i0, int i1, int i2, int i3) +void CGPUProgramParams::set(uint index, int i0, int i1, int i2, int i3) { int *i = getPtrIByOffset(allocOffset(index, 4, Int)); i[0] = i0; @@ -112,7 +113,7 @@ void CGPUProgramParams::setI(uint index, int i0, int i1, int i2, int i3) i[3] = i3; } -void CGPUProgramParams::setF(uint index, const NLMISC::CVector& v) +void CGPUProgramParams::set(uint index, const NLMISC::CVector& v) { float *f = getPtrFByOffset(allocOffset(index, 3, Float)); f[0] = v.x; @@ -120,7 +121,7 @@ void CGPUProgramParams::setF(uint index, const NLMISC::CVector& v) f[2] = v.z; } -void CGPUProgramParams::setF(uint index, const NLMISC::CMatrix& m) +void CGPUProgramParams::set(uint index, const NLMISC::CMatrix& m) { // TODO: Verify this! float *f = getPtrFByOffset(allocOffset(index, 16, Float)); @@ -129,11 +130,18 @@ void CGPUProgramParams::setF(uint index, const NLMISC::CMatrix& m) mt.get(f); } -void CGPUProgramParams::setF(uint index, uint num, const float *src) +void CGPUProgramParams::set(uint index, const float *arr, size_t sz) { - float *f = getPtrFByOffset(allocOffset(index, num, Float)); - for (uint i = 0; i < num; ++i) - f[i] = src[i]; + float *f = getPtrFByOffset(allocOffset(index, sz, Float)); + for (uint c = 0; c < sz; ++c) + f[c] = arr[c]; +} + +void CGPUProgramParams::set(uint index, const sint32 *arr, size_t sz) +{ + int *i = getPtrIByOffset(allocOffset(index, sz, Int)); + for (uint c = 0; c < sz; ++c) + i[c] = arr[c]; } /// Allocate specified number of components if necessary diff --git a/code/nel/src/3d/stereo_ovr.cpp b/code/nel/src/3d/stereo_ovr.cpp index 8c8c6ff63..e02ccd50c 100644 --- a/code/nel/src/3d/stereo_ovr.cpp +++ b/code/nel/src/3d/stereo_ovr.cpp @@ -563,6 +563,7 @@ bool CStereoOVR::endRenderTarget() NL3D::IDriver *drvInternal = (static_cast(m_Driver))->getDriver(); NL3D::CMaterial *barrelMat = m_BarrelMat.getObjectPtr(); barrelMat->setTexture(0, m_BarrelTex); + drvInternal->activePixelProgram(m_PixelProgram); float w = float(m_BarrelQuadLeft.V1.x),// / float(width), @@ -582,20 +583,21 @@ bool CStereoOVR::endRenderTarget() float scaleY = (h / 2); float scaleInX = (2 / w); float scaleInY = (2 / h); - drvInternal->setPixelProgramConstant(0, lensCenterX, lensCenterY, 0.f, 0.f); - drvInternal->setPixelProgramConstant(1, screenCenterX, screenCenterY, 0.f, 0.f); - drvInternal->setPixelProgramConstant(2, scaleX, scaleY, 0.f, 0.f); - drvInternal->setPixelProgramConstant(3, scaleInX, scaleInY, 0.f, 0.f); - drvInternal->setPixelProgramConstant(4, 1, m_DevicePtr->HMDInfo.DistortionK); - + + drvInternal->setPixelProgram2f(0, lensCenterX, lensCenterY); + drvInternal->setPixelProgram2f(1, screenCenterX, screenCenterY); + drvInternal->setPixelProgram2f(2, scaleX, scaleY); + drvInternal->setPixelProgram2f(3, scaleInX, scaleInY); + drvInternal->setPixelProgram4fv(4, 1, m_DevicePtr->HMDInfo.DistortionK); m_Driver->drawQuad(m_BarrelQuadLeft, m_BarrelMat); x = w; lensCenterX = x + (w - lensViewportShift * 0.5f) * 0.5f; screenCenterX = x + w * 0.5f; - drvInternal->setPixelProgramConstant(0, lensCenterX, lensCenterY, 0.f, 0.f); - drvInternal->setPixelProgramConstant(1, screenCenterX, screenCenterY, 0.f, 0.f); + + drvInternal->setPixelProgram2f(0, lensCenterX, lensCenterY); + drvInternal->setPixelProgram2f(1, screenCenterX, screenCenterY); m_Driver->drawQuad(m_BarrelQuadRight, m_BarrelMat);