From 680f2608033fc2c07b10616c5b8bf03411d74fc5 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Tue, 10 Sep 2013 00:31:26 +0200 Subject: [PATCH] Use CSmartPtr for vertex program --- code/nel/include/nel/3d/gpu_program.h | 5 ++ .../include/nel/3d/meshvp_per_pixel_light.h | 2 +- code/nel/include/nel/3d/meshvp_wind_tree.h | 2 +- code/nel/include/nel/3d/water_shape.h | 16 +++--- .../driver/opengl/driver_opengl_uniform.cpp | 2 +- code/nel/src/3d/gpu_program.cpp | 57 +++++++++++-------- code/nel/src/3d/meshvp_per_pixel_light.cpp | 6 +- code/nel/src/3d/meshvp_wind_tree.cpp | 10 ++-- code/nel/src/3d/water_model.cpp | 6 +- code/nel/src/3d/water_shape.cpp | 32 +++++------ 10 files changed, 77 insertions(+), 61 deletions(-) diff --git a/code/nel/include/nel/3d/gpu_program.h b/code/nel/include/nel/3d/gpu_program.h index ebb06f4c4..6ff2ed940 100644 --- a/code/nel/include/nel/3d/gpu_program.h +++ b/code/nel/include/nel/3d/gpu_program.h @@ -86,6 +86,9 @@ struct CGPUProgramFeatures ModelViewProjectionTranspose = 0x00000400, ModelViewProjectionInverseTranspose = 0x00000800, + // Fog + Fog = 0x00001000, + // // Rough example, modify as necessary. // @@ -144,6 +147,8 @@ struct CGPUProgramIndices uint ModelViewProjectionTranspose; uint ModelViewProjectionInverseTranspose; + uint Fog; + // // Rough example, modify as necessary. // diff --git a/code/nel/include/nel/3d/meshvp_per_pixel_light.h b/code/nel/include/nel/3d/meshvp_per_pixel_light.h index d7be0f3f9..5df1bfc16 100644 --- a/code/nel/include/nel/3d/meshvp_per_pixel_light.h +++ b/code/nel/include/nel/3d/meshvp_per_pixel_light.h @@ -84,7 +84,7 @@ private: bool _IsPointLight; // enum { NumVp = 8}; - static std::auto_ptr _VertexProgram[NumVp]; + static NLMISC::CSmartPtr _VertexProgram[NumVp]; }; } // NL3D diff --git a/code/nel/include/nel/3d/meshvp_wind_tree.h b/code/nel/include/nel/3d/meshvp_wind_tree.h index 7553d7cca..4e5d2875a 100644 --- a/code/nel/include/nel/3d/meshvp_wind_tree.h +++ b/code/nel/include/nel/3d/meshvp_wind_tree.h @@ -112,7 +112,7 @@ private: /** The 16 versions: Specular or not (0 or 2), + normalize normal or not (0 or 1). * All multiplied by 4, because support from 0 to 3 pointLights activated. (0.., 4.., 8.., 12..) */ - static std::auto_ptr _VertexProgram[NumVp]; + static NLMISC::CSmartPtr _VertexProgram[NumVp]; // WindTree Time for this mesh param setup. Stored in mesh because same for all instances. float _CurrentTime[HrcDepth]; diff --git a/code/nel/include/nel/3d/water_shape.h b/code/nel/include/nel/3d/water_shape.h index f7a7e1b0b..ae0fda5c6 100644 --- a/code/nel/include/nel/3d/water_shape.h +++ b/code/nel/include/nel/3d/water_shape.h @@ -247,17 +247,17 @@ private: static bool _GridSizeTouched; // - static std::auto_ptr _VertexProgramBump1; - static std::auto_ptr _VertexProgramBump2; + static NLMISC::CSmartPtr _VertexProgramBump1; + static NLMISC::CSmartPtr _VertexProgramBump2; // - static std::auto_ptr _VertexProgramBump1Diffuse; - static std::auto_ptr _VertexProgramBump2Diffuse; + static NLMISC::CSmartPtr _VertexProgramBump1Diffuse; + static NLMISC::CSmartPtr _VertexProgramBump2Diffuse; // - static std::auto_ptr _VertexProgramNoBump; - static std::auto_ptr _VertexProgramNoBumpDiffuse; + static NLMISC::CSmartPtr _VertexProgramNoBump; + static NLMISC::CSmartPtr _VertexProgramNoBumpDiffuse; // - static std::auto_ptr _VertexProgramNoWave; - static std::auto_ptr _VertexProgramNoWaveDiffuse; + static NLMISC::CSmartPtr _VertexProgramNoWave; + static NLMISC::CSmartPtr _VertexProgramNoWaveDiffuse; }; diff --git a/code/nel/src/3d/driver/opengl/driver_opengl_uniform.cpp b/code/nel/src/3d/driver/opengl/driver_opengl_uniform.cpp index a8434b3bc..6fe7e1f1c 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl_uniform.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl_uniform.cpp @@ -415,7 +415,7 @@ void CDriverGL::setUniformParams(TProgram program, const CGPUProgramParams ¶ { const std::string &name = params.getNameByOffset(offset); nlassert(!name.empty() /* missing both parameter name and index, code error */); - uint index = prog->getUniformIndex(name); + uint index = prog->getUniformIndex(name.c_str()); nlassert(index != ~0 /* invalid parameter name */); params.map(index, name); } diff --git a/code/nel/src/3d/gpu_program.cpp b/code/nel/src/3d/gpu_program.cpp index ee16f1104..0ffdb49d9 100644 --- a/code/nel/src/3d/gpu_program.cpp +++ b/code/nel/src/3d/gpu_program.cpp @@ -84,112 +84,121 @@ void IGPUProgram::buildInfo(CSource *source) if (features.DriverFlags & CGPUProgramFeatures::ModelView) { - m_Indices.ModelView = getUniformIndex("nlModelView"); + m_Indices.ModelView = getUniformIndex("modelView"); if (m_Indices.ModelView == ~0) { - nlwarning("Missing 'nlModelView' in gpu program '%s', ModelView disabled", source->DisplayName.c_str()); + nlwarning("Missing 'modelView' in gpu program '%s', ModelView disabled", source->DisplayName.c_str()); features.DriverFlags &= ~CGPUProgramFeatures::ModelView; } } if (features.DriverFlags & CGPUProgramFeatures::ModelViewInverse) { - m_Indices.ModelViewInverse = getUniformIndex("nlModelViewInverse"); + m_Indices.ModelViewInverse = getUniformIndex("modelViewInverse"); if (m_Indices.ModelViewInverse == ~0) { - nlwarning("Missing 'nlModelViewInverse' in gpu program '%s', ModelViewInverse disabled", source->DisplayName.c_str()); + nlwarning("Missing 'modelViewInverse' in gpu program '%s', ModelViewInverse disabled", source->DisplayName.c_str()); features.DriverFlags &= ~CGPUProgramFeatures::ModelViewInverse; } } if (features.DriverFlags & CGPUProgramFeatures::ModelViewTranspose) { - m_Indices.ModelViewTranspose = getUniformIndex("nlModelViewTranspose"); + m_Indices.ModelViewTranspose = getUniformIndex("modelViewTranspose"); if (m_Indices.ModelViewTranspose == ~0) { - nlwarning("Missing 'nlModelViewTranspose' in gpu program '%s', ModelViewTranspose disabled", source->DisplayName.c_str()); + nlwarning("Missing 'modelViewTranspose' in gpu program '%s', ModelViewTranspose disabled", source->DisplayName.c_str()); features.DriverFlags &= ~CGPUProgramFeatures::ModelViewTranspose; } } if (features.DriverFlags & CGPUProgramFeatures::ModelViewInverseTranspose) { - m_Indices.ModelViewInverseTranspose = getUniformIndex("nlModelViewInverseTranspose"); + m_Indices.ModelViewInverseTranspose = getUniformIndex("modelViewInverseTranspose"); if (m_Indices.ModelViewInverseTranspose == ~0) { - nlwarning("Missing 'nlModelViewInverseTranspose' in gpu program '%s', ModelViewInverseTranspose disabled", source->DisplayName.c_str()); + nlwarning("Missing 'modelViewInverseTranspose' in gpu program '%s', ModelViewInverseTranspose disabled", source->DisplayName.c_str()); features.DriverFlags &= ~CGPUProgramFeatures::ModelViewInverseTranspose; } } if (features.DriverFlags & CGPUProgramFeatures::Projection) { - m_Indices.Projection = getUniformIndex("nlProjection"); + m_Indices.Projection = getUniformIndex("projection"); if (m_Indices.Projection == ~0) { - nlwarning("Missing 'nlProjection' in gpu program '%s', Projection disabled", source->DisplayName.c_str()); + nlwarning("Missing 'projection' in gpu program '%s', Projection disabled", source->DisplayName.c_str()); features.DriverFlags &= ~CGPUProgramFeatures::Projection; } } if (features.DriverFlags & CGPUProgramFeatures::ProjectionInverse) { - m_Indices.ProjectionInverse = getUniformIndex("nlProjectionInverse"); + m_Indices.ProjectionInverse = getUniformIndex("projectionInverse"); if (m_Indices.ProjectionInverse == ~0) { - nlwarning("Missing 'nlProjectionInverse' in gpu program '%s', ProjectionInverse disabled", source->DisplayName.c_str()); + nlwarning("Missing 'projectionInverse' in gpu program '%s', ProjectionInverse disabled", source->DisplayName.c_str()); features.DriverFlags &= ~CGPUProgramFeatures::ProjectionInverse; } } if (features.DriverFlags & CGPUProgramFeatures::ProjectionTranspose) { - m_Indices.ProjectionTranspose = getUniformIndex("nlProjectionTranspose"); + m_Indices.ProjectionTranspose = getUniformIndex("projectionTranspose"); if (m_Indices.ProjectionTranspose == ~0) { - nlwarning("Missing 'nlProjectionTranspose' in gpu program '%s', ProjectionTranspose disabled", source->DisplayName.c_str()); + nlwarning("Missing 'projectionTranspose' in gpu program '%s', ProjectionTranspose disabled", source->DisplayName.c_str()); features.DriverFlags &= ~CGPUProgramFeatures::ProjectionTranspose; } } if (features.DriverFlags & CGPUProgramFeatures::ProjectionInverseTranspose) { - m_Indices.ProjectionInverseTranspose = getUniformIndex("nlProjectionInverseTranspose"); + m_Indices.ProjectionInverseTranspose = getUniformIndex("projectionInverseTranspose"); if (m_Indices.ProjectionInverseTranspose == ~0) { - nlwarning("Missing 'nlProjectionInverseTranspose' in gpu program '%s', ProjectionInverseTranspose disabled", source->DisplayName.c_str()); + nlwarning("Missing 'projectionInverseTranspose' in gpu program '%s', ProjectionInverseTranspose disabled", source->DisplayName.c_str()); features.DriverFlags &= ~CGPUProgramFeatures::ProjectionInverseTranspose; } } if (features.DriverFlags & CGPUProgramFeatures::ModelViewProjection) { - m_Indices.ModelViewProjection = getUniformIndex("nlModelViewProjection"); + m_Indices.ModelViewProjection = getUniformIndex("modelViewProjection"); if (m_Indices.ModelViewProjection == ~0) { - nlwarning("Missing 'nlModelViewProjection' in gpu program '%s', ModelViewProjection disabled", source->DisplayName.c_str()); + nlwarning("Missing 'modelViewProjection' in gpu program '%s', ModelViewProjection disabled", source->DisplayName.c_str()); features.DriverFlags &= ~CGPUProgramFeatures::ModelViewProjection; } } if (features.DriverFlags & CGPUProgramFeatures::ModelViewProjectionInverse) { - m_Indices.ModelViewProjectionInverse = getUniformIndex("nlModelViewProjectionInverse"); + m_Indices.ModelViewProjectionInverse = getUniformIndex("modelViewProjectionInverse"); if (m_Indices.ModelViewProjectionInverse == ~0) { - nlwarning("Missing 'nlModelViewProjectionInverse' in gpu program '%s', ModelViewProjectionInverse disabled", source->DisplayName.c_str()); + nlwarning("Missing 'modelViewProjectionInverse' in gpu program '%s', ModelViewProjectionInverse disabled", source->DisplayName.c_str()); features.DriverFlags &= ~CGPUProgramFeatures::ModelViewProjectionInverse; } } if (features.DriverFlags & CGPUProgramFeatures::ModelViewProjectionTranspose) { - m_Indices.ModelViewProjectionTranspose = getUniformIndex("nlModelViewProjectionTranspose"); + m_Indices.ModelViewProjectionTranspose = getUniformIndex("modelViewProjectionTranspose"); if (m_Indices.ModelViewProjectionTranspose == ~0) { - nlwarning("Missing 'nlModelViewProjectionTranspose' in gpu program '%s', ModelViewProjectionTranspose disabled", source->DisplayName.c_str()); + nlwarning("Missing 'modelViewProjectionTranspose' in gpu program '%s', ModelViewProjectionTranspose disabled", source->DisplayName.c_str()); features.DriverFlags &= ~CGPUProgramFeatures::ModelViewProjectionTranspose; } } if (features.DriverFlags & CGPUProgramFeatures::ModelViewProjectionInverseTranspose) { - m_Indices.ModelViewProjectionInverseTranspose = getUniformIndex("nlModelViewProjectionInverseTranspose"); + m_Indices.ModelViewProjectionInverseTranspose = getUniformIndex("modelViewProjectionInverseTranspose"); if (m_Indices.ModelViewProjectionInverseTranspose == ~0) { - nlwarning("Missing 'nlModelViewProjectionInverseTranspose' in gpu program '%s', ModelViewProjectionInverseTranspose disabled", source->DisplayName.c_str()); + nlwarning("Missing 'modelViewProjectionInverseTranspose' in gpu program '%s', ModelViewProjectionInverseTranspose disabled", source->DisplayName.c_str()); features.DriverFlags &= ~CGPUProgramFeatures::ModelViewProjectionInverseTranspose; } } + if (features.DriverFlags & CGPUProgramFeatures::Fog) + { + m_Indices.Fog = getUniformIndex("fog"); + if (m_Indices.Fog == ~0) + { + nlwarning("Missing 'fog' in gpu program '%s', Fog disabled", source->DisplayName.c_str()); + features.DriverFlags &= ~CGPUProgramFeatures::Fog; + } + } // // Rough example, modify as necessary. diff --git a/code/nel/src/3d/meshvp_per_pixel_light.cpp b/code/nel/src/3d/meshvp_per_pixel_light.cpp index dd06e951c..e4f43efc5 100644 --- a/code/nel/src/3d/meshvp_per_pixel_light.cpp +++ b/code/nel/src/3d/meshvp_per_pixel_light.cpp @@ -32,7 +32,7 @@ namespace NL3D { -std::auto_ptr CMeshVPPerPixelLight::_VertexProgram[NumVp]; +NLMISC::CSmartPtr CMeshVPPerPixelLight::_VertexProgram[NumVp]; // *************************************************************************** // Light VP fragment constants start at 24 @@ -414,7 +414,7 @@ void CMeshVPPerPixelLight::initInstance(CMeshBaseInstance *mbi) nlassert(0); } #endif - _VertexProgram[vp]= std::auto_ptr(new CVertexProgram(vpCode.c_str())); + _VertexProgram[vp] = new CVertexProgram(vpCode.c_str()); } } @@ -521,7 +521,7 @@ void CMeshVPPerPixelLight::enable(bool enabled, IDriver *drv) | (SpecularLighting ? 2 : 0) | (_IsPointLight ? 1 : 0); // - drv->activeVertexProgram(_VertexProgram[idVP].get()); + drv->activeVertexProgram(_VertexProgram[idVP]); } else { diff --git a/code/nel/src/3d/meshvp_wind_tree.cpp b/code/nel/src/3d/meshvp_wind_tree.cpp index 6d7901ec2..bf1bc0c4e 100644 --- a/code/nel/src/3d/meshvp_wind_tree.cpp +++ b/code/nel/src/3d/meshvp_wind_tree.cpp @@ -39,7 +39,7 @@ static const uint VPLightConstantStart= 24; // *************************************************************************** -std::auto_ptr CMeshVPWindTree::_VertexProgram[CMeshVPWindTree::NumVp]; +NLMISC::CSmartPtr CMeshVPWindTree::_VertexProgram[CMeshVPWindTree::NumVp]; static const char* WindTreeVPCodeWave= "!!VP1.0 \n\ @@ -157,7 +157,7 @@ void CMeshVPWindTree::initInstance(CMeshBaseInstance *mbi) vpCode= string(WindTreeVPCodeWave) + CRenderTrav::getLightVPFragment(numPls, VPLightConstantStart, specular, normalize) + WindTreeVPCodeEnd; - _VertexProgram[i]= std::auto_ptr(new CVertexProgram(vpCode.c_str())); + _VertexProgram[i] = new CVertexProgram(vpCode.c_str()); // TODO_VP_GLSL } } @@ -312,7 +312,7 @@ bool CMeshVPWindTree::begin(IDriver *driver, CScene *scene, CMeshBaseInstance *m idVP= numPls*4 + idVP; // activate VP. - driver->activeVertexProgram(_VertexProgram[idVP].get()); + driver->activeVertexProgram(_VertexProgram[idVP]); return true; @@ -383,7 +383,7 @@ void CMeshVPWindTree::beginMBRMesh(IDriver *driver, CScene *scene) _LastMBRIdVP= 0; // activate VP. - driver->activeVertexProgram(_VertexProgram[_LastMBRIdVP].get()); + driver->activeVertexProgram(_VertexProgram[_LastMBRIdVP]); } // *************************************************************************** @@ -407,7 +407,7 @@ void CMeshVPWindTree::beginMBRInstance(IDriver *driver, CScene *scene, CMeshBase if( idVP!=_LastMBRIdVP ) { _LastMBRIdVP= idVP; - driver->activeVertexProgram(_VertexProgram[_LastMBRIdVP].get()); + driver->activeVertexProgram(_VertexProgram[_LastMBRIdVP]); } } diff --git a/code/nel/src/3d/water_model.cpp b/code/nel/src/3d/water_model.cpp index e72d7bab9..7ad9274b0 100644 --- a/code/nel/src/3d/water_model.cpp +++ b/code/nel/src/3d/water_model.cpp @@ -908,6 +908,10 @@ void CWaterModel::setupMaterialNVertexShader(IDriver *drv, CWaterShape *shape, c //=========================// // setup Water material // //=========================// + shape->initVertexProgram(); + CVertexProgram *program = shape->_ColorMap ? CWaterShape::_VertexProgramNoWaveDiffuse : CWaterShape::_VertexProgramNoWave; + drv->activeVertexProgram(program); + // TODO_VP_MATERIAL CWaterModel::_WaterMat.setTexture(0, shape->_BumpMap[0]); CWaterModel::_WaterMat.setTexture(1, shape->_BumpMap[1]); CWaterModel::_WaterMat.setTexture(3, shape->_ColorMap); @@ -969,8 +973,6 @@ void CWaterModel::setupMaterialNVertexShader(IDriver *drv, CWaterShape *shape, c cst[10].set(0.5f, 0.5f, 0.f, 1.f); // used to scale reflected ray into the envmap /// set all our constants in one call drv->setConstant(cstOffset, sizeof(cst) / sizeof(cst[0]) - cstOffset, (float *) &cst[cstOffset]); - shape->initVertexProgram(); - drv->activeVertexProgram(shape->_ColorMap ? CWaterShape::_VertexProgramNoWaveDiffuse.get() : CWaterShape::_VertexProgramNoWave.get()); drv->setConstantFog(4); } diff --git a/code/nel/src/3d/water_shape.cpp b/code/nel/src/3d/water_shape.cpp index bb43dc5f5..2376cdfe6 100644 --- a/code/nel/src/3d/water_shape.cpp +++ b/code/nel/src/3d/water_shape.cpp @@ -188,15 +188,15 @@ uint32 CWaterShape::_XGridBorder = 4; uint32 CWaterShape::_YGridBorder = 4; uint32 CWaterShape::_MaxGridSize; bool CWaterShape::_GridSizeTouched = true; -std::auto_ptr CWaterShape::_VertexProgramBump1; -std::auto_ptr CWaterShape::_VertexProgramBump2; -std::auto_ptr CWaterShape::_VertexProgramBump1Diffuse; -std::auto_ptr CWaterShape::_VertexProgramBump2Diffuse; -std::auto_ptr CWaterShape::_VertexProgramNoBump; -std::auto_ptr CWaterShape::_VertexProgramNoBumpDiffuse; +NLMISC::CSmartPtr CWaterShape::_VertexProgramBump1; +NLMISC::CSmartPtr CWaterShape::_VertexProgramBump2; +NLMISC::CSmartPtr CWaterShape::_VertexProgramBump1Diffuse; +NLMISC::CSmartPtr CWaterShape::_VertexProgramBump2Diffuse; +NLMISC::CSmartPtr CWaterShape::_VertexProgramNoBump; +NLMISC::CSmartPtr CWaterShape::_VertexProgramNoBumpDiffuse; // water with no waves -std::auto_ptr CWaterShape::_VertexProgramNoWave; -std::auto_ptr CWaterShape::_VertexProgramNoWaveDiffuse; +NLMISC::CSmartPtr CWaterShape::_VertexProgramNoWave; +NLMISC::CSmartPtr CWaterShape::_VertexProgramNoWaveDiffuse; /** Build a vertex program for water depending on requirements @@ -322,17 +322,17 @@ void CWaterShape::initVertexProgram() if (!created) { // waves - _VertexProgramBump1 = std::auto_ptr(BuildWaterVP(false, true, false)); - _VertexProgramBump2 = std::auto_ptr(BuildWaterVP(false, true, true)); + _VertexProgramBump1 = BuildWaterVP(false, true, false); + _VertexProgramBump2 = BuildWaterVP(false, true, true); - _VertexProgramBump1Diffuse = std::auto_ptr(BuildWaterVP(true, true, false)); - _VertexProgramBump2Diffuse = std::auto_ptr(BuildWaterVP(true, true, true)); + _VertexProgramBump1Diffuse = BuildWaterVP(true, true, false); + _VertexProgramBump2Diffuse = BuildWaterVP(true, true, true); - _VertexProgramNoBump = std::auto_ptr(BuildWaterVP(false, false, false)); - _VertexProgramNoBumpDiffuse = std::auto_ptr(BuildWaterVP(true, false, false)); + _VertexProgramNoBump = BuildWaterVP(false, false, false); + _VertexProgramNoBumpDiffuse = BuildWaterVP(true, false, false); // no waves - _VertexProgramNoWave.reset(new CVertexProgram(WaterVPNoWave)); // TODO_VP_GLSL - _VertexProgramNoWaveDiffuse.reset(new CVertexProgram(WaterVPNoWaveDiffuse)); // TODO_VP_GLSL + _VertexProgramNoWave = new CVertexProgram(WaterVPNoWave); // TODO_VP_GLSL + _VertexProgramNoWaveDiffuse = new CVertexProgram(WaterVPNoWaveDiffuse); // TODO_VP_GLSL created = true; } }