Make gpu programs use abstract gpu program class

This commit is contained in:
kaetemi 2013-09-07 20:41:07 +02:00
parent d54774f978
commit 47716d7247
17 changed files with 552 additions and 599 deletions

View file

@ -151,9 +151,10 @@ protected:
TVBDrvInfoPtrList _VBDrvInfos; TVBDrvInfoPtrList _VBDrvInfos;
TIBDrvInfoPtrList _IBDrvInfos; TIBDrvInfoPtrList _IBDrvInfos;
TPolygonMode _PolygonMode; TPolygonMode _PolygonMode;
TVtxPrgDrvInfoPtrList _VtxPrgDrvInfos; TGPUPrgDrvInfoPtrList _GPUPrgDrvInfos;
TPixelPrgDrvInfoPtrList _PixelPrgDrvInfos; // TPixelPrgDrvInfoPtrList _PixelPrgDrvInfos;
TShaderDrvInfoPtrList _ShaderDrvInfos; // TGeomPrgDrvInfoPtrList _GeomPrgDrvInfos;
// TShaderDrvInfoPtrList _ShaderDrvInfos;
uint _ResetCounter; uint _ResetCounter;
@ -317,11 +318,6 @@ public:
virtual bool setupMaterial(CMaterial& mat)=0; virtual bool setupMaterial(CMaterial& mat)=0;
/**
* Activate a shader, NULL to disable the current shader.
*/
virtual bool activeShader(CShader *shd)=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.
* Visual Errors may arise if you don't correctly call endSpecularBatch(). * Visual Errors may arise if you don't correctly call endSpecularBatch().
*/ */
@ -1303,9 +1299,10 @@ protected:
friend class CTextureDrvShare; friend class CTextureDrvShare;
friend class ITextureDrvInfos; friend class ITextureDrvInfos;
friend class IMaterialDrvInfos; friend class IMaterialDrvInfos;
friend class IVertexProgramDrvInfos; // friend class IVertexProgramDrvInfos;
friend class IPixelProgramDrvInfos; // friend class IPixelProgramDrvInfos;
friend class IShaderDrvInfos; // friend class IShaderDrvInfos;
friend class IGPUProgramDrvInfos;
/// remove ptr from the lists in the driver. /// remove ptr from the lists in the driver.
void removeVBDrvInfoPtr(ItVBDrvInfoPtrList vbDrvInfoIt); void removeVBDrvInfoPtr(ItVBDrvInfoPtrList vbDrvInfoIt);
@ -1313,9 +1310,10 @@ protected:
void removeTextureDrvInfoPtr(ItTexDrvInfoPtrMap texDrvInfoIt); void removeTextureDrvInfoPtr(ItTexDrvInfoPtrMap texDrvInfoIt);
void removeTextureDrvSharePtr(ItTexDrvSharePtrList texDrvShareIt); void removeTextureDrvSharePtr(ItTexDrvSharePtrList texDrvShareIt);
void removeMatDrvInfoPtr(ItMatDrvInfoPtrList shaderIt); void removeMatDrvInfoPtr(ItMatDrvInfoPtrList shaderIt);
void removeShaderDrvInfoPtr(ItShaderDrvInfoPtrList shaderIt); // void removeShaderDrvInfoPtr(ItShaderDrvInfoPtrList shaderIt);
void removeVtxPrgDrvInfoPtr(ItVtxPrgDrvInfoPtrList vtxPrgDrvInfoIt); // void removeVtxPrgDrvInfoPtr(ItVtxPrgDrvInfoPtrList vtxPrgDrvInfoIt);
void removePixelPrgDrvInfoPtr(ItPixelPrgDrvInfoPtrList pixelPrgDrvInfoIt); // void removePixelPrgDrvInfoPtr(ItPixelPrgDrvInfoPtrList pixelPrgDrvInfoIt);
void removeGPUPrgDrvInfoPtr(ItGPUPrgDrvInfoPtrList gpuPrgDrvInfoIt);
private: private:
bool _StaticMemoryToVRAM; bool _StaticMemoryToVRAM;

View file

@ -0,0 +1,83 @@
/** \file geometry_program.h
* Geometry program definition
*/
/* Copyright, 2000, 2001 Nevrax Ltd.
*
* This file is part of NEVRAX NEL.
* NEVRAX NEL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
* NEVRAX NEL is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with NEVRAX NEL; see the file COPYING. If not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*/
#ifndef NL_GEOMETRY_PROGRAM_H
#define NL_GEOMETRY_PROGRAM_H
#include <nel/misc/types_nl.h>
#include <nel/misc/smart_ptr.h>
#include <nel/3d/gpu_program.h>
#include <nel/3d/gpu_program_source.h>
#include <list>
namespace NL3D {
/**
* \brief CGeometryProgramInfo
* \date 2013-09-07 15:00GMT
* \author Jan Boon (Kaetemi)
* Read-only information structure.
*/
struct CGeometryProgramInfo
{
public:
std::string DisplayName;
/*enum TFeatures
{
};*/
// Bitfield containing features used by this geometry program
uint Features;
// Indices of parameters used by features
// ...
};
class CGeometryProgram : public IGPUProgram
{
public:
/// Constructor
CGeometryProgram(CGPUProgramSourceCont *programSource);
/// Destructor
virtual ~CGeometryProgram ();
/// Build feature information
void buildInfo(const char *displayName, uint features);
/// Get feature information
inline const CGeometryProgramInfo *getInfo() const { return _Info; }
private:
/// Feature information
CGeometryProgramInfo *_Info;
};
} // NL3D
#endif // NL_GEOMETRY_PROGRAM_H
/* End of vertex_program.h */

View file

