Cleanup driver interface

--HG--
branch : multipass-stereo
hg/feature/sound
kaetemi 12 years ago
parent 235bfcfd94
commit 05583d134a

@ -31,6 +31,7 @@
#include "nel/3d/vertex_program.h" #include "nel/3d/vertex_program.h"
#include "nel/3d/pixel_program.h" #include "nel/3d/pixel_program.h"
#include "nel/3d/geometry_program.h" #include "nel/3d/geometry_program.h"
#include "nel/3d/gpu_program_params.h"
#include "nel/3d/material.h" #include "nel/3d/material.h"
#include "nel/misc/mutex.h" #include "nel/misc/mutex.h"
#include "nel/3d/primitive_profile.h" #include "nel/3d/primitive_profile.h"
@ -134,7 +135,6 @@ public:
*/ */
enum TPolygonMode { Filled = 0, Line, Point }; enum TPolygonMode { Filled = 0, Line, Point };
/** /**
* Driver Max matrix count. * Driver Max matrix count.
* Kept for backward compatibility. Suppose any Hardware VertexProgram can handle only 16 matrix * Kept for backward compatibility. Suppose any Hardware VertexProgram can handle only 16 matrix
@ -142,29 +142,66 @@ public:
*/ */
enum TMatrixCount { MaxModelMatrix = 16 }; enum TMatrixCount { MaxModelMatrix = 16 };
protected: enum TMatrix
{
ModelView= 0,
Projection,
ModelViewProjection,
NumMatrix
};
CSynchronized<TTexDrvInfoPtrMap> _SyncTexDrvInfos; enum TTransform
{
Identity=0,
Inverse,
Transpose,
InverseTranspose,
NumTransform
};
protected:
CSynchronized<TTexDrvInfoPtrMap> _SyncTexDrvInfos;
TTexDrvSharePtrList _TexDrvShares; TTexDrvSharePtrList _TexDrvShares;
TMatDrvInfoPtrList _MatDrvInfos; TMatDrvInfoPtrList _MatDrvInfos;
TVBDrvInfoPtrList _VBDrvInfos; TVBDrvInfoPtrList _VBDrvInfos;
TIBDrvInfoPtrList _IBDrvInfos; TIBDrvInfoPtrList _IBDrvInfos;
TPolygonMode _PolygonMode;
TGPUPrgDrvInfoPtrList _GPUPrgDrvInfos; TGPUPrgDrvInfoPtrList _GPUPrgDrvInfos;
TPolygonMode _PolygonMode;
uint _ResetCounter; uint _ResetCounter;
public: public:
IDriver(void); IDriver();
virtual ~IDriver(void); 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. // 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) // 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; 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 /// \name Disable Hardware Feature
/** Disable some Feature that may be supported by the Hardware /** Disable some Feature that may be supported by the Hardware
* Call before setDisplay() to work properly * Call before setDisplay() to work properly
@ -176,6 +213,10 @@ public:
virtual void disableHardwareTextureShader() = 0; virtual void disableHardwareTextureShader() = 0;
// @} // @}
/// \name Windowing
// @{
// first param is the associated window. // first param is the associated window.
// Must be a HWND for Windows (WIN32). // 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;
@ -185,13 +226,10 @@ public:
/// Set the title of the NeL window /// 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 /// Set icon(s) of the NeL window
virtual void setWindowIcon(const std::vector<NLMISC::CBitmap> &bitmaps) = 0; virtual void setWindowIcon(const std::vector<NLMISC::CBitmap> &bitmaps) = 0;
/// Set the position of the NeL window /// 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 /// Show or hide the NeL window
virtual void showWindow(bool show) = 0; virtual void showWindow(bool show) = 0;
@ -206,42 +244,107 @@ public:
// Must be a HWND for Windows (WIN32). // Must be a HWND for Windows (WIN32).
virtual nlWindow getDisplay() = 0; virtual nlWindow getDisplay() = 0;
/** /// Setup monitor color properties. Return false if setup failed
* Setup monitor color properties.
*
* Return false if setup failed.
*/
virtual bool setMonitorColorProperties(const CMonitorColorProperties &properties) = 0; virtual bool setMonitorColorProperties(const CMonitorColorProperties &properties) = 0;
// Return is the associated default window proc for the driver. (Implementation dependent) // 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). // Must be a void GlWndProc(IDriver *driver, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) for Windows (WIN32).
virtual emptyProc getWindowProc() = 0; virtual emptyProc getWindowProc() = 0;
/// Before rendering via a driver in a thread, must activate() (per thread). virtual NLMISC::IEventEmitter *getEventEmitter() = 0;
virtual bool activate(void) = 0;
/// Get the number of texture stage available, for multi texturing (Normal material shaders). Valid only after setDisplay(). /// Copy a string to system clipboard.
virtual uint getNbTextureStages() const = 0; virtual bool copyTextToClipboard(const ucstring &text) = 0;
/** is the texture is set up in the driver /// Paste a string from system clipboard.
* NB: this method is thread safe. virtual bool pasteTextFromClipboard(ucstring &text) = 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 bool isTextureExist(const ITexture&tex)=0; virtual TMessageBoxId systemMessageBox(const char *message, const char *title, TMessageBoxType type = okType, TMessageBoxIcon icon = noIcon);
/// 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;
// @}
virtual NLMISC::IEventEmitter* getEventEmitter(void) = 0;
/* Clear the current target surface pixels. The function ignores the viewport settings but uses the scissor. */ /// \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; 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; 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; virtual bool clearStencilBuffer(float stencilval=0) = 0;
/// Set the color mask filter through where the operation done will pass /// 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<float> &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<float> &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) /** 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. * This mapping occurs after clipping of primitives and division by w of vertices coordinates.
* Default depth range is [0, 1]. * Default depth range is [0, 1].
@ -250,8 +353,17 @@ public:
virtual void setDepthRange(float znear, float zfar) = 0; virtual void setDepthRange(float znear, float zfar) = 0;
// Get the current depth range // Get the current depth range
virtual void getDepthRange(float &znear, float &zfar) const = 0; 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); /** 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;
@ -305,14 +417,36 @@ public:
*/ */
virtual void forceTextureResize(uint divisor) = 0; virtual void forceTextureResize(uint divisor) = 0;
/** Sets enforcement of native fragment programs. This is by default enabled. /** Get the number of texture stage available, for multi texturing (Normal material shaders). Valid only after setDisplay().
*
* \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; 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;
// @}
/// \name Material
// @{
virtual bool setupMaterial(CMaterial &mat) = 0; virtual bool setupMaterial(CMaterial &mat) = 0;
/** Special for Faster Specular Setup. Call this between lot of primitives rendered with Specular Materials. /** Special for Faster Specular Setup. Call this between lot of primitives rendered with Specular Materials.
@ -335,6 +469,14 @@ public:
virtual void endMaterialMultiPass() = 0; 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). // 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 setFrustum(float left, float right, float bottom, float top, float znear, float zfar, bool perspective = true) = 0;
virtual void setFrustumMatrix(CMatrix &frust) = 0; virtual void setFrustumMatrix(CMatrix &frust) = 0;
@ -368,9 +510,13 @@ public:
*/ */
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. /** Force input normal to be normalized by the driver. default is false.
* NB: driver force the normalization himself if: * NB: driver force the normalization himself if:
* - current Model matrix has a scale. * - current Model matrix has a scale.
@ -381,14 +527,12 @@ public:
/** return the forceNormalize() state. /** 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. /** return true if driver support VertexBufferHard.
*/ */
virtual bool supportVertexBufferHard() const = 0; virtual bool supportVertexBufferHard() const = 0;
@ -406,8 +550,12 @@ public:
/** return true if driver support VertexBufferHard, but vbHard->unlock() are slow (ATI-openGL). /** 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. /* Returns true if static vertex and index buffers must by allocated in VRAM, false in AGP.
* Default is false. * Default is false.
*/ */
@ -418,16 +566,15 @@ public:
*/ */
void setStaticMemoryToVRAM(bool staticMemoryToVRAM); 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 /** 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()). /** Allocate the initial VertexArray Memory. (no-op if !supportVertexBufferHard()).
* VertexArrayRange is first reseted, so any VBhard created before will be deleted. * 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); * NB: call it after setDisplay(). But setDisplay() by default call initVertexBufferHard(16Mo, 0);
@ -446,8 +593,12 @@ public:
/** Return the amount of video memory allocated by initVertexBufferHard() to store vertices. /** 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(). /** active a current VB, for future render().
* This method suppose that all vertices in the VB will be used. * This method suppose that all vertices in the VB will be used.
* *
@ -459,15 +610,18 @@ public:
*/ */
virtual bool activeVertexBuffer(CVertexBuffer &VB) = 0; virtual bool activeVertexBuffer(CVertexBuffer &VB) = 0;
/** active a current IB, for future render(). /** active a current IB, for future render().
* *
* Don't change the index buffer format/size after having activated it. * Don't change the index buffer format/size after having activated it.
* Don't lock the index buffer 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. /** Render a list of indexed lines with previously setuped VertexBuffer / IndexBuffer / Matrixes.
* \param mat is the material to use during this rendering * \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 firstIndex is the first index in the index buffer to use as first line.
@ -541,7 +695,12 @@ public:
* \param numQuad is the number of quad to render. * \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. /** Say what Texture Stage use what UV coord.
* by default activeVertexBuffer*() methods map all stage i to UV i. You can change this behavior, * by default activeVertexBuffer*() methods map all stage i to UV i. You can change this behavior,
* after calling activeVertexBuffer*(), by using this method. * after calling activeVertexBuffer*(), by using this method.
@ -554,15 +713,14 @@ public:
* (and so render*()) is called. But Normal shader doesn't do it. * (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;
// @}
/// 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. /// \name Buffer swapping
virtual bool pasteTextFromClipboard(ucstring &text) =0; // @{
/// Swap the back and front buffers.
virtual bool swapBuffers() = 0;
/** set the number of VBL wait when a swapBuffers() is issued. 0 means no synchronisation to the VBL /** 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. * Default is 1. Values >1 may be clamped to 1 by the driver.
@ -570,12 +728,14 @@ public:
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 /// 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.
// @{
/// \name Profiling.
// @{
/** Get the number of primitives rendered from the last swapBuffers() call. /** Get the number of primitives rendered from the last swapBuffers() call.
* \param pIn the number of requested rendered primitive. * \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 * \param pOut the number of effective rendered primitive. pOut==pIn if no multi-pass material is used
@ -583,34 +743,28 @@ public:
*/ */
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. /** 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 :). * 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. /** 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. /** 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(). /** 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 /** Return the amount of texture video memory used since last swapBuffers() call. Before use this method, you should enable
* the sum with enableUsedTextureMemorySum(). * the sum with enableUsedTextureMemorySum().
*/ */
virtual uint32 getUsedTextureMemory() const = 0; virtual uint32 getUsedTextureMemory() const = 0;
/** If the driver support it, enable profile VBHard locks. /** If the driver support it, enable profile VBHard locks.
* No-Op if already profiling * No-Op if already profiling
*/ */
@ -638,42 +792,26 @@ public:
/** For each texture setuped in the driver, "print" result: type, shareName, format and size (mipmap included) /** For each texture setuped in the driver, "print" result: type, shareName, format and size (mipmap included)
*/ */
void profileTextureUsage(std::vector<std::string> &result); void profileTextureUsage(std::vector<std::string> &result);
// @} // @}
/// \name Fog support. /// \name Fog support.
// @{ // @{
virtual bool fogEnabled() = 0; virtual bool fogEnabled() = 0;
virtual void enableFog(bool enable)=0; virtual void enableFog(bool enable = true) = 0;
/// setup fog parameters. fog must enabled to see result. start and end are distance values. /// 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. /// Get.
virtual float getFogStart() const = 0; virtual float getFogStart() const = 0;
virtual float getFogEnd() const = 0; virtual float getFogEnd() const = 0;
virtual CRGBA getFogColor() 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 /** Set the current viewport
* *
* \param viewport is a viewport to setup as current viewport. * \param viewport is a viewport to setup as current viewport.
@ -684,13 +822,16 @@ public:
*/ */
virtual void getViewport(CViewport &viewport) = 0; virtual void getViewport(CViewport &viewport) = 0;
/** Set the current Scissor. /** Set the current Scissor.
* \param scissor is a scissor to setup the current Scissor, in Window relative coordinate (0,1). * \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. * Get the driver version. Not the same than interface version. Incremented at each implementation change.
* *
@ -709,6 +850,9 @@ public:
* get the official name of the driver * get the official name of the driver
*/ */
virtual const char *getVideocardInformation () = 0; virtual const char *getVideocardInformation () = 0;
// @}
/// \name Mouse / Keyboard / Game devices /// \name Mouse / Keyboard / Game devices
// @{ // @{
@ -764,53 +908,10 @@ public:
virtual NLMISC::IInputDeviceManager *getLowLevelInputDeviceManager() = 0; 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<float> &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<float> &zbuffer, NLMISC::CRect &rect) = 0;
/// \name Render target // TODO: Handle Color/ZBuffer/Stencil consistently
// @{
/** Set the current render target. /** Set the current render target.
* *
* The render target can be a texture (tex pointer) or the back buffer (tex = NULL). * The render target can be a texture (tex pointer) or the back buffer (tex = NULL).
@ -854,6 +955,12 @@ public:
virtual ITexture *getRenderTarget() const = 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. /** Trick method : copy the current texture target into another texture without updating the current texture.
* *
* This method copies the current texture into another texture. * This method copies the current texture into another texture.
@ -889,21 +996,12 @@ public:
uint32 height = 0, uint32 height = 0,
uint32 mipmapLevel = 0 uint32 mipmapLevel = 0
) = 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 /** Set the global polygon mode. Can be filled, line or point. The implementation driver must
* call IDriver::setPolygonMode and active this mode. * call IDriver::setPolygonMode and active this mode.
* *
@ -915,7 +1013,21 @@ public:
_PolygonMode=mode; _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. * return the number of light supported by driver. typically 8.
* *
@ -951,13 +1063,13 @@ public:
* \param color is the new global ambient color for the scene. * \param color is the new global ambient color for the scene.
* \see setLight(), enableLight() * \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. /** 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' * This is only useful for material that have their shader set as 'PerPixelLighting'
* \param the light used for per pixel lighting * \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. /** Setup the unique light used for Lightmap Shader.
* Lightmaped primitives are lit per vertex with this light (should be local attenuated for maximum efficiency) * Lightmaped primitives are lit per vertex with this light (should be local attenuated for maximum efficiency)
@ -965,111 +1077,120 @@ public:
* \param the light used for per pixel lighting * \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
// @{
enum TMatrix
{
ModelView= 0,
Projection,
ModelViewProjection,
NumMatrix
};
enum TTransform /// \name Vertex Program
{ // @{
Identity=0,
Inverse,
Transpose,
InverseTranspose,
NumTransform
};
/** // Order of preference
* Does the driver supports vertex programs ? // - activeVertexProgram
*/ // - CMaterial pass[n] VP (uses activeVertexProgram, but does not override if one already set by code)
virtual bool supportVertexProgram () const =0; // - default generic VP that mimics fixed pipeline / no VP with fixed pipeline
/** /**
* Does the driver supports vertex program, but emulated by CPU ? * Does the driver supports vertex program, but emulated by CPU ?
*/ */
virtual bool isVertexProgramEmulated() const = 0; virtual bool isVertexProgramEmulated() const = 0;
/** /** Return true if the driver supports the specified vertex program profile.
* Does the driver supports pixel programs ?
*/ */
virtual bool supportPixelProgram() const =0; virtual bool supportVertexProgram(CVertexProgram::TProfile profile = CVertexProgram::nelvp) const = 0;
virtual bool supportPixelProgram(CPixelProgram::TProfile profile) const =0;
/** Compile the given vertex program, return if successful. Error information is returned as a string.
*/
virtual bool compileVertexProgram(CVertexProgram *program, std::string &error) const = 0;
/** /** Set the active vertex program. This will override vertex programs specified in CMaterial render calls.
* Activate / disactivate a vertex program * Also used internally by setupMaterial(CMaterial) when getVertexProgram returns NULL.
* * The vertex program is activated immediately.
* \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.
*/ */
virtual bool activeVertexProgram(CVertexProgram *program) = 0; virtual bool activeVertexProgram(CVertexProgram *program) = 0;
/** /** Get the currently active vertex program.
* Activate / disactivate a pixel program */
* virtual CVertexProgram *getActiveVertexProgram() const = 0;
* \param program is a pointer on a pixel program. Can be NULL to disable the current pixel program.
* // Set parameters
* \return true if setup/unsetup successed, false else. 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 activePixelProgram (CPixelProgram *program) =0; 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.
* Setup vertex program constant (uniform) values.
*/ */
virtual void setConstant (uint index, float, float, float, float) =0; virtual bool compilePixelProgram(CPixelProgram *program, std::string &error) const = 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;
/// 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
/** /** Set the active pixel program. This will override pixel programs specified in CMaterial render calls.
* Setup pixel program constant (uniform) values. * Also used internally by setupMaterial(CMaterial) when getPixelProgram returns NULL.
* The pixel program is activated immediately.
*/ */
virtual void setPixelProgramConstant (uint index, float, float, float, float) =0; virtual bool activePixelProgram(CPixelProgram *program) = 0;
virtual void setPixelProgramConstant (uint index, double, double, double, double) =0;
virtual void setPixelProgramConstant (uint index, const NLMISC::CVector& value) =0; /** Get the currently active pixel program.
virtual void setPixelProgramConstant (uint index, const NLMISC::CVectorD& value) =0; */
/// setup several 4 float csts taken from the given tab virtual CPixelProgram *getActivePixelProgram() const = 0;
virtual void setPixelProgramConstant (uint index, uint num, const float *src) =0;
/// setup several 4 double csts taken from the given tab // Set parameters
virtual void setPixelProgramConstant (uint index, uint num, const double *src) =0; virtual void setPixelProgram1f(uint index, float f0) = 0;
// TODO: uint32 and sint32 uniform types supported in opengl from gp4fp and gp5fp and sint32 in d3d 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 constants with a current matrix. * Setup constant values.
*
* 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 setPixelProgramConstantMatrix (uint index, TMatrix matrix, TTransform transform) =0; 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
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. * Setup constants with a current matrix.
@ -1097,13 +1218,25 @@ public:
* *
*/ */
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 // test if support for cloud render in a single pass
virtual bool supportCloudRenderSinglePass() const = 0; 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 * Activate VertexProgram 2Sided Color mode. In 2Sided mode, the BackFace (if material 2Sided enabled) read the
* result from o[BFC0], and not o[COL0]. * result from o[BFC0], and not o[COL0].
@ -1111,9 +1244,10 @@ public:
* NB: no-op if not supported by driver * NB: no-op if not supported by driver
*/ */
virtual void enableVertexProgramDoubleSidedColor(bool doubleSided) =0; virtual void enableVertexProgramDoubleSidedColor(bool doubleSided) =0;
// @} // @}
/// \name Texture addressing modes aka textures/pixels shaders /// \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) /// test whether the device supports some form of texture shader. (could be limited to DX6 EMBM for example)
@ -1132,6 +1266,7 @@ public:
//@} //@}
/** \name EMBM support. If texture shaders are present, this is not available, must use them instead. /** \name EMBM support. If texture shaders are present, this is not available, must use them instead.
* EMBM is a color op of CMaterial. * EMBM is a color op of CMaterial.
* NB : EMBM is the equivalent of the CMaterial::OffsetTexture addressing mode. However, it is both a texture * NB : EMBM is the equivalent of the CMaterial::OffsetTexture addressing mode. However, it is both a texture
@ -1151,13 +1286,10 @@ public:
virtual void setEMBMMatrix(const uint stage, const float mat[4]) = 0; 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 /// \name Misc
// @{ // @{
/** Does the driver support Blend Constant Color ??? If yes CMaterial::blendConstant* enum can be used /** 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. * for blend Src ord Dst factor. If no, using these enum will have undefined results.
*/ */
@ -1187,10 +1319,10 @@ public:
/// see enablePolygonSmoothing() /// see enablePolygonSmoothing()
virtual bool isPolygonSmoothingEnabled() const = 0; virtual bool isPolygonSmoothingEnabled() const = 0;
// @} // @}
/** Special method to internally swap the Driver handle of 2 textures. /** Special method to internally swap the Driver handle of 2 textures.
* USE IT WITH CARE (eg: may have Size problems, mipmap problems, format problems ...) * 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. * Actually, it is used only by CAsyncTextureManager, to manage Lods of DXTC CTextureFile.
@ -1247,9 +1379,10 @@ public:
*/ */
virtual CVertexBuffer::TVertexColorType getVertexColorFormat() const =0; virtual CVertexBuffer::TVertexColorType getVertexColorFormat() const =0;
/// \name Bench /// \name Bench
// @{ // @{
// Start the bench. See CHTimer::startBench(); // 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;
@ -1258,9 +1391,10 @@ public:
// Display the bench result // Display the bench result
virtual void displayBench (class NLMISC::CLog *log) =0; virtual void displayBench (class NLMISC::CLog *log) =0;
// @} // @}
/// \name Occlusion query mechanism /// \name Occlusion query mechanism
// @{ // @{
// Test whether this device supports the occlusion query mechanism // Test whether this device supports the occlusion query mechanism
@ -1273,8 +1407,8 @@ public:
virtual void deleteOcclusionQuery(IOcclusionQuery *oq) = 0; 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 /** Set cull mode
* Useful for mirrors / cube map rendering or when the scene must be rendered upside down * Useful for mirrors / cube map rendering or when the scene must be rendered upside down
@ -1297,6 +1431,7 @@ protected:
friend class ITextureDrvInfos; friend class ITextureDrvInfos;
friend class IMaterialDrvInfos; friend class IMaterialDrvInfos;
friend class IGPUProgramDrvInfos; friend class IGPUProgramDrvInfos;
friend class IGPUProgramParamsDrvInfos;
/// remove ptr from the lists in the driver. /// remove ptr from the lists in the driver.
void removeVBDrvInfoPtr(ItVBDrvInfoPtrList vbDrvInfoIt); void removeVBDrvInfoPtr(ItVBDrvInfoPtrList vbDrvInfoIt);
@ -1308,6 +1443,7 @@ protected:
private: private:
bool _StaticMemoryToVRAM; bool _StaticMemoryToVRAM;
}; };
// -------------------------------------------------- // --------------------------------------------------

@ -474,7 +474,6 @@ public:
virtual void forceDXTCCompression(bool dxtcComp); virtual void forceDXTCCompression(bool dxtcComp);
virtual void setAnisotropicFilter(sint filter); virtual void setAnisotropicFilter(sint filter);
virtual void forceTextureResize(uint divisor); virtual void forceTextureResize(uint divisor);
virtual void forceNativeFragmentPrograms(bool nativeOnly);
virtual bool setMonitorColorProperties (const CMonitorColorProperties &properties); virtual bool setMonitorColorProperties (const CMonitorColorProperties &properties);
// @} // @}

@ -48,10 +48,10 @@ namespace NL3D {
* \brief CGPUProgramParams * \brief CGPUProgramParams
* \date 2013-09-07 22:17GMT * \date 2013-09-07 22:17GMT
* \author Jan Boon (Kaetemi) * \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. * Allows for fast updating and iteration of parameters.
* NOTE TO DRIVER IMPLEMENTORS: DO NOT USE FOR STORING COPIES * 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 class CGPUProgramParams
{ {
@ -66,36 +66,70 @@ public:
CGPUProgramParams(); CGPUProgramParams();
virtual ~CGPUProgramParams(); virtual ~CGPUProgramParams();
void setF(uint index, float f0); // Copy from another params storage
void setF(uint index, float f0, float f1); void copy(CGPUProgramParams *params);
void setF(uint index, float f0, float f1, float f2);
void setF(uint index, float f0, float f1, float f2, float f3); // Set by index, available only when the associated program has been compiled
void setI(uint index, int i0); void set1f(uint index, float f0);
void setI(uint index, int i0, int i1); void set2f(uint index, float f0, float f1);
void setI(uint index, int i0, int i1, int i2); void set3f(uint index, float f0, float f1, float f2);
void setI(uint index, int i0, int i1, int i2, int i3); void set4f(uint index, float f0, float f1, float f2, float f3);
void setF(uint index, const NLMISC::CVector& v); void set1i(uint index, sint32 i0);
void setF(uint index, const NLMISC::CMatrix& m); void set2i(uint index, sint32 i0, sint32 i1);
void setF(uint index, uint num, const float *src); 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 // Internal
/// Allocate specified number of components if necessary /// Allocate specified number of components if necessary
size_t allocOffset(uint index, uint count, TType type); 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 /// Return offset for specified index
size_t getOffset(uint index) const; size_t getOffset(uint index) const;
size_t getOffset(const std::string &name) const;
/// Remove by offset /// Remove by offset
void freeOffset(size_t 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 getBegin() const { return m_Meta.size() ? m_First : s_End; }
size_t getNext(size_t offset) const { return m_Meta[offset].Next; } size_t getNext(size_t offset) const { return m_Meta[offset].Next; }
size_t getEnd() const { return s_End; } size_t getEnd() const { return s_End; }
// Data access // 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; } float *getPtrFByOffset(size_t offset) { return m_Vec[offset].F; }
int *getPtrIByOffset(size_t offset) { return m_Vec[offset].I; } int *getPtrIByOffset(size_t offset) { return m_Vec[offset].I; }
TType getTypeByOffset(size_t offset) { return m_Meta[offset].Type; } 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 // Utility
static inline uint getNbRegistersByComponents(uint count) { return (count + 3) >> 2; } // vector register per 4 components static inline uint getNbRegistersByComponents(uint count) { return (count + 3) >> 2; } // vector register per 4 components
@ -103,7 +137,8 @@ public:
private: private:
std::vector<CVec> m_Vec; std::vector<CVec> m_Vec;
std::vector<CMeta> m_Meta; std::vector<CMeta> m_Meta;
std::vector<size_t> m_Map; // map from index to buffer index std::vector<size_t> m_Map; // map from index to offset
std::map<std::string, size_t> m_MapName; // map from name to offset
size_t m_First; size_t m_First;
size_t m_Last; size_t m_Last;
static const size_t s_End = -1; static const size_t s_End = -1;

@ -673,13 +673,6 @@ public:
*/ */
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.
*/
virtual void forceNativeFragmentPrograms(bool nativeOnly) = 0;
/** Setup monitor color properties. /** Setup monitor color properties.
* *
* Return false if setup failed. * Return false if setup failed.

@ -240,24 +240,9 @@ void IDriver::removeMatDrvInfoPtr(ItMatDrvInfoPtrList shaderIt)
_MatDrvInfos.erase(shaderIt); _MatDrvInfos.erase(shaderIt);
} }
// *************************************************************************** // ***************************************************************************
/*void IDriver::removeShaderDrvInfoPtr(ItShaderDrvInfoPtrList shaderIt) void IDriver::removeGPUPrgDrvInfoPtr(ItGPUPrgDrvInfoPtrList gpuPrgDrvInfoIt)
{ {
_ShaderDrvInfos.erase(shaderIt); _GPUPrgDrvInfos.erase(gpuPrgDrvInfoIt);
}
// ***************************************************************************
void IDriver::removeVtxPrgDrvInfoPtr(ItVtxPrgDrvInfoPtrList vtxPrgDrvInfoIt)
{
_VtxPrgDrvInfos.erase(vtxPrgDrvInfoIt);
}
// ***************************************************************************
void IDriver::removePixelPrgDrvInfoPtr(ItPixelPrgDrvInfoPtrList pixelPrgDrvInfoIt)
{
_PixelPrgDrvInfos.erase(pixelPrgDrvInfoIt);
}*/
// ***************************************************************************
void IDriver::removeGPUPrgDrvInfoPtr(ItGPUPrgDrvInfoPtrList vtxPrgDrvInfoIt)
{
_GPUPrgDrvInfos.erase(vtxPrgDrvInfoIt);
} }
// *************************************************************************** // ***************************************************************************

