From 3865e6e56f52cc1074972317affe43e616f9cc90 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Wed, 19 Jun 2013 05:03:47 +0200 Subject: [PATCH] Add function to check which pixel program profiles are available on a driver --- code/nel/include/nel/3d/driver.h | 20 ++++++++++++++++++- code/nel/src/3d/driver.cpp | 2 +- .../3d/driver/direct3d/driver_direct3d.cpp | 9 +++++---- .../src/3d/driver/direct3d/driver_direct3d.h | 5 ++--- .../direct3d/driver_direct3d_material.cpp | 6 +++--- .../driver_direct3d_pixel_program.cpp | 9 ++++++++- code/nel/src/3d/driver/opengl/driver_opengl.h | 1 + .../opengl/driver_opengl_pixel_program.cpp | 7 ++++++- code/snowballs2/client/src/commands.cpp | 12 +++++++---- 9 files changed, 53 insertions(+), 18 deletions(-) diff --git a/code/nel/include/nel/3d/driver.h b/code/nel/include/nel/3d/driver.h index 9a079d95d..9e77e31d6 100644 --- a/code/nel/include/nel/3d/driver.h +++ b/code/nel/include/nel/3d/driver.h @@ -142,6 +142,23 @@ public: */ enum TMatrixCount { MaxModelMatrix= 16 }; + enum TPixelProgramProfile + { + // direct3d + 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 + arbfp1 = 0x061A0100, // made up values + fp20 = 0x06100200, + fp30 = 0x06100300, + fp40 = 0x06100400, + }; protected: @@ -1015,7 +1032,8 @@ public: /** * Does the driver supports pixel programs ? */ - virtual bool isPixelProgramSupported () const =0; + virtual bool isPixelProgramSupported() const =0; + virtual bool isPixelProgramSupported(TPixelProgramProfile profile) const =0; diff --git a/code/nel/src/3d/driver.cpp b/code/nel/src/3d/driver.cpp index d44079749..5a08da982 100644 --- a/code/nel/src/3d/driver.cpp +++ b/code/nel/src/3d/driver.cpp @@ -33,7 +33,7 @@ namespace NL3D { // *************************************************************************** -const uint32 IDriver::InterfaceVersion = 0x6b; // added anisotropic filter +const uint32 IDriver::InterfaceVersion = 0x6c; // pixel program interface // *************************************************************************** IDriver::IDriver() : _SyncTexDrvInfos( "IDriver::_SyncTexDrvInfos" ) diff --git a/code/nel/src/3d/driver/direct3d/driver_direct3d.cpp b/code/nel/src/3d/driver/direct3d/driver_direct3d.cpp index 26cf628e0..e33075b60 100644 --- a/code/nel/src/3d/driver/direct3d/driver_direct3d.cpp +++ b/code/nel/src/3d/driver/direct3d/driver_direct3d.cpp @@ -1551,14 +1551,15 @@ bool CDriverD3D::setDisplay(nlWindow wnd, const GfxMode& mode, bool show, bool r #endif // NL_FORCE_TEXTURE_STAGE_COUNT _VertexProgram = !_DisableHardwareVertexProgram && ((caps.VertexShaderVersion&0xffff) >= 0x0100); - _PixelProgram = !_DisableHardwarePixelProgram && (caps.PixelShaderVersion&0xffff) >= 0x0101; - _PixelShader = !_DisableHardwarePixelShader && (caps.PixelShaderVersion&0xffff) >= 0x0101; + _PixelProgramVersion = _DisableHardwareVertexProgram ? 0x0000 : caps.PixelShaderVersion & 0xffff; + nldebug("Pixel Program Version: %i.%i", (uint32)((_PixelProgramVersion & 0xFF00) >> 8), (uint32)(_PixelProgramVersion & 0xFF)); + _PixelProgram = _PixelProgramVersion >= 0x0101; _MaxVerticesByVertexBufferHard = caps.MaxVertexIndex; _MaxLight = caps.MaxActiveLights; if(_MaxLight > 0xFF) _MaxLight = 3; - if (_PixelShader) + if (_PixelProgram) { _MaxNumPerStageConstantLighted = _NbNeLTextureStages; _MaxNumPerStageConstantUnlighted = _NbNeLTextureStages; @@ -3626,7 +3627,7 @@ void CDriverD3D::CVertexProgramPtrState::apply(CDriverD3D *driver) void CDriverD3D::CPixelShaderPtrState::apply(CDriverD3D *driver) { H_AUTO_D3D(CDriverD3D_CPixelShaderPtrState); - if (!driver->supportPixelShaders()) return; + if (!driver->isPixelProgramSupported()) return; driver->_DeviceInterface->SetPixelShader(PixelShader); } diff --git a/code/nel/src/3d/driver/direct3d/driver_direct3d.h b/code/nel/src/3d/driver/direct3d/driver_direct3d.h index 7668bd63c..465689838 100644 --- a/code/nel/src/3d/driver/direct3d/driver_direct3d.h +++ b/code/nel/src/3d/driver/direct3d/driver_direct3d.h @@ -1008,6 +1008,7 @@ public: // Vertex program virtual bool isVertexProgramSupported () const; virtual bool isPixelProgramSupported () const; + virtual bool isPixelProgramSupported (TPixelProgramProfile profile) const; virtual bool isVertexProgramEmulated () const; virtual bool activeVertexProgram (CVertexProgram *program); virtual bool activePixelProgram (CPixelProgram *program); @@ -1065,8 +1066,6 @@ public: uint32 getMaxVertexIndex() const { return _MaxVertexIndex; } - bool supportPixelShaders() const { return _PixelShader; } - // *** Inline info uint inlGetNumTextStages() const { return _NbNeLTextureStages; } @@ -2232,7 +2231,7 @@ private: bool _TextureCubeSupported; bool _VertexProgram; bool _PixelProgram; - bool _PixelShader; + uint16 _PixelProgramVersion; bool _DisableHardwareVertexProgram; bool _DisableHardwarePixelProgram; bool _DisableHardwareVertexArrayAGP; diff --git a/code/nel/src/3d/driver/direct3d/driver_direct3d_material.cpp b/code/nel/src/3d/driver/direct3d/driver_direct3d_material.cpp index a7d218e79..eb550c2cc 100644 --- a/code/nel/src/3d/driver/direct3d/driver_direct3d_material.cpp +++ b/code/nel/src/3d/driver/direct3d/driver_direct3d_material.cpp @@ -567,7 +567,7 @@ bool CDriverD3D::setupMaterial(CMaterial &mat) normalShaderDesc.TexEnvMode[stage] = mat.getTexEnvMode(uint8(stage)); } - if (_PixelShader) + if (_PixelProgram) { #ifdef NL_DEBUG_D3D // Check, should not occured @@ -933,7 +933,7 @@ bool CDriverD3D::setupMaterial(CMaterial &mat) activeShader (NULL); /* If unlighted trick is needed, set the shader later */ - if (!pShader->NeedsConstantForDiffuse && _PixelShader) + if (!pShader->NeedsConstantForDiffuse && _PixelProgram) setPixelShader (pShader->PixelShader); } break; @@ -2019,7 +2019,7 @@ void CDriverD3D::endMaterialMultiPass() bool CDriverD3D::supportCloudRenderSinglePass () const { H_AUTO_D3D(CDriver3D_supportCloudRenderSinglePass); - return _PixelShader; + return _PixelProgram; } // *************************************************************************** diff --git a/code/nel/src/3d/driver/direct3d/driver_direct3d_pixel_program.cpp b/code/nel/src/3d/driver/direct3d/driver_direct3d_pixel_program.cpp index 08ac5d74b..2d7303589 100644 --- a/code/nel/src/3d/driver/direct3d/driver_direct3d_pixel_program.cpp +++ b/code/nel/src/3d/driver/direct3d/driver_direct3d_pixel_program.cpp @@ -56,10 +56,17 @@ CPixelProgramDrvInfosD3D::~CPixelProgramDrvInfosD3D() bool CDriverD3D::isPixelProgramSupported () const { - H_AUTO_D3D(CDriverD3D_isPixelProgramSupported ) + H_AUTO_D3D(CDriverD3D_isPixelProgramSupported) return _PixelProgram; } +bool CDriverD3D::isPixelProgramSupported (TPixelProgramProfile profile) const +{ + H_AUTO_D3D(CDriverD3D_isPixelProgramSupported_profile) + return ((profile & 0xFFFF0000) == 0xD3D00000) + && (_PixelProgramVersion >= (uint16)(profile & 0x0000FFFF)); +} + // *************************************************************************** bool CDriverD3D::activePixelProgram(CPixelProgram *program) diff --git a/code/nel/src/3d/driver/opengl/driver_opengl.h b/code/nel/src/3d/driver/opengl/driver_opengl.h index f53f6f535..3f7487937 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl.h +++ b/code/nel/src/3d/driver/opengl/driver_opengl.h @@ -1305,6 +1305,7 @@ private: bool isVertexProgramSupported () const; bool isPixelProgramSupported () const; + bool isPixelProgramSupported (TPixelProgramProfile profile) const; bool isVertexProgramEmulated () const; bool activeVertexProgram (CVertexProgram *program); bool activePixelProgram (CPixelProgram *program); diff --git a/code/nel/src/3d/driver/opengl/driver_opengl_pixel_program.cpp b/code/nel/src/3d/driver/opengl/driver_opengl_pixel_program.cpp index 18ce82846..5cc3316c1 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl_pixel_program.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl_pixel_program.cpp @@ -57,11 +57,16 @@ CPixelProgamDrvInfosGL::CPixelProgamDrvInfosGL (CDriverGL *drv, ItPixelPrgDrvInf } // *************************************************************************** -bool CDriverGL::isPixelProgramSupported () const +bool CDriverGL::isPixelProgramSupported() const { H_AUTO_OGL(CPixelProgamDrvInfosGL_isPixelProgramSupported) return _Extensions.ARBFragmentProgram; } +bool CDriverGL::isPixelProgramSupported(TPixelProgramProfile profile) const +{ + H_AUTO_OGL(CPixelProgamDrvInfosGL_isPixelProgramSupported_profile) + return profile == arbfp1 && _Extensions.ARBFragmentProgram; +} // *************************************************************************** bool CDriverGL::activePixelProgram(CPixelProgram *program) diff --git a/code/snowballs2/client/src/commands.cpp b/code/snowballs2/client/src/commands.cpp index fe33e566a..a92f296c8 100644 --- a/code/snowballs2/client/src/commands.cpp +++ b/code/snowballs2/client/src/commands.cpp @@ -246,7 +246,7 @@ void cbUpdateCommands (CConfigFile::CVar &var) #if SBCLIENT_DEV_PIXEL_PROGRAM namespace { -CPixelProgram *a_DevPixelProgram; +CPixelProgram *a_DevPixelProgram = NULL; } #endif @@ -294,16 +294,20 @@ void initCommands() #if SBCLIENT_DEV_PIXEL_PROGRAM CommandsMaterial.getObjectPtr()->setShader(NL3D::CMaterial::PostProcessing); - static const char *program_arbfp10 = + static const char *program_arbfp1 = "!!ARBfp1.0\n" "PARAM red = {1.0, 0.0, 0.0, 1.0};\n" "MOV result.color, red;\n" "END\n"; - static const char *program_ps10 = + static const char *program_ps_1_1 = "ps.1.1\n" "def c0, 1.0, 0.0, 0.0, 1.0\n" "mov r0, c0\n"; - a_DevPixelProgram = new CPixelProgram(program_ps10); + NL3D::IDriver *d = dynamic_cast(Driver)->getDriver(); + if (d->isPixelProgramSupported(IDriver::arbfp1)) + a_DevPixelProgram = new CPixelProgram(program_arbfp1); + if (d->isPixelProgramSupported(IDriver::ps_1_1)) + a_DevPixelProgram = new CPixelProgram(program_ps_1_1); #endif }