@ -1,6 +1,6 @@
/** /**
* \file gpu_program.h * \file gpu_program.h
* \brief CGPUProgram * \brief IGPUProgram
* \date 2013-09-07 15:00GMT * \date 2013-09-07 15:00GMT
* \author Jan Boon (Kaetemi) * \author Jan Boon (Kaetemi)
* IGPUProgram * IGPUProgram
@ -38,110 +38,33 @@
namespace NL3D { namespace NL3D {
/** // List typedef.
* \brief CVertexProgramInfo class IDriver;
* \date 2013-09-07 15:00GMT class IGPUProgramDrvInfos;
* \author Jan Boon (Kaetemi) typedef std::list<IGPUProgramDrvInfos*> TGPUPrgDrvInfoPtrList;
* Read-only information structure. typedef TGPUPrgDrvInfoPtrList::iterator ItGPUPrgDrvInfoPtrList;
*/
struct CVertexProgramInfo // Class for interaction of vertex program with Driver.
// IGPUProgramDrvInfos represent the real data of the GPU program, stored into the driver (eg: just a GLint for opengl).
class IGPUProgramDrvInfos : public NLMISC::CRefCount
{ {
private:
IDriver *_Driver;
ItGPUPrgDrvInfoPtrList _DriverIterator;
public: public:
std::string DisplayName; IGPUProgramDrvInfos (IDriver *drv, ItGPUPrgDrvInfoPtrList it);
// The virtual dtor is important.
virtual ~IGPUProgramDrvInfos(void);
enum TFeatures virtual uint getParamIdx(char *name) const { return ~0; }; // STEREO_TODO
{
// World
// transform
// Lights
Ambient = 0x0001,
Sun = 0x0002,
PointLight0 = 0x0004,
PointLight1 = 0x0008,
PointLight2 = 0x0010,
// Lights, additional parameters for user shaders
/// Adds an enabled/disabled parameter to all of the lights
DynamicLights = 0x0020,
};
/// Bitfield containing features used by this vertex program.
uint Features;
/// Indices of parameters used by features.
/// Lights, NeL supports:
/// - Ambient light
uint AmbientIdx; // (Ambient)
/// - One directional light
uint SunDirectionIdx; // (Sun)
uint SunDiffuseIdx; // (Sun)
/// - Zero to three point lights
uint PointLight0PositionIdx; // (PointLight0)
uint PointLight0DiffuseIdx; // (PointLight0)
uint PointLight1PositionIdx; // (PointLight1)
uint PointLight1DiffuseIdx; // (PointLight1)
uint PointLight2PositionIdx; // (PointLight2)
uint PointLight2DiffuseIdx; // (PointLight2)
/// DynamicLights
uint SunEnabledIdx; // (DynamicLights && Sun)
uint PointLight0EnabledIdx; // (DynamicLights && PointLight0)
uint PointLight1EnabledIdx; // (DynamicLights && PointLight1)
uint PointLight2EnabledIdx; // (DynamicLights && PointLight2)
}; };
/** class CGPUProgramSource;
* \brief CPixelProgramInfo class CGPUProgramSourceCont;
* \date 2013-09-07 15:00GMT
* \author Jan Boon (Kaetemi)
* Read-only information structure.
*/
struct CPixelProgramInfo
{
public:
std::string DisplayName;
enum TFeatures
{
/// Use texture stages from CMaterial as texture parameters
MaterialTextures = 0x0001,
/// Set driver fog parameters on this program
Fog = 0x0002,
/// Adds an enabled/disabled parameter to the fog, for user shaders
DynamicFog = 0x0004,
};
// Bitfield containing features used by this pixel program
uint Features;
// Indices of parameters used by features
uint FogEnabledIdx; // (Fog && DynamicFog) nlFogEnabled, fog enabled
uint FogStartEndIdx; // (Fog) nlFogStartEnd, start and end of fog
uint FogColorIdx; // (Fog) nlFogColor, fog color
};
/** /**
* \brief CGeometryProgramInfo * \brief IGPUProgram
* \date 2013-09-07 15:00GMT
* \author Jan Boon (Kaetemi)
* Read-only information structure.
*/
struct CGeometryProgramInfo
{
public:
/*enum TFeatures
{
};*/
/// Bitfield containing features used by this pixel program.
// uint Features;
/// Indices of parameters used by features.
};
/**
* \brief CGPUProgram
* \date 2013-09-07 15:00GMT * \date 2013-09-07 15:00GMT
* \author Jan Boon (Kaetemi) * \author Jan Boon (Kaetemi)
* A compiled GPU program * A compiled GPU program
@ -202,27 +125,22 @@ public:
public: public:
IGPUProgram(); IGPUProgram();
IGPUProgram(CGPUProgramSourceCont *programSource);
virtual ~IGPUProgram(); virtual ~IGPUProgram();
/// Get the idx of a parameter (ogl: uniform, d3d: constant, etcetera) by name. Invalid name returns ~0 /// Get the idx of a parameter (ogl: uniform, d3d: constant, etcetera) by name. Invalid name returns ~0
virtual uint getParamIdx(char *name) const = 0; inline uint getParamIdx(char *name) const { return _DrvInfo->getParamIdx(name); };
void buildVPInfo(const char *displayName, uint features); /// Get the program
void buildPPInfo(const char *displayName, uint features); inline const CGPUProgramSourceCont *getProgramSource() const { return _ProgramSource; };
void buildGPInfo(const char *displayName, uint features);
inline const CVertexProgramInfo *getVPInfo() const { return Info.VertexProgram; } protected:
inline const CPixelProgramInfo *getPPInfo() const { return Info.PixelProgram; } /// The progam source
inline const CGeometryProgramInfo *getGPInfo() const { return Info.GeometryProgram; } NLMISC::CSmartPtr<CGPUProgramSourceCont> _ProgramSource;
private: public:
union /// The driver information. For the driver implementation only.
{ NLMISC::CRefPtr<IGPUProgramDrvInfos> _DrvInfo;
CVertexProgramInfo *VertexProgram;
CPixelProgramInfo *PixelProgram;
CGeometryProgramInfo *GeometryProgram;
void *Ptr;
} Info;
}; /* class IGPUProgram */ }; /* class IGPUProgram */

View file