@ -880,7 +880,6 @@ public:
virtual void forceDXTCCompression(bool dxtcComp); virtual void forceDXTCCompression(bool dxtcComp);
virtual void setAnisotropicFilter(sint filter); virtual void setAnisotropicFilter(sint filter);
virtual void forceTextureResize(uint divisor); virtual void forceTextureResize(uint divisor);
virtual void forceNativeFragmentPrograms(bool /* nativeOnly */) {} // ignored
// Driver information // Driver information
virtual uint getNumAdapter() const; virtual uint getNumAdapter() const;

@ -1993,12 +1993,6 @@ static void fetchPerturbedEnvMapR200()
#endif #endif
} }
// ***************************************************************************
void CDriverGL::forceNativeFragmentPrograms(bool nativeOnly)
{
_ForceNativeFragmentPrograms = nativeOnly;
}
// *************************************************************************** // ***************************************************************************
void CDriverGL::initFragmentShaders() void CDriverGL::initFragmentShaders()
{ {

@ -370,8 +370,6 @@ public:
virtual void forceTextureResize(uint divisor); virtual void forceTextureResize(uint divisor);
virtual void forceNativeFragmentPrograms(bool nativeOnly);
/// Setup texture env functions. Used by setupMaterial /// Setup texture env functions. Used by setupMaterial
void setTextureEnvFunction(uint stage, CMaterial& mat); void setTextureEnvFunction(uint stage, CMaterial& mat);

@ -1496,12 +1496,6 @@ void CDriverUser::forceTextureResize(uint divisor)
_Driver->forceTextureResize(divisor); _Driver->forceTextureResize(divisor);
} }
void CDriverUser::forceNativeFragmentPrograms(bool nativeOnly)
{
NL3D_HAUTO_UI_DRIVER;
_Driver->forceNativeFragmentPrograms(nativeOnly);
}
bool CDriverUser::setMonitorColorProperties (const CMonitorColorProperties &properties) bool CDriverUser::setMonitorColorProperties (const CMonitorColorProperties &properties)
{ {
NL3D_HAUTO_UI_DRIVER; NL3D_HAUTO_UI_DRIVER;

@ -36,6 +36,7 @@
#include <nel/misc/matrix.h> #include <nel/misc/matrix.h>
// Project includes // Project includes
#include <nel/3d/driver.h>
using namespace std; using namespace std;
// using namespace NLMISC; // 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)); float *f = getPtrFByOffset(allocOffset(index, 1, Float));
f[0] = f0; 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)); float *f = getPtrFByOffset(allocOffset(index, 2, Float));
f[0] = f0; f[0] = f0;
f[1] = f1; 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)); float *f = getPtrFByOffset(allocOffset(index, 3, Float));
f[0] = f0; f[0] = f0;
@ -73,7 +74,7 @@ void CGPUProgramParams::setF(uint index, float f0, float f1, float f2)
f[2] = 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)); float *f = getPtrFByOffset(allocOffset(index, 4, Float));
f[0] = f0; f[0] = f0;
@ -82,20 +83,20 @@ void CGPUProgramParams::setF(uint index, float f0, float f1, float f2, float f3)
f[3] = 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)); int *i = getPtrIByOffset(allocOffset(index, 1, Int));
i[0] = i0; 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)); int *i = getPtrIByOffset(allocOffset(index, 2, Int));
i[0] = i0; i[0] = i0;
i[1] = i1; 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)); int *i = getPtrIByOffset(allocOffset(index, 3, Int));
i[0] = i0; i[0] = i0;
@ -103,7 +104,7 @@ void CGPUProgramParams::setI(uint index, int i0, int i1, int i2)
i[2] = 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)); int *i = getPtrIByOffset(allocOffset(index, 4, Int));
i[0] = i0; i[0] = i0;
@ -112,7 +113,7 @@ void CGPUProgramParams::setI(uint index, int i0, int i1, int i2, int i3)
i[3] = 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)); float *f = getPtrFByOffset(allocOffset(index, 3, Float));
f[0] = v.x; f[0] = v.x;
@ -120,7 +121,7 @@ void CGPUProgramParams::setF(uint index, const NLMISC::CVector& v)
f[2] = v.z; 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! // TODO: Verify this!
float *f = getPtrFByOffset(allocOffset(index, 16, Float)); float *f = getPtrFByOffset(allocOffset(index, 16, Float));
@ -129,11 +130,18 @@ void CGPUProgramParams::setF(uint index, const NLMISC::CMatrix& m)
mt.get(f); 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)); float *f = getPtrFByOffset(allocOffset(index, sz, Float));
for (uint i = 0; i < num; ++i) for (uint c = 0; c < sz; ++c)
f[i] = src[i]; 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 /// Allocate specified number of components if necessary

