From 235bfcfd94dcea43240e14a2509046afbe5d7731 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Sun, 8 Sep 2013 01:49:34 +0200 Subject: [PATCH] Add additional set functions --HG-- branch : multipass-stereo --- code/nel/include/nel/3d/gpu_program_params.h | 21 +++++- code/nel/src/3d/gpu_program_params.cpp | 74 +++++++++++++++++++- 2 files changed, 90 insertions(+), 5 deletions(-) diff --git a/code/nel/include/nel/3d/gpu_program_params.h b/code/nel/include/nel/3d/gpu_program_params.h index a94a0ccf8..d1a3125a2 100644 --- a/code/nel/include/nel/3d/gpu_program_params.h +++ b/code/nel/include/nel/3d/gpu_program_params.h @@ -37,6 +37,11 @@ // Project includes +namespace NLMISC { + class CVector; + class CMatrix; +} + namespace NL3D { /** @@ -61,8 +66,17 @@ public: CGPUProgramParams(); virtual ~CGPUProgramParams(); - void set(uint index, float f0, float f1, float f2, float f3); - void set(uint index, int i0, int i1, int i2, int i3); + 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); // Internal /// Allocate specified number of components if necessary @@ -83,6 +97,9 @@ public: int *getPtrIByOffset(size_t offset) { return m_Vec[offset].I; } TType getTypeByOffset(size_t offset) { return m_Meta[offset].Type; } + // Utility + static inline uint getNbRegistersByComponents(uint count) { return (count + 3) >> 2; } // vector register per 4 components + private: std::vector m_Vec; std::vector m_Meta; diff --git a/code/nel/src/3d/gpu_program_params.cpp b/code/nel/src/3d/gpu_program_params.cpp index 78dcab15c..0a03500ea 100644 --- a/code/nel/src/3d/gpu_program_params.cpp +++ b/code/nel/src/3d/gpu_program_params.cpp @@ -32,6 +32,8 @@ // NeL includes // #include +#include +#include // Project includes @@ -50,7 +52,28 @@ CGPUProgramParams::~CGPUProgramParams() } -void CGPUProgramParams::set(uint index, float f0, float f1, float f2, float f3) +void CGPUProgramParams::setF(uint index, float f0) +{ + float *f = getPtrFByOffset(allocOffset(index, 1, Float)); + f[0] = f0; +} + +void CGPUProgramParams::setF(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) +{ + float *f = getPtrFByOffset(allocOffset(index, 3, Float)); + f[0] = f0; + f[1] = f1; + f[2] = f2; +} + +void CGPUProgramParams::setF(uint index, float f0, float f1, float f2, float f3) { float *f = getPtrFByOffset(allocOffset(index, 4, Float)); f[0] = f0; @@ -59,7 +82,28 @@ void CGPUProgramParams::set(uint index, float f0, float f1, float f2, float f3) f[3] = f3; } -void CGPUProgramParams::set(uint index, int i0, int i1, int i2, int i3) +void CGPUProgramParams::setI(uint index, int i0) +{ + int *i = getPtrIByOffset(allocOffset(index, 1, Int)); + i[0] = i0; +} + +void CGPUProgramParams::setI(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) +{ + int *i = getPtrIByOffset(allocOffset(index, 3, Int)); + i[0] = i0; + i[1] = i1; + i[2] = i2; +} + +void CGPUProgramParams::setI(uint index, int i0, int i1, int i2, int i3) { int *i = getPtrIByOffset(allocOffset(index, 4, Int)); i[0] = i0; @@ -68,6 +112,30 @@ void CGPUProgramParams::set(uint index, int i0, int i1, int i2, int i3) i[3] = i3; } +void CGPUProgramParams::setF(uint index, const NLMISC::CVector& v) +{ + float *f = getPtrFByOffset(allocOffset(index, 3, Float)); + f[0] = v.x; + f[1] = v.y; + f[2] = v.z; +} + +void CGPUProgramParams::setF(uint index, const NLMISC::CMatrix& m) +{ + // TODO: Verify this! + float *f = getPtrFByOffset(allocOffset(index, 16, Float)); + NLMISC::CMatrix mt = m; + mt.transpose(); + mt.get(f); +} + +void CGPUProgramParams::setF(uint index, uint num, const float *src) +{ + float *f = getPtrFByOffset(allocOffset(index, num, Float)); + for (uint i = 0; i < num; ++i) + f[i] = src[i]; +} + /// Allocate specified number of components if necessary size_t CGPUProgramParams::allocOffset(uint index, uint count, TType type) { @@ -96,7 +164,7 @@ size_t CGPUProgramParams::allocOffset(uint index, uint count, TType type) // Allocate space offset = m_Meta.size(); - uint blocks = (count + 3) >> 2; // per 4 components + uint blocks = getNbRegistersByComponents(count); // per 4 components m_Meta.resize(offset + blocks); m_Vec.resize(offset + blocks);