@ -45,7 +45,7 @@ namespace NL3D {
* \author Jan Boon (Kaetemi) * \author Jan Boon (Kaetemi)
* A single GPU program with a specific profile. * A single GPU program with a specific profile.
*/ */
struct CGPUProgramSource struct CGPUProgramSource : public NLMISC::CRefCount
{ {
public: public:
std::string DisplayName; std::string DisplayName;
@ -53,11 +53,11 @@ public:
/// Minimal required profile for this GPU program /// Minimal required profile for this GPU program
IGPUProgram::TProfile Profile; IGPUProgram::TProfile Profile;
char *SourcePtr; const char *CodePtr;
/// Copy the source string /// Copy the source code string
inline void setSource(char *source) { SourceCopy = source; SourcePtr = &source[0]; } inline void setCode(const char *source) { CodeCopy = source; CodePtr = &source[0]; }
/// Set pointer to source string without copying the string /// Set pointer to source code string without copying the string
inline void setSourcePtr(char *sourcePtr) { SourceCopy.clear(); SourcePtr = sourcePtr; } inline void setCodePtr(const char *sourcePtr) { CodeCopy.clear(); CodePtr = sourcePtr; }
/// CVertexProgramInfo/CPixelProgramInfo/... NeL features /// CVertexProgramInfo/CPixelProgramInfo/... NeL features
uint Features; uint Features;
@ -66,7 +66,7 @@ public:
std::map<std::string, uint> ParamIndices; std::map<std::string, uint> ParamIndices;
private: private:
std::string SourceCopy; std::string CodeCopy;
}; /* class CGPUProgramSource */ }; /* class CGPUProgramSource */
@ -77,10 +77,10 @@ private:
* Container for the source code of a single GPU program, allowing * Container for the source code of a single GPU program, allowing
* variations in different language profiles. * variations in different language profiles.
*/ */
struct CGPUProgramSourceCont struct CGPUProgramSourceCont : public NLMISC::CRefCount
{ {
public: public:
std::vector<CGPUProgramSource> Sources; std::vector<NLMISC::CSmartPtr<CGPUProgramSource> > Sources;
}; /* class CGPUProgramSourceCont */ }; /* class CGPUProgramSourceCont */

View file

@ -1,7 +1,5 @@
/** \file pixel_program.h /** \file pixel_program.h
* Pixel program definition * Pixel program definition
*
* $Id: pixel_program.h,v 1.1.2.3 2007/07/06 15:58:45 legallo Exp $
*/ */
/* Copyright, 2000, 2001 Nevrax Ltd. /* Copyright, 2000, 2001 Nevrax Ltd.
@ -28,81 +26,62 @@
#include <nel/misc/types_nl.h> #include <nel/misc/types_nl.h>
#include <nel/misc/smart_ptr.h> #include <nel/misc/smart_ptr.h>
#include <nel/3d/gpu_program.h>
#include <nel/3d/gpu_program_source.h>
#include <list> #include <list>
namespace NL3D { namespace NL3D {
// List typedef. /**
class IDriver; * \brief CPixelProgramInfo
class IPixelProgramDrvInfos; * \date 2013-09-07 15:00GMT
typedef std::list<IPixelProgramDrvInfos*> TPixelPrgDrvInfoPtrList; * \author Jan Boon (Kaetemi)
typedef TPixelPrgDrvInfoPtrList::iterator ItPixelPrgDrvInfoPtrList; * Read-only information structure.
*/
// Class for interaction of pixel program with Driver. struct CPixelProgramInfo
// IPixelProgramDrvInfos represent the real data of the pixel program, stored into the driver.
class IPixelProgramDrvInfos : public NLMISC::CRefCount
{
private:
IDriver *_Driver;
ItPixelPrgDrvInfoPtrList _DriverIterator;
public:
IPixelProgramDrvInfos (IDriver *drv, ItPixelPrgDrvInfoPtrList it);
// The virtual dtor is important.
virtual ~IPixelProgramDrvInfos(void);
};
//-------------------------------------------------------------------------------
class CPixelProgram : public NLMISC::CRefCount
{ {
public: public:
std::string DisplayName;
enum TProfile enum TFeatures
{ {
// TODO: /// Use texture stages from CMaterial as texture parameters
// If it's more useful, change this to a flags bitfield and MaterialTextures = 0x0001,
// change the d3d (and gl) code to generate the bitfield of /// Set driver fog parameters on this program
// supported modes instead of doing a >= version check. Fog = 0x0002,
/// Adds an enabled/disabled parameter to the fog, for user shaders
// direct3d - 0xD3D0,major,minor DynamicFog = 0x0004,
ps_1_1 = 0xD3D00101,
ps_1_2 = 0xD3D00102,
ps_1_3 = 0xD3D00103,
ps_1_4 = 0xD3D00104,
ps_2_0 = 0xD3D00200,
ps_2_x = 0xD3D00201, // not sure...
ps_3_0 = 0xD3D00300,
// opengl - 0x0610,bitfield
// fp20 = 0x061B0001, // very limited and outdated, unnecessary
// fp30 = 0x06100002, // NV_fragment_program, now arbfp1, redundant
arbfp1 = 0x06100004, // ARB_fragment_program
fp40 = 0x06100008, // NV_fragment_program2, arbfp1 with "OPTION NV_fragment_program2;\n"
gp4fp = 0x06100010, // NV_gpu_program4
gp5fp = 0x06100020, // NV_gpu_program5
}; };
/// Constructor // Bitfield containing features used by this pixel program
CPixelProgram (const char* program); uint Features;
// Indices of parameters used by features
uint FogEnabledIdx; // (Fog && DynamicFog) nlFogEnabled, fog enabled
uint FogStartEndIdx; // (Fog) nlFogStartEnd, start and end of fog
uint FogColorIdx; // (Fog) nlFogColor, fog color
};
class CPixelProgram : public IGPUProgram
{
public:
/// Constructor
CPixelProgram(CGPUProgramSourceCont *programSource);
/// Destructor /// Destructor
virtual ~CPixelProgram (); virtual ~CPixelProgram ();
/// Get the program /// Build feature information
inline const std::string& getProgram() const { return _Program; }; void buildInfo(const char *displayName, uint features);
/// Get feature information
inline const CPixelProgramInfo *getInfo() const { return _Info; }
/// The driver informations. For the driver implementation only. private:
NLMISC::CRefPtr<IPixelProgramDrvInfos> _DrvInfo;
protected: /// Feature information
CPixelProgramInfo *_Info;
/// The progam
std::string _Program;
}; };
} // NL3D } // NL3D

View file