@ -563,6 +563,7 @@ bool CStereoOVR::endRenderTarget()
NL3D::IDriver *drvInternal = (static_cast<CDriverUser *>(m_Driver))->getDriver(); NL3D::IDriver *drvInternal = (static_cast<CDriverUser *>(m_Driver))->getDriver();
NL3D::CMaterial *barrelMat = m_BarrelMat.getObjectPtr(); NL3D::CMaterial *barrelMat = m_BarrelMat.getObjectPtr();
barrelMat->setTexture(0, m_BarrelTex); barrelMat->setTexture(0, m_BarrelTex);
drvInternal->activePixelProgram(m_PixelProgram); drvInternal->activePixelProgram(m_PixelProgram);
float w = float(m_BarrelQuadLeft.V1.x),// / float(width), float w = float(m_BarrelQuadLeft.V1.x),// / float(width),
@ -582,20 +583,21 @@ bool CStereoOVR::endRenderTarget()
float scaleY = (h / 2); float scaleY = (h / 2);
float scaleInX = (2 / w); float scaleInX = (2 / w);
float scaleInY = (2 / h); 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); m_Driver->drawQuad(m_BarrelQuadLeft, m_BarrelMat);
x = w; x = w;
lensCenterX = x + (w - lensViewportShift * 0.5f) * 0.5f; lensCenterX = x + (w - lensViewportShift * 0.5f) * 0.5f;
screenCenterX = x + w * 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); m_Driver->drawQuad(m_BarrelQuadRight, m_BarrelMat);

Loading…
Cancel
Save