Cleanup driver interface

This commit is contained in:
kaetemi 2013-09-08 21:57:27 +02:00
parent 879fe9da61
commit b0079c38be
11 changed files with 661 additions and 518 deletions

File diff suppressed because it is too large Load diff

View file

@ -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);
// @} // @}

View file

@ -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;

View file

@ -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.

View file

@ -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);
} }
// *************************************************************************** // ***************************************************************************

View file

@ -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;

View file

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

View file

@ -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);

View file

@ -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;

View file

@ -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

View file

@ -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);