@ -24,73 +24,6 @@
namespace NL3D { namespace NL3D {
using NLMISC::CRefCount;
class IDriver;
// List typedef.
class IShaderDrvInfos;
typedef std::list<IShaderDrvInfos*> TShaderDrvInfoPtrList;
typedef TShaderDrvInfoPtrList::iterator ItShaderDrvInfoPtrList;
/**
* Interface for shader driver infos.
*/
class IShaderDrvInfos : public CRefCount
{
private:
IDriver *_Driver;
ItShaderDrvInfoPtrList _DriverIterator;
public:
IShaderDrvInfos(IDriver *drv, ItShaderDrvInfoPtrList it) {_Driver= drv; _DriverIterator= it;}
// The virtual dtor is important.
virtual ~IShaderDrvInfos();
};
/**
* Shader resource for the driver. It is just a container for a ".fx" text file.
*/
/* *** IMPORTANT ********************
* *** IF YOU MODIFY THE STRUCTURE OF THIS CLASS, PLEASE INCREMENT IDriver::InterfaceVersion TO INVALIDATE OLD DRIVER DLL
* **********************************
*/
// --------------------------------------------------
class CShader
{
public:
CShader();
~CShader();
// Load a shader file
bool loadShaderFile (const char *filename);
// Set the shader text
void setText (const char *text);
// Get the shader text
const char *getText () const { return _Text.c_str(); }
// Set the shader name
void setName (const char *name);
// Get the shader name
const char *getName () const { return _Name.c_str(); }
public:
// Private. For Driver only.
bool _ShaderChanged;
NLMISC::CRefPtr<IShaderDrvInfos> _DrvInfo;
private:
// The shader
std::string _Text;
// The shader name
std::string _Name;
};
} // NL3D } // NL3D

View file

@ -19,90 +19,87 @@
#include "nel/misc/types_nl.h" #include "nel/misc/types_nl.h"
#include "nel/misc/smart_ptr.h" #include "nel/misc/smart_ptr.h"
#include "nel/3d/gpu_program.h"
#include "nel/3d/gpu_program_source.h"
#include <list> #include <list>
namespace NL3D { namespace NL3D {
// List typedef. /**
class IDriver; * \brief CVertexProgramInfo
class IVertexProgramDrvInfos; * \date 2013-09-07 15:00GMT
typedef std::list<IVertexProgramDrvInfos*> TVtxPrgDrvInfoPtrList; * \author Jan Boon (Kaetemi)
typedef TVtxPrgDrvInfoPtrList::iterator ItVtxPrgDrvInfoPtrList; * Read-only information structure.
*/
// Class for interaction of vertex program with Driver. struct CVertexProgramInfo
// IVertexProgramDrvInfos represent the real data of the vertex program, stored into the driver (eg: just a GLint for opengl).
class IVertexProgramDrvInfos : public NLMISC::CRefCount
{ {
private:
IDriver *_Driver;
ItVtxPrgDrvInfoPtrList _DriverIterator;
public: public:
IVertexProgramDrvInfos (IDriver *drv, ItVtxPrgDrvInfoPtrList it); std::string DisplayName;
// The virtual dtor is important.
virtual ~IVertexProgramDrvInfos(void); enum TFeatures
{
// World
// transform
// Lights
Ambient = 0x0001,
Sun = 0x0002,
PointLight0 = 0x0004,
PointLight1 = 0x0008,
PointLight2 = 0x0010,
// Lights, additional parameters for user shaders
/// Adds an enabled/disabled parameter to all of the lights
DynamicLights = 0x0020,
};
/// Bitfield containing features used by this vertex program.
uint Features;
/// Indices of parameters used by features.
/// Lights, NeL supports:
/// - Ambient light
uint AmbientIdx; // (Ambient)
/// - One directional light
uint SunDirectionIdx; // (Sun)
uint SunDiffuseIdx; // (Sun)
/// - Zero to three point lights
uint PointLight0PositionIdx; // (PointLight0)
uint PointLight0DiffuseIdx; // (PointLight0)
uint PointLight1PositionIdx; // (PointLight1)
uint PointLight1DiffuseIdx; // (PointLight1)
uint PointLight2PositionIdx; // (PointLight2)
uint PointLight2DiffuseIdx; // (PointLight2)
/// DynamicLights
uint SunEnabledIdx; // (DynamicLights && Sun)
uint PointLight0EnabledIdx; // (DynamicLights && PointLight0)
uint PointLight1EnabledIdx; // (DynamicLights && PointLight1)
uint PointLight2EnabledIdx; // (DynamicLights && PointLight2)
}; };
class CVertexProgram : public IGPUProgram
/**
* This class is a vertex program.
*
* D3D / OPENGL compatibility notes:
* ---------------------------------
*
* To make your program compatible with D3D and OPENGL nel drivers, please follow thoses directives to write your vertex programs
*
* - Use only v[0], v[1] etc.. syntax for input registers. Don't use v0, v1 or v[OPOS] etc..
* - Use only c[0], c[1] etc.. syntax for constant registers. Don't use c0, c1 etc..
* - Use only o[HPOS], o[COL0] etc.. syntax for output registers. Don't use oPos, oD0 etc..
* - Use only uppercase for registers R1, R2 etc.. Don't use lowercase r1, r2 etc..
* - Use a semicolon to delineate instructions.
* - Use ARL instruction to load the adress register and not MOV.
* - Don't use the NOP instruction.
* - Don't use macros.
*
* -> Thoses programs work without any change under OpenGL.
* -> Direct3D driver implementation will have to modify the syntax on the fly before the setup like this:
* - "v[0]" must be changed in "v0" etc..
* - "o[HPOS]" must be changed in oPos etc..
* - Semicolon must be changed in line return character.
* - ARL instruction must be changed in MOV.
*
* Behaviour of LOG may change depending on implementation: You can only expect to have dest.z = log2(abs(src.w)).
* LIT may or may not clamp the specular exponent to [-128, 128] (not done when EXT_vertex_shader is used for example ..)
*
* Depending on the implementation, some optimizations can be achieved by masking the unused output values of instructions
* as LIT, EXPP ..
*
* \author Cyril 'Hulud' Corvazier
* \author Nevrax France
* \date 2001
*/
class CVertexProgram : public NLMISC::CRefCount
{ {
public: public:
/// Constructor /// Constructor
CVertexProgram (const char* program); CVertexProgram(CGPUProgramSourceCont *programSource);
CVertexProgram(const char *nelvp);
/// Destructor /// Destructor
virtual ~CVertexProgram (); virtual ~CVertexProgram ();
/// Get the program /// Build feature information
const std::string& getProgram () const { return _Program; }; void buildInfo(const char *displayName, uint features);
/// Get feature information
inline const CVertexProgramInfo *getInfo() const { return _Info; }
private: private:
/// The progam
std::string _Program;
public: /// Feature information
/// The driver information. For the driver implementation only. CVertexProgramInfo *_Info;
NLMISC::CRefPtr<IVertexProgramDrvInfos> _DrvInfo;
}; };
} // NL3D } // NL3D

View file

@ -21,6 +21,40 @@
#include <vector> #include <vector>
/**
* This class is a vertex program.
*
* D3D / OPENGL compatibility notes:
* ---------------------------------
*
* To make your program compatible with D3D and OPENGL nel drivers, please follow thoses directives to write your vertex programs
*
* - Use only v[0], v[1] etc.. syntax for input registers. Don't use v0, v1 or v[OPOS] etc..
* - Use only c[0], c[1] etc.. syntax for constant registers. Don't use c0, c1 etc..
* - Use only o[HPOS], o[COL0] etc.. syntax for output registers. Don't use oPos, oD0 etc..
* - Use only uppercase for registers R1, R2 etc.. Don't use lowercase r1, r2 etc..
* - Use a semicolon to delineate instructions.
* - Use ARL instruction to load the adress register and not MOV.
* - Don't use the NOP instruction.
* - Don't use macros.
*
* -> Thoses programs work without any change under OpenGL.
* -> Direct3D driver implementation will have to modify the syntax on the fly before the setup like this:
* - "v[0]" must be changed in "v0" etc..
* - "o[HPOS]" must be changed in oPos etc..
* - Semicolon must be changed in line return character.
* - ARL instruction must be changed in MOV.
*
* Behaviour of LOG may change depending on implementation: You can only expect to have dest.z = log2(abs(src.w)).
* LIT may or may not clamp the specular exponent to [-128, 128] (not done when EXT_vertex_shader is used for example ..)
*
* Depending on the implementation, some optimizations can be achieved by masking the unused output values of instructions
* as LIT, EXPP ..
*
* \author Cyril 'Hulud' Corvazier
* \author Nevrax France
* \date 2001
*/
/// Swizzle of an operand in a vertex program /// Swizzle of an operand in a vertex program
struct CVPSwizzle struct CVPSwizzle

View file

@ -167,6 +167,8 @@ SOURCE_GROUP(Driver FILES
../../include/nel/3d/vertex_program_parse.h ../../include/nel/3d/vertex_program_parse.h
pixel_program.cpp pixel_program.cpp
../../include/nel/3d/pixel_program.h ../../include/nel/3d/pixel_program.h
geometry_program.cpp
../../include/nel/3d/geometry_program.h
gpu_program.cpp gpu_program.cpp
../../include/nel/3d/gpu_program.h ../../include/nel/3d/gpu_program.h
gpu_program_source.cpp gpu_program_source.cpp

View file

@ -58,7 +58,7 @@ IDriver::~IDriver()
nlassert(_MatDrvInfos.size()==0); nlassert(_MatDrvInfos.size()==0);
nlassert(_VBDrvInfos.size()==0); nlassert(_VBDrvInfos.size()==0);
nlassert(_IBDrvInfos.size()==0); nlassert(_IBDrvInfos.size()==0);
nlassert(_VtxPrgDrvInfos.size()==0); nlassert(_GPUPrgDrvInfos.size()==0);
} }
@ -94,14 +94,14 @@ bool IDriver::release(void)
// NB: at IShader deletion, this->_MatDrvInfos is updated (entry deleted); // NB: at IShader deletion, this->_MatDrvInfos is updated (entry deleted);
delete *itmat; delete *itmat;
} }
/*
// Release Shader drv. // Release Shader drv.
ItShaderDrvInfoPtrList itshd; ItShaderDrvInfoPtrList itshd;
while( (itshd = _ShaderDrvInfos.begin()) != _ShaderDrvInfos.end() ) while( (itshd = _ShaderDrvInfos.begin()) != _ShaderDrvInfos.end() )
{ {
// NB: at IShader deletion, this->_MatDrvInfos is updated (entry deleted); // NB: at IShader deletion, this->_MatDrvInfos is updated (entry deleted);
delete *itshd; delete *itshd;
} }*/
// Release VBs drv. // Release VBs drv.
ItVBDrvInfoPtrList itvb; ItVBDrvInfoPtrList itvb;
@ -119,12 +119,12 @@ bool IDriver::release(void)
delete *itib; delete *itib;
} }
// Release VtxPrg drv. // Release GPUPrg drv.
ItVtxPrgDrvInfoPtrList itVtxPrg; ItGPUPrgDrvInfoPtrList itGPUPrg;
while( (itVtxPrg = _VtxPrgDrvInfos.begin()) != _VtxPrgDrvInfos.end() ) while( (itGPUPrg = _GPUPrgDrvInfos.begin()) != _GPUPrgDrvInfos.end() )
{ {
// NB: at IVertexProgramDrvInfos deletion, this->_VtxPrgDrvInfos is updated (entry deleted); // NB: at IVertexProgramDrvInfos deletion, this->_GPUPrgDrvInfos is updated (entry deleted);
delete *itVtxPrg; delete *itGPUPrg;
} }
return true; return true;
@ -249,7 +249,7 @@ void IDriver::removeMatDrvInfoPtr(ItMatDrvInfoPtrList shaderIt)
_MatDrvInfos.erase(shaderIt); _MatDrvInfos.erase(shaderIt);
} }
// *************************************************************************** // ***************************************************************************
void IDriver::removeShaderDrvInfoPtr(ItShaderDrvInfoPtrList shaderIt) /*void IDriver::removeShaderDrvInfoPtr(ItShaderDrvInfoPtrList shaderIt)
{ {
_ShaderDrvInfos.erase(shaderIt); _ShaderDrvInfos.erase(shaderIt);
} }
@ -262,6 +262,11 @@ void IDriver::removeVtxPrgDrvInfoPtr(ItVtxPrgDrvInfoPtrList vtxPrgDrvInfoIt)
void IDriver::removePixelPrgDrvInfoPtr(ItPixelPrgDrvInfoPtrList pixelPrgDrvInfoIt) void IDriver::removePixelPrgDrvInfoPtr(ItPixelPrgDrvInfoPtrList pixelPrgDrvInfoIt)
{ {
_PixelPrgDrvInfos.erase(pixelPrgDrvInfoIt); _PixelPrgDrvInfos.erase(pixelPrgDrvInfoIt);
}*/
// ***************************************************************************
void IDriver::removeGPUPrgDrvInfoPtr(ItGPUPrgDrvInfoPtrList vtxPrgDrvInfoIt)
{
_GPUPrgDrvInfos.erase(vtxPrgDrvInfoIt);
} }
// *************************************************************************** // ***************************************************************************

View file

@ -0,0 +1,59 @@
/** \file geometry_program.cpp
* Geometry program definition
*/
/* Copyright, 2000, 2001 Nevrax Ltd.
*
* This file is part of NEVRAX NEL.
* NEVRAX NEL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
* NEVRAX NEL is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with NEVRAX NEL; see the file COPYING. If not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*/
#include "std3d.h"
#include <nel/3d/geometry_program.h>
#include <nel/3d/driver.h>
namespace NL3D
{
// ***************************************************************************
CGeometryProgram::CGeometryProgram(CGPUProgramSourceCont *programSource) : _Info(NULL), IGPUProgram(programSource)
{
}
// ***************************************************************************
CGeometryProgram::~CGeometryProgram ()
{
delete _Info;
_Info = NULL;
}
// ***************************************************************************
void CGeometryProgram::buildInfo(const char *displayName, uint features)
{
nlassert(_Info == NULL);
_Info = new CGeometryProgramInfo();
CGeometryProgramInfo *info = _Info;
info->DisplayName = displayName;
info->Features = features;
}
} // NL3D

View file

@ -1,9 +1,9 @@
/** /**
* \file gpu_program.cpp * \file gpu_program.cpp
* \brief CGPUProgram * \brief IGPUProgram
* \date 2013-09-07 15:00GMT * \date 2013-09-07 15:00GMT
* \author Jan Boon (Kaetemi) * \author Jan Boon (Kaetemi)
* CGPUProgram * IGPUProgram
*/ */
/* /*
@ -35,157 +35,50 @@
#include <nel/misc/string_mapper.h> #include <nel/misc/string_mapper.h>
// Project includes // Project includes
#include <nel/3d/driver.h>
using namespace std; using namespace std;
// using namespace NLMISC; // using namespace NLMISC;
namespace NL3D { namespace NL3D {
// ***************************************************************************
IGPUProgramDrvInfos::IGPUProgramDrvInfos(IDriver *drv, ItGPUPrgDrvInfoPtrList it)
{
_Driver = drv;
_DriverIterator = it;
}
// ***************************************************************************
IGPUProgramDrvInfos::~IGPUProgramDrvInfos ()
{
_Driver->removeGPUPrgDrvInfoPtr(_DriverIterator);
}
// ***************************************************************************
IGPUProgram::IGPUProgram() IGPUProgram::IGPUProgram()
{ {
Info.Ptr = NULL;
} }
// ***************************************************************************
IGPUProgram::IGPUProgram(CGPUProgramSourceCont *programSource) : _ProgramSource(programSource)
{
}
// ***************************************************************************
IGPUProgram::~IGPUProgram() IGPUProgram::~IGPUProgram()
{ {
delete Info.Ptr; // Must kill the drv mirror of this program.
Info.Ptr = NULL; _DrvInfo.kill();
} }
void IGPUProgram::buildVPInfo(const char *displayName, uint features)
{
nlassert(Info.VertexProgram == NULL);
Info.VertexProgram = new CVertexProgramInfo();
CVertexProgramInfo *info = Info.VertexProgram;
info->DisplayName = displayName;
info->Features = features;
if (features & CVertexProgramInfo::Ambient)
{
info->AmbientIdx = getParamIdx("nlAmbient");
if (info->AmbientIdx == ~0)
{
nlwarning("Missing 'nlAmbient' in gpu program '%s', Ambient disabled", displayName);
info->Features &= ~CVertexProgramInfo::Ambient;
}
}
if (features & CVertexProgramInfo::Sun)
{
if (features & CVertexProgramInfo::DynamicLights)
{
info->SunEnabledIdx = getParamIdx("nlSunEnabled");
if (info->SunEnabledIdx == ~0)
{
nlwarning("Missing 'nlSunEnabled' in gpu program '%s', DynamicLights disabled", displayName);
info->Features &= ~CVertexProgramInfo::DynamicLights;
}
}
info->SunDirectionIdx = getParamIdx("nlSunDirection");
info->SunDiffuseIdx = getParamIdx("nlSunDiffuse");
if (info->SunDirectionIdx == ~0
|| info->SunDiffuseIdx == ~0)
{
nlwarning("Missing 'nlSunDirection/nlSunDiffuse' in gpu program '%s', Sun disabled", displayName);
info->Features &= ~CVertexProgramInfo::Sun;
}
}
if (features & CVertexProgramInfo::PointLight0)
{
if (features & CVertexProgramInfo::DynamicLights)
{
info->PointLight0EnabledIdx = getParamIdx("nlPointLight0Enabled");
if (info->PointLight0EnabledIdx == ~0)
{
nlwarning("Missing 'nlPointLight0Enabled' in gpu program '%s', DynamicLights disabled", displayName);
info->Features &= ~CVertexProgramInfo::DynamicLights;
}
}
info->PointLight0PositionIdx = getParamIdx("nlPointLight0Position");
info->PointLight0DiffuseIdx = getParamIdx("nlPointLight0Diffuse");
if (info->PointLight0PositionIdx == ~0
|| info->PointLight0DiffuseIdx == ~0)
{
nlwarning("Missing 'nlPointLight0Position/nlPointLight0Diffuse' in gpu program '%s', PointLight0 disabled", displayName);
info->Features &= ~CVertexProgramInfo::PointLight0;
}
}
if (features & CVertexProgramInfo::PointLight1)
{
if (features & CVertexProgramInfo::DynamicLights)
{
info->PointLight1EnabledIdx = getParamIdx("nlPointLight1Enabled");
if (info->PointLight1EnabledIdx == ~0)
{
nlwarning("Missing 'nlPointLight1Enabled' in gpu program '%s', DynamicLights disabled", displayName);
info->Features &= ~CVertexProgramInfo::DynamicLights;
}
}
info->PointLight1PositionIdx = getParamIdx("nlPointLight1Position");
info->PointLight1DiffuseIdx = getParamIdx("nlPointLight1Diffuse");
if (info->PointLight1PositionIdx == ~0
|| info->PointLight1DiffuseIdx == ~0)
{
nlwarning("Missing 'nlPointLight1Position/nlPointLight1Diffuse' in gpu program '%s', PointLight1 disabled", displayName);
info->Features &= ~CVertexProgramInfo::PointLight1;
}
}
if (features & CVertexProgramInfo::PointLight2)
{
if (features & CVertexProgramInfo::DynamicLights)
{
info->PointLight2EnabledIdx = getParamIdx("nlPointLight2Enabled");
if (info->PointLight2EnabledIdx == ~0)
{
nlwarning("Missing 'nlPointLight2Enabled' in gpu program '%s', DynamicLights disabled", displayName);
info->Features &= ~CVertexProgramInfo::DynamicLights;
}
}
info->PointLight2PositionIdx = getParamIdx("nlPointLight2Position");
info->PointLight2DiffuseIdx = getParamIdx("nlPointLight2Diffuse");
if (info->PointLight2PositionIdx == ~0
|| info->PointLight2DiffuseIdx == ~0)
{
nlwarning("Missing 'nlPointLight2Position/nlPointLight2Diffuse' in gpu program '%s', PointLight2 disabled", displayName);
info->Features &= ~CVertexProgramInfo::PointLight2;
}
}
}
void IGPUProgram::buildPPInfo(const char *displayName, uint features)
{
nlassert(Info.PixelProgram == NULL);
Info.PixelProgram = new CPixelProgramInfo();
CPixelProgramInfo *info = Info.PixelProgram;
info->DisplayName = displayName;
info->Features = features;
if (features & CPixelProgramInfo::Fog)
{
if (features & CPixelProgramInfo::DynamicFog)
{
info->FogEnabledIdx = getParamIdx("nlFogEnabled");
if (info->FogEnabledIdx == ~0)
{
nlwarning("Missing 'nlFogEnabled' in gpu program '%s', DynamicFog disabled", displayName);
info->Features &= ~CPixelProgramInfo::DynamicFog;
}
}
info->FogStartEndIdx = getParamIdx("nlFogStartEnd");
info->FogColorIdx = getParamIdx("nlFogColor");
if (info->FogStartEndIdx == ~0
|| info->FogStartEndIdx == ~0)
{
nlwarning("Missing 'nlFogStartEnd/nlFogColor' in gpu program '%s', Fog disabled", displayName);
info->Features &= ~CPixelProgramInfo::Fog;
}
}
}
void IGPUProgram::buildGPInfo(const char *displayName, uint features)
{
nlassert(Info.GeometryProgram == NULL);
Info.GeometryProgram = new CGeometryProgramInfo();
}
} /* namespace NL3D */ } /* namespace NL3D */
/* end of file */ /* end of file */

View file

@ -1,7 +1,5 @@
/** \file pixel_program.cpp /** \file pixel_program.cpp
* Pixel program definition * Pixel program definition
*
* $Id: pixel_program.cpp,v 1.1.2.1 2007/04/27 17:35:07 legallo Exp $
*/ */
/* Copyright, 2000, 2001 Nevrax Ltd. /* Copyright, 2000, 2001 Nevrax Ltd.
@ -33,31 +31,49 @@ namespace NL3D
{ {
// *************************************************************************** // ***************************************************************************
IPixelProgramDrvInfos::IPixelProgramDrvInfos (IDriver *drv, ItPixelPrgDrvInfoPtrList it)
{
_Driver= drv;
_DriverIterator= it;
}
CPixelProgram::CPixelProgram(CGPUProgramSourceCont *programSource) : _Info(NULL), IGPUProgram(programSource)
// ***************************************************************************
IPixelProgramDrvInfos::~IPixelProgramDrvInfos ()
{
_Driver->removePixelPrgDrvInfoPtr (_DriverIterator);
}
// ***************************************************************************
CPixelProgram::CPixelProgram(const char* program) : _Program(program)
{ {
} }
// ***************************************************************************
CPixelProgram::~CPixelProgram ()
{
delete _Info;
_Info = NULL;
}
// *************************************************************************** // ***************************************************************************
CPixelProgram::~CPixelProgram()
{
void CPixelProgram::buildInfo(const char *displayName, uint features)
{
nlassert(_Info == NULL);
_Info = new CPixelProgramInfo();
CPixelProgramInfo *info = _Info;
info->DisplayName = displayName;
info->Features = features;
if (features & CPixelProgramInfo::Fog)
{
if (features & CPixelProgramInfo::DynamicFog)
{
info->FogEnabledIdx = getParamIdx("nlFogEnabled");
if (info->FogEnabledIdx == ~0)
{
nlwarning("Missing 'nlFogEnabled' in gpu program '%s', DynamicFog disabled", displayName);
info->Features &= ~CPixelProgramInfo::DynamicFog;
}
}
info->FogStartEndIdx = getParamIdx("nlFogStartEnd");
info->FogColorIdx = getParamIdx("nlFogColor");
if (info->FogStartEndIdx == ~0
|| info->FogStartEndIdx == ~0)
{
nlwarning("Missing 'nlFogStartEnd/nlFogColor' in gpu program '%s', Fog disabled", displayName);
info->Features &= ~CPixelProgramInfo::Fog;
}
}
} }
} // NL3D } // NL3D

View file

@ -27,85 +27,4 @@ using namespace NLMISC;
namespace NL3D namespace NL3D
{ {
// ***************************************************************************
CShader::~CShader()
{
// Must kill the drv mirror of this shader.
_DrvInfo.kill();
}
// ***************************************************************************
CShader::CShader()
{
_ShaderChanged = true;
}
// ***************************************************************************
void CShader::setText (const char *text)
{
_Text = text;
_ShaderChanged = true;
}
// ***************************************************************************
void CShader::setName (const char *name)
{
_Name = name;
_ShaderChanged = true;
}
// ***************************************************************************
bool CShader::loadShaderFile (const char *filename)
{
_Text = "";
// Lookup
string _filename = CPath::lookup(filename, false, true, true);
if (!_filename.empty())
{
// File length
uint size = CFile::getFileSize (_filename);
_Text.reserve (size+1);
try
{
CIFile file;
if (file.open (_filename))
{
// Read it
while (!file.eof ())
{
char line[512];
file.getline (line, 512);
_Text += line;
}
// Set the shader name
_Name = CFile::getFilename (filename);
return true;
}
else
{
nlwarning ("Can't open the file %s for reading", _filename.c_str());
}
}
catch (const Exception &e)
{
nlwarning ("Error while reading %s : %s", _filename.c_str(), e.what());
}
}
return false;
}
// ***************************************************************************
IShaderDrvInfos::~IShaderDrvInfos()
{
_Driver->removeShaderDrvInfoPtr(_DriverIterator);
}
} // NL3D } // NL3D

View file

@ -115,6 +115,12 @@ void CStereoDebugger::setDriver(NL3D::UDriver *driver)
nlassert(!m_PixelProgram); nlassert(!m_PixelProgram);
NL3D::IDriver *drvInternal = (static_cast<CDriverUser *>(driver))->getDriver(); NL3D::IDriver *drvInternal = (static_cast<CDriverUser *>(driver))->getDriver();
CGPUProgramSource *source = new CGPUProgramSource();
CGPUProgramSourceCont *sourceCont = new CGPUProgramSourceCont();
sourceCont->Sources.push_back(source);
source->Features = CPixelProgramInfo::MaterialTextures;
/*if (drvInternal->supportPixelProgram(CPixelProgram::fp40) && drvInternal->supportBloomEffect() && drvInternal->supportNonPowerOfTwoTextures()) /*if (drvInternal->supportPixelProgram(CPixelProgram::fp40) && drvInternal->supportBloomEffect() && drvInternal->supportNonPowerOfTwoTextures())
{ {
nldebug("VR: fp40"); nldebug("VR: fp40");
@ -123,7 +129,9 @@ void CStereoDebugger::setDriver(NL3D::UDriver *driver)
else*/ if (drvInternal->supportPixelProgram(CPixelProgram::arbfp1) && drvInternal->supportBloomEffect() && drvInternal->supportNonPowerOfTwoTextures()) else*/ if (drvInternal->supportPixelProgram(CPixelProgram::arbfp1) && drvInternal->supportBloomEffect() && drvInternal->supportNonPowerOfTwoTextures())
{ {
nldebug("VR: arbfp1"); nldebug("VR: arbfp1");
m_PixelProgram = new CPixelProgram(a_arbfp1); source->Profile = IGPUProgram::arbfp1;
source->setCodePtr(a_arbfp1);
m_PixelProgram = new CPixelProgram(sourceCont);
} }
/*else if (drvInternal->supportPixelProgram(CPixelProgram::ps_2_0)) /*else if (drvInternal->supportPixelProgram(CPixelProgram::ps_2_0))
{ {

View file

@ -238,20 +238,32 @@ void CStereoOVR::setDriver(NL3D::UDriver *driver)
nlassert(!m_PixelProgram); nlassert(!m_PixelProgram);
NL3D::IDriver *drvInternal = (static_cast<CDriverUser *>(driver))->getDriver(); NL3D::IDriver *drvInternal = (static_cast<CDriverUser *>(driver))->getDriver();
CGPUProgramSource *source = new CGPUProgramSource();
CGPUProgramSourceCont *sourceCont = new CGPUProgramSourceCont();
sourceCont->Sources.push_back(source);
source->Features = CPixelProgramInfo::MaterialTextures;
if (drvInternal->supportPixelProgram(CPixelProgram::fp40) && drvInternal->supportBloomEffect() && drvInternal->supportNonPowerOfTwoTextures()) if (drvInternal->supportPixelProgram(CPixelProgram::fp40) && drvInternal->supportBloomEffect() && drvInternal->supportNonPowerOfTwoTextures())
{ {
nldebug("VR: fp40"); nldebug("VR: fp40");
m_PixelProgram = new CPixelProgram(g_StereoOVR_fp40); source->Profile = IGPUProgram::fp40;
source->setCodePtr(g_StereoOVR_fp40);
m_PixelProgram = new CPixelProgram(sourceCont);
} }
else if (drvInternal->supportPixelProgram(CPixelProgram::arbfp1) && drvInternal->supportBloomEffect() && drvInternal->supportNonPowerOfTwoTextures()) else if (drvInternal->supportPixelProgram(CPixelProgram::arbfp1) && drvInternal->supportBloomEffect() && drvInternal->supportNonPowerOfTwoTextures())
{ {
nldebug("VR: arbfp1"); nldebug("VR: arbfp1");
m_PixelProgram = new CPixelProgram(g_StereoOVR_arbfp1); source->Profile = IGPUProgram::arbfp1;
source->setCodePtr(g_StereoOVR_arbfp1);
m_PixelProgram = new CPixelProgram(sourceCont);
} }
else if (drvInternal->supportPixelProgram(CPixelProgram::ps_2_0)) else if (drvInternal->supportPixelProgram(CPixelProgram::ps_2_0))
{ {
nldebug("VR: ps_2_0"); nldebug("VR: ps_2_0");
m_PixelProgram = new CPixelProgram(g_StereoOVR_ps_2_0); source->Profile = IGPUProgram::ps_2_0;
source->setCodePtr(g_StereoOVR_ps_2_0);
m_PixelProgram = new CPixelProgram(sourceCont);
} }
if (m_PixelProgram) if (m_PixelProgram)

View file

@ -24,34 +24,131 @@
namespace NL3D namespace NL3D
{ {
// *************************************************************************** // ***************************************************************************
IVertexProgramDrvInfos::IVertexProgramDrvInfos (IDriver *drv, ItVtxPrgDrvInfoPtrList it)
CVertexProgram::CVertexProgram(CGPUProgramSourceCont *programSource) : _Info(NULL), IGPUProgram(programSource)
{ {
_Driver= drv;
_DriverIterator= it;
} }
// *************************************************************************** // ***************************************************************************
IVertexProgramDrvInfos::~IVertexProgramDrvInfos ()
CVertexProgram::CVertexProgram(const char *nelvp) : _Info(NULL)
{ {
_Driver->removeVtxPrgDrvInfoPtr (_DriverIterator); CGPUProgramSource *source = new CGPUProgramSource();
_ProgramSource = new CGPUProgramSourceCont();
_ProgramSource->Sources.push_back(source);
source->Profile = IGPUProgram::nelvp;
source->setCode(nelvp);
source->Features = 0;
} }
// *************************************************************************** // ***************************************************************************
CVertexProgram::CVertexProgram (const char* program)
{
_Program=program;
}
// ***************************************************************************
CVertexProgram::~CVertexProgram () CVertexProgram::~CVertexProgram ()
{ {
// Must kill the drv mirror of this VB. delete _Info;
_DrvInfo.kill(); _Info = NULL;
}
// ***************************************************************************
void CVertexProgram::buildInfo(const char *displayName, uint features)
{
nlassert(_Info == NULL);
_Info = new CVertexProgramInfo();
CVertexProgramInfo *info = _Info;
info->DisplayName = displayName;
info->Features = features;
if (features & CVertexProgramInfo::Ambient)
{
info->AmbientIdx = getParamIdx("nlAmbient");
if (info->AmbientIdx == ~0)
{
nlwarning("Missing 'nlAmbient' in gpu program '%s', Ambient disabled", displayName);
info->Features &= ~CVertexProgramInfo::Ambient;
}
}
if (features & CVertexProgramInfo::Sun)
{
if (features & CVertexProgramInfo::DynamicLights)
{
info->SunEnabledIdx = getParamIdx("nlSunEnabled");
if (info->SunEnabledIdx == ~0)
{
nlwarning("Missing 'nlSunEnabled' in gpu program '%s', DynamicLights disabled", displayName);
info->Features &= ~CVertexProgramInfo::DynamicLights;
}
}
info->SunDirectionIdx = getParamIdx("nlSunDirection");
info->SunDiffuseIdx = getParamIdx("nlSunDiffuse");
if (info->SunDirectionIdx == ~0
|| info->SunDiffuseIdx == ~0)
{
nlwarning("Missing 'nlSunDirection/nlSunDiffuse' in gpu program '%s', Sun disabled", displayName);
info->Features &= ~CVertexProgramInfo::Sun;
}
}
if (features & CVertexProgramInfo::PointLight0)
{
if (features & CVertexProgramInfo::DynamicLights)
{
info->PointLight0EnabledIdx = getParamIdx("nlPointLight0Enabled");
if (info->PointLight0EnabledIdx == ~0)
{
nlwarning("Missing 'nlPointLight0Enabled' in gpu program '%s', DynamicLights disabled", displayName);
info->Features &= ~CVertexProgramInfo::DynamicLights;
}
}
info->PointLight0PositionIdx = getParamIdx("nlPointLight0Position");
info->PointLight0DiffuseIdx = getParamIdx("nlPointLight0Diffuse");
if (info->PointLight0PositionIdx == ~0
|| info->PointLight0DiffuseIdx == ~0)
{
nlwarning("Missing 'nlPointLight0Position/nlPointLight0Diffuse' in gpu program '%s', PointLight0 disabled", displayName);
info->Features &= ~CVertexProgramInfo::PointLight0;
}
}
if (features & CVertexProgramInfo::PointLight1)
{
if (features & CVertexProgramInfo::DynamicLights)
{
info->PointLight1EnabledIdx = getParamIdx("nlPointLight1Enabled");
if (info->PointLight1EnabledIdx == ~0)
{
nlwarning("Missing 'nlPointLight1Enabled' in gpu program '%s', DynamicLights disabled", displayName);
info->Features &= ~CVertexProgramInfo::DynamicLights;
}
}
info->PointLight1PositionIdx = getParamIdx("nlPointLight1Position");
info->PointLight1DiffuseIdx = getParamIdx("nlPointLight1Diffuse");
if (info->PointLight1PositionIdx == ~0
|| info->PointLight1DiffuseIdx == ~0)
{
nlwarning("Missing 'nlPointLight1Position/nlPointLight1Diffuse' in gpu program '%s', PointLight1 disabled", displayName);
info->Features &= ~CVertexProgramInfo::PointLight1;
}
}
if (features & CVertexProgramInfo::PointLight2)
{
if (features & CVertexProgramInfo::DynamicLights)
{
info->PointLight2EnabledIdx = getParamIdx("nlPointLight2Enabled");
if (info->PointLight2EnabledIdx == ~0)
{
nlwarning("Missing 'nlPointLight2Enabled' in gpu program '%s', DynamicLights disabled", displayName);
info->Features &= ~CVertexProgramInfo::DynamicLights;
}
}
info->PointLight2PositionIdx = getParamIdx("nlPointLight2Position");
info->PointLight2DiffuseIdx = getParamIdx("nlPointLight2Diffuse");
if (info->PointLight2PositionIdx == ~0
|| info->PointLight2DiffuseIdx == ~0)
{
nlwarning("Missing 'nlPointLight2Position/nlPointLight2Diffuse' in gpu program '%s', PointLight2 disabled", displayName);
info->Features &= ~CVertexProgramInfo::PointLight2;
}
}
} }
} // NL3D } // NL3D