diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 7366425c8..8313aad7a 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -22,7 +22,7 @@
# gitlab-runner exec docker --timeout=3600 'Linux client debian_amd64_strech build'
# gitlab-runner exec docker --timeout=3600 'Linux client_static debian_amd64_strech build'
# gitlab-runner exec docker --kubernetes-memory-limit='10g' --timeout=3600 'Linux client build'
-# gitlab-runner exec docker --kubernetes-memory-limit='10g' --timeout=3600 'Linux client archlinux build'
+# gitlab-runner exec docker --kubernetes-memory-limit='10g' --timeout=3600 'Linux client archlinux build'
# gitlab-runner exec docker --kubernetes-memory-limit='10g' --timeout=3600 'Linux client fedora_amd64_27 build'
# gitlab-runner exec docker --kubernetes-memory-limit='10g' --timeout=3600 'Linux client ubuntu_amd64_17_10 build'
# gitlab-runner exec docker --kubernetes-memory-limit='10g' --timeout=3600 'Windows client build'
@@ -1055,7 +1055,7 @@ Windows client build:
- find codebis -type f -name "*.rc" -exec unix2dos {} \;
- mkdir -p build
- cd build
- - wine cmake.exe -DWITH_RYZOM_CUSTOM_PATCH_SERVER=ON -DWITH_RYZOM_SERVER=OFF -DWITH_RYZOM_TOOLS=OFF -DWITH_RYZOM_CLIENT=ON -DWITH_RYZOM_PATCH=ON -DWITH_NEL_TESTS=OFF -DWITH_NEL_TOOLS=OFF -DWITH_TOOLS=OFF -DWITH_NEL_SAMPLES=OFF -DWITH_LUA53=ON -DWITH_LUA51=OFF -DWITH_STLPORT=OFF -DWITH_DRIVER_DSOUND=ON -G "NMake Makefiles JOM" -DWITH_STATIC=ON -DWITH_STATIC_DRIVERS=ON -DWITH_DRIVER_OPENAL=OFF -DWITH_DRIVER_DSOUND=ON -DWITH_DRIVER_XAUDIO2=ON -DWITH_DRIVER_FMOD=ON -DWITH_DRIVER_DIRECT3D=ON ../codebis
+ - wine cmake.exe -DWITH_RYZOM_CUSTOM_PATCH_SERVER=ON -DWITH_RYZOM_SERVER=OFF -DWITH_RYZOM_TOOLS=OFF -DWITH_RYZOM_CLIENT=ON -DWITH_RYZOM_PATCH=ON -DWITH_NEL_TESTS=OFF -DWITH_NEL_TOOLS=OFF -DWITH_TOOLS=OFF -DWITH_NEL_SAMPLES=OFF -DWITH_LUA53=ON -DWITH_LUA51=OFF -DWITH_STLPORT=OFF -G "NMake Makefiles JOM" -DWITH_STATIC=ON -DWITH_STATIC_DRIVERS=ON -DWITH_DRIVER_OPENAL=OFF -DWITH_DRIVER_FMOD=ON ../codebis
- wine jom.exe
artifacts:
name: "khanat-client-windows-$CI_COMMIT_REF_NAME"
@@ -1104,7 +1104,7 @@ Linux client test:
- ./khanat-$(echo $CI_BUILD_REF | head -c 7 )-$CI_PIPELINE_ID-Linux-x86_64.run
dependencies:
- Linux client build
-
+
.OSX client test:
stage: test
only:
@@ -1120,7 +1120,7 @@ Linux client test:
##DEPLOYEMENT TO STAGING (TEST SERVER)
-# Job de déploiment vers le staging. Inutilisé pour le moment, il pourrait servir à l'avenir pour déployer automatiquement les nouvelles versions du client/serveur vers l'environnement de staging (zone de test)
+# Job de déploiment vers le staging. Inutilisé pour le moment, il pourrait servir à l'avenir pour déployer automatiquement les nouvelles versions du client/serveur vers l'environnement de staging (zone de test)
.Deploy to Staging:
stage: staging
environment: Staging
@@ -1138,9 +1138,9 @@ Linux client test:
- OSX client test
when: manual
-##DEPLOYEMENT TO PRODUCTION
+##DEPLOYEMENT TO PRODUCTION
-# Job de déploiment vers la production. Inutilisé pour le moment, il pourrait servir à l'avenir pour déployer automatiquement les nouvelles versions du client/serveur vers l'environnement de production
+# Job de déploiment vers la production. Inutilisé pour le moment, il pourrait servir à l'avenir pour déployer automatiquement les nouvelles versions du client/serveur vers l'environnement de production
.Release to Production:
stage: production
environment: Production
diff --git a/code/CMakeModules/ConfigureChecks.cmake b/code/CMakeModules/ConfigureChecks.cmake
index cab7a08c1..ca0b39c51 100644
--- a/code/CMakeModules/ConfigureChecks.cmake
+++ b/code/CMakeModules/ConfigureChecks.cmake
@@ -10,10 +10,6 @@ MACRO(NL_CONFIGURE_CHECKS)
SET(NL_OPENGLES_AVAILABLE 1)
ENDIF()
- IF(WITH_DRIVER_DIRECT3D)
- SET(NL_DIRECT3D_AVAILABLE 1)
- ENDIF()
-
# sound drivers
IF(WITH_DRIVER_FMOD)
SET(NL_FMOD_AVAILABLE 1)
@@ -23,14 +19,6 @@ MACRO(NL_CONFIGURE_CHECKS)
SET(NL_OPENAL_AVAILABLE 1)
ENDIF()
- IF(WITH_DRIVER_DSOUND)
- SET(NL_DSOUND_AVAILABLE 1)
- ENDIF()
-
- IF(WITH_DRIVER_XAUDIO2)
- SET(NL_XAUDIO2_AVAILABLE 1)
- ENDIF()
-
IF(NOT RYZOM_VERSION_MAJOR)
SET(RYZOM_VERSION_MAJOR ${NL_VERSION_MAJOR})
SET(RYZOM_VERSION_MINOR ${NL_VERSION_MINOR})
diff --git a/code/CMakeModules/Find3dsMaxSDK.cmake b/code/CMakeModules/Find3dsMaxSDK.cmake
index cf49a90d3..bedc6c368 100644
--- a/code/CMakeModules/Find3dsMaxSDK.cmake
+++ b/code/CMakeModules/Find3dsMaxSDK.cmake
@@ -1,6 +1,3 @@
-# - Find DirectInput
-# Find the DirectSound includes and libraries
-#
# MAXSDK_DIR - 3DSMAX SDK root directory
# MAXSDK_INCLUDE_DIR - where to find baseinterface.h
# MAXSDK_LIBRARIES - List of libraries when using 3DSMAX.
diff --git a/code/CMakeModules/FindDSound.cmake b/code/CMakeModules/FindDSound.cmake
deleted file mode 100644
index dde5212ab..000000000
--- a/code/CMakeModules/FindDSound.cmake
+++ /dev/null
@@ -1,36 +0,0 @@
-# - Find DirectSound
-# Find the DirectSound includes and libraries
-#
-# DSOUND_INCLUDE_DIR - where to find dsound.h
-# DSOUND_LIBRARIES - List of libraries when using dsound.
-# DSOUND_FOUND - True if dsound found.
-
-if(DSOUND_INCLUDE_DIR)
- # Already in cache, be silent
- set(DSOUND_FIND_QUIETLY TRUE)
-ENDIF()
-
-find_path(DSOUND_INCLUDE_DIR dsound.h
- "$ENV{DXSDK_DIR}"
- "$ENV{DXSDK_DIR}/Include"
-)
-
-find_library(DSOUND_LIBRARY dsound
- "$ENV{DXSDK_DIR}"
- "$ENV{DXSDK_DIR}/Lib"
- "$ENV{DXSDK_DIR}/Lib/x86"
-)
-
-# Handle the QUIETLY and REQUIRED arguments and set DSOUND_FOUND to TRUE if
-# all listed variables are TRUE.
-include(FindPackageHandleStandardArgs)
-find_package_handle_standard_args(DSOUND DEFAULT_MSG
- DSOUND_INCLUDE_DIR DSOUND_LIBRARY)
-
-if(DSOUND_FOUND)
- set(DSOUND_LIBRARIES ${DSOUND_LIBRARY})
-ELSE()
- set(DSOUND_LIBRARIES)
-ENDIF()
-
-mark_as_advanced(DSOUND_INCLUDE_DIR DSOUND_LIBRARY)
diff --git a/code/CMakeModules/FindDirectXSDK.cmake b/code/CMakeModules/FindDirectXSDK.cmake
deleted file mode 100644
index 4519ef16d..000000000
--- a/code/CMakeModules/FindDirectXSDK.cmake
+++ /dev/null
@@ -1,69 +0,0 @@
-# - Find DirectX
-# Find the DirectX includes and libraries
-#
-# DXSDK_INCLUDE_DIR - where to find baseinterface.h
-# DXSDK_LIBRARIES - List of libraries when using 3DSMAX.
-# DXSDK_FOUND - True if MAX SDK found.
-
-IF(DXSDK_DIR)
- # Already in cache, be silent
- SET(DXSDK_FIND_QUIETLY TRUE)
-ENDIF()
-
-FIND_PATH(DXSDK_DIR
- "Include/dxsdkver.h"
- PATHS
- "$ENV{DXSDK_DIR}"
- "C:/Program Files (x86)/Microsoft DirectX SDK (June 2010)"
- "C:/Program Files/Microsoft DirectX SDK (June 2010)"
- "C:/Program Files (x86)/Microsoft DirectX SDK (February 2010)"
- "C:/Program Files/Microsoft DirectX SDK (February 2010)"
- "C:/Program Files (x86)/Microsoft DirectX SDK (November 2007)"
- "C:/Program Files/Microsoft DirectX SDK (November 2007)"
- "C:/Program Files (x86)/Microsoft DirectX SDK"
- "C:/Program Files/Microsoft DirectX SDK"
-)
-
-MACRO(FIND_DXSDK_LIBRARY MYLIBRARY MYLIBRARYNAME)
- FIND_LIBRARY(${MYLIBRARY}
- NAMES ${MYLIBRARYNAME}
- HINTS
- "${DXSDK_LIBRARY_DIR}"
- )
-ENDMACRO()
-
-IF(DXSDK_DIR)
- SET(DXSDK_INCLUDE_DIR "${DXSDK_DIR}/Include")
-
- IF(TARGET_X64)
- SET(DXSDK_LIBRARY_DIRS ${DXSDK_DIR}/Lib/x64 ${DXSDK_DIR}/lib/amd64)
- ELSE()
- SET(DXSDK_LIBRARY_DIRS ${DXSDK_DIR}/Lib/x86 ${DXSDK_DIR}/lib)
- ENDIF()
-
- FIND_PATH(DXSDK_LIBRARY_DIR
- dxguid.lib
- PATHS
- ${DXSDK_LIBRARY_DIRS})
-
- FIND_DXSDK_LIBRARY(DXSDK_GUID_LIBRARY dxguid)
- FIND_DXSDK_LIBRARY(DXSDK_DINPUT_LIBRARY dinput8)
- FIND_DXSDK_LIBRARY(DXSDK_DSOUND_LIBRARY dsound)
- FIND_DXSDK_LIBRARY(DXSDK_XAUDIO_LIBRARY x3daudio)
- FIND_DXSDK_LIBRARY(DXSDK_D3DX9_LIBRARY d3dx9)
- FIND_DXSDK_LIBRARY(DXSDK_D3D9_LIBRARY d3d9)
-ENDIF()
-
-# Handle the QUIETLY and REQUIRED arguments and set DXSDK_FOUND to TRUE if
-# all listed variables are TRUE.
-INCLUDE(FindPackageHandleStandardArgs)
-
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(DirectXSDK DEFAULT_MSG DXSDK_DIR DXSDK_GUID_LIBRARY DXSDK_DINPUT_LIBRARY)
-
-MARK_AS_ADVANCED(DXSDK_INCLUDE_DIR
- DXSDK_GUID_LIBRARY
- DXSDK_DINPUT_LIBRARY
- DXSDK_DSOUND_LIBRARY
- DXSDK_XAUDIO_LIBRARY
- DXSDK_D3DX9_LIBRARY
- DXSDK_D3D9_LIBRARY)
diff --git a/code/CMakeModules/FindMySQL.cmake b/code/CMakeModules/FindMySQL.cmake
index 8a92cb0c4..f045d3497 100644
--- a/code/CMakeModules/FindMySQL.cmake
+++ b/code/CMakeModules/FindMySQL.cmake
@@ -30,12 +30,16 @@ ELSE()
FIND_LIBRARY(MYSQL_LIBRARY_RELEASE NAMES libmysql mysqlclient
PATHS
$ENV{ProgramFiles}/MySQL/*/lib/opt
- $ENV{SystemDrive}/MySQL/*/lib/opt)
+ $ENV{SystemDrive}/MySQL/*/lib/opt
+ $ENV{ProgramFiles}/MySQL/*/lib
+ $ENV{SystemDrive}/MySQL/*/lib)
FIND_LIBRARY(MYSQL_LIBRARY_DEBUG NAMES libmysqld mysqlclientd
PATHS
$ENV{ProgramFiles}/MySQL/*/lib/opt
- $ENV{SystemDrive}/MySQL/*/lib/opt)
+ $ENV{SystemDrive}/MySQL/*/lib/opt
+ $ENV{ProgramFiles}/MySQL/*/lib
+ $ENV{SystemDrive}/MySQL/*/lib)
ELSE()
FIND_LIBRARY(MYSQL_LIBRARY_RELEASE NAMES mysqlclient
PATHS
diff --git a/code/CMakeModules/nel.cmake b/code/CMakeModules/nel.cmake
index 95b28bb8a..37935016a 100644
--- a/code/CMakeModules/nel.cmake
+++ b/code/CMakeModules/nel.cmake
@@ -122,12 +122,6 @@ ENDMACRO(NL_ADD_RUNTIME_FLAGS)
MACRO(NL_ADD_STATIC_VID_DRIVERS name)
IF(WITH_STATIC_DRIVERS)
- IF(WIN32)
- IF(WITH_DRIVER_DIRECT3D)
- TARGET_LINK_LIBRARIES(${name} nel_drv_direct3d_win)
- ENDIF()
- ENDIF()
-
IF(WITH_DRIVER_OPENGL)
IF(WIN32)
TARGET_LINK_LIBRARIES(${name} nel_drv_opengl_win)
@@ -149,14 +143,6 @@ ENDMACRO(NL_ADD_STATIC_VID_DRIVERS)
MACRO(NL_ADD_STATIC_SND_DRIVERS name)
IF(WITH_STATIC_DRIVERS)
IF(WIN32)
- IF(WITH_DRIVER_DSOUND)
- TARGET_LINK_LIBRARIES(${name} nel_drv_dsound_win)
- ENDIF()
-
- IF(WITH_DRIVER_XAUDIO2)
- TARGET_LINK_LIBRARIES(${name} nel_drv_xaudio2_win)
- ENDIF()
-
IF(WITH_DRIVER_OPENAL)
TARGET_LINK_LIBRARIES(${name} nel_drv_openal_win)
ENDIF()
@@ -299,11 +285,8 @@ MACRO(NL_SETUP_NEL_DEFAULT_OPTIONS)
###
OPTION(WITH_DRIVER_OPENGL "Build OpenGL Driver (3D)" ON )
OPTION(WITH_DRIVER_OPENGLES "Build OpenGL ES Driver (3D)" OFF)
- OPTION(WITH_DRIVER_DIRECT3D "Build Direct3D Driver (3D)" OFF)
OPTION(WITH_DRIVER_OPENAL "Build OpenAL Driver (Sound)" ON )
OPTION(WITH_DRIVER_FMOD "Build FMOD Driver (Sound)" OFF)
- OPTION(WITH_DRIVER_DSOUND "Build DirectSound Driver (Sound)" OFF)
- OPTION(WITH_DRIVER_XAUDIO2 "Build XAudio2 Driver (Sound)" OFF)
###
# Optional support
@@ -665,7 +648,7 @@ MACRO(NL_SETUP_BUILD)
IF(APPLE)
SET(OBJC_FLAGS -fobjc-abi-version=2 -fobjc-legacy-dispatch -fobjc-weak)
-
+
IF(NOT XCODE)
IF(CMAKE_OSX_ARCHITECTURES)
SET(TARGETS_COUNT 0)
@@ -1198,14 +1181,6 @@ MACRO(SETUP_EXTERNAL)
INCLUDE_DIRECTORIES(${STLPORT_INCLUDE_DIR})
ENDIF()
- IF(WIN32)
- # Must include DXSDK before WINSDK
- FIND_PACKAGE(DirectXSDK REQUIRED)
- # IF(DXSDK_INCLUDE_DIR)
- # INCLUDE_DIRECTORIES(${DXSDK_INCLUDE_DIR})
- # ENDIF()
- ENDIF()
-
IF(MSVC)
FIND_PACKAGE(MSVC REQUIRED)
FIND_PACKAGE(WindowsSDK REQUIRED)
diff --git a/code/config.h.cmake b/code/config.h.cmake
index 69171cf68..1ead86c20 100644
--- a/code/config.h.cmake
+++ b/code/config.h.cmake
@@ -3,12 +3,9 @@
#cmakedefine NL_OPENGL_AVAILABLE ${NL_OPENGL_AVAILABLE}
#cmakedefine NL_OPENGLES_AVAILABLE ${NL_OPENGLES_AVAILABLE}
-#cmakedefine NL_DIRECT3D_AVAILABLE ${NL_DIRECT3D_AVAILABLE}
#cmakedefine NL_FMOD_AVAILABLE ${NL_FMOD_AVAILABLE}
#cmakedefine NL_OPENAL_AVAILABLE ${NL_OPENAL_AVAILABLE}
-#cmakedefine NL_DSOUND_AVAILABLE ${NL_DSOUND_AVAILABLE}
-#cmakedefine NL_XAUDIO2_AVAILABLE ${NL_XAUDIO2_AVAILABLE}
#cmakedefine NL_STEREO_AVAILABLE ${NL_STEREO_AVAILABLE}
diff --git a/code/nel/include/nel/3d/bloom_effect.h b/code/nel/include/nel/3d/bloom_effect.h
index 49c959e23..0b3ecc2a0 100644
--- a/code/nel/include/nel/3d/bloom_effect.h
+++ b/code/nel/include/nel/3d/bloom_effect.h
@@ -37,7 +37,7 @@ class CTextureUser;
//---------------------------------------- CBloomEffect -----------------------------------------------------
//-----------------------------------------------------------------------------------------------------------
// CBloomEffect class apply a bloom effect on the whole scene. The whole scene is rendered in a
-// render target (a Frame Buffer Object on OpengL, the normal back buffer in Direct3D) which is stretched
+// render target (a Frame Buffer Object on OpengL) which is stretched
// in a 256*256 another render target.
// We apply a horizontal blur on this 256*256 render target, then a vertical blur on the result of this first pass.
// The final blurred render target is blend with the initial render target of scene, with a dest + src - dest*src
@@ -93,7 +93,6 @@ public:
// to keep Z tests correct.
// This method is called at the end of interfaces display in the main loop, to display final render target
// (with added interfaces) in the color frame buffer.
- // NB : In Direct3D, the final render target is displayed at the end of endBloom call.
// void endInterfacesDisplayBloom();
private:
diff --git a/code/nel/include/nel/3d/driver.h b/code/nel/include/nel/3d/driver.h
index 52bda8576..a2ef613ba 100644
--- a/code/nel/include/nel/3d/driver.h
+++ b/code/nel/include/nel/3d/driver.h
@@ -188,9 +188,6 @@ public:
/// Before rendering via a driver in a thread, must activate() (per thread).
virtual bool activate() = 0;
- // Test if the device is lost. Can only happen with D3D.
- // The calling application may skip some part of its rendering when it is the case (this is not a requirement, but may save cpu for other applications)
- virtual bool isLost() const = 0;
/// Return true if driver is still active. Return false else. If he user close the window, must return false.
virtual bool isActive() = 0;
@@ -437,8 +434,7 @@ public:
virtual uint getNbTextureStages() const = 0;
/** Get max number of per stage constant that can be used simultaneously.
- * This will usually match the number of texture stages, but with a D3D driver, this feature is not available most of the time
- * so it is emulated. If pixel shaders are available this will be fully supported.
+ * This will usually match the number of texture stages. If pixel shaders are available this will be fully supported.
* Under OpenGL this simply returns the maximum number of texture stages (getNbTextureStages) in both return values.
*/
virtual void getNumPerStageConstant(uint &lightedMaterial, uint &unlightedMaterial) const = 0;
@@ -1363,7 +1359,7 @@ public:
*/
virtual bool setAdapter(uint adapter) = 0;
- /** Tell if the vertex color memory format is RGBA (openGL) or BGRA (directx)
+ /** Tell if the vertex color memory format is RGBA (openGL) or BGRA
* BGRA :
* *****************************************************************
* Offset: * 0 * 1 * 2 * 3 *
@@ -1446,4 +1442,3 @@ private:
}
#endif // NL_DRV_H
-
diff --git a/code/nel/include/nel/3d/driver_user.h b/code/nel/include/nel/3d/driver_user.h
index 62c6fd6db..d553fa928 100644
--- a/code/nel/include/nel/3d/driver_user.h
+++ b/code/nel/include/nel/3d/driver_user.h
@@ -133,8 +133,6 @@ public:
virtual ~CDriverUser();
// @}
- virtual bool isLost() const;
-
/// \name Window / driver management.
// @{
diff --git a/code/nel/include/nel/3d/dru.h b/code/nel/include/nel/3d/dru.h
index fda543ecd..ab4db8819 100644
--- a/code/nel/include/nel/3d/dru.h
+++ b/code/nel/include/nel/3d/dru.h
@@ -27,11 +27,9 @@
#if defined (NL_COMP_MINGW)
# define NL3D_GL_DLL_NAME "libnel_drv_opengl_win"
# define NL3D_GLES_DLL_NAME "libnel_drv_opengles_win"
-# define NL3D_D3D_DLL_NAME "libnel_drv_direct3d_win"
#elif defined (NL_OS_WINDOWS)
# define NL3D_GL_DLL_NAME "nel_drv_opengl_win"
# define NL3D_GLES_DLL_NAME "nel_drv_opengles_win"
-# define NL3D_D3D_DLL_NAME "nel_drv_direct3d_win"
#elif defined (NL_OS_UNIX)
# define NL3D_GL_DLL_NAME "nel_drv_opengl"
# define NL3D_GLES_DLL_NAME "nel_drv_opengles"
@@ -100,34 +98,6 @@ struct EDruOpenglEsDriverCantCreateDriver : public EDru
EDruOpenglEsDriverCantCreateDriver() : EDru( NL3D_GLES_DLL_NAME " can't create driver" ) {}
};
-#ifdef NL_OS_WINDOWS
-// Direct3D
-struct EDruDirect3dDriverNotFound : public EDru
-{
- EDruDirect3dDriverNotFound() : EDru( NL3D_D3D_DLL_NAME " not found" ) {}
-};
-
-struct EDruDirect3dDriverCorrupted : public EDru
-{
- EDruDirect3dDriverCorrupted() : EDru( "Can't get NL3D_createIDriverInstance from " NL3D_D3D_DLL_NAME " (Bad dll?)" ) {}
-};
-
-struct EDruDirect3dDriverOldVersion : public EDru
-{
- EDruDirect3dDriverOldVersion() : EDru( NL3D_D3D_DLL_NAME " is a too old version. Ask for a more recent file" ) {}
-};
-
-struct EDruDirect3dDriverUnknownVersion : public EDru
-{
- EDruDirect3dDriverUnknownVersion() : EDru( NL3D_D3D_DLL_NAME " is more recent than the application" ) {}
-};
-
-struct EDruDirect3dDriverCantCreateDriver : public EDru
-{
- EDruDirect3dDriverCantCreateDriver() : EDru( NL3D_D3D_DLL_NAME " can't create driver" ) {}
-};
-#endif // NL_OS_WINDOWS
-
/// The driver Utilities class of static.
class CDRU
{
@@ -139,11 +109,6 @@ public:
/// Portable Function which create a GL ES Driver (using gl dll...).
static IDriver *createGlEsDriver() throw(EDru);
-#ifdef NL_OS_WINDOWS
- /// Windows Function which create a Direct3d Driver.
- static IDriver *createD3DDriver() throw(EDru);
-#endif // NL_OS_WINDOWS
-
/// \name 2D render.
// @{
/// Draw a bitmap 2D. Warning: this is slow...
diff --git a/code/nel/include/nel/3d/material.h b/code/nel/include/nel/3d/material.h
index 7a300da45..8a1a18a76 100644
--- a/code/nel/include/nel/3d/material.h
+++ b/code/nel/include/nel/3d/material.h
@@ -223,8 +223,7 @@ public:
/** \name Texture Addressing Modes. They are valid only with the normal texture shader.
* All modes are not supported everywhere, so you should check for it in the driver.
- * The modes are similar to those introduced with DirectX 8.0 Pixel Shaders and OpenGL
- * TEXTURE_SHADERS_NV
+ * The modes are similar to those introduced with OpenGL TEXTURE_SHADERS_NV
*/
// @{
enum TTexAddressingMode {
@@ -416,7 +415,7 @@ public:
*
* For compatibility problems:
* - no scaling is allowed (some cards do not implement this well).
- * - Texture can be the source only for Arg0 (DirectX restriction). nlassert...
+ * - Texture can be the source only for Arg0. nlassert...
*
* NB: for Alpha Aguments, only operands SrcAlpha and InvSrcAlpha are valid (nlassert..).
*/
diff --git a/code/nel/include/nel/3d/nelu.h b/code/nel/include/nel/3d/nelu.h
index fb30a5012..5c25fc515 100644
--- a/code/nel/include/nel/3d/nelu.h
+++ b/code/nel/include/nel/3d/nelu.h
@@ -64,7 +64,7 @@ public:
*
* You can access the driver with CNELU::Driver.
*/
- static bool initDriver(uint w, uint h, uint bpp=32, bool windowed=true, nlWindow systemWindow=EmptyWindow, bool offscreen=false, bool direct3d=false) throw(EDru);
+ static bool initDriver(uint w, uint h, uint bpp=32, bool windowed=true, nlWindow systemWindow=EmptyWindow, bool offscreen=false) throw(EDru);
/** Init all that we need for a Scene.
* - register scene basics models,
@@ -108,7 +108,7 @@ public:
* - initScene();
* - initEventServer();
*/
- static bool init(uint w, uint h, CViewport viewport=CViewport(), uint bpp=32, bool windowed=true, nlWindow systemWindow=EmptyWindow, bool offscreen = false, bool direct3d = false) throw(EDru);
+ static bool init(uint w, uint h, CViewport viewport=CViewport(), uint bpp=32, bool windowed=true, nlWindow systemWindow=EmptyWindow, bool offscreen = false) throw(EDru);
/** Delete all:
* - releaseEventServer();
diff --git a/code/nel/include/nel/3d/program.h b/code/nel/include/nel/3d/program.h
index 77e6baa62..2183b9c07 100644
--- a/code/nel/include/nel/3d/program.h
+++ b/code/nel/include/nel/3d/program.h
@@ -6,20 +6,20 @@
* IProgram
*/
-/*
+/*
* Copyright (C) 2013 by authors
- *
+ *
* This file is part of NL3D.
* NL3D is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
- *
+ *
* NL3D 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 Affero General
* Public License for more details.
- *
+ *
* You should have received a copy of the GNU Affero General Public
* License along with NL3D. If not, see
* .
@@ -61,7 +61,7 @@ public:
};
// Features exposed by a program. Used to set builtin parameters on user provided shaders.
-// This is only used for user provided shaders, not for builtin shaders,
+// This is only used for user provided shaders, not for builtin shaders,
// as it is a slow method which has to go through all of the options every time.
// Builtin shaders should set all flags to 0.
// Example:
@@ -81,18 +81,18 @@ struct CProgramFeatures
enum TDriverFlags
{
// Matrices
- Matrices = 0x00000001,
+ Matrices = 0x00000001,
// Fog
- Fog = 0x00000002,
+ Fog = 0x00000002,
};
uint32 DriverFlags;
enum TMaterialFlags
{
/// Use the CMaterial texture stages as the textures for a Pixel Program
- TextureStages = 0x00000001,
- TextureMatrices = 0x00000002,
+ TextureStages = 0x00000001,
+ TextureMatrices = 0x00000002,
};
// Material builtin parameters
uint32 MaterialFlags;
@@ -104,22 +104,22 @@ struct CProgramIndex
{
enum TName
{
- ModelView,
- ModelViewInverse,
- ModelViewTranspose,
- ModelViewInverseTranspose,
+ ModelView,
+ ModelViewInverse,
+ ModelViewTranspose,
+ ModelViewInverseTranspose,
- Projection,
- ProjectionInverse,
- ProjectionTranspose,
- ProjectionInverseTranspose,
+ Projection,
+ ProjectionInverse,
+ ProjectionTranspose,
+ ProjectionInverseTranspose,
- ModelViewProjection,
- ModelViewProjectionInverse,
- ModelViewProjectionTranspose,
- ModelViewProjectionInverseTranspose,
+ ModelViewProjection,
+ ModelViewProjectionInverse,
+ ModelViewProjectionTranspose,
+ ModelViewProjectionInverseTranspose,
- Fog,
+ Fog,
NUM_UNIFORMS
};
@@ -148,22 +148,6 @@ public:
// nel - 0x31,type,bitfield
nelvp = 0x31010001, // VP supported by CVertexProgramParser, similar to arbvp1, can be translated to vs_1_1
- // direct3d - 0xD9,type,major,minor
- // vertex programs
- vs_1_1 = 0xD9010101,
- vs_2_0 = 0xD9010200,
- // vs_2_sw = 0xD9010201, // not sure...
- // vs_2_x = 0xD9010202, // not sure...
- // vs_3_0 = 0xD9010300, // not supported
- // pixel programs
- ps_1_1 = 0xD9020101,
- ps_1_2 = 0xD9020102,
- ps_1_3 = 0xD9020103,
- ps_1_4 = 0xD9020104,
- ps_2_0 = 0xD9020200,
- // ps_2_x = 0xD9020201, // not sure...
- // ps_3_0 = 0xD9020300, // not supported
-
// opengl - 0x61,type,bitfield
// vertex programs
// vp20 = 0x61010001, // NV_vertex_program1_1, outdated
@@ -211,7 +195,7 @@ public:
/// Map with known parameter indices, used for assembly programs
std::map ParamIndices;
-
+
private:
std::string SourceCopy;
};
@@ -227,7 +211,7 @@ public:
inline size_t addSource(CSource *source) { nlassert(!m_Source); m_Sources.push_back(source); return (m_Sources.size() - 1); }
inline void removeSource(size_t i) { nlassert(!m_Source); m_Sources.erase(m_Sources.begin() + i); }
- // 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, etcetera) by name. Invalid name returns ~0
inline uint getUniformIndex(const char *name) const { return m_DrvInfo->getUniformIndex(name); };
inline uint getUniformIndex(const std::string &name) const { return m_DrvInfo->getUniformIndex(name.c_str()); };
inline uint getUniformIndex(CProgramIndex::TName name) const { return m_Index.Indices[name]; }
diff --git a/code/nel/include/nel/3d/ps_attrib_maker.h b/code/nel/include/nel/3d/ps_attrib_maker.h
index fb96cb86e..855dba45c 100644
--- a/code/nel/include/nel/3d/ps_attrib_maker.h
+++ b/code/nel/include/nel/3d/ps_attrib_maker.h
@@ -287,7 +287,7 @@ public:
// misc
- // used by colors only : set the internal color format. useful to write in vertex buffer (format differs between D3D & OpenGL)
+ // used by colors only : set the internal color format. useful to write in vertex buffer
virtual void setColorType(CVertexBuffer::TVertexColorType /* type */) {}
protected:
diff --git a/code/nel/include/nel/3d/texture.h b/code/nel/include/nel/3d/texture.h
index bd71a00fd..1a5c583ac 100644
--- a/code/nel/include/nel/3d/texture.h
+++ b/code/nel/include/nel/3d/texture.h
@@ -470,7 +470,7 @@ public:
/** See if filter mode or wrap mode have been touched.
* If this is the case, the driver should resetup them for that texture (If driver stores filter & wrap mode
- * per texture (OpenGL) rather than globally (D3D))
+ * per texture (OpenGL))
*/
bool filterOrWrapModeTouched() const { return _FilterOrWrapModeTouched; }
diff --git a/code/nel/include/nel/3d/u_driver.h b/code/nel/include/nel/3d/u_driver.h
index 0500192ad..f33e93020 100644
--- a/code/nel/include/nel/3d/u_driver.h
+++ b/code/nel/include/nel/3d/u_driver.h
@@ -140,7 +140,7 @@ public:
enum TStencilFunc { never = 0, less, lessequal, equal, notequal, greaterequal, greater, always};
// Existing drivers
- enum TDriver { Direct3d = 0, OpenGl, OpenGlEs };
+ enum TDriver { OpenGl = 1, OpenGlEs };
public:
/// The EventServer of this driver. Init after setDisplay()!!
@@ -157,10 +157,6 @@ public:
virtual ~UDriver();
// @}
- // Test if the device is lost. Can only happen with D3D.
- // The calling application may skip some part of its rendering when it is the case (this is not a requirement, but may save cpu for other applications)
- virtual bool isLost() const = 0;
-
/// \name Disable Hardware Feature
/** Disable some Feature that may be supported by the Hardware
@@ -200,7 +196,6 @@ public:
virtual void showWindow(bool show = true)=0;
/* Pass in dialog box mode. After having called this method, you can use normal GUI.
- * In fullscreen under direct3d, the main 3d window is minimized.
*
* \code
* Driver->beginDialogMode();
@@ -215,7 +210,6 @@ public:
virtual void beginDialogMode() =0;
/* Leave the dialog box mode. After having called this method, you can't use normal GUI anymore.
- * In fullscreen under direct3d, the main 3d window is maximized.
*/
virtual void endDialogMode() =0;
@@ -841,7 +835,7 @@ public:
/**
* This is the static function which build a UDriver, the root for all 3D functions.
*/
- static UDriver *createDriver(uintptr_t windowIcon = 0, bool direct3d = false, emptyProc exitFunc = 0);
+ static UDriver *createDriver(uintptr_t windowIcon = 0, emptyProc exitFunc = 0);
static UDriver *createDriver(uintptr_t windowIcon, TDriver driver, emptyProc exitFunc = 0);
/**
diff --git a/code/nel/include/nel/3d/vertex_buffer.h b/code/nel/include/nel/3d/vertex_buffer.h
index 1f1c789ae..60e047df2 100644
--- a/code/nel/include/nel/3d/vertex_buffer.h
+++ b/code/nel/include/nel/3d/vertex_buffer.h
@@ -178,7 +178,7 @@ public:
/**
- * Value type, there is 13 kind of value type as in DirectX8 and gl_vertex_program used in exteneded mode
+ * Value type, there is 13 kind of value type as in gl_vertex_program used in exteneded mode
*/
enum TType
{
@@ -1267,24 +1267,3 @@ inline void CVertexBuffer::unlock () const
#endif // NL_VERTEX_BUFFER_H
/* End of vertex_buffer.h */
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/code/nel/include/nel/3d/vertex_program_parse.h b/code/nel/include/nel/3d/vertex_program_parse.h
index 88538da07..de039e79b 100644
--- a/code/nel/include/nel/3d/vertex_program_parse.h
+++ b/code/nel/include/nel/3d/vertex_program_parse.h
@@ -24,10 +24,10 @@
/**
* This class is a vertex program.
*
- * D3D / OPENGL compatibility notes:
+ * OPENGL compatibility notes:
* ---------------------------------
*
- * To make your program compatible with D3D and OPENGL nel drivers, please follow thoses directives to write your vertex programs
+ * To make your program compatible with 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..
@@ -39,11 +39,6 @@
* - 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 ..)
@@ -166,7 +161,7 @@ struct CVPInstruction
enum EOpcode
{
MOV = 0,
- ARL, // in D3D, is equivalent to MOV
+ ARL,
MUL,
ADD,
MAD,
@@ -266,4 +261,3 @@ private:
#endif
-
diff --git a/code/nel/include/nel/sound/driver/buffer.h b/code/nel/include/nel/sound/driver/buffer.h
index 8e6030949..4bc82a432 100644
--- a/code/nel/include/nel/sound/driver/buffer.h
+++ b/code/nel/include/nel/sound/driver/buffer.h
@@ -46,7 +46,6 @@ public:
/// Standard PCM format.
FormatPcm = 1,
/// Intel/DVI ADPCM format, only available for 1 channel at 16 bits per sample, encoded at 4 bits per sample.
- /// This is only implemented in the DSound and XAudio2 driver.
FormatDviAdpcm = 11,
/// No format set. Used when a TBufferFormat value has not been set to any value yet.
FormatNotSet = (~0),
@@ -55,13 +54,13 @@ public:
enum TStorageMode
{
/// Put buffer in sound hardware memory if possible, else in machine ram.
- StorageAuto,
+ StorageAuto,
/// Put buffer in sound hardware memory (fails if not possible). It is recommended to use StorageAuto instead of StorageHardware.
- StorageHardware,
+ StorageHardware,
/// Put buffer in machine ram (used for streaming). It behaves as if OptionSoftwareBuffer and OptionLocalBufferCopy are both enabled.
StorageSoftware
};
-
+
/** Preset the name of the buffer. Used for async loading to give a name
* before the buffer is effectivly loaded.
* If the name after loading of the buffer doesn't match the preset name,
@@ -86,16 +85,16 @@ public:
virtual bool unlock(uint size) = 0;
/// Copy the data with specified size into the buffer. A readable local copy is only guaranteed when OptionLocalBufferCopy is set. Returns true if ok.
virtual bool fill(const uint8 *src, uint size) = 0;
-
+
/// Return the size of the buffer, in bytes.
virtual uint getSize() const = 0;
/// Return the duration (in ms) of the sample in the buffer.
virtual float getDuration() const = 0;
/// Return true if the buffer is stereo (multi-channel), false if mono.
- virtual bool isStereo() const = 0;
+ virtual bool isStereo() const = 0;
/// Return true if the buffer is loaded. Used for async load/unload.
virtual bool isBufferLoaded() const = 0;
-
+
//@{
//\name ***deprecated***
/// Set the sample format. Example: freq=44100. ***deprecated***
@@ -115,7 +114,7 @@ public:
/// Return duration in seconds from pcm size in bytes.
static float getDurationFromPCMSize(uint size, uint8 channels, uint8 bitsPerSample, uint32 frequency);
//@}
-
+
//@{
//\name ADPCM and sample bank building utility methods
struct TADPCMState
@@ -128,7 +127,7 @@ public:
/// Encode 16bit Mono PCM buffer into Mono ADPCM.
static void encodeADPCM(const sint16 *indata, uint8 *outdata, uint nbSample, TADPCMState &state);
/// Decode Mono ADPCM into 16bit Mono PCM.
- static void decodeADPCM(const uint8 *indata, sint16 *outdata, uint nbSample, TADPCMState &state);
+ static void decodeADPCM(const uint8 *indata, sint16 *outdata, uint nbSample, TADPCMState &state);
/// Read a wav file. Data type uint8 is used as unspecified buffer format.
static bool readWav(const uint8 *wav, uint size, std::vector &result, TBufferFormat &bufferFormat, uint8 &channels, uint8 &bitsPerSample, uint32 &frequency);
/// Write a wav file. Data type uint8 does not imply a buffer of any format.
@@ -138,20 +137,20 @@ public:
/// Convert 16bit Mono PCM buffer data to ADPCM.
static bool convertMono16PCMToMonoADPCM(const sint16 *buffer, uint samples, std::vector &result);
//@}
-
+
private:
static const sint _IndexTable[16];
static const uint _StepsizeTable[89];
//@}
-
+
protected:
/// Constructor
IBuffer() { }
-
+
public:
/// Destructor
virtual ~IBuffer() { }
-
+
};
} // NLSOUND
diff --git a/code/nel/include/nel/sound/driver/sound_driver.h b/code/nel/include/nel/sound/driver/sound_driver.h
index e38126fff..f8abfe75b 100644
--- a/code/nel/include/nel/sound/driver/sound_driver.h
+++ b/code/nel/include/nel/sound/driver/sound_driver.h
@@ -64,16 +64,12 @@ public:
/// Driver Creation Choice
enum TDriver
{
- /// DriverAuto automatically picks the most awesome driver (picks first available in this order: FMod, OpenAl, XAudio2, DSound).
+ /// DriverAuto automatically picks the most awesome driver (picks first available in this order: FMod, OpenAl).
DriverAuto = 0,
/// DriverFMod is a driver that runs on FMod, nice quality, but not fully implemented.
DriverFMod,
/// DriverOpenAl is the recommended driver, especially if you have hardware sound acceleration.
DriverOpenAl,
- /// DriverDSound is deprecated.
- DriverDSound,
- /// DriverXAudio2 runs on a fully software-based audio processing API without artificial limits.
- DriverXAudio2,
NumDrivers
};
@@ -81,25 +77,25 @@ public:
enum TSoundOptions
{
/// Enable EAX/I3DL2 environment effects. (not implemented on FMod driver).
- OptionEnvironmentEffects = 0x01,
+ OptionEnvironmentEffects = 0x01,
/// Allow the user to use the ADPCM encoding. (verify availability with getOption)
- OptionAllowADPCM = 0x02,
- /// Force software buffering (always true for XAudio2).
- OptionSoftwareBuffer = 0x04,
+ OptionAllowADPCM = 0x02,
+ /// Force software buffering.
+ OptionSoftwareBuffer = 0x04,
/**
- * Configuration to use manual or API (directx or open AL) rolloff factor.
- * 0 => API (directx, open AL, etc) rollOff control.
+ * Configuration to use manual or API (open AL) rolloff factor.
+ * 0 => API (open AL, etc) rollOff control.
* ISource::setAlpha() will fail.
* IListener::setRollOffFactor() works
* 1 => Manual rollOff control
* ISource::setAlpha() change the shape of attenuation (change the curve)
* IListener::setRollOffFactor() will fail
*/
- OptionManualRolloff = 0x08,
+ OptionManualRolloff = 0x08,
/// Enable local copy of buffer (used by OpenAL driver, required to build sample bank).
- OptionLocalBufferCopy = 0x10,
+ OptionLocalBufferCopy = 0x10,
/// Use to check availability of buffer streaming. (verify with getOption)
- OptionHasBufferStreaming = 0x20,
+ OptionHasBufferStreaming = 0x20,
};
/** The interface must be implemented and provided to the driver
@@ -137,7 +133,7 @@ public:
/// Return a list of available devices for the user. The value at index 0 is empty, and is used for automatic device selection.
virtual void getDevices(std::vector &devices) = 0;
- /** Initialize the driver with a user selected device.
+ /** Initialize the driver with a user selected device.
* In case of failure, can throw one of these ESoundDriver exception objects:
* ESoundDriverNotFound, ESoundDriverCorrupted, ESoundDriverOldVersion, ESoundDriverUnknownVersion
* The driver instance should be deleted by the user after init failure.
@@ -171,10 +167,10 @@ public:
virtual uint countMaxSources() = 0;
/// Return the maximum number of effects that can be created
virtual uint countMaxEffects() { return 0; }
-
+
/// Write information about the driver to the output stream.
virtual void writeProfile(std::string& out) = 0;
-
+
/// Stuff
virtual void startBench() = 0;
virtual void endBench() = 0;
@@ -182,7 +178,7 @@ public:
/// Filled at createDriver()
const std::string &getDllName() const { return _DllName; }
-
+
/// \name Stuff for drivers that have native music support
//@{
/// Create a native music channel, only supported by the FMod driver.
@@ -198,10 +194,10 @@ public:
/// Return if a music extension is supported by the driver's music channel.
virtual bool isMusicExtensionSupported(const std::string &extension) const = 0;
//@}
-
+
private:
std::string _DllName;
-
+
};
diff --git a/code/nel/include/nel/sound/driver/source.h b/code/nel/include/nel/sound/driver/source.h
index d2f4a5186..3112bc3f3 100644
--- a/code/nel/include/nel/sound/driver/source.h
+++ b/code/nel/include/nel/sound/driver/source.h
@@ -33,7 +33,7 @@
#include "sound_driver.h"
-/**
+/**
* The minimum allowed gain is specified as 0.0f.
* Inverting the wave by specifying a negative gain is not allowed.
* \brief Minimum allowed gain (volume).
@@ -41,7 +41,7 @@
#define NLSOUND_MIN_GAIN 0.0f
/**
* The maximum allowed gain is specified as 1.0f.
- * OpenAL implementations may or may not clamp the gain to a maximum
+ * OpenAL implementations may or may not clamp the gain to a maximum
* of 1.0f, so this maximum is forced on all implementations.
* If you pass a value outside the minimum and maximum bounds,
* it will automatically be clamped between them.
@@ -58,10 +58,8 @@
#define NLSOUND_MIN_PITCH 0.0f
/**
* The maximum allowed pitch is specified as 8.0f.
- * Tests indicate that with OpenAL the pitch can be set to 8.0f,
- * and with FMod to somewhere around 9.0f. The XAudio2 implementation
- * uses this value directly to configure the maximum pitch, which can
- * technically be as high as XAUDIO2_MAX_FREQ_RATIO which is 1024.0f.
+ * Tests indicate that with OpenAL the pitch can be set to 8.0f,
+ * and with FMod to somewhere around 9.0f.
* If you pass a value outside the minimum and maximum bounds,
* it will automatically be clamped between them.
* \brief Maximum allowed pitch.
@@ -123,8 +121,8 @@ namespace NLSOUND {
/**
* Sound source interface (implemented in sound driver dynamic library)
- *
- * - If the buffer is mono, the source is played in 3D mode. For
+ *
+ * - If the buffer is mono, the source is played in 3D mode. For
* arguments as 3D vectors, use the NeL vector coordinate system:
\verbatim
(top)
@@ -136,7 +134,7 @@ namespace NLSOUND {
*
* - If the buffer is multi-channel, only distance rolloff is applied.
* - All streaming related functionalities are thread-safe.
- *
+ *
* \author Olivier Cado
* \author Nevrax France
* \author Jan Boon (Kaetemi)
@@ -148,70 +146,70 @@ class ISource
public:
enum TFilter
{
- FilterLowPass,
- FilterBandPass,
- FilterHighPass,
+ FilterLowPass,
+ FilterBandPass,
+ FilterHighPass,
};
-
+
/// Constructor
ISource() { }
/// Destructor
virtual ~ISource() { }
-
+
/// \name Initialization
//@{
/**
- * This function is used to switch between streaming and static
+ * This function is used to switch between streaming and static
* buffer modes. By default, streaming mode is off.
- * Streaming mode must be enabled before calling functions
- * related to buffer streaming, such as 'submitStreamingBuffer'
+ * Streaming mode must be enabled before calling functions
+ * related to buffer streaming, such as 'submitStreamingBuffer'
* and 'countStreamingBuffers'.
- * In the default static buffer mode, only one buffer is set
- * active on this source, and can be replayed or looped as many
+ * In the default static buffer mode, only one buffer is set
+ * active on this source, and can be replayed or looped as many
* times as needed.
* When in streaming mode, multiple buffers are chained after each
- * other, and you must make sure that the source does not run out
+ * other, and you must make sure that the source does not run out
* of data, to avoid sound stopping glitches.
- * The source must be stopped before trying to change the mode,
+ * The source must be stopped before trying to change the mode,
* if a static buffer was set it must be detached as well.
* \brief Switch between streaming and static buffer modes.
- * \param streaming Set to true to enable streaming mode, or
+ * \param streaming Set to true to enable streaming mode, or
* false to use static buffers. If you omit this parameter, it
* will be set as true, and streaming will be enabled.
*/
virtual void setStreaming(bool streaming = true) = 0;
/**
* Sets the buffer that is used for playback by this source.
- * The static buffer will remain active on the source until
- * this function is called with a NULL parameter, or until the
- * mode is changed to streaming. It is possible to play or loop
- * this buffer as often as needed, as long as it is attached
+ * The static buffer will remain active on the source until
+ * this function is called with a NULL parameter, or until the
+ * mode is changed to streaming. It is possible to play or loop
+ * this buffer as often as needed, as long as it is attached
* to this source.
- * If you attach a multichannel (stereo) buffer, the source will
- * automatically be set to relative mode. Setting a mono channel
+ * If you attach a multichannel (stereo) buffer, the source will
+ * automatically be set to relative mode. Setting a mono channel
* buffer will automatically set the relative mode back to it's
- * original setting. It is not possible to enable relative mode
- * with a multichannel buffer, instead you must manually split
+ * original setting. It is not possible to enable relative mode
+ * with a multichannel buffer, instead you must manually split
* the sound data into multiple channels and use multiple sources.
- * You cannot use this function in streaming mode, where you must
+ * You cannot use this function in streaming mode, where you must
* use submitStreamingBuffer() instead.
* A buffer can be attached to more than once source.
- * Before destroying a buffer, it must be detached from all
- * sources it's attached to, which can be done by calling this
+ * Before destroying a buffer, it must be detached from all
+ * sources it's attached to, which can be done by calling this
* function with a NULL parameter as buffer on all relevant sources.
* If you set the buffer while the source is already playing or in
- * paused status, this function does nothing. You must stop() the
+ * paused status, this function does nothing. You must stop() the
* source, or wait until it isStopped() before changing the buffer.
* \brief Attach a buffer to this source.
- * \param buffer The buffer to be attached on this source. It must
- * be created on the same sound driver instance as this source. Set
+ * \param buffer The buffer to be attached on this source. It must
+ * be created on the same sound driver instance as this source. Set
* this parameter to NULL to detach a previously set buffer.
*/
virtual void setStaticBuffer(IBuffer *buffer) = 0;
/**
- * Returns the buffer that was attached to this source. A buffer
+ * Returns the buffer that was attached to this source. A buffer
* can by attached to this source by calling setStaticBuffer().
- * If no static buffer is set, or if the source is in streaming
+ * If no static buffer is set, or if the source is in streaming
* mode, this function will return NULL.
* \brief Get the buffer that is attached to this source.
* \return A pointer to the attached IBuffer, or NULL if none.
@@ -222,16 +220,16 @@ public:
virtual void submitStreamingBuffer(IBuffer *buffer) = 0;
/**
* Returns the amount of buffers that are currently in the queue.
- * This includes buffers that are waiting to be played, as well as
- * the buffer that is currently playing. Buffers that have finished
- * playing are removed from the queue, and do not count towards the
+ * This includes buffers that are waiting to be played, as well as
+ * the buffer that is currently playing. Buffers that have finished
+ * playing are removed from the queue, and do not count towards the
* result of this function.
- * It is recommended to have at least 2 or 3 buffers queued up when
+ * It is recommended to have at least 2 or 3 buffers queued up when
* streaming, to avoid sound stopping glitches.
- * If you need to know the total amount of buffers that were added
- * into the queue, you should count them manually by increasing a
+ * If you need to know the total amount of buffers that were added
+ * into the queue, you should count them manually by increasing a
* value each time 'submitStreamingBuffer' is called.
- * This function always returns 0 when the source is in static
+ * This function always returns 0 when the source is in static
* mode, when the source is stopped, or when no buffers have been
* added yet into the queue.
* \brief Get the number of buffers in the streaming queue.
@@ -239,100 +237,100 @@ public:
*/
virtual uint countStreamingBuffers() const = 0;
//@}
-
+
/// \name Playback control
//@{
/**
* This function is used to enable or disable looping this source.
- * By default, looping is off. The current looping status can be
+ * By default, looping is off. The current looping status can be
* obtained by calling getLooping().
- * It is possible to call this function either before the source
+ * It is possible to call this function either before the source
* has started playing, or while it is already playing.
- * To cleanly exit a loop, you can call setLooping(false) instead
- * of using stop(). Calling stop() on a source that is looping will
+ * To cleanly exit a loop, you can call setLooping(false) instead
+ * of using stop(). Calling stop() on a source that is looping will
* immediately stop the source, which may suffer sound clicks.
- * The looping state is useful on static buffers only. Setting this
+ * The looping state is useful on static buffers only. Setting this
* while in streaming mode will have no effect, however, the loop
* setting will be remembered when switching back to static mode.
* \brief Enable or disable looping this source.
- * \param l Set to true to enable, false to disable looping or to
+ * \param l Set to true to enable, false to disable looping or to
* exit the current loop.
*/
virtual void setLooping(bool l = true) = 0;
/**
* Returns the looping status that was last set by setLooping().
* This function will always return the last set looping option.
- * If you call this while in streaming mode, the result will be the
+ * If you call this while in streaming mode, the result will be the
* setting that will be used when you go back to static buffer mode.
* Looping has no effect on streaming.
* \brief Get the currently set looping status.
* \return Returns true if looping is enabled, false if disabled.
*/
virtual bool getLooping() const = 0;
-
+
/**
- * This function is used to enter playing mode. It will return
- * true in case of success. The playing status can also be verified
+ * This function is used to enter playing mode. It will return
+ * true in case of success. The playing status can also be verified
* by calling isPlaying() on this source.
- * If the source is stopped, or has not started playing yet, the
- * source will start playing from the beginning from the currently
- * attached static buffer when in static mode. If no static buffer
- * was set, the source will remain in stopped mode, and this
- * will return false. A buffer can be attached to this source by
+ * If the source is stopped, or has not started playing yet, the
+ * source will start playing from the beginning from the currently
+ * attached static buffer when in static mode. If no static buffer
+ * was set, the source will remain in stopped mode, and this
+ * will return false. A buffer can be attached to this source by
* calling the setStaticBuffer() method.
- * When the source is stopped and in streaming mode, this function
- * will always enter playing state. If no buffers were queued yet,
- * it will effectively start playing this source once the first
- * buffer has been submitted. It is recommended to queue up the
- * first few buffers before calling play() to avoid running out of
- * buffers early. In streaming mode, buffers can be submitted to
+ * When the source is stopped and in streaming mode, this function
+ * will always enter playing state. If no buffers were queued yet,
+ * it will effectively start playing this source once the first
+ * buffer has been submitted. It is recommended to queue up the
+ * first few buffers before calling play() to avoid running out of
+ * buffers early. In streaming mode, buffers can be submitted to
* the queue by calling the submitStreamingBuffer() method.
- * If the source is in paused mode, it will simply resume.
- * In case it was already in playing mode, the source will be
- * automatically stopped before re-entering playing status. In
- * static buffer mode this is essentially the same as restarting
- * the source from the beginning, while doing this in streaming
+ * If the source is in paused mode, it will simply resume.
+ * In case it was already in playing mode, the source will be
+ * automatically stopped before re-entering playing status. In
+ * static buffer mode this is essentially the same as restarting
+ * the source from the beginning, while doing this in streaming
* mode will result in the streaming queue being cleared.
* \brief Start or resume playback.
* \return Returns true in case of success.
*/
virtual bool play() = 0;
/**
- * This function stops playing the source immediately. If the
- * source is already stopped, it does nothing. If the source was
+ * This function stops playing the source immediately. If the
+ * source is already stopped, it does nothing. If the source was
* paused, this will do the same as if it was playing.
- * When the source is in static mode, the attached buffer will
- * remain attached for later usage. To exit a loop, it is
- * recommended to call setLooping(false) instead of stop(),
- * to avoid sound clicks. The source will enter stopped state
+ * When the source is in static mode, the attached buffer will
+ * remain attached for later usage. To exit a loop, it is
+ * recommended to call setLooping(false) instead of stop(),
+ * to avoid sound clicks. The source will enter stopped state
* automatically when it has finished playing.
- * If this source uses streaming buffers, calling this function
- * will immediately stop output, and clear the buffer queue, which
+ * If this source uses streaming buffers, calling this function
+ * will immediately stop output, and clear the buffer queue, which
* means that any queued buffers that have not played yet are lost.
* \brief Stop playback.
*/
virtual void stop() = 0;
/**
- * This function pauses playback of this source at it's current
- * position. If the source is stopped or already paused, this
- * function does nothing. You can verify if the source is paused
+ * This function pauses playback of this source at it's current
+ * position. If the source is stopped or already paused, this
+ * function does nothing. You can verify if the source is paused
* by calling isPaused(). To resume playback, you must call play().
* \brief Pause playback.
*/
virtual void pause() = 0;
/**
* Returns if the source is currently playing.
- * In streaming mode this will return true, even if no buffers are
+ * In streaming mode this will return true, even if no buffers are
* available for playback when in playing status.
- * This will also return true if the source is paused. To know if
+ * This will also return true if the source is paused. To know if
* the source has been paused, use isPaused().
* \brief Get the playing state.
* \return Returns the playing state.
*/
virtual bool isPlaying() const = 0;
/**
- * Returns true if the source has not started playing yet, when it
- * has been stopped using the stop() method, or when the static
+ * Returns true if the source has not started playing yet, when it
+ * has been stopped using the stop() method, or when the static
* buffer has finished playback.
* If the source is playing or paused, this returns false.
* \brief Get the stopped state.
@@ -341,36 +339,36 @@ public:
virtual bool isStopped() const = 0;
/**
* Returns true if the source has been paused by calling pause().
- * If the source is playing, stopped, or has finished playback
+ * If the source is playing, stopped, or has finished playback
* this returns false.
* \brief Get the paused state.
* \return Returns the paused state.
*/
virtual bool isPaused() const = 0;
/**
- * Returns the number of milliseconds the current static buffer or
+ * Returns the number of milliseconds the current static buffer or
* streaming queue has effectively been playing.
- * In streaming mode, the time spent during buffer outruns is not
- * counted towards the playback time, and the playback time is
+ * In streaming mode, the time spent during buffer outruns is not
+ * counted towards the playback time, and the playback time is
* be the current time position in the entire submitted queue.
- * When using static buffers, the result is the total time that the
- * attached buffer has been playing. If the source is looping, the
+ * When using static buffers, the result is the total time that the
+ * attached buffer has been playing. If the source is looping, the
* time will be the total of all playbacks of the buffer.
- * When the source is stopped, this will return the time where the
- * source was stopped. The value is reset to 0 when re-entering
+ * When the source is stopped, this will return the time where the
+ * source was stopped. The value is reset to 0 when re-entering
* playing status.
- * A buffer that is played at a higher pitch will result in a lower
- * playback time. The result is not the buffer's playback position,
+ * A buffer that is played at a higher pitch will result in a lower
+ * playback time. The result is not the buffer's playback position,
* but the actual time that has passed playing.
- * It is not guaranteed that this function returns an accurate
- * value, or that it even works. If it is not implemented, the result
+ * It is not guaranteed that this function returns an accurate
+ * value, or that it even works. If it is not implemented, the result
* will always be 0.
* \brief Get the current playback time in milliseconds.
* \return Returns the current playback time in milliseconds.
*/
virtual uint32 getTime() = 0;
//@}
-
+
/// \name Source properties
//@{
/// Set the position vector (default: (0,0,0)).
@@ -405,29 +403,29 @@ public:
virtual void setCone(float innerAngle, float outerAngle, float outerGain) = 0;
/// Get the cone angles (in radian)
virtual void getCone(float& innerAngle, float& outerAngle, float& outerGain) const = 0;
- /**
+ /**
* Set the alpha value for the volume-distance curve.
- *
+ *
* Used only with OptionManualRolloff.
* Value ranges from -1.0 to 1.0, the default is 0.0.
- *
- * - alpha = 0.0: The volume will decrease linearly between 0dB
+ *
+ * - alpha = 0.0: The volume will decrease linearly between 0dB
* and -100 dB.
- * - alpha = 1.0: The volume will decrease linearly between 1.0f
+ * - alpha = 1.0: The volume will decrease linearly between 1.0f
* and 0.0f (linear scale).
- * - alpha = -1.0: The volume will decrease inversely with the
- * distance (1/dist). This is the default distance attenuation
+ * - alpha = -1.0: The volume will decrease inversely with the
+ * distance (1/dist). This is the default distance attenuation
* used without OptionManualRolloff.
- *
- * For any other value of alpha, an interpolation is be done
- * between the two adjacent curves. For example, if alpha equals
- * 0.5, the volume will be halfway between the linear dB curve and
+ *
+ * For any other value of alpha, an interpolation is be done
+ * between the two adjacent curves. For example, if alpha equals
+ * 0.5, the volume will be halfway between the linear dB curve and
* the linear amplitude curve.
* \brief Set the alpha value for the volume-distance curve
*/
virtual void setAlpha(double a) = 0;
//@}
-
+
/// \name Direct output
//@{
/// Enable or disable direct output [true/false], default: true
@@ -438,7 +436,7 @@ public:
virtual void setDirectGain(float gain = NLSOUND_DEFAULT_DIRECT_GAIN) = 0;
/// Get the gain for the direct path
virtual float getDirectGain() const = 0;
-
+
/// Enable or disable the filter for the direct channel
virtual void enableDirectFilter(bool enable = true) = 0;
/// Check if the filter on the direct channel is enabled
@@ -452,7 +450,7 @@ public:
/// Get the direct filter gain
virtual float getDirectFilterPassGain() const = 0;
//@}
-
+
/// \name Effect output
//@{
/// Set the effect send for this source, NULL to disable. [IEffect], default: NULL
@@ -463,7 +461,7 @@ public:
virtual void setEffectGain(float gain = NLSOUND_DEFAULT_EFFECT_GAIN) = 0;
/// Get the gain for the effect path
virtual float getEffectGain() const = 0;
-
+
/// Enable or disable the filter for the effect channel
virtual void enableEffectFilter(bool enable = true) = 0;
/// Check if the filter on the effect channel is enabled
@@ -477,9 +475,9 @@ public:
/// Get the effect filter gain
virtual float getEffectFilterPassGain() const = 0;
//@}
-
+
protected:
-
+
// common method used only with OptionManualRolloff. return the volume in 1/100th DB ( = mB)modified
static sint32 computeManualRollOff(sint32 volumeMB, sint32 mbMin, sint32 mbMax, double alpha, float sqrdist, float distMin, float distMax);
// common method used only with OptionManualRolloff. return the rolloff in amplitude ratio (gain)
diff --git a/code/nel/include/nel/sound/u_audio_mixer.h b/code/nel/include/nel/sound/u_audio_mixer.h
index c3059152c..b29bdd143 100644
--- a/code/nel/include/nel/sound/u_audio_mixer.h
+++ b/code/nel/include/nel/sound/u_audio_mixer.h
@@ -82,8 +82,6 @@ public:
DriverAuto = 0,
DriverFMod,
DriverOpenAl,
- DriverDSound,
- DriverXAudio2,
NumDrivers
};
@@ -124,42 +122,42 @@ public:
}
}
};
-
+
/// Initialization information for the audio mixer. Use instead of the long parametered init function for readability. *** Subject to change. ***
struct CInitInfo
{
public:
- CInitInfo()
- : MaxTrack(32),
- EnableReverb(false),
- EnableOccludeObstruct(false),
- UseADPCM(false),
- ForceSoftware(false),
+ CInitInfo()
+ : MaxTrack(32),
+ EnableReverb(false),
+ EnableOccludeObstruct(false),
+ UseADPCM(false),
+ ForceSoftware(false),
ManualRolloff(true)
{ }
/// The number of allocated physical playback tracks. Default: 32.
uint MaxTrack;
-
+
/// Enable environment reverberation effect. Default: false.
bool EnableReverb;
/// Enable occlusion and obstruction lowpass filters from walls and objects. Default: false.
bool EnableOccludeObstruct;
-
+
/// Use lower quality ADPCM encoded sources for lower memory usage. Default: false.
bool UseADPCM;
/// Force using a software sound device. Default: false. [KAETEMI TODO: Allow sound device selection.]
bool ForceSoftware;
-
+
/// Use NeL's distance rolloff math. Default: true.
bool ManualRolloff;
/// I forgot what this does, but it's fairly important.
bool AutoLoadSample;
};
-
+
//@{
//@name Init methods
/// Create the audio mixer singleton and return a pointer to its instance
@@ -175,7 +173,7 @@ public:
* mixer config file, you MUST set the sample path
* BEFORE calling init.
*/
-
+
virtual void setSamplePath(const std::string& path) = 0;
/** Set the global path to the sample banks
* If you have specified some sample bank to load in the
@@ -199,17 +197,17 @@ public:
* deactivated. (lies!)
* autoLoadSample is used for tools like georges or object viewer where you don't bother to
* specify each sample bank to load, you just want to ear the sound.
- *
+ *
* Deprecated by initDriver/getDevices/initDevice.
- *
+ *
* \param forceSoftware: to force the driver to load in software buffer, not hardware
*/
virtual void init(uint maxTrack = 32, bool useEax = true, bool useADPCM = true, NLMISC::IProgressCallback *progressCallBack = NULL, bool autoLoadSample = false, TDriver driverType = DriverAuto, bool forceSoftware = false, bool manualRolloff = true) = 0;
-
+
/// Initialize the NeL Sound Driver with given driverName.
virtual void initDriver(const std::string &driverName) = 0;
/// Get the available devices on the loaded driver.
- virtual void getDevices(std::vector &devices) = 0;
+ virtual void getDevices(std::vector &devices) = 0;
/// Initialize the selected device on the currently initialized driver. Leave deviceName empty to select the default device.
virtual void initDevice(const std::string &deviceName, const CInitInfo &initInfo, NLMISC::IProgressCallback *progressCallback = NULL) = 0;
@@ -451,7 +449,7 @@ public:
virtual void setEventMusicVolume(float gain) =0;
/** true if the event music is ended
*/
- virtual bool isEventMusicEnded() =0;
+ virtual bool isEventMusicEnded() =0;
/// Get audio/container extensions that are currently supported by nel or the used driver implementation.
virtual void getMusicExtensions(std::vector &extensions) = 0;
//@}
diff --git a/code/nel/samples/3d/cegui/main.cpp b/code/nel/samples/3d/cegui/main.cpp
index eda1ac666..897adc81e 100644
--- a/code/nel/samples/3d/cegui/main.cpp
+++ b/code/nel/samples/3d/cegui/main.cpp
@@ -77,9 +77,9 @@ bool handleCheck(const CEGUI::EventArgs& e);
#endif // CEGUI_DATA_DIR
#ifdef NL_OS_WINDOWS
-int WINAPI WinMain( HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPSTR lpCmdLine,
+int WINAPI WinMain( HINSTANCE hInstance,
+ HINSTANCE hPrevInstance,
+ LPSTR lpCmdLine,
int nCmdShow ) {
ghInstance = hInstance;
#else
@@ -100,7 +100,7 @@ int main(int argc, char **argv)
NELRENDERER_CREATE_PROC createNelRenderer = reinterpret_cast(driverLib.getSymbolAddress(NELRENDERER_CREATE_PROC_NAME));
// CCeguiRendererNelLibrary *nelCeguiDriverLib = dynamic_cast(driverLib.getNelLibraryInterface());
-
+
NL3D::UDriver *driver;
// Create a driver
@@ -108,9 +108,8 @@ int main(int argc, char **argv)
#ifdef NL_OS_WINDOWS
icon = (uint)LoadIcon(ghInstance,MAKEINTRESOURCE(IDI_ICON1));
#endif
- bool useD3D = false;
#ifdef NL_INDEX_BUFFER_H //new 3d
- NL3D::UDriver *driver = NL3D::UDriver::createDriver(icon,useD3D);
+ NL3D::UDriver *driver = NL3D::UDriver::createDriver(icon);
#else
driver = NL3D::UDriver::createDriver(icon);
#endif
@@ -123,7 +122,7 @@ int main(int argc, char **argv)
// start up the Gui system.
//gGuiLogger = nelCeguiDriverLib->createNelLogger();
//gGuiRenderer = new CEGUI::NeLRenderer(driver);
-
+
gGuiRenderer = createNelRenderer(driver, true);
gGuiSystem = new CEGUI::System(gGuiRenderer);
CEGUI::NeLRenderer *rndr = (CEGUI::NeLRenderer *)gGuiRenderer;
@@ -134,7 +133,7 @@ int main(int argc, char **argv)
nlinfo("Start up and configure the GUI system.");
try {
using namespace CEGUI;
-
+
Logger::getSingleton().setLoggingLevel(Insane);
// load scheme and set up defaults
@@ -328,5 +327,3 @@ bool handleCheck(const CEGUI::EventArgs& e)
return true;
}
-
-
diff --git a/code/nel/samples/3d/font/main.cpp b/code/nel/samples/3d/font/main.cpp
index bd1a91a09..3cbfdb24a 100644
--- a/code/nel/samples/3d/font/main.cpp
+++ b/code/nel/samples/3d/font/main.cpp
@@ -54,7 +54,7 @@ int main(int argc, char **argv)
#endif
{
// look at 3dinit example
- CNELU::init (800, 600, CViewport(), 32, true, 0, false, false);
+ CNELU::init (800, 600, CViewport(), 32, true, 0, false);
NLMISC::CPath::addSearchPath(FONT_DIR);
diff --git a/code/nel/samples/3d/nel_qt/graphics_viewport.cpp b/code/nel/samples/3d/nel_qt/graphics_viewport.cpp
index 611e0d440..30ca5d645 100644
--- a/code/nel/samples/3d/nel_qt/graphics_viewport.cpp
+++ b/code/nel/samples/3d/nel_qt/graphics_viewport.cpp
@@ -51,18 +51,18 @@ QString nli18n(const char *label)
} /* anonymous namespace */
-CGraphicsViewport::CGraphicsViewport(QWidget *parent)
+CGraphicsViewport::CGraphicsViewport(QWidget *parent)
: QWidget(parent),
- m_GraphicsConfig(NULL),
- m_Driver(NULL),
+ m_GraphicsConfig(NULL),
+ m_Driver(NULL),
m_TextContext(NULL)
{
-
+
}
CGraphicsViewport::~CGraphicsViewport()
{
-
+
}
void CGraphicsViewport::init(CGraphicsConfig *graphicsConfig)
@@ -72,44 +72,35 @@ void CGraphicsViewport::init(CGraphicsConfig *graphicsConfig)
// copy parameters
m_GraphicsConfig = graphicsConfig;
-
+
// check stuff we need
nlassert(m_GraphicsConfig);
// create the driver
nlassert(!m_Driver);
- m_Direct3D = false;
std::string driver = m_GraphicsConfig->getGraphicsDriver();
- if (driver == "Direct3D") m_Direct3D = true; //m_Driver = Direct3D;
- else if (driver == "OpenGL") m_Direct3D = false; //m_Driver = OpenGL;
- else
- {
- nlwarning("Invalid driver specified, defaulting to OpenGL");
- //m_Configuration->getConfigFile().getVar("GraphicsDriver").forceAsString("OpenGL");
- //m_Driver = OpenGL;
- }
- m_Driver = UDriver::createDriver(NULL, m_Direct3D, NULL);
+ m_Driver = UDriver::createDriver(NULL, NULL);
nlassert(m_Driver);
// initialize the window with config file values
m_Driver->setDisplay(winId(), NL3D::UDriver::CMode(width(), height(), 32));
// register config callbacks
- connect(m_GraphicsConfig, SIGNAL(onBackgroundColor(NLMISC::CRGBA)),
+ connect(m_GraphicsConfig, SIGNAL(onBackgroundColor(NLMISC::CRGBA)),
this, SLOT(cfcbBackgroundColor(NLMISC::CRGBA)));
m_BackgroundColor = m_GraphicsConfig->getBackgroundColor();
// set the cache size for the font manager(in bytes)
m_Driver->setFontManagerMaxMemory(2097152);
-
+
// create the text context
nlassert(!m_TextContext);
m_TextContext = m_Driver->createTextContext(CPath::lookup(
m_GraphicsConfig->getFontName()));
nlassert(m_TextContext);
- connect(m_GraphicsConfig, SIGNAL(onFontShadow(bool)),
+ connect(m_GraphicsConfig, SIGNAL(onFontShadow(bool)),
this, SLOT(cfcbFontShadow(bool)));
- m_TextContext->setShaded(m_GraphicsConfig->getFontShadow());
+ m_TextContext->setShaded(m_GraphicsConfig->getFontShadow());
}
void CGraphicsViewport::release()
@@ -119,14 +110,14 @@ void CGraphicsViewport::release()
// release text context
nlassert(m_TextContext);
- disconnect(m_GraphicsConfig, SIGNAL(onFontShadow(bool)),
+ disconnect(m_GraphicsConfig, SIGNAL(onFontShadow(bool)),
this, SLOT(cfcbFontShadow(bool)));
m_Driver->deleteTextContext(m_TextContext);
m_TextContext = NULL;
// release driver
nlassert(m_Driver);
- disconnect(m_GraphicsConfig, SIGNAL(onBackgroundColor(NLMISC::CRGBA)),
+ disconnect(m_GraphicsConfig, SIGNAL(onBackgroundColor(NLMISC::CRGBA)),
this, SLOT(cfcbBackgroundColor(NLMISC::CRGBA)));
m_Driver->release();
delete m_Driver;
@@ -185,7 +176,7 @@ void CGraphicsViewport::saveScreenshot(const string &name, bool jpg, bool png, b
//H_AUTO2
// FIXME: create screenshot path if it doesn't exist!
-
+
// empty bitmap
CBitmap bitmap;
// copy the driver buffer to the bitmap
@@ -221,13 +212,12 @@ void CGraphicsViewport::saveScreenshot(const string &name, bool jpg, bool png, b
void CGraphicsViewport::resizeEvent(QResizeEvent *resizeEvent)
{
QWidget::resizeEvent(resizeEvent);
- if (m_Driver && !m_Direct3D)
+ if (m_Driver)
{
m_Driver->setMode(UDriver::CMode(resizeEvent->size().width(), resizeEvent->size().height(), 32));
}
// The OpenGL driver does not resize automatically.
- // The Direct3D driver breaks the window mode to include window borders when calling setMode windowed.
// Resizing the window after switching drivers a few times becomes slow.
// There is probably something inside the drivers not being released properly.
diff --git a/code/nel/samples/3d/nel_qt/graphics_viewport.h b/code/nel/samples/3d/nel_qt/graphics_viewport.h
index 0b9dde03a..040be0db3 100644
--- a/code/nel/samples/3d/nel_qt/graphics_viewport.h
+++ b/code/nel/samples/3d/nel_qt/graphics_viewport.h
@@ -72,7 +72,7 @@ public:
inline NL3D::UTextContext *getTextContext() { return m_TextContext; }
inline NL3D::UScene *getScene() { return m_Scene; }
-public slots:
+public slots:
void saveScreenshot();
private slots:
@@ -91,12 +91,10 @@ private:
NL3D::UTextContext *m_TextContext;
NL3D::UScene *m_Scene;
- bool m_Direct3D;
-
private:
CGraphicsViewport(const CGraphicsViewport &);
CGraphicsViewport &operator=(const CGraphicsViewport &);
-
+
}; /* class CGraphicsViewport */
} /* namespace NLQT */
diff --git a/code/nel/samples/3d/nel_qt/nel_qt_default.cfg b/code/nel/samples/3d/nel_qt/nel_qt_default.cfg
index f8fd47131..a08854cff 100644
--- a/code/nel/samples/3d/nel_qt/nel_qt_default.cfg
+++ b/code/nel/samples/3d/nel_qt/nel_qt_default.cfg
@@ -55,9 +55,9 @@ LoginBackground = "login_background.dds";
// Graphics //////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
-// Use OpenGL or Direct3D (Windows)
+// Use OpenGL (Windows)
GraphicsEnabled = 1;
-GraphicsDrivers = { "OpenGL", "Direct3D" };
+GraphicsDrivers = { "OpenGL" };
GraphicsDriver = "OpenGL";
// Resolution of the screen
@@ -134,9 +134,9 @@ FpsSmoothing = 64;
// Sound /////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
-// The sound driver, choose between "Auto", "FMod", "DSound" and "OpenAl"
+// The sound driver, choose between "Auto", "FMod" and "OpenAl"
SoundEnabled = 1;
-SoundDrivers = { "Auto", "OpenAL", "XAudio2", "FMod", "DSound" };
+SoundDrivers = { "Auto", "OpenAL", "FMod" };
SoundDriver = "OpenAL";
SoundDevice = "";
SoundMaxTrack = 48;
@@ -153,46 +153,46 @@ SoundAutoLoadSample = 1;
//////////////////////////////////////////////////////////////////////////////
// This setting is used to bind keys to actions.
-// "key_handler", "args", "***", "Key1|Key2",
+// "key_handler", "args", "***", "Key1|Key2",
// *** -> CTRL, SHIFT, ALT don't matter
// --- -> CTRL, SHIFT, ALT must all be disabled
// -+- -> only SHIFT must be down
KeySettings = {
- "screenshot", "", "***", "KeyF5",
- "command", "set_state Exit", "-+-", "KeyESCAPE",
- "command", "set_state Login", "+--", "KeyESCAPE",
- "command", "set_state Unload", "***", "KeyF8",
- "command", "set_state Demo", "***", "KeyF7",
- "move_forward", "", "***", "KeyUP|KeyZ|KeyW",
- "move_backward", "", "***", "KeyDOWN|KeyS",
- "move_left", "", "***", "KeyLEFT|KeyQ|KeyA",
- "move_right", "", "***", "KeyRIGHT|KeyD",
- "move_forward", "", "***", "KeyZ|KeyW",
- "move_backward", "", "***", "KeyS",
- "move_left", "", "***", "KeyQ|KeyA",
- "move_right", "", "***", "KeyD",
- "chat_begin", "", "***", "KeyT",
- "chat_send", "", "***", "KeyENTER",
- "chat_leave", "", "***", "KeyESCAPE",
- "display_test", "", "***", "KeyTAB",
- "send_action", "0", "---", "Key1",
- "send_action", "1", "---", "Key2",
- "send_action", "2", "---", "Key3",
- "send_action", "3", "---", "Key4",
- "send_action", "4", "---", "Key5",
- "send_action", "5", "---", "Key6",
- "send_action", "6", "---", "Key7",
- "send_action", "7", "---", "Key8",
- "send_action", "8", "---", "Key9",
- "send_action", "9", "---", "Key0",
- "demo_crystal_spawn", "", "---", "KeyO",
- "demo_crystal_explode", "", "---", "KeyP",
- "free_camera_forward", "", "---", "KeyNUMPAD8",
- "free_camera_backward", "", "---", "KeyNUMPAD2",
- "free_camera_left", "", "---", "KeyNUMPAD4",
- "free_camera_right", "", "---", "KeyNUMPAD6",
- "switch_camera", "", "---", "KeyF4",
- "switch_ui_visible" ,"", "---", "KeyF6",
+ "screenshot", "", "***", "KeyF5",
+ "command", "set_state Exit", "-+-", "KeyESCAPE",
+ "command", "set_state Login", "+--", "KeyESCAPE",
+ "command", "set_state Unload", "***", "KeyF8",
+ "command", "set_state Demo", "***", "KeyF7",
+ "move_forward", "", "***", "KeyUP|KeyZ|KeyW",
+ "move_backward", "", "***", "KeyDOWN|KeyS",
+ "move_left", "", "***", "KeyLEFT|KeyQ|KeyA",
+ "move_right", "", "***", "KeyRIGHT|KeyD",
+ "move_forward", "", "***", "KeyZ|KeyW",
+ "move_backward", "", "***", "KeyS",
+ "move_left", "", "***", "KeyQ|KeyA",
+ "move_right", "", "***", "KeyD",
+ "chat_begin", "", "***", "KeyT",
+ "chat_send", "", "***", "KeyENTER",
+ "chat_leave", "", "***", "KeyESCAPE",
+ "display_test", "", "***", "KeyTAB",
+ "send_action", "0", "---", "Key1",
+ "send_action", "1", "---", "Key2",
+ "send_action", "2", "---", "Key3",
+ "send_action", "3", "---", "Key4",
+ "send_action", "4", "---", "Key5",
+ "send_action", "5", "---", "Key6",
+ "send_action", "6", "---", "Key7",
+ "send_action", "7", "---", "Key8",
+ "send_action", "8", "---", "Key9",
+ "send_action", "9", "---", "Key0",
+ "demo_crystal_spawn", "", "---", "KeyO",
+ "demo_crystal_explode", "", "---", "KeyP",
+ "free_camera_forward", "", "---", "KeyNUMPAD8",
+ "free_camera_backward", "", "---", "KeyNUMPAD2",
+ "free_camera_left", "", "---", "KeyNUMPAD4",
+ "free_camera_right", "", "---", "KeyNUMPAD6",
+ "switch_camera", "", "---", "KeyF4",
+ "switch_ui_visible" ,"", "---", "KeyF6",
};
diff --git a/code/nel/samples/sound/sound_sources/main.cpp b/code/nel/samples/sound/sound_sources/main.cpp
index 75f732b5a..49e171a67 100644
--- a/code/nel/samples/sound/sound_sources/main.cpp
+++ b/code/nel/samples/sound/sound_sources/main.cpp
@@ -67,8 +67,6 @@ void Init()
printf("Select NLSOUND Driver:\n");
printf(" [1] FMod\n");
printf(" [2] OpenAl\n");
- printf(" [3] DSound\n");
- printf(" [4] XAudio2\n");
printf("> ");
int selection = getchar();
printf("\n");
diff --git a/code/nel/samples/sound/stream_file/stream_file.cpp b/code/nel/samples/sound/stream_file/stream_file.cpp
index 6362a0414..ee1968a24 100644
--- a/code/nel/samples/sound/stream_file/stream_file.cpp
+++ b/code/nel/samples/sound/stream_file/stream_file.cpp
@@ -64,30 +64,28 @@ static void initSample()
new CApplicationContext();
CSheetId::initWithoutSheet();
CPath::addSearchPath(NL_SOUND_DATA"/data", true, false);
-
+
printf("Sample demonstrating OGG playback using stream file .sound sheets.");
printf("\n\n");
-
+
s_AudioMixer = UAudioMixer::createAudioMixer();
-
+
// Set the sample path before init, this allow the mixer to build the sample banks
s_AudioMixer->setSamplePath(NL_SOUND_DATA"/data/samplebank");
// Packed sheet option, this mean we want packed sheet generated in 'data' folder
s_AudioMixer->setPackedSheetOption(NL_SOUND_DATA"/data", true);
-
+
printf("Select NLSOUND Driver:\n");
printf(" [1] FMod\n");
printf(" [2] OpenAl\n");
- printf(" [3] DSound\n");
- printf(" [4] XAudio2\n");
printf("> ");
int selection = getchar(); getchar();
printf("\n");
-
+
// init with 8 tracks, EAX enabled, no ADPCM, and automatic sample bank loading
s_AudioMixer->init(8, true, false, NULL, true, (UAudioMixer::TDriver)(selection - '0'));
s_AudioMixer->setLowWaterMark(1);
-
+
CVector initpos(0.0f, 0.0f, 0.0f);
CVector frontvec(0.0f, 1.0f, 0.0f);
CVector upvec(0.0f, 0.0f, 1.0f);
@@ -95,14 +93,14 @@ static void initSample()
s_AudioMixer->getListener()->setOrientation(frontvec, upvec);
CPath::addSearchPath(RYZOM_DATA, true, false);
-
+
//NLMISC::CHTimer::startBench();
s_Source = s_AudioMixer->createSource(CSheetId("stream_file.sound"));
nlassert(s_Source);
s_StreamFileSource = dynamic_cast(s_Source);
nlassert(s_StreamFileSource);
- // s_Source->setSourceRelativeMode(true);
+ // s_Source->setSourceRelativeMode(true);
// s_Source->setPitch(2.0f);
s_GroupController = s_AudioMixer->getGroupController("sound:dialog");
@@ -111,7 +109,7 @@ static void initSample()
static void runSample()
{
s_Source->play();
-
+
printf("Change volume with - and +\n");
printf("Press ANY other key to exit\n");
for (; ; )
@@ -154,7 +152,7 @@ static void runSample()
}
s_AudioMixer->update();
-
+
nlSleep(40);
}
}
diff --git a/code/nel/samples/sound/stream_ogg_vorbis/stream_ogg_vorbis.cpp b/code/nel/samples/sound/stream_ogg_vorbis/stream_ogg_vorbis.cpp
index 1f491b21c..ceaded2f0 100644
--- a/code/nel/samples/sound/stream_ogg_vorbis/stream_ogg_vorbis.cpp
+++ b/code/nel/samples/sound/stream_ogg_vorbis/stream_ogg_vorbis.cpp
@@ -61,21 +61,19 @@ static void initSample()
new CApplicationContext();
CSheetId::initWithoutSheet();
CPath::addSearchPath(NL_SOUND_DATA"/database/build/", true, false);
-
+
printf("Sample demonstrating OGG playback using UStreamSource.");
printf("\n\n");
-
+
s_AudioMixer = UAudioMixer::createAudioMixer();
-
+
printf("Select NLSOUND Driver:\n");
printf(" [1] FMod\n");
printf(" [2] OpenAl\n");
- printf(" [3] DSound\n");
- printf(" [4] XAudio2\n");
printf("> ");
int selection = getchar(); getchar();
printf("\n");
-
+
// init with 128 tracks, EAX enabled, no ADPCM, and automatic sample bank loading
s_AudioMixer->init(8, true, false, NULL, true, (UAudioMixer::TDriver)(selection - '0'));
s_AudioMixer->setLowWaterMark(1);
@@ -85,7 +83,7 @@ static void initSample()
CVector upvec(0.0f, 0.0f, 1.0f);
s_AudioMixer->getListener()->setPos(initpos);
s_AudioMixer->getListener()->setOrientation(frontvec, upvec);
-
+
//NLMISC::CHTimer::startBench();
USource *source = s_AudioMixer->createSource(CSheetId("default_stream.sound"));
@@ -136,7 +134,7 @@ static void runSample()
//bufferMore(bytes);
s_StreamSource->play();
-
+
printf("Change volume with - and +\n");
printf("Press ANY other key to exit\n");
while (!s_AudioDecoder->isMusicEnded())
@@ -177,13 +175,13 @@ static void runSample()
nlSleep(40);
s_AudioMixer->update();
}
-
+
s_StreamSource->stop();
-
+
printf("End of song\n");
printf("Press ANY key to exit\n");
#ifdef NL_OS_WINDOWS
- while (!_kbhit())
+ while (!_kbhit())
#else
char ch;
while (!read(0, &ch, 1))
diff --git a/code/nel/src/3d/coarse_mesh_manager.cpp b/code/nel/src/3d/coarse_mesh_manager.cpp
index 2d4792263..847d37968 100644
--- a/code/nel/src/3d/coarse_mesh_manager.cpp
+++ b/code/nel/src/3d/coarse_mesh_manager.cpp
@@ -120,7 +120,7 @@ void CCoarseMeshManager::flushRender (IDriver *drv)
H_AUTO( NL3D_StaticLod_Render );
if (_Meshs.empty()) return;
- // if the driver is BGRA (Direct3D), then invert color format
+ // if the driver is BGRA, then invert color format
if(!_VBuffer.isResident() && drv->getVertexColorFormat()==CVertexBuffer::TBGRA)
{
// since actually empty, no need to swap current memory
diff --git a/code/nel/src/3d/driver/CMakeLists.txt b/code/nel/src/3d/driver/CMakeLists.txt
index 8f1693716..39a52d9b4 100644
--- a/code/nel/src/3d/driver/CMakeLists.txt
+++ b/code/nel/src/3d/driver/CMakeLists.txt
@@ -5,9 +5,3 @@ ENDIF()
IF(WITH_DRIVER_OPENGLES)
ADD_SUBDIRECTORY(opengles)
ENDIF()
-
-IF(WIN32)
- IF(WITH_DRIVER_DIRECT3D)
- ADD_SUBDIRECTORY(direct3d)
- ENDIF()
-ENDIF()
diff --git a/code/nel/src/3d/driver/direct3d/CMakeLists.txt b/code/nel/src/3d/driver/direct3d/CMakeLists.txt
deleted file mode 100644
index d74bdeceb..000000000
--- a/code/nel/src/3d/driver/direct3d/CMakeLists.txt
+++ /dev/null
@@ -1,24 +0,0 @@
-FILE(GLOB SRC *.cpp *.h *.def *.rc)
-
-NL_TARGET_DRIVER(nel_drv_direct3d_win ${SRC})
-
-INCLUDE_DIRECTORIES(BEFORE ${DXSDK_INCLUDE_DIR})
-
-TARGET_LINK_LIBRARIES(nel_drv_direct3d_win nel3d nelmisc ${DXSDK_D3DX9_LIBRARY} ${DXSDK_D3D9_LIBRARY})
-
-NL_DEFAULT_PROPS(nel_drv_direct3d_win "NeL, Driver, Video: Direct3D")
-NL_ADD_RUNTIME_FLAGS(nel_drv_direct3d_win)
-NL_ADD_LIB_SUFFIX(nel_drv_direct3d_win)
-
-ADD_DEFINITIONS(-DRIVER_DIRECT3D_EXPORTS)
-
-IF(WITH_PCH)
- ADD_NATIVE_PRECOMPILED_HEADER(nel_drv_direct3d_win ${CMAKE_CURRENT_SOURCE_DIR}/stddirect3d.h ${CMAKE_CURRENT_SOURCE_DIR}/stddirect3d.cpp)
-ENDIF()
-
-IF((WITH_INSTALL_LIBRARIES AND WITH_STATIC_DRIVERS) OR NOT WITH_STATIC_DRIVERS)
- INSTALL(TARGETS nel_drv_direct3d_win LIBRARY DESTINATION ${NL_DRIVER_PREFIX} ARCHIVE DESTINATION ${NL_LIB_PREFIX} RUNTIME DESTINATION ${NL_DRIVER_PREFIX} COMPONENT drivers3d)
- IF(WITH_MAXPLUGIN)
- INSTALL(TARGETS nel_drv_direct3d_win RUNTIME DESTINATION maxplugin COMPONENT drivers3d)
- ENDIF()
-ENDIF()
diff --git a/code/nel/src/3d/driver/direct3d/driver_direct3d.cpp b/code/nel/src/3d/driver/direct3d/driver_direct3d.cpp
deleted file mode 100644
index be7a74722..000000000
--- a/code/nel/src/3d/driver/direct3d/driver_direct3d.cpp
+++ /dev/null
@@ -1,4062 +0,0 @@
-// NeL - MMORPG Framework
-// Copyright (C) 2010 Winch Gate Property Limited
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Affero General Public License as
-// published by the Free Software Foundation, either version 3 of the
-// License, or (at your option) any later version.
-//
-// This program 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 Affero General Public License for more details.
-//
-// You should have received a copy of the GNU Affero General Public License
-// along with this program. If not, see .
-
-#include "stddirect3d.h"
-
-// by default, we disable the windows menu keys (F10, ALT and ALT+SPACE key doesn't freeze or open the menu)
-#define NL_DISABLE_MENU
-
-#include
-
-#include "nel/3d/vertex_buffer.h"
-#include "nel/3d/light.h"
-#include "nel/3d/index_buffer.h"
-#include "nel/misc/rect.h"
-#include "nel/misc/dynloadlib.h"
-#include "nel/3d/viewport.h"
-#include "nel/3d/scissor.h"
-#include "nel/3d/u_driver.h"
-
-#include "driver_direct3d.h"
-
-#ifdef DEBUG_NEW
-#define new DEBUG_NEW
-#endif
-
-using namespace std;
-using namespace NLMISC;
-
-#define RASTERIZER D3DDEVTYPE_HAL
-//#define RASTERIZER D3DDEVTYPE_REF
-
-#define D3D_WINDOWED_STYLE (WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_THICKFRAME|WS_MINIMIZEBOX|WS_MAXIMIZEBOX)
-#define D3D_FULLSCREEN_STYLE (WS_POPUP)
-
-// ***************************************************************************
-
-// Try to allocate 16Mo by default of AGP Ram.
-#define NL3D_DRV_VERTEXARRAY_AGP_INIT_SIZE (16384*1024)
-
-// Initial volatile vertex buffer size
-#define NL_VOLATILE_RAM_VB_SIZE 512*1024
-#define NL_VOLATILE_AGP_VB_SIZE 128*1024
-#define NL_VOLATILE_RAM_IB_SIZE 64*1024
-#define NL_VOLATILE_AGP_IB_SIZE 1024
-//
-#define NL_VOLATILE_RAM_VB_MAXSIZE 512*1024
-#define NL_VOLATILE_AGP_VB_MAXSIZE 2500*1024
-#define NL_VOLATILE_RAM_IB_MAXSIZE 1024*1024
-#define NL_VOLATILE_AGP_IB_MAXSIZE 256*1024
-
-
-
-// ***************************************************************************
-
-#ifndef NL_STATIC
-
-HINSTANCE HInstDLL = NULL;
-
-BOOL WINAPI DllMain(HINSTANCE hinstDLL,ULONG fdwReason,LPVOID lpvReserved)
-{
- HInstDLL = hinstDLL;
-
- return true;
-}
-
-class CDriverD3DNelLibrary : public INelLibrary {
- void onLibraryLoaded(bool firstTime) { }
- void onLibraryUnloaded(bool lastTime) { }
-};
-NLMISC_DECL_PURE_LIB(CDriverD3DNelLibrary)
-
-#endif /* #ifndef NL_STATIC */
-
-// ***************************************************************************
-
-namespace NL3D
-{
-
-// ***************************************************************************
-
-// Version of the driver. Not the interface version!! Increment when implementation of the driver change.
-const uint32 CDriverD3D::ReleaseVersion = 0xe;
-
-
-
-// ***************************************************************************
-
-#ifdef NL_STATIC
-
-# pragma comment(lib, "d3dx9")
-# pragma comment(lib, "d3d9")
-# pragma comment(lib, "dinput8")
-# pragma comment(lib, "dxguid")
-
-IDriver* createD3DDriverInstance ()
-{
- return new CDriverD3D;
-}
-
-#else
-
-#ifdef NL_COMP_MINGW
-extern "C"
-{
-#endif
-__declspec(dllexport) IDriver* NL3D_createIDriverInstance ()
-{
- return new CDriverD3D;
-}
-
-__declspec(dllexport) uint32 NL3D_interfaceVersion ()
-{
- return IDriver::InterfaceVersion;
-}
-#ifdef NL_COMP_MINGW
-}
-#endif
-#endif
-
-/*static*/ bool CDriverD3D::_CacheTest[CacheTest_Count] =
-{
- false, // CacheTest_CullMode = 0;
- false, // CacheTest_RenderState = 1,
- false, // CacheTest_TextureState = 2,
- false, // CacheTest_TextureIndexMode = 3,
- false, // CacheTest_TextureIndexUV = 4,
- false, // CacheTest_Texture = 5,
- false, // CacheTest_VertexProgram = 6,
- false, // CacheTest_PixelShader = 7,
- false, // CacheTest_VertexProgramConstant = 8,
- false, // CacheTest_PixelShaderConstant = 9,
- false, // CacheTest_SamplerState = 10,
- false, // CacheTest_VertexBuffer = 11,
- false, // CacheTest_IndexBuffer = 12,
- false, // CacheTest_VertexDecl = 13,
- false, // CacheTest_Matrix = 14,
- false, // CacheTest_RenderTarget = 15,
- false, // CacheTest_MaterialState = 16,
- false // CacheTest_DepthRange = 17,
-};
-
-
-
-
-// ***************************************************************************
-
-CDriverD3D::CDriverD3D()
-{
- _SwapBufferCounter = 0;
- _CurrentOcclusionQuery = NULL;
- _D3D = NULL;
- _HWnd = NULL;
- _DeviceInterface = NULL;
- _DestroyWindow = false;
- _CurrentMode.Width = 640;
- _CurrentMode.Height = 480;
- _WindowX = 0;
- _WindowY = 0;
- _FullScreen = false;
-
- _ColorDepth = ColorDepth32;
-
- _DefaultCursor = EmptyCursor;
-
- _AlphaBlendedCursorSupported = false;
- _AlphaBlendedCursorSupportRetrieved = false;
- _CurrCol = CRGBA::White;
- _CurrRot = 0;
- _CurrHotSpotX = 0;
- _CurrHotSpotY = 0;
- _CursorScale = 1.f;
-
- _UserViewMtx.identity();
- _UserModelMtx.identity();
- _PZBCameraPos = CVector::Null;
- _CurrentMaterial = NULL;
- _CurrentMaterialInfo = NULL;
- _CurrentShader = NULL;
- _BackBuffer = NULL;
- _Maximized = false;
- _HandlePossibleSizeChangeNextSize = false;
- _Interval = 1;
- _AGPMemoryAllocated = 0;
- _VRAMMemoryAllocated = 0;
- _Rasterizer = RASTERIZER;
-#ifdef NL_DISABLE_HARDWARE_VERTEX_PROGAM
- _DisableHardwareVertexProgram = true;
-#else // NL_DISABLE_HARDWARE_VERTEX_PROGAM
- _DisableHardwareVertexProgram = false;
-#endif // NL_DISABLE_HARDWARE_VERTEX_PROGAM
-#ifdef NL_DISABLE_HARDWARE_PIXEL_PROGAM
- _DisableHardwarePixelProgram = true;
-#else // NL_DISABLE_HARDWARE_PIXEL_PROGAM
- _DisableHardwarePixelProgram = false;
-#endif // NL_DISABLE_HARDWARE_PIXEL_PROGAM
-#ifdef NL_DISABLE_HARDWARE_VERTEX_ARRAY_AGP
- _DisableHardwareVertexArrayAGP = true;
-#else // NL_DISABLE_HARDWARE_VERTEX_ARRAY_AGP
- _DisableHardwareVertexArrayAGP = false;
-#endif // NL_DISABLE_HARDWARE_VERTEX_ARRAY_AGP
-#ifdef NL_DISABLE_HARDWARE_INDEX_ARRAY_AGP
- _DisableHardwareIndexArrayAGP = true;
-#else // NL_DISABLE_HARDWARE_INDEX_ARRAY_AGP
- _DisableHardwareIndexArrayAGP = false;
-#endif // NL_DISABLE_HARDWARE_INDEX_ARRAY_AGP
-#ifdef NL_DISABLE_HARDWARE_PIXEL_SHADER
- _DisableHardwarePixelShader = true;
-#else // NL_DISABLE_HARDWARE_PIXEL_SHADER
- _DisableHardwarePixelShader = false;
-#endif // NL_DISABLE_HARDWARE_PIXEL_SHADER
-
- // Compute the Flag which say if one texture has been changed in CMaterial.
- _MaterialAllTextureTouchedFlag= 0;
- uint i;
- for(i=0; i < IDRV_MAT_MAXTEXTURES; i++)
- {
- _MaterialAllTextureTouchedFlag|= IDRV_TOUCHED_TEX[i];
- }
-
- // Default adapter
- _Adapter = 0xffffffff;
- _ModifiedRenderState = NULL;
-
- // Create a Direct 3d object
- if ( NULL == (_D3D = Direct3DCreate9(D3D_SDK_VERSION)))
- {
- nlwarning ("Can't create the direct 3d 9 object.");
-
-#ifdef NL_OS_WINDOWS
- sint val = MessageBoxA(NULL, "Your DirectX version is too old. You need to install the latest one.\r\n\r\nPressing OK will quit the game and automatically open your browser to download the latest version of DirectX.\r\nPress Cancel will just quit the game.\r\n", "Mtp Target Error", MB_OKCANCEL);
- if(val == IDOK)
- {
- openURL("http://www.microsoft.com/downloads/details.aspx?FamilyID=4b1f5d0c-5e44-4864-93cd-464ef59da050");
- }
-#endif
- exit(EXIT_FAILURE);
-
- }
- _DepthRangeNear = 0.f;
- _DepthRangeFar = 1.f;
- // default for lightmap
- _LightMapDynamicLightDirty= false;
- _LightMapDynamicLightEnabled= false;
- _CurrentMaterialSupportedShader= CMaterial::Normal;
- // to avoid any problem if light0 never setuped, and ligthmap rendered
- _UserLight0.setupDirectional(CRGBA::Black, CRGBA::White, CRGBA::White, CVector::K);
- // All User Light are disabled by Default
- for(i=0;i::max();
- _CurStencilOpFail = D3DSTENCILOP_KEEP;
- _CurStencilOpZFail = D3DSTENCILOP_KEEP;
- _CurStencilOpZPass = D3DSTENCILOP_KEEP;
- _CurStencilWriteMask = std::numeric_limits::max();
-
-
- for(uint k = 0; k < MaxTexture; ++k)
- {
- _CurrentUVRouting[k] = (uint8) k;
- }
- _VolatileVertexBufferRAM[0] = new CVolatileVertexBuffer;
- _VolatileVertexBufferRAM[1] = new CVolatileVertexBuffer;
- _VolatileVertexBufferAGP[0] = new CVolatileVertexBuffer;
- _VolatileVertexBufferAGP[1] = new CVolatileVertexBuffer;
- _VolatileIndexBuffer16RAM[0]= new CVolatileIndexBuffer;
- _VolatileIndexBuffer16RAM[1]= new CVolatileIndexBuffer;
- _VolatileIndexBuffer16AGP[0]= new CVolatileIndexBuffer;
- _VolatileIndexBuffer16AGP[1]= new CVolatileIndexBuffer;
- _VolatileIndexBuffer32RAM[0]= new CVolatileIndexBuffer;
- _VolatileIndexBuffer32RAM[1]= new CVolatileIndexBuffer;
- _VolatileIndexBuffer32AGP[0]= new CVolatileIndexBuffer;
- _VolatileIndexBuffer32AGP[1]= new CVolatileIndexBuffer;
- _MustRestoreLight = false;
- _Lost = false;
- _SceneBegun = false;
- _MaxVertexIndex = 0;
- _QuadIB = NULL;
- _MaxNumPerStageConstantLighted = 0;
- _MaxNumPerStageConstantUnlighted = 0;
- D3DXMatrixIdentity(&_D3DMatrixIdentity);
- _FogColor = 0xffffffff;
- _CurrIndexBufferFormat = CIndexBuffer::IndicesUnknownFormat;
- _IsGeforce = false;
- _NonPowerOfTwoTexturesSupported = false;
- _MaxAnisotropy = 0;
- _AnisotropicMinSupported = false;
- _AnisotropicMagSupported = false;
- _AnisotropicMinCubeSupported = false;
- _AnisotropicMagCubeSupported = false;
-
- _FrustumLeft= -1.f;
- _FrustumRight= 1.f;
- _FrustumTop= 1.f;
- _FrustumBottom= -1.f;
- _FrustumZNear= -1.f;
- _FrustumZFar= 1.f;
- _FrustumPerspective= false;
- _FogStart = 0;
- _FogEnd = 1;
-
- _SumTextureMemoryUsed = false;
-
-
- _DesktopGammaRampValid = false;
-}
-
-// ***************************************************************************
-
-CDriverD3D::~CDriverD3D()
-{
- release();
-
- if(_D3D != NULL)
- {
- _D3D->Release();
- _D3D = NULL;
- }
- delete _VolatileVertexBufferRAM[0];
- delete _VolatileVertexBufferRAM[1];
- delete _VolatileVertexBufferAGP[0];
- delete _VolatileVertexBufferAGP[1];
- delete _VolatileIndexBuffer16RAM[0];
- delete _VolatileIndexBuffer16RAM[1];
- delete _VolatileIndexBuffer16AGP[0];
- delete _VolatileIndexBuffer16AGP[1];
- delete _VolatileIndexBuffer32RAM[0];
- delete _VolatileIndexBuffer32RAM[1];
- delete _VolatileIndexBuffer32AGP[0];
- delete _VolatileIndexBuffer32AGP[1];
-}
-
-// ***************************************************************************
-
-void CDriverD3D::resetRenderVariables()
-{
- H_AUTO_D3D(CDriver3D_resetRenderVariables);
-
- uint i;
- for (i=0; iinit (CVertexBuffer::RAMResident, _VolatileVertexBufferRAM[0]->Size, _VolatileVertexBufferRAM[0]->MaxSize, this);
- _VolatileVertexBufferRAM[0]->reset ();
- _VolatileVertexBufferRAM[1]->init (CVertexBuffer::RAMResident, _VolatileVertexBufferRAM[1]->Size, _VolatileVertexBufferRAM[1]->MaxSize, this);
- _VolatileVertexBufferRAM[1]->reset ();
- _VolatileVertexBufferAGP[0]->init (vertexAgpLocation, _VolatileVertexBufferAGP[0]->Size, _VolatileVertexBufferAGP[0]->MaxSize, this);
- _VolatileVertexBufferAGP[0]->reset ();
- _VolatileVertexBufferAGP[1]->init (vertexAgpLocation, _VolatileVertexBufferAGP[1]->Size, _VolatileVertexBufferAGP[1]->MaxSize, this);
- _VolatileVertexBufferAGP[1]->reset ();
- //
- _VolatileIndexBuffer16RAM[0]->init (CIndexBuffer::RAMResident, _VolatileIndexBuffer16RAM[0]->Size, _VolatileIndexBuffer16RAM[0]->MaxSize, this, CIndexBuffer::Indices16);
- _VolatileIndexBuffer16RAM[0]->reset ();
- _VolatileIndexBuffer16RAM[1]->init (CIndexBuffer::RAMResident, _VolatileIndexBuffer16RAM[1]->Size, _VolatileIndexBuffer16RAM[1]->MaxSize, this, CIndexBuffer::Indices16);
- _VolatileIndexBuffer16RAM[1]->reset ();
- _VolatileIndexBuffer16AGP[0]->init (indexAgpLocation, _VolatileIndexBuffer16AGP[0]->Size, _VolatileIndexBuffer16AGP[0]->MaxSize, this, CIndexBuffer::Indices16);
- _VolatileIndexBuffer16AGP[0]->reset ();
- _VolatileIndexBuffer16AGP[1]->init (indexAgpLocation, _VolatileIndexBuffer16AGP[1]->Size, _VolatileIndexBuffer16AGP[1]->MaxSize, this, CIndexBuffer::Indices16);
- _VolatileIndexBuffer16AGP[1]->reset ();
- //
- if (_MaxVertexIndex > 0xffff) // supports 32 bits ?
- {
- _VolatileIndexBuffer32RAM[0]->init (CIndexBuffer::RAMResident, _VolatileIndexBuffer32RAM[0]->Size, _VolatileIndexBuffer32RAM[0]->MaxSize, this, CIndexBuffer::Indices32);
- _VolatileIndexBuffer32RAM[0]->reset ();
- _VolatileIndexBuffer32RAM[1]->init (CIndexBuffer::RAMResident, _VolatileIndexBuffer32RAM[1]->Size, _VolatileIndexBuffer32RAM[1]->MaxSize, this, CIndexBuffer::Indices32);
- _VolatileIndexBuffer32RAM[1]->reset ();
- _VolatileIndexBuffer32AGP[0]->init (indexAgpLocation, _VolatileIndexBuffer32AGP[0]->Size, _VolatileIndexBuffer32AGP[0]->MaxSize, this, CIndexBuffer::Indices32);
- _VolatileIndexBuffer32AGP[0]->reset ();
- _VolatileIndexBuffer32AGP[1]->init (indexAgpLocation, _VolatileIndexBuffer32AGP[1]->Size, _VolatileIndexBuffer32AGP[1]->MaxSize, this, CIndexBuffer::Indices32);
- _VolatileIndexBuffer32AGP[1]->reset ();
- }
- _ScissorTouched = true;
-}
-
-// ***************************************************************************
-
-void CDriverD3D::initRenderVariables()
-{
- H_AUTO_D3D(CDriver3D_initRenderVariables);
- uint i;
- for (i=0; i=MatrixStateRemap)?i-MatrixStateRemap+256:i);
- memset (&(_MatrixCache[i].Matrix), 0xcc, sizeof(D3DXMATRIX));
- _MatrixCache[i].Modified = false;
- }
- _VertexBufferCache.Modified = false;
- _VertexBufferCache.VertexBuffer = NULL;
- _IndexBufferCache.Modified = false;
- _IndexBufferCache.IndexBuffer = NULL;
- _VertexDeclCache.Modified = false;
- _VertexDeclCache.Decl = NULL;
- for (i=0; iType)
- {
- case CRenderVariable::RenderState:
- {
- CRenderState *renderState = static_cast(currentRenderState);
- _DeviceInterface->SetRenderState (renderState->StateID, renderState->Value);
- }
- break;
- case CRenderVariable::TextureState:
- {
- CTextureState *textureState = static_cast(currentRenderState);
- _DeviceInterface->SetTextureStageState (textureState->StageID, textureState->StateID, textureState->Value);
- }
- break;
- case CRenderVariable::TextureIndexState:
- {
- CTextureIndexState *textureState = static_cast(currentRenderState);
- if (textureState->TexGen)
- setTextureState (textureState->StageID, D3DTSS_TEXCOORDINDEX, textureState->TexGenMode);
- else
- setTextureState (textureState->StageID, D3DTSS_TEXCOORDINDEX, textureState->UVChannel);
- }
- break;
- case CRenderVariable::TexturePtrState:
- {
- CTexturePtrState *textureState = static_cast(currentRenderState);
- _DeviceInterface->SetTexture (textureState->StageID, textureState->Texture);
- }
- break;
- case CRenderVariable::VertexProgramPtrState:
- {
- CVertexProgramPtrState *vertexProgram = static_cast(currentRenderState);
- _DeviceInterface->SetVertexShader(vertexProgram->VertexProgram);
- }
- break;
- case CRenderVariable::PixelShaderPtrState:
- {
- CPixelShaderPtrState *pixelShader = static_cast(currentRenderState);
- _DeviceInterface->SetPixelShader(pixelShader->PixelShader);
- }
- break;
- case CRenderVariable::VertexProgramConstantState:
- {
- CVertexProgramConstantState *vertexProgramConstant = static_cast(currentRenderState);
- switch (vertexProgramConstant->ValueType)
- {
- case CVertexProgramConstantState::Float:
- _DeviceInterface->SetVertexShaderConstantF (vertexProgramConstant->StateID, (float*)vertexProgramConstant->Values, 1);
- break;
- case CVertexProgramConstantState::Int:
- _DeviceInterface->SetVertexShaderConstantI (vertexProgramConstant->StateID, (int*)vertexProgramConstant->Values, 1);
- break;
- }
- }
- break;
- case CRenderVariable::PixelShaderConstantState:
- {
- CPixelShaderConstantState *pixelShaderConstant = static_cast(currentRenderState);
- switch (pixelShaderConstant->ValueType)
- {
- case CPixelShaderConstantState::Float:
- _DeviceInterface->SetPixelShaderConstantF (pixelShaderConstant->StateID, (float*)pixelShaderConstant->Values, 1);
- break;
- case CPixelShaderConstantState::Int:
- _DeviceInterface->SetPixelShaderConstantI (pixelShaderConstant->StateID, (int*)pixelShaderConstant->Values, 1);
- break;
- }
- }
- break;
- case CRenderVariable::SamplerState:
- {
- CSamplerState *samplerState = static_cast(currentRenderState);
- _DeviceInterface->SetSamplerState (samplerState->SamplerID, samplerState->StateID, samplerState->Value);
- }
- break;
- case CRenderVariable::MatrixState:
- {
- CMatrixState *renderMatrix = static_cast(currentRenderState);
- _DeviceInterface->SetTransform (renderMatrix->TransformType, &(renderMatrix->Matrix));
- }
- break;
- case CRenderVariable::VBState:
- {
- CVBState *renderVB = static_cast(currentRenderState);
- if (renderVB->VertexBuffer)
- {
- _DeviceInterface->SetStreamSource (0, renderVB->VertexBuffer, renderVB->Offset, renderVB->Stride);
- }
- }
- break;
- case CRenderVariable::IBState:
- {
- CIBState *renderIB = static_cast(currentRenderState);
- if (renderIB->IndexBuffer)
- {
- _DeviceInterface->SetIndices (renderIB->IndexBuffer);
- }
- }
- break;
- case CRenderVariable::VertexDecl:
- {
- CVertexDeclState *renderVB = static_cast(currentRenderState);
- if (renderVB->Decl)
- {
- _DeviceInterface->SetVertexDeclaration (renderVB->Decl);
- }
- }
- break;
- case CRenderVariable::LightState:
- {
- CLightState *renderLight = static_cast(currentRenderState);
-
- // Enabel state modified ?
- if (renderLight->EnabledTouched)
- _DeviceInterface->LightEnable (renderLight->LightIndex, renderLight->Enabled);
-
- // Light enabled ?
- if (renderLight->Enabled)
- {
- if (renderLight->SettingsTouched)
- {
- // New position
- renderLight->Light.Position.x -= _PZBCameraPos.x;
- renderLight->Light.Position.y -= _PZBCameraPos.y;
- renderLight->Light.Position.z -= _PZBCameraPos.z;
- _DeviceInterface->SetLight (renderLight->LightIndex, &(renderLight->Light));
- renderLight->SettingsTouched = false;
- }
- }
-
- // Clean
- renderLight->EnabledTouched = false;
- }
- break;
- case CRenderVariable::RenderTargetState:
- {
- CRenderTargetState *renderTarget = static_cast(currentRenderState);
- _DeviceInterface->SetRenderTarget (0, renderTarget->Target);
- setupViewport (_Viewport);
- setupScissor (_Scissor);
- }
- break;
- }
-}*/
-
-
-
-
-// ***************************************************************************
-#ifdef NL_DEBUG
- inline
-#endif
-void CDriverD3D::replaceArgumentAtStage(D3DTEXTURESTAGESTATETYPE state, DWORD stage, DWORD from, DWORD to)
-{
- if ((_TextureStateCache[stage][state].Value & D3DTA_SELECTMASK) == from)
- {
- setTextureState (stage, state, (_TextureStateCache[stage][state].Value&~D3DTA_SELECTMASK)|to);
- }
-}
-
-// ***************************************************************************
-// Replace a constant with diffuse color at the given stage
-#ifdef NL_DEBUG
- inline
-#endif
-void CDriverD3D::replaceAllRGBArgumentAtStage(uint stage, DWORD from, DWORD to, DWORD blendOpFrom)
-{
- replaceArgumentAtStage(D3DTSS_COLORARG1, stage, from, to);
- if (_CurrentMaterialInfo->NumColorArg[stage] > 1)
- {
- replaceArgumentAtStage(D3DTSS_COLORARG2, stage, from, to);
- if (_CurrentMaterialInfo->NumColorArg[stage] > 2)
- {
- replaceArgumentAtStage(D3DTSS_COLORARG0, stage, from, to);
- }
- }
- //
- // Operator is D3DTOP_BLENDDIFFUSEALPHA ?
- if (_TextureStateCache[stage][D3DTSS_COLOROP].Value == blendOpFrom)
- {
- setTextureState (stage, D3DTSS_COLOROP, D3DTOP_LERP);
- setTextureState (stage, D3DTSS_COLORARG0, to|D3DTA_ALPHAREPLICATE);
- }
-
-}
-
-#ifdef NL_DEBUG
- inline
-#endif
-void CDriverD3D::replaceAllAlphaArgumentAtStage(uint stage, DWORD from, DWORD to, DWORD blendOpFrom)
-{
- replaceArgumentAtStage(D3DTSS_ALPHAARG1, stage, from, to);
- if (_CurrentMaterialInfo->NumAlphaArg[stage] > 1)
- {
- replaceArgumentAtStage(D3DTSS_ALPHAARG2, stage, from, to);
- if (_CurrentMaterialInfo->NumAlphaArg[stage] > 2)
- {
- replaceArgumentAtStage(D3DTSS_ALPHAARG0, stage, from, to);
- }
- }
- if (_TextureStateCache[stage][D3DTSS_ALPHAOP].Value == blendOpFrom)
- {
- setTextureState (stage, D3DTSS_ALPHAOP, D3DTOP_LERP);
- setTextureState (stage, D3DTSS_ALPHAARG0, to);
- }
-}
-
-#ifdef NL_DEBUG
- inline
-#endif
-void CDriverD3D::replaceAllArgumentAtStage(uint stage, DWORD from, DWORD to, DWORD blendOpFrom)
-{
- if (_CurrentMaterialInfo->RGBPipe[stage])
- {
- replaceAllRGBArgumentAtStage(stage, from, to, blendOpFrom);
- }
- if (_CurrentMaterialInfo->AlphaPipe[stage])
- {
- replaceAllAlphaArgumentAtStage(stage, from, to, blendOpFrom);
- }
-}
-
-// ***************************************************************************
-// Replace all argument at relevant stages with the given value
-#ifdef NL_DEBUG
- inline
-#endif
-void CDriverD3D::replaceAllArgument(DWORD from, DWORD to, DWORD blendOpFrom)
-{
- const uint maxTexture = inlGetNumTextStages();
- // Look for texture state
- for (uint i=0; iColorOp[i] == D3DTOP_DISABLE) break;
- replaceAllArgumentAtStage(i, from, to, blendOpFrom);
- }
-}
-
-// ***************************************************************************
-#ifdef NL_DEBUG
- inline
-#endif
-void CDriverD3D::setupConstantDiffuseColorFromLightedMaterial(D3DCOLOR color)
-{
- for(uint i=1;i<_MaxLight;++i)
- enableLightInternal(uint8(i), false);
- _LightMapDynamicLightDirty= true;
- D3DMATERIAL9 d3dMat;
- setColor(d3dMat.Diffuse, 0.f, 0.f, 0.f, (1.f / 255.f) * (color >> 24));
- setColor(d3dMat.Ambient, 0.f, 0.f, 0.f, 0.f);
- setColor(d3dMat.Specular, 0.f, 0.f, 0.f, 0.f);
- setColor(d3dMat.Emissive, color);
- setMaterialState(d3dMat);
- setRenderState(D3DRS_LIGHTING, TRUE);
-}
-
-
-// ***************************************************************************
-void CDriverD3D::updateRenderVariablesInternal()
-{
- H_AUTO_D3D(CDriver3D_updateRenderVariablesInternal);
- nlassert (_DeviceInterface);
- bool aliasDiffuseToSpecular = false;
- bool enableVertexColorFlag = true;
- if (_CurrentMaterialInfo && (_CurrentMaterialInfo->NeedsConstantForDiffuse || _CurrentMaterialInfo->MultipleConstantNoPixelShader)) /* The "unlighted without vertex color" trick */
- {
- // The material IS unlighted
- // No pixel shader ?
- if (_CurrentMaterialInfo->PixelShader)
- {
- /*
- * We have to set the pixel shader now, because we have to choose between normal pixel shader and pixel shader without vertex color */
- // Must have two pixel shader
- nlassert (_CurrentMaterialInfo->PixelShaderUnlightedNoVertexColor);
- if (!_UseVertexColor && (_VertexProgramCache.VertexProgram == NULL))
- {
- setPixelShader (_CurrentMaterialInfo->PixelShaderUnlightedNoVertexColor);
- }
- else
- {
- setPixelShader (_CurrentMaterialInfo->PixelShader);
- }
- }
- else
- {
- setPixelShader (NULL);
- if (_CurrentMaterialInfo->NeedsConstantForDiffuse)
- {
- /*
- * We have to change all texture state setuped to D3DTA_DIFFUSE into D3DTA_TFACTOR
- * if we use a vertex buffer with diffuse color vertex with an unlighted material and no vertex program */
- if (_VertexProgramCache.VertexProgram)
- {
- // Diffuse should be output from vertex program
- // So we can only emulate 1 per stage constant (it has already been setup in CDriverD3D::setupMaterial)
- #ifdef NL_DEBUG
- nlassert(!_CurrentMaterialInfo->MultipleConstantNoPixelShader);
- #endif
- }
- else
- {
- if (!_UseVertexColor)
- {
- if (!_CurrentMaterialInfo->MultipleConstantNoPixelShader)
- {
- // Diffuse is used, but no other constant is used in the shader
- // Max texture
- replaceAllArgument(D3DTA_DIFFUSE, D3DTA_TFACTOR, D3DTOP_BLENDDIFFUSEALPHA);
- setRenderState (D3DRS_TEXTUREFACTOR, _CurrentMaterialInfo->UnlightedColor);
- }
- else
- {
- #ifdef NL_DEBUG
- nlassert(!_CurrentMaterialInfo->MultiplePerStageConstant); // Can't render this material on current hardware
- #endif
- //replaceAllArgumentAtStage(_CurrentMaterialInfo->ConstantIndex, D3DTA_TFACTOR, D3DTA_DIFFUSE, D3DTOP_BLENDFACTORALPHA);
- setupConstantDiffuseColorFromLightedMaterial(_CurrentMaterialInfo->UnlightedColor);
- }
- }
- else
- {
- if (_CurrentMaterialInfo->MultiplePerStageConstant)
- {
- // vertex color, 1st constant from CMaterial::getColor (already setuped in CDriverD3D::setupMaterial)
- // 2nd constant from a stage constant
- // Vertex color is aliased to the specular stream -> all references to D3DTA_DIFFUSE must be replaced with references to D3DTA_SPECULAR
- replaceAllArgument(D3DTA_DIFFUSE, D3DTA_SPECULAR, 0xffffffff);
- aliasDiffuseToSpecular = true;
- replaceAllArgumentAtStage(_CurrentMaterialInfo->ConstantIndex2, D3DTA_TFACTOR, D3DTA_DIFFUSE, D3DTOP_BLENDFACTORALPHA);
- setupConstantDiffuseColorFromLightedMaterial(NL_D3DCOLOR_RGBA(_CurrentMaterialInfo->Constant2)); // set 2nd per stage constant
- #ifdef NL_DEBUG
- nlassert(_VertexDeclCache.DeclAliasDiffuseToSpecular); // VB must not have specular used ... else this material can't render
- #endif
- // NB : currently this don't work with the GeForce2 (seems to be a driver bug). Fortunately, this case isn't encountered with Ryzom materials :)
- // So it's provided for convenience.
- }
- }
- }
- }
- else
- {
- nlassert(_CurrentMaterialInfo->MultipleConstantNoPixelShader);
- // If vertex color is used, alias it to specular
- /*
- if (_UseVertexColor)
- {
- replaceAllArgument(D3DTA_DIFFUSE, D3DTA_SPECULAR, 0xffffffff);
- aliasDiffuseToSpecular = true; // VB must not have specular used ... else this material can't render
- }
- */
- // up to 2 constants with no pixel shaders
- // look for constant at other stages and replaces then with diffuse color
- // first constant color has already been set yet (in CD3DDriver::setupMaterial)
- replaceAllArgumentAtStage(_CurrentMaterialInfo->ConstantIndex2, D3DTA_TFACTOR, D3DTA_DIFFUSE, D3DTOP_BLENDFACTORALPHA);
- setupConstantDiffuseColorFromLightedMaterial(NL_D3DCOLOR_RGBA(_CurrentMaterialInfo->Constant2)); // set 2nd per stage constant
- }
- }
- }
- else
- {
- if (_CurrentMaterialInfo) enableVertexColorFlag = _CurrentMaterialInfo->VertexColorLighted;
- }
-
-
- if (_NbNeLTextureStages == 3)
- {
- // Fix (one more...) for Radeon 7xxx
- // Don't know why, but the lighting is broken when MULTIPLYADD is used as in the lightmap shader..
- // Correct behaviour with GeForce & Ref. rasterizer...
- // The fix is to disable the light contribution from dynamic lights
- if (_TextureStateCache[0][D3DTSS_COLOROP].Value == D3DTOP_MULTIPLYADD &&
- _TextureStateCache[0][D3DTSS_COLORARG0].Value == D3DTA_DIFFUSE
- )
- {
- _TextureStateCache[0][D3DTSS_COLOROP].Value = D3DTOP_MODULATE;
- touchRenderVariable(&_TextureStateCache[0][D3DTSS_COLOROP]);
- }
- // fix for radeon 7xxx -> should enable vertex color only if really used in pixel pipe
- setEnableVertexColor(enableVertexColorFlag);
- }
- setAliasDiffuseToSpecular(aliasDiffuseToSpecular);
-
-
- // Flush all the modified render states
- while (_ModifiedRenderState)
- {
- // Current variable
- CRenderVariable *currentRenderState = _ModifiedRenderState;
-
- // It is clean now
- currentRenderState->Modified = false;
-
- // Unlinked
- _ModifiedRenderState = currentRenderState->NextModified;
- currentRenderState->apply(this);
- }
-
-
- // Maybe it is a driver bug : in some situation with GeForce, I got vertex color set to (0, 0, 0, 0) with unlighted vertices and vertex color.
- // Forcing to resetup material solves the prb.. (though D3DRS_LIGHTING is set to FALSE ...)
- // I only have the prb with GeForce. The behaviour doesn't exhibit when using the D3D debug dll.
- if (_IsGeforce)
- {
- if (_RenderStateCache[D3DRS_LIGHTING].Value == FALSE && _VertexProgramCache.VertexProgram == NULL)
- {
- _MaterialState.apply(this);
- }
- }
-
-}
-
-
-
-// ***************************************************************************
-
-void D3DWndProc(CDriverD3D *driver, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
-{
- H_AUTO_D3D(D3DWndProc);
-
- // Check this message in parents
-
- if ((message == WM_SIZE) || (message == WM_EXITSIZEMOVE) || (message == WM_MOVE))
- {
- if (driver != NULL)
- {
- // *** Check the hwnd is the root parent of driver->_HWnd
-
- // hwnd must be a _HWnd parent
- bool sameWindow = hWnd == driver->_HWnd;
- bool rootWindow = false;
- HWND tmp = driver->_HWnd;
- while (tmp)
- {
- if (tmp == hWnd)
- {
- rootWindow = true;
- break;
- }
- tmp = GetParent (tmp);
- }
-
- // hwnd must be a top window
- rootWindow &= (GetParent (hWnd) == NULL);
-
- // This is a root parent, not _HWnd
- if (rootWindow)
- {
- if (message == WM_SIZE)
- {
- if( SIZE_MAXIMIZED == wParam)
- {
- driver->_Maximized = true;
- if (sameWindow)
- driver->handlePossibleSizeChange();
- else
- driver->_HandlePossibleSizeChangeNextSize = true;
- }
- else if( SIZE_RESTORED == wParam)
- {
- if (driver->_Maximized)
- {
- driver->_Maximized = false;
- if (sameWindow)
- driver->handlePossibleSizeChange();
- else
- driver->_HandlePossibleSizeChangeNextSize = true;
- }
- }
- }
- else if(message == WM_EXITSIZEMOVE)
- {
- if (driver != NULL)
- {
- driver->handlePossibleSizeChange();
- }
- }
- else if(message == WM_MOVE)
- {
- if (driver != NULL)
- {
- RECT rect;
- GetWindowRect (hWnd, &rect);
- driver->_WindowX = rect.left;
- driver->_WindowY = rect.top;
- }
- }
- }
- // This is the window itself
- else if (sameWindow)
- {
- if (message == WM_SIZE)
- {
- if (driver->_HandlePossibleSizeChangeNextSize)
- {
- driver->handlePossibleSizeChange();
- driver->_HandlePossibleSizeChangeNextSize = false;
- }
- }
- }
-
- }
- }
-
- if (driver->_EventEmitter.getNumEmitters() > 0)
- {
- CWinEventEmitter *we = NLMISC::safe_cast(driver->_EventEmitter.getEmitter(0));
- // Process the message by the emitter
- we->setHWnd(hWnd);
- we->processMessage (hWnd, message, wParam, lParam);
- }
-}
-
-// ***************************************************************************
-
-bool CDriverD3D::handlePossibleSizeChange()
-{
- //DUMP_AUTO(handlePossibleSizeChange);
- H_AUTO_D3D(CDriver3D_handlePossibleSizeChange);
- // If windowed, check if the size as changed
- if (_CurrentMode.Windowed)
- {
- RECT rect;
- GetClientRect (_HWnd, &rect);
-
- // Setup d3d resolution
- uint16 newWidth = uint16(rect.right-rect.left);
- uint16 newHeight = uint16(rect.bottom-rect.top);
-
- // Set the new mode. Only change the size, keep the last setDisplay/setMode settings
- GfxMode mode = _CurrentMode;
- mode.Width = newWidth;
- mode.Height = newHeight;
-
- if ( ( (mode.Width != _CurrentMode.Width) || (mode.Height != _CurrentMode.Height) ) &&
- ( mode.Width != 0 ) &&
- ( mode.Height != 0 ) )
- {
- return reset (mode);
- }
- }
- return false;
-}
-
-// ***************************************************************************
-
-static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
-{
- H_AUTO_D3D(WndProc);
- // Get the driver pointer..
- CDriverD3D *pDriver=(CDriverD3D*)GetWindowLongPtrW (hWnd, GWLP_USERDATA);
- if (pDriver != NULL)
- {
- D3DWndProc (pDriver, hWnd, message, wParam, lParam);
- }
-
-#ifdef NL_DISABLE_MENU
- // disable menu (F10, ALT and ALT+SPACE key doesn't freeze or open the menu)
- if(message == WM_SYSCOMMAND && wParam == SC_KEYMENU)
- return 0;
-#endif // NL_DISABLE_MENU
-
- // ace: if we receive close, exit now or it'll assert after
- if(message == WM_CLOSE)
- {
- if(pDriver && pDriver->ExitFunc)
- {
- pDriver->ExitFunc();
- }
- else
- {
-#ifndef NL_DISABLE_MENU
- // if we don't disable menu, alt F4 make a direct exit else we discard the message
- exit(0);
-#endif // NL_DISABLE_MENU
- }
- return 0;
- }
-
- return DefWindowProcW(hWnd, message, wParam, lParam);
-}
-
-// ***************************************************************************
-
-bool CDriverD3D::init (uintptr_t windowIcon, emptyProc exitFunc)
-{
- H_AUTO_D3D(CDriver3D_init );
-
- ExitFunc = exitFunc;
-
- createCursors();
-
- _WindowClass = "NLD3D" + toString(windowIcon);
-
- // Register a window class
- WNDCLASSA wc;
-
- memset(&wc,0,sizeof(wc));
- wc.style = 0; // CS_HREDRAW | CS_VREDRAW ;//| CS_DBLCLKS;
- wc.lpfnWndProc = (WNDPROC)WndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = GetModuleHandleA(NULL);
- wc.hIcon = (HICON)windowIcon;
- wc.hCursor = _DefaultCursor;
- wc.hbrBackground = WHITE_BRUSH;
- wc.lpszClassName = _WindowClass.c_str();
- wc.lpszMenuName = NULL;
- if (!RegisterClassA(&wc))
- {
- DWORD error = GetLastError();
- if (error != ERROR_CLASS_ALREADY_EXISTS)
- {
- nlwarning("CDriverD3D::init: Can't register window class %s (error code %i)", _WindowClass.c_str(), (sint)error);
- _WindowClass.clear();
- return false;
- }
- }
-
- return true;
-}
-
-// ***************************************************************************
-
-// From the SDK
-bool CDriverD3D::isDepthFormatOk(UINT adapter, D3DDEVTYPE rasterizer, D3DFORMAT DepthFormat,
- D3DFORMAT AdapterFormat,
- D3DFORMAT BackBufferFormat)
-{
- H_AUTO_D3D(CDriverD3D_isDepthFormatOk);
- // Verify that the depth format exists
- HRESULT hr = _D3D->CheckDeviceFormat(adapter,
- rasterizer,
- AdapterFormat,
- D3DUSAGE_DEPTHSTENCIL,
- D3DRTYPE_SURFACE,
- DepthFormat);
-
- if(FAILED(hr)) return FALSE;
-
- // Verify that the depth format is compatible
- hr = _D3D->CheckDepthStencilMatch(adapter,
- (D3DDEVTYPE) rasterizer,
- AdapterFormat,
- BackBufferFormat,
- DepthFormat);
-
- return SUCCEEDED(hr);
-
-}
-
-// ***************************************************************************
-
-const D3DFORMAT FinalPixelFormat[ITexture::UploadFormatCount][CDriverD3D::FinalPixelFormatChoice]=
-{
- { D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 }, // Auto
- { D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 }, // RGBA8888
- { D3DFMT_A4R4G4B4, D3DFMT_A1R5G5B5, D3DFMT_A8R3G3B2, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 }, // RGBA4444
- { D3DFMT_A1R5G5B5, D3DFMT_A4R4G4B4, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 }, // RGBA5551
- { D3DFMT_R8G8B8, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 }, // RGB888
- { D3DFMT_R5G6B5, D3DFMT_A1R5G5B5, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 }, // RGB565
- { D3DFMT_DXT1, D3DFMT_R3G3B2, D3DFMT_A1R5G5B5, D3DFMT_R5G6B5, D3DFMT_A8R8G8B8 }, // DXTC1
- { D3DFMT_DXT1, D3DFMT_R3G3B2, D3DFMT_A1R5G5B5, D3DFMT_R5G6B5, D3DFMT_A8R8G8B8 }, // DXTC1Alpha
- { D3DFMT_DXT3, D3DFMT_A4R4G4B4, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 }, // DXTC3
- { D3DFMT_DXT5, D3DFMT_A4R4G4B4, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 }, // DXTC5
- { D3DFMT_L8, D3DFMT_A8L8, D3DFMT_R5G6B5, D3DFMT_A1R5G5B5, D3DFMT_A8R8G8B8 }, // Luminance
- { D3DFMT_A8, D3DFMT_A8L8, D3DFMT_A8R3G3B2, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 }, // Alpha
- { D3DFMT_A8L8, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 }, // AlphaLuminance
- { D3DFMT_V8U8, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 }, // DsDt
-};
-
-// ***************************************************************************
-
-bool CDriverD3D::setDisplay(nlWindow wnd, const GfxMode& mode, bool show, bool resizeable) throw(EBadDisplay)
-{
- H_AUTO_D3D(CDriver3D_setDisplay);
-
- if (!mode.OffScreen)
- NLMISC::INelContext::getInstance().setWindowedApplication(true);
-
- if (!_D3D)
- return false;
-#ifndef NL_NO_ASM
- CFpuRestorer fpuRestorer;
-#endif
- // Release the driver if already setuped
- release ();
-
- // Should be initialized
- nlassert (!_WindowClass.empty());
-
- // Should be released
- nlassert (_DeviceInterface == NULL);
- nlassert (_HWnd == NULL);
-
- // memorize desktop gamma ramp
- HDC dc = CreateDCW (L"DISPLAY", NULL, NULL, NULL);
- if (dc)
- {
- _DesktopGammaRampValid = GetDeviceGammaRamp (dc, _DesktopGammaRamp) != FALSE;
- // Release the DC
- ReleaseDC (NULL, dc);
- }
-
- // Create a window
- _HWnd = wnd;
-
- // Reset window state
- _Maximized = false;
- _HandlePossibleSizeChangeNextSize = false;
-
- if (_HWnd)
- {
- // We don't have to destroy this window
- _DestroyWindow = false;
-
- // Init Window Width and Height
- RECT clientRect;
- GetClientRect (_HWnd, &clientRect);
- _CurrentMode.OffScreen = false;
- _CurrentMode.Width = (uint16)(clientRect.right-clientRect.left);
- _CurrentMode.Height = (uint16)(clientRect.bottom-clientRect.top);
- _CurrentMode.Frequency = 0;
- _CurrentMode.Windowed = true;
- _CurrentMode.Depth = 32;
- }
- else
- {
- _CurrentMode = mode;
-
- // We have to destroy this window
- _DestroyWindow = true;
-
- // Window flags
- //ULONG WndFlags=(mode.Windowed?D3D_WINDOWED_STYLE:D3D_FULLSCREEN_STYLE)&~WS_VISIBLE;
- ULONG WndFlags;
- if(mode.Windowed)
- {
- WndFlags = D3D_WINDOWED_STYLE;
- if(!resizeable)
- {
- WndFlags &= ~(WS_THICKFRAME|WS_MAXIMIZEBOX);
- }
- }
- else
- {
- WndFlags = D3D_FULLSCREEN_STYLE;
- findNearestFullscreenVideoMode();
- }
-
- WndFlags &= ~WS_VISIBLE;
-
- // Window rect
- RECT WndRect;
- WndRect.left=0;
- WndRect.top=0;
- WndRect.right=_CurrentMode.Width;
- WndRect.bottom=_CurrentMode.Height;
- AdjustWindowRect(&WndRect,WndFlags,FALSE);
-
- // Create
- ucstring ustr(_WindowClass);
- _HWnd = CreateWindowW((LPCWSTR)ustr.c_str(), L"", WndFlags, CW_USEDEFAULT,CW_USEDEFAULT, WndRect.right-WndRect.left,WndRect.bottom-WndRect.top, NULL, NULL,
- GetModuleHandleW(NULL), NULL);
- if (!_HWnd)
- {
- nlwarning ("CreateWindowW failed");
- release();
- return false;
- }
-
- // Set the window long integer
- SetWindowLongPtrW (_HWnd, GWLP_USERDATA, (LONG_PTR)this);
-
- // Show the window
- if (show || !_CurrentMode.Windowed)
- showWindow(true);
- }
-
- // Choose an adapter
- UINT adapter = (_Adapter==0xffffffff)?D3DADAPTER_DEFAULT:(UINT)_Adapter;
-
- // Get adapter format
- D3DDISPLAYMODE adapterMode;
- if (_D3D->GetAdapterDisplayMode (adapter, &adapterMode) != D3D_OK)
- {
- nlwarning ("GetAdapterDisplayMode failed");
- release();
- return false;
- }
-
- // The following code is taken from the NVPerfHud user guide
- // Set default settings
- _Rasterizer = RASTERIZER;
-#ifdef NL_D3D_USE_NV_PERF_HUD
- // Look for 'NVIDIA NVPerfHUD' adapter
- // If it is present, override default settings
- for (UINT adapterIndex = 0; adapterIndex < _D3D->GetAdapterCount(); adapterIndex++)
- {
- D3DADAPTER_IDENTIFIER9 identifier;
- HRESULT res = _D3D->GetAdapterIdentifier(adapterIndex, 0, &identifier);
- if (strstr(identifier.Description, "PerfHUD") != 0)
- {
- adapter = adapterIndex;
- _Adapter = adapter;
- _Rasterizer = D3DDEVTYPE_REF;
- nlinfo("Using NVIDIA NVPerfHUD adapter");
- break;
- }
- }
-#endif
-
- // Create device options
- D3DPRESENT_PARAMETERS parameters;
- D3DFORMAT adapterFormat;
- if (!fillPresentParameter (parameters, adapterFormat, _CurrentMode, adapterMode))
- {
- release();
- return false;
- }
-
- #if WITH_PERFHUD
- // Look for 'NVIDIA PerfHUD' adapter
- // If it is present, override default settings
- for (UINT gAdapter=0;gAdapter<_D3D->GetAdapterCount();gAdapter++)
- {
- D3DADAPTER_IDENTIFIER9 Identifier;
- HRESULT Res;
- Res = _D3D->GetAdapterIdentifier(gAdapter,0,&Identifier);
-
- if (strstr(Identifier.Description,"PerfHUD") != 0)
- {
- nlinfo ("Setting up with PerfHUD");
- adapter=gAdapter;
- _Rasterizer=D3DDEVTYPE_REF;
- break;
- }
- }
- #endif /* WITH_PERFHUD */
- // Create the D3D device
- HRESULT result = _D3D->CreateDevice (adapter, _Rasterizer, _HWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING|D3DCREATE_PUREDEVICE, ¶meters, &_DeviceInterface);
- if (result != D3D_OK)
- {
- nlwarning ("Can't create device hr:0x%x adap:0x%x rast:0x%x", result, adapter, _Rasterizer);
-
- // Create the D3D device without puredevice
- HRESULT result = _D3D->CreateDevice (adapter, _Rasterizer, _HWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, ¶meters, &_DeviceInterface);
- if (result != D3D_OK)
- {
- nlwarning ("Can't create device without puredevice hr:0x%x adap:0x%x rast:0x%x", result, adapter, _Rasterizer);
-
- // Create the D3D device without puredevice and hardware
- HRESULT result = _D3D->CreateDevice (adapter, _Rasterizer, _HWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, ¶meters, &_DeviceInterface);
- if (result != D3D_OK)
- {
- nlwarning ("Can't create device without puredevice and hardware hr:0x%x adap:0x%x rast:0x%x", result, adapter, _Rasterizer);
- release();
- return false;
- }
- }
- }
-
- // Check some caps
- D3DCAPS9 caps;
- if (_DeviceInterface->GetDeviceCaps(&caps) == D3D_OK)
- {
- _TextureCubeSupported = (caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP) != 0;
- _NbNeLTextureStages = (caps.MaxSimultaneousTextures= D3DPS_VERSION(2, 0) || caps.PixelShaderVersion < D3DPS_VERSION(1, 4));
- _NonPowerOfTwoTexturesSupported = !(caps.TextureCaps & D3DPTEXTURECAPS_POW2) || (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL);
- _MaxAnisotropy = caps.MaxAnisotropy;
- _AnisotropicMinSupported = (caps.TextureFilterCaps & D3DPTFILTERCAPS_MINFANISOTROPIC) != 0;
- _AnisotropicMagSupported = (caps.TextureFilterCaps & D3DPTFILTERCAPS_MAGFANISOTROPIC) != 0;
- _AnisotropicMinCubeSupported = (caps.CubeTextureFilterCaps & D3DPTFILTERCAPS_MINFANISOTROPIC) != 0;
- _AnisotropicMagCubeSupported = (caps.CubeTextureFilterCaps & D3DPTFILTERCAPS_MAGFANISOTROPIC) != 0;
- }
- else
- {
- _TextureCubeSupported = false;
- _NbNeLTextureStages = 1;
- _MADOperatorSupported = false;
- _EMBMSupported = false;
- _CubbedMipMapSupported = false;
- _PixelShaderVersion = 0;
- _MaxPrimitiveCount = 0xffff;
- _MaxVertexIndex = 0xffff;
- _IsGeforce = false;
- _NonPowerOfTwoTexturesSupported = false;
- _MaxAnisotropy = 0;
- _AnisotropicMinSupported = false;
- _AnisotropicMagSupported = false;
- _AnisotropicMinCubeSupported = false;
- _AnisotropicMagCubeSupported = false;
- }
- // If 16 bits vertices only, build a vb for quads rendering
- if (_MaxVertexIndex <= 0xffff)
- {
- if (!buildQuadIndexBuffer()) return false;
- }
-
- // test for occlusion query support
- IDirect3DQuery9 *dummyQuery = NULL;
- if (_DeviceInterface->CreateQuery(D3DQUERYTYPE_OCCLUSION, &dummyQuery) == D3DERR_NOTAVAILABLE)
- {
- _OcclusionQuerySupported = false;
- }
- else
- {
- _OcclusionQuerySupported = true;
- if (dummyQuery) dummyQuery->Release();
- }
-
-
-#ifdef NL_FORCE_TEXTURE_STAGE_COUNT
- _NbNeLTextureStages = min ((uint)NL_FORCE_TEXTURE_STAGE_COUNT, (uint)IDRV_MAT_MAXTEXTURES);
-#endif // NL_FORCE_TEXTURE_STAGE_COUNT
-
- _VertexProgram = !_DisableHardwareVertexProgram && ((caps.VertexShaderVersion&0xffff) >= 0x0100);
- _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 (_PixelProgram)
- {
- _MaxNumPerStageConstantLighted = _NbNeLTextureStages;
- _MaxNumPerStageConstantUnlighted = _NbNeLTextureStages;
- }
- else
- {
- // emulation of per stage constant through diffuse
- _MaxNumPerStageConstantLighted = 1;
- _MaxNumPerStageConstantUnlighted = 2;
- }
-
- if (_DisableHardwarePixelShader && _NbNeLTextureStages > 3) // yes, 3 is not a bug
- {
- // If pixel shader are disabled, then can't emulate the texEnvColor feature with more than 2 stages. (only 2 constant available by using material emissive in addition to the texture factor)
- // Radeon with 3 stages cases : let the third stage to ensure availability of the EMBM feature
- // There is a special fix in CMaterial::isSupportedByDriver to force the number of stages to 2 for the radeons
- _NbNeLTextureStages = 2;
- }
-
- // *** Check textures caps
- uint j;
- uint i;
- for (i=0; iinit (CVertexBuffer::RAMResident, NL_VOLATILE_RAM_VB_SIZE, NL_VOLATILE_RAM_VB_MAXSIZE, this);
- _VolatileVertexBufferRAM[0]->reset ();
- _VolatileVertexBufferRAM[1]->init (CVertexBuffer::RAMResident, NL_VOLATILE_RAM_VB_SIZE, NL_VOLATILE_RAM_VB_MAXSIZE, this);
- _VolatileVertexBufferRAM[1]->reset ();
- _VolatileVertexBufferAGP[0]->init (CVertexBuffer::AGPResident, NL_VOLATILE_AGP_VB_SIZE, (uint) (NL_VOLATILE_AGP_VB_MAXSIZE * maxAGPbufferSizeRatio), this);
- _VolatileVertexBufferAGP[0]->reset ();
- _VolatileVertexBufferAGP[1]->init (CVertexBuffer::AGPResident, NL_VOLATILE_AGP_VB_SIZE, (uint) (NL_VOLATILE_AGP_VB_MAXSIZE * maxAGPbufferSizeRatio), this);
- _VolatileVertexBufferAGP[1]->reset ();
- //
- _VolatileIndexBuffer16RAM[0]->init (CIndexBuffer::RAMResident, NL_VOLATILE_RAM_IB_SIZE, NL_VOLATILE_RAM_IB_MAXSIZE, this, CIndexBuffer::Indices16);
- _VolatileIndexBuffer16RAM[0]->reset ();
- _VolatileIndexBuffer16RAM[1]->init (CIndexBuffer::RAMResident, NL_VOLATILE_RAM_IB_SIZE, NL_VOLATILE_RAM_IB_MAXSIZE, this, CIndexBuffer::Indices16);
- _VolatileIndexBuffer16RAM[1]->reset ();
- _VolatileIndexBuffer16AGP[0]->init (CIndexBuffer::AGPResident, NL_VOLATILE_AGP_IB_SIZE, (uint) (NL_VOLATILE_AGP_IB_MAXSIZE * maxAGPbufferSizeRatio), this, CIndexBuffer::Indices16);
- _VolatileIndexBuffer16AGP[0]->reset ();
- _VolatileIndexBuffer16AGP[1]->init (CIndexBuffer::AGPResident, NL_VOLATILE_AGP_IB_SIZE, (uint) (NL_VOLATILE_AGP_IB_MAXSIZE * maxAGPbufferSizeRatio), this, CIndexBuffer::Indices16);
- _VolatileIndexBuffer16AGP[1]->reset ();
- // 32 bits indices supported
- if (_MaxVertexIndex > 0xffff)
- {
- _VolatileIndexBuffer32RAM[0]->init (CIndexBuffer::RAMResident, NL_VOLATILE_RAM_IB_SIZE, NL_VOLATILE_RAM_IB_MAXSIZE, this, CIndexBuffer::Indices32);
- _VolatileIndexBuffer32RAM[0]->reset ();
- _VolatileIndexBuffer32RAM[1]->init (CIndexBuffer::RAMResident, NL_VOLATILE_RAM_IB_SIZE, NL_VOLATILE_RAM_IB_MAXSIZE, this, CIndexBuffer::Indices32);
- _VolatileIndexBuffer32RAM[1]->reset ();
- _VolatileIndexBuffer32AGP[0]->init (CIndexBuffer::AGPResident, NL_VOLATILE_AGP_IB_SIZE, (uint) (NL_VOLATILE_AGP_IB_MAXSIZE * maxAGPbufferSizeRatio), this, CIndexBuffer::Indices32);
- _VolatileIndexBuffer32AGP[0]->reset ();
- _VolatileIndexBuffer32AGP[1]->init (CIndexBuffer::AGPResident, NL_VOLATILE_AGP_IB_SIZE, (uint) (NL_VOLATILE_AGP_IB_MAXSIZE * maxAGPbufferSizeRatio), this, CIndexBuffer::Indices32);
- _VolatileIndexBuffer32AGP[1]->reset ();
- }
- //
- setupViewport (CViewport());
-
-
-
- // Begin now
- //nldebug("BeginScene");
- if (!beginScene()) return false;
-
- // Done
- return true;
-}
-
-// ***************************************************************************
-extern uint indexCount;
-extern uint vertexCount;
-
-bool CDriverD3D::release()
-{
- H_AUTO_D3D(CDriver3D_release);
- // Call IDriver::release() before, to destroy textures, shaders and VBs...
- IDriver::release();
-
- ItShaderDrvInfoPtrList itshd;
- while( (itshd = _ShaderDrvInfos.begin()) != _ShaderDrvInfos.end() )
- {
- // NB: at IShader deletion, this->_MatDrvInfos is updated (entry deleted);
- delete *itshd;
- }
-
- _SwapBufferCounter = 0;
-
- if (_QuadIB)
- {
- _QuadIB->Release();
- _QuadIB = NULL;
- }
-
- // delete queries
- while (!_OcclusionQueryList.empty())
- {
- deleteOcclusionQuery(_OcclusionQueryList.front());
- }
-
- // Back buffer ref
- if (_BackBuffer)
- _BackBuffer->Release();
- _BackBuffer = NULL;
-
- // Release all the vertex declaration
- std::list::iterator ite = _VertexDeclarationList.begin();
- while (ite != _VertexDeclarationList.end())
- {
- ite->VertexDecl->Release();
- ite++;
- }
- _VertexDeclarationList.clear ();
-
- // Release pixel shaders
- _NormalPixelShaders[0].clear ();
- _NormalPixelShaders[1].clear ();
-
- if( _DeviceInterface != NULL)
- {
- _DeviceInterface->Release();
- _DeviceInterface = NULL;
- }
-
- if (_HWnd)
- {
- releaseCursors();
-
- // make sure window icons are deleted
- std::vector bitmaps;
- setWindowIcon(bitmaps);
-
- if (_DestroyWindow)
- DestroyWindow (_HWnd);
- _HWnd = NULL;
- }
-
-
- nlassert (indexCount == 0);
- nlassert (vertexCount == 0);
-
- // restore desktop gamma ramp
- if (_DesktopGammaRampValid)
- {
- HDC dc = CreateDCW (L"DISPLAY", NULL, NULL, NULL);
- if (dc)
- {
- SetDeviceGammaRamp (dc, _DesktopGammaRamp);
- }
- _DesktopGammaRampValid = false;
- }
- return true;
-};
-
-// ***************************************************************************
-
-emptyProc CDriverD3D::getWindowProc()
-{
- return (emptyProc)D3DWndProc;
-};
-
-// ***************************************************************************
-
-IDriver::TMessageBoxId CDriverD3D::systemMessageBox (const char* message, const char* title, TMessageBoxType type, TMessageBoxIcon icon)
-{
- switch (::MessageBoxW (_HWnd, utf8ToWide(message), utf8ToWide(title), ((type==retryCancelType)?MB_RETRYCANCEL:
- (type==yesNoCancelType)?MB_YESNOCANCEL:
- (type==okCancelType)?MB_OKCANCEL:
- (type==abortRetryIgnoreType)?MB_ABORTRETRYIGNORE:
- (type==yesNoType)?MB_YESNO|MB_ICONQUESTION:MB_OK)|
-
- ((icon==handIcon)?MB_ICONHAND:
- (icon==questionIcon)?MB_ICONQUESTION:
- (icon==exclamationIcon)?MB_ICONEXCLAMATION:
- (icon==asteriskIcon)?MB_ICONASTERISK:
- (icon==warningIcon)?MB_ICONWARNING:
- (icon==errorIcon)?MB_ICONERROR:
- (icon==informationIcon)?MB_ICONINFORMATION:
- (icon==stopIcon)?MB_ICONSTOP:0)))
- {
- case IDOK:
- return okId;
- case IDCANCEL:
- return cancelId;
- case IDABORT:
- return abortId;
- case IDRETRY:
- return retryId;
- case IDIGNORE:
- return ignoreId;
- case IDYES:
- return yesId;
- case IDNO:
- return noId;
- }
- return okId;
-}
-
-// ***************************************************************************
-bool CDriverD3D::activate()
-{
- return true;
-}
-
-// ***************************************************************************
-bool CDriverD3D::isActive ()
-{
- return (IsWindow(_HWnd) != 0);
-}
-
-// ***************************************************************************
-nlWindow CDriverD3D::getDisplay()
-{
- return _HWnd;
-}
-
-// ***************************************************************************
-NLMISC::IEventEmitter *CDriverD3D::getEventEmitter()
-{
- return &_EventEmitter;
-}
-
-// ***************************************************************************
-void CDriverD3D::getWindowSize (uint32 &width, uint32 &height)
-{
- H_AUTO_D3D(CDriverD3D_getWindowSize);
- width = _CurrentMode.Width;
- height = _CurrentMode.Height;
-}
-
-// ***************************************************************************
-
-void CDriverD3D::getWindowPos (sint32 &x, sint32 &y)
-{
- H_AUTO_D3D(CDriverD3D_getWindowPos);
- x = _WindowX;
- y = _WindowY;
-}
-
-// ***************************************************************************
-uint32 CDriverD3D::getImplementationVersion () const
-{
- H_AUTO_D3D(CDriverD3D_getImplementationVersion);
- return ReleaseVersion;
-}
-
-// ***************************************************************************
-const char *CDriverD3D::getDriverInformation ()
-{
- return "Directx 9 NeL Driver";
-}
-
-// ***************************************************************************
-uint8 CDriverD3D::getBitPerPixel ()
-{
- return _CurrentMode.Depth;
-}
-
-// ***************************************************************************
-bool CDriverD3D::clear2D(CRGBA rgba)
-{
- H_AUTO_D3D(CDriverD3D_clear2D);
- nlassert (_DeviceInterface);
-
- // Backup viewport
- CViewport oldViewport = _Viewport;
- setupViewport (CViewport());
- updateRenderVariables ();
-
- bool result = _DeviceInterface->Clear( 0, NULL, D3DCLEAR_TARGET, NL_D3DCOLOR_RGBA(rgba), 1.0f, 0 ) == D3D_OK;
-
- // Restore the old viewport
- setupViewport (oldViewport);
- return result;
-}
-
-// ***************************************************************************
-
-bool CDriverD3D::clearZBuffer(float zval)
-{
- H_AUTO_D3D(CDriverD3D_clearZBuffer);
- nlassert (_DeviceInterface);
-
- // Backup viewport
- CViewport oldViewport = _Viewport;
- setupViewport (CViewport());
- updateRenderVariables ();
-
- bool result = _DeviceInterface->Clear( 0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0,0,0,0), zval, 0 ) == D3D_OK;
-
- // Restore the old viewport
- setupViewport (oldViewport);
-
- // NVidia driver 56.72 needs to reset the vertex buffer after a clear Z
- touchRenderVariable (&_VertexBufferCache);
-
- return result;
-}
-
-// ***************************************************************************
-
-bool CDriverD3D::clearStencilBuffer(float stencilval)
-{
- H_AUTO_D3D(CDriverD3D_clearStencilBuffer);
- nlassert (_DeviceInterface);
-
- // Backup viewport
- CViewport oldViewport = _Viewport;
- setupViewport (CViewport());
- updateRenderVariables ();
-
- bool result = _DeviceInterface->Clear( 0, NULL, D3DCLEAR_STENCIL, D3DCOLOR_ARGB(0,0,0,0), 1.0f, (unsigned long)stencilval ) == D3D_OK;
-
- // Restore the old viewport
- setupViewport (oldViewport);
-
- return result;
-}
-
-// ***************************************************************************
-
-void CDriverD3D::setColorMask (bool bRed, bool bGreen, bool bBlue, bool bAlpha)
-{
- H_AUTO_D3D(CDriverD3D_setColorMask);
- setRenderState (D3DRS_COLORWRITEENABLE,
- (bAlpha?D3DCOLORWRITEENABLE_ALPHA:0)|
- (bRed?D3DCOLORWRITEENABLE_RED:0)|
- (bGreen?D3DCOLORWRITEENABLE_GREEN:0)|
- (bBlue?D3DCOLORWRITEENABLE_BLUE:0)
- );
-}
-
-
-
-
-// ***************************************************************************
-bool CDriverD3D::swapBuffers()
-{
- //DUMP_AUTO(swapBuffers);
- H_AUTO_D3D(CDriverD3D_swapBuffers);
- nlassert (_DeviceInterface);
-
- ++ _SwapBufferCounter;
- // Swap & reset volatile buffers
- _CurrentRenderPass++;
- _VolatileVertexBufferRAM[_CurrentRenderPass&1]->reset ();
- _VolatileVertexBufferAGP[_CurrentRenderPass&1]->reset ();
- _VolatileIndexBuffer16RAM[_CurrentRenderPass&1]->reset ();
- _VolatileIndexBuffer16AGP[_CurrentRenderPass&1]->reset ();
- _VolatileIndexBuffer32RAM[_CurrentRenderPass&1]->reset ();
- _VolatileIndexBuffer32AGP[_CurrentRenderPass&1]->reset ();
-
- // todo hulud volatile
- //_DeviceInterface->SetStreamSource(0, _VolatileVertexBufferRAM[1]->VertexBuffer, 0, 12);
-
- // End now
- if (!endScene())
- {
- nlstop;
- return false;
- }
-
- HRESULT result = _DeviceInterface->Present( NULL, NULL, NULL, NULL);
- if (result != D3D_OK)
- {
- // Device lost ?
- if (result == D3DERR_DEVICELOST)
- {
- _Lost = true;
- // check if we can exit lost state
- if (_DeviceInterface->TestCooperativeLevel() == D3DERR_DEVICENOTRESET)
- {
- // Reset the driver
- reset (_CurrentMode);
- }
- }
- }
-
- // Check window size
- handlePossibleSizeChange ();
-
- // Reset the profiling counter.
- _PrimitiveProfileIn.reset();
- _PrimitiveProfileOut.reset();
- _NbSetupMaterialCall= 0;
- _NbSetupModelMatrixCall= 0;
-
- // Reset the texture set
- _TextureUsed.clear();
-
- // Reset vertex program
- setVertexProgram (NULL, NULL);
- // Reset pixel program
- setPixelShader (NULL);
-
- if (_VBHardProfiling)
- {
- ++_NumVBHardProfileFrame;
- }
- if (_IBProfiling)
- {
- ++ _NumIBProfileFrame;
- }
-
- // Begin now
- return beginScene();
-};
-
-// ***************************************************************************
-
-void CDriverD3D::setPolygonMode (TPolygonMode mode)
-{
- H_AUTO_D3D(CDriverD3D_setPolygonMode);
- IDriver::setPolygonMode (mode);
-
- setRenderState (D3DRS_FILLMODE, mode==Point?D3DFILL_POINT:mode==Line?D3DFILL_WIREFRAME:D3DFILL_SOLID);
-}
-
-// ***************************************************************************
-
-bool CDriverD3D::isTextureFormatOk(UINT adapter, D3DDEVTYPE rasterizer, D3DFORMAT TextureFormat, D3DFORMAT AdapterFormat)
-{
- H_AUTO_D3D(CDriverD3D_isTextureFormatOk);
- HRESULT hr = _D3D->CheckDeviceFormat( adapter,
- rasterizer,
- AdapterFormat,
- 0,
- D3DRTYPE_TEXTURE,
- TextureFormat);
-
- return SUCCEEDED( hr ) != FALSE;
-}
-
-// ***************************************************************************
-
-void CDriverD3D::forceDXTCCompression(bool dxtcComp)
-{
- H_AUTO_D3D(CDriverD3D_forceDXTCCompression);
- _ForceDXTCCompression = dxtcComp;
-}
-
-// ***************************************************************************
-
-void CDriverD3D::setAnisotropicFilter(sint filter)
-{
- H_AUTO_D3D(CDriverD3D_setAnisotropicFilter);
-
- // anisotropic filter not supported
- if (_MaxAnisotropy < 2) return;
-
- if (filter < 0 || filter > _MaxAnisotropy)
- {
- _AnisotropicFilter = _MaxAnisotropy;
- }
- else
- {
- _AnisotropicFilter = filter;
- }
-}
-
-// ***************************************************************************
-
-uint CDriverD3D::getAnisotropicFilter() const
-{
- H_AUTO_D3D(CDriverD3D_getAnisotropicFilter);
-
- return _AnisotropicFilter;
-}
-
-// ***************************************************************************
-
-uint CDriverD3D::getAnisotropicFilterMaximum() const
-{
- H_AUTO_D3D(CDriverD3D_getAnisotropicFilterMaximum);
-
- return _MaxAnisotropy;
-}
-
-// ***************************************************************************
-
-void CDriverD3D::forceTextureResize(uint divisor)
-{
- H_AUTO_D3D(CDriverD3D_forceTextureResize);
- clamp(divisor, 1U, 256U);
-
- // 16 -> 4.
- _ForceTextureResizePower= getPowerOf2(divisor);
-}
-
-// ***************************************************************************
-
-bool CDriverD3D::fogEnabled()
-{
- H_AUTO_D3D(CDriverD3D_fogEnabled);
- // Return _RenderStateCache[D3DRS_FOGENABLE].Value == TRUE;
- // Nico Patch : must return the _FogEnabled value here, because it MAY be
- // different of the one found in _RenderStateCache[D3DRS_FOGENABLE]
- // this happens for example when dest blend is one : the actual content of _RenderStateCache[D3DRS_FOGENABLE]
- // is then restored when current material alpha blending settings are modified, or when a new material is set.
- return _FogEnabled;
-}
-
-// ***************************************************************************
-
-void CDriverD3D::enableFog(bool enable)
-{
- H_AUTO_D3D(CDriverD3D_enableFog);
- _FogEnabled = enable;
- setRenderState (D3DRS_FOGENABLE, enable?TRUE:FALSE);
-}
-
-// ***************************************************************************
-
-void CDriverD3D::setupFog(float start, float end, CRGBA color)
-{
- H_AUTO_D3D(CDriverD3D_setupFog);
- // Remember fog start and end
- _FogStart = start;
- _FogEnd = end;
- _FogColor = NL_D3DCOLOR_RGBA(color);
-
- // Set the fog
- setRenderState (D3DRS_FOGCOLOR, _FogColor);
- setRenderState (D3DRS_FOGSTART, *((DWORD*) (&_FogStart)));
- setRenderState (D3DRS_FOGEND, *((DWORD*) (&_FogEnd)));
-}
-
-// ***************************************************************************
-
-float CDriverD3D::getFogStart() const
-{
- return _FogStart;
-}
-
-// ***************************************************************************
-
-float CDriverD3D::getFogEnd() const
-{
- return _FogEnd;
-}
-
-// ***************************************************************************
-
-CRGBA CDriverD3D::getFogColor() const
-{
- return D3DCOLOR_NL_RGBA(_RenderStateCache[D3DRS_FOGCOLOR].Value);
-}
-
-// ***************************************************************************
-
-CVertexBuffer::TVertexColorType CDriverD3D::getVertexColorFormat() const
-{
- return CVertexBuffer::TBGRA;
-}
-
-// ***************************************************************************
-
-uint CDriverD3D::getNbTextureStages() const
-{
- return _NbNeLTextureStages;
-}
-
-// ***************************************************************************
-
-bool CDriverD3D::getModes(std::vector &modes)
-{
- H_AUTO_D3D(CDriverD3D_getModes);
- static const D3DFORMAT format[]=
- {
- D3DFMT_A8R8G8B8,
- D3DFMT_X8R8G8B8,
- D3DFMT_R8G8B8,
- D3DFMT_A1R5G5B5,
- D3DFMT_R5G6B5,
- };
- static const uint8 depth[]=
- {
- 32,
- 32,
- 24,
- 16,
- 16,
- };
- uint f;
- for (f=0; fGetAdapterModeCount(adapter, format[f]);
- uint i;
- for (i=0; iEnumAdapterModes( adapter, format[f], i, &mode) == D3D_OK)
- {
- GfxMode gfxMode;
- gfxMode.Windowed=false;
- gfxMode.Width=(uint16)mode.Width;
- gfxMode.Height=(uint16)mode.Height;
- gfxMode.Depth=depth[f];
- gfxMode.Frequency=(uint8)mode.RefreshRate;
- modes.push_back (gfxMode);
- }
- }
- }
- return true;
-}
-
-// ***************************************************************************
-bool CDriverD3D::getCurrentScreenMode(GfxMode &gfxMode)
-{
- H_AUTO_D3D(CDriverD3D_getCurrentScreenMode);
- UINT adapter = (_Adapter==0xffffffff)?D3DADAPTER_DEFAULT:(UINT)_Adapter;
- D3DDISPLAYMODE mode;
- _D3D->GetAdapterDisplayMode(adapter, &mode);
- gfxMode.Windowed = !_FullScreen;
- gfxMode.Width = (uint16)mode.Width;
- gfxMode.Height = (uint16)mode.Height;
- gfxMode.Depth = ((mode.Format==D3DFMT_A8R8G8B8)||(mode.Format==D3DFMT_X8R8G8B8))?32:16;
- gfxMode.Frequency = (uint8)mode.RefreshRate;
-
- return true;
-}
-
-// ***************************************************************************
-void CDriverD3D::setWindowTitle(const ucstring &title)
-{
- if (!SetWindowTextW(_HWnd, (WCHAR*)title.c_str()))
- {
- nlwarning("SetWindowText failed: %s", formatErrorMessage(getLastError()).c_str());
- }
-}
-
-// ***************************************************************************
-void CDriverD3D::setWindowIcon(const std::vector &bitmaps)
-{
- if (!_HWnd)
- return;
-
- static HICON winIconBig = NULL;
- static HICON winIconSmall = NULL;
-
- if (winIconBig)
- {
- DestroyIcon(winIconBig);
- winIconBig = NULL;
- }
-
- if (winIconSmall)
- {
- DestroyIcon(winIconSmall);
- winIconSmall = NULL;
- }
-
- sint smallIndex = -1;
- uint smallWidth = GetSystemMetrics(SM_CXSMICON);
- uint smallHeight = GetSystemMetrics(SM_CYSMICON);
-
- sint bigIndex = -1;
- uint bigWidth = GetSystemMetrics(SM_CXICON);
- uint bigHeight = GetSystemMetrics(SM_CYICON);
-
- // find icons with the exact size
- for(uint i = 0; i < bitmaps.size(); ++i)
- {
- if (smallIndex == -1 && bitmaps[i].getWidth() == smallWidth && bitmaps[i].getHeight() == smallHeight)
- smallIndex = i;
-
- if (bigIndex == -1 && bitmaps[i].getWidth() == bigWidth && bitmaps[i].getHeight() == bigHeight)
- bigIndex = i;
- }
-
- // find icons with taller size (we will resize them)
- for(uint i = 0; i < bitmaps.size(); ++i)
- {
- if (smallIndex == -1 && bitmaps[i].getWidth() >= smallWidth && bitmaps[i].getHeight() >= smallHeight)
- smallIndex = i;
-
- if (bigIndex == -1 && bitmaps[i].getWidth() >= bigWidth && bitmaps[i].getHeight() >= bigHeight)
- bigIndex = i;
- }
-
- if (smallIndex > -1)
- convertBitmapToIcon(bitmaps[smallIndex], winIconSmall, smallWidth, smallHeight, 32);
-
- if (bigIndex > -1)
- convertBitmapToIcon(bitmaps[bigIndex], winIconBig, bigWidth, bigHeight, 32);
-
- if (winIconBig)
- {
- SendMessageA(_HWnd, WM_SETICON, 0 /* ICON_SMALL */, (LPARAM)winIconSmall);
- SendMessageA(_HWnd, WM_SETICON, 1 /* ICON_BIG */, (LPARAM)winIconBig);
- }
- else
- {
- SendMessageA(_HWnd, WM_SETICON, 0 /* ICON_SMALL */, (LPARAM)winIconSmall);
- SendMessageA(_HWnd, WM_SETICON, 1 /* ICON_BIG */, (LPARAM)winIconSmall);
- }
-}
-
-// ***************************************************************************
-void CDriverD3D::setWindowPos(sint32 x, sint32 y)
-{
- _WindowX = x;
- _WindowY = y;
- SetWindowPos(_HWnd, NULL, _WindowX, _WindowY, 0, 0, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE);
-}
-
-// ***************************************************************************
-void CDriverD3D::showWindow(bool show)
-{
- ShowWindow (_HWnd, show ? SW_SHOW:SW_HIDE);
-}
-
-// ***************************************************************************
-
-uint CDriverD3D::getNumAdapter() const
-{
-H_AUTO_D3D(CDriverD3D_getNumAdapter);
- if (_D3D)
- return _D3D->GetAdapterCount();
- else
- return 0;
-}
-
-// ***************************************************************************
-
-bool CDriverD3D::getAdapter(uint adapter, IDriver::CAdapter &desc) const
-{
- H_AUTO_D3D(CDriverD3D_getAdapter);
- if (_D3D)
- {
- D3DADAPTER_IDENTIFIER9 identifier;
- UINT _adapter = (adapter==0xffffffff)?D3DADAPTER_DEFAULT:(UINT)adapter;
- if (_D3D->GetAdapterIdentifier(_adapter, 0, &identifier) == D3D_OK)
- {
- desc.Description = identifier.Description;
- desc.DeviceId = identifier.DeviceId;
- desc.DeviceName = identifier.DeviceName;
- desc.Driver = identifier.Driver;
- desc.DriverVersion = (((sint64)identifier.DriverVersion.HighPart<<32))|(sint64)identifier.DriverVersion.LowPart;
- desc.Revision = identifier.Revision;
- desc.SubSysId = identifier.SubSysId;
- desc.VendorId = identifier.VendorId;
- desc.VideoMemory = _Adapter == _adapter ? getTotalVideoMemory():-1;
- return true;
- }
- }
- return false;
-}
-
-// ***************************************************************************
-
-bool CDriverD3D::setAdapter(uint adapter)
-{
- H_AUTO_D3D(CDriverD3D_setAdapter);
- if (_D3D)
- {
- D3DDISPLAYMODE adapterMode;
- UINT _adapter = (adapter==0xffffffff)?D3DADAPTER_DEFAULT:(UINT)adapter;
- if (_D3D->GetAdapterDisplayMode (_adapter, &adapterMode) != D3D_OK)
- {
- nlwarning ("CDriverD3D::setDisplay: GetAdapterDisplayMode failed");
- release();
- return false;
- }
- _Adapter = adapter;
- return true;
- }
- return false;
-}
-
-// ***************************************************************************
-
-bool CDriverD3D::supportMADOperator() const
-{
- H_AUTO_D3D(CDriverD3D_supportMADOperator);
- if (_DeviceInterface)
- {
- return _MADOperatorSupported;
- }
- return false; // don't know..
-}
-
-// ***************************************************************************
-
-bool CDriverD3D::setMode (const GfxMode& mode)
-{
- H_AUTO_D3D(CDriverD3D_setMode);
-
- // if fullscreen
- if(!mode.Windowed)
- {
- // Must check if mode exist, else crash at reset() time
- std::vector modes;
- if(getModes(modes))
- {
- bool found= false;
- for(uint i=0;iIndexBufferPtr;
- // If resident in RAM, content has not been lost
- if (ib->getLocation () != CIndexBuffer::RAMResident)
- {
- // Realloc local memory
- ib->setLocation (CIndexBuffer::NotResident);
- delete indexBuffer;
- }
-}
-
-
-// ***************************************************************************
-bool CDriverD3D::reset (const GfxMode& mode)
-{
- //DUMP_AUTO(reset);
- H_AUTO_D3D(CDriverD3D_reset);
- if (_DeviceInterface->TestCooperativeLevel() == D3DERR_DEVICELOST) return false;
-
- // Choose an adapter
- UINT adapter = (_Adapter==0xffffffff)?D3DADAPTER_DEFAULT:(UINT)_Adapter;
-
- // Get adapter format
- D3DDISPLAYMODE adapterMode;
- if (_D3D->GetAdapterDisplayMode (adapter, &adapterMode) != D3D_OK)
- {
- nlwarning ("CDriverD3D::reset: GetAdapterDisplayMode failed");
- release();
- return false;
- }
-
- // Do the reset
- // Increment the IDriver reset counter
-
- D3DPRESENT_PARAMETERS parameters;
- D3DFORMAT adapterFormat;
- if (!fillPresentParameter (parameters, adapterFormat, mode, adapterMode))
- return false;
-
- // Current mode
- _CurrentMode = mode;
- _CurrentMaterial = NULL;
- _CurrentMaterialInfo = NULL;
-
- // Restore non managed vertex buffer in system memory
- ItVBDrvInfoPtrList iteVb = _VBDrvInfos.begin();
- while (iteVb != _VBDrvInfos.end())
- {
- ItVBDrvInfoPtrList iteVbNext = iteVb;
- iteVbNext++;
-
- CVBDrvInfosD3D *vertexBuffer = static_cast(*iteVb);
- CVertexBuffer *vb = vertexBuffer->VertexBufferPtr;
-
- // If resident in RAM, content has not been lost
- if (vb->getLocation () != CVertexBuffer::RAMResident)
- {
- // Realloc local memory
- vb->setLocation (CVertexBuffer::NotResident); // If resident in RAM, content backuped by setLocation
- delete vertexBuffer;
- }
-
- iteVb = iteVbNext;
- }
-
- // Restore non managed index buffer in system memory
- ItIBDrvInfoPtrList iteIb = _IBDrvInfos.begin();
- while (iteIb != _IBDrvInfos.end())
- {
- ItIBDrvInfoPtrList iteIbNext = iteIb;
- iteIbNext++;
- deleteIndexBuffer(static_cast(*iteIb));
- iteIb = iteIbNext;
- }
- deleteIndexBuffer(static_cast((IIBDrvInfos *) _QuadIndexesAGP.DrvInfos));
-
- // Remove render targets
- ItTexDrvSharePtrList ite = _TexDrvShares.begin();
- while (ite != _TexDrvShares.end())
- {
- ItTexDrvSharePtrList iteNext = ite;
- iteNext++;
-
- // Render target ?
- nlassert ((*ite)->DrvTexture != NULL);
- CTextureDrvInfosD3D *info = static_cast(static_cast((*ite)->DrvTexture));
- if (info->RenderTarget)
- {
- // Remove it
- delete *ite;
- }
- ite = iteNext;
- }
-
- // Free volatile buffers
- _VolatileVertexBufferRAM[0]->release ();
- _VolatileVertexBufferRAM[1]->release ();
- _VolatileVertexBufferAGP[0]->release ();
- _VolatileVertexBufferAGP[1]->release ();
- _VolatileIndexBuffer16RAM[0]->release ();
- _VolatileIndexBuffer16RAM[1]->release ();
- _VolatileIndexBuffer16AGP[0]->release ();
- _VolatileIndexBuffer16AGP[1]->release ();
- _VolatileIndexBuffer32RAM[0]->release ();
- _VolatileIndexBuffer32RAM[1]->release ();
- _VolatileIndexBuffer32AGP[0]->release ();
- _VolatileIndexBuffer32AGP[1]->release ();
-
- // Back buffer ref
- if (_BackBuffer)
- _BackBuffer->Release();
- _BackBuffer = NULL;
-
- // Invalidate all occlusion queries.
- // TODO nico : for now, even if a result has been retrieved successfully by the query, the query is put in the lost state. See if its worth improving...
- for(TOcclusionQueryList::iterator it = _OcclusionQueryList.begin(); it != _OcclusionQueryList.end(); ++it)
- {
- if ((*it)->Query)
- {
- (*it)->WasLost = true;
- (*it)->Query->Release();
- (*it)->Query = NULL;
- }
- }
-
- // Release internal shaders
- //releaseInternalShaders();
-
-
- notifyAllShaderDrvOfLostDevice();
-
-
-
- /* Do not reset if reset will fail */
- _ResetCounter++;
- bool sceneBegun = hasSceneBegun();
- if (sceneBegun)
- {
- //nldebug("EndScene");
- endScene();
- }
-
- // delete all .fx caches
- for(TMatDrvInfoPtrList::iterator it = _MatDrvInfos.begin(); it != _MatDrvInfos.end(); ++it)
- {
- CMaterialDrvInfosD3D *mi = NLMISC::safe_cast(*it);
- if (mi->FXCache)
- {
- mi->FXCache->reset();
- }
- }
-
- {
-#ifndef NL_NO_ASM
- CFpuRestorer fpuRestorer; // fpu control word is changed by "Reset"
-#endif
- if (_Rasterizer!=D3DDEVTYPE_REF)
- {
- HRESULT hr = _DeviceInterface->Reset (¶meters);
- if (hr != D3D_OK)
- {
- nlwarning("CDriverD3D::reset: Reset on _DeviceInterface error 0x%x", hr);
- // tmp
- nlstopex(("CDriverD3D::reset: Reset on _DeviceInterface"));
- return false;
- }
- }
- }
-
- _Lost = false;
- // BeginScene now
- if (sceneBegun)
- {
- //nldebug("BeginScene");
- beginScene();
- }
-
- notifyAllShaderDrvOfResetDevice();
-
- // Reset internal caches
- resetRenderVariables();
-
- // Init shaders
- //initInternalShaders();
-
- // reallocate occlusion queries
- for(TOcclusionQueryList::iterator it = _OcclusionQueryList.begin(); it != _OcclusionQueryList.end(); ++it)
- {
- if (!(*it)->Query)
- {
- _DeviceInterface->CreateQuery(D3DQUERYTYPE_OCCLUSION, &(*it)->Query);
- }
- }
- return true;
-}
-
-// ***************************************************************************
-
-bool CDriverD3D::fillPresentParameter (D3DPRESENT_PARAMETERS ¶meters, D3DFORMAT &adapterFormat, const GfxMode& mode, const D3DDISPLAYMODE &adapterMode)
-{
- UINT adapter = (_Adapter==0xffffffff)?D3DADAPTER_DEFAULT:(UINT)_Adapter;
- H_AUTO_D3D(CDriverD3D_fillPresentParameter);
- memset (¶meters, 0, sizeof(D3DPRESENT_PARAMETERS));
- parameters.BackBufferWidth = mode.Width;
- parameters.BackBufferHeight = mode.Height;
- parameters.BackBufferCount = 1;
- parameters.MultiSampleType = D3DMULTISAMPLE_NONE;
- parameters.MultiSampleQuality = 0;
- parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
- parameters.hDeviceWindow = NULL;
- parameters.Windowed = mode.Windowed;
- parameters.EnableAutoDepthStencil = TRUE;
- parameters.FullScreen_RefreshRateInHz = mode.Windowed?0:mode.Frequency;
- switch (_Interval)
- {
- case 0:
- parameters.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
- break;
- case 1:
- parameters.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
- break;
- case 2:
- parameters.PresentationInterval = D3DPRESENT_INTERVAL_TWO;
- break;
- case 3:
- parameters.PresentationInterval = D3DPRESENT_INTERVAL_THREE;
- break;
- default:
- parameters.PresentationInterval = D3DPRESENT_INTERVAL_FOUR;
- break;
- }
-
- // Build a depth index
- const uint depthIndex = (mode.Depth==16)?0:(mode.Depth==24)?1:2;
-
- // Choose a back buffer format
- const uint numFormat = 4;
- D3DFORMAT backBufferFormats[3][numFormat]=
- {
- {D3DFMT_R5G6B5, D3DFMT_A1R5G5B5, D3DFMT_X1R5G5B5, D3DFMT_A4R4G4B4},
- {D3DFMT_R8G8B8, D3DFMT_A8R8G8B8, D3DFMT_X8R8G8B8, D3DFMT_X8R8G8B8},
- {D3DFMT_A8R8G8B8, D3DFMT_X8R8G8B8, D3DFMT_X8R8G8B8, D3DFMT_X8R8G8B8},
- };
- bool found = false;
- if (mode.Windowed)
- {
- uint backBuffer;
- for (backBuffer=0; backBufferCheckDeviceType(adapter, _Rasterizer, adapterMode.Format, backBufferFormats[depthIndex][backBuffer], TRUE) == D3D_OK)
- {
- parameters.BackBufferFormat = backBufferFormats[depthIndex][backBuffer];
- adapterFormat = adapterMode.Format;
- found = true;
- break;
- }
- }
- }
- else
- {
- // Found a pair display and back buffer format
- uint backBuffer;
- for (backBuffer=0; backBufferCheckDeviceType(adapter, _Rasterizer, backBufferFormats[depthIndex][display], backBufferFormats[depthIndex][display], FALSE) == D3D_OK)
- {
- parameters.BackBufferFormat = backBufferFormats[depthIndex][backBuffer];
- adapterFormat = backBufferFormats[depthIndex][display];
- found = true;
- break;
- }
- }
- if (found)
- break;
- }
- }
-
- // Not found ?
- if (!found)
- {
- nlwarning ("Can't create backbuffer");
- return false;
- }
-
- // Choose a zbuffer format
- D3DFORMAT zbufferFormats[]=
- {
- //uncomment to save zbuffer D3DFMT_D32F_LOCKABLE,
- //uncomment to save zbuffer D3DFMT_D16_LOCKABLE,
- /*D3DFMT_D32,
- D3DFMT_D24X8,*/
- D3DFMT_D24S8,
- D3DFMT_D24X4S4,
- D3DFMT_D24FS8,
- //D3DFMT_D16,
- };
-
- const uint zbufferFormatCount = sizeof(zbufferFormats)/sizeof(D3DFORMAT);
- uint i;
- for (i=0; i=zbufferFormatCount)
- {
- nlwarning ("Can't create zbuffer");
- return false;
- }
-
- // Set the zbuffer format
- parameters.AutoDepthStencilFormat = zbufferFormats[i];
-
- if(mode.AntiAlias == -1)
- {
- parameters.Flags |= D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
- }
- else
- {
- DWORD aa = 0;
- if(mode.AntiAlias == 0)
- {
- if(SUCCEEDED(_D3D->CheckDeviceMultiSampleType(adapter, _Rasterizer, adapterFormat, mode.Windowed, D3DMULTISAMPLE_NONMASKABLE, &aa)))
- {
- parameters.MultiSampleType = D3DMULTISAMPLE_NONMASKABLE;
- parameters.MultiSampleQuality = aa - 1;
- nlinfo("Use AntiAlias with %d sample", aa);
- }
- else
- {
- nlwarning("No AntiAlias support found");
- }
- }
- else
- {
- parameters.MultiSampleType = D3DMULTISAMPLE_NONMASKABLE;
- parameters.MultiSampleQuality = mode.AntiAlias - 1;
- nlinfo("Use AntiAlias with %d sample", mode.AntiAlias);
- }
- }
-
- return true;
-}
-
-// ***************************************************************************
-
-const char *CDriverD3D::getVideocardInformation ()
-{
- H_AUTO_D3D(CDriverD3D_getVideocardInformation);
- static char name[1024];
-
-// if (!_DeviceInterface)
-// return "Direct3d isn't initialized";
-
- D3DADAPTER_IDENTIFIER9 identifier;
- UINT adapter = (_Adapter==0xffffffff)?D3DADAPTER_DEFAULT:(UINT)_Adapter;
- if (_D3D->GetAdapterIdentifier(adapter, 0, &identifier) == D3D_OK)
- {
- uint64 version = ((uint64)identifier.DriverVersion.HighPart) << 32;
- version |= identifier.DriverVersion.LowPart;
- smprintf (name, 1024, "Direct3d / %s / %s / %s / driver version : %d.%d.%d.%d", identifier.Driver, identifier.Description, identifier.DeviceName,
- (uint16)((version>>48)&0xFFFF),(uint16)((version>>32)&0xFFFF),(uint16)((version>>16)&0xFFFF),(uint16)(version&0xffff));
- return name;
- }
- else
- return "Can't get video card information";
-}
-
-// ***************************************************************************
-
-sint CDriverD3D::getTotalVideoMemory () const
-{
- H_AUTO_D3D(CDriverD3D_getTotalVideoMemory);
-
- // Can't use _DeviceInterface->GetAvailableTextureMem() because it's not reliable
- // Returns 4 GiB instead of 2 with my GPU
- return -1;
-}
-
-// ***************************************************************************
-
-void CDriverD3D::getBuffer (CBitmap &bitmap)
-{
- H_AUTO_D3D(CDriverD3D_getBuffer);
- NLMISC::CRect rect;
- rect.setWH (0, 0, _CurrentMode.Width, _CurrentMode.Height);
- getBufferPart (bitmap, rect);
-}
-
-// ***************************************************************************
-
-void CDriverD3D::getBufferPart (CBitmap &bitmap, NLMISC::CRect &rect)
-{
- H_AUTO_D3D(CDriverD3D_getBufferPart);
- if (_DeviceInterface)
- {
- // Resize the bitmap
- const uint lineCount = rect.Height;
- const uint width = rect.Width;
- bitmap.resize (width, lineCount, CBitmap::RGBA);
-
- // Lock the back buffer
- IDirect3DSurface9 *surface;
- if (_DeviceInterface->GetBackBuffer (0, 0, D3DBACKBUFFER_TYPE_MONO, &surface) == D3D_OK)
- {
- // Surface desc
- D3DSURFACE_DESC desc;
- if (surface->GetDesc(&desc) == D3D_OK)
- {
- // 32 bits format supported
- if ((desc.Format == D3DFMT_R8G8B8) ||
- (desc.Format == D3DFMT_A8R8G8B8) ||
- (desc.Format == D3DFMT_X8R8G8B8) ||
- (desc.Format == D3DFMT_A8B8G8R8) ||
- (desc.Format == D3DFMT_X8B8G8R8))
- {
- // Invert RGBA ?
- bool invertRGBA = (desc.Format == D3DFMT_R8G8B8) || (desc.Format == D3DFMT_A8R8G8B8) || (desc.Format == D3DFMT_X8R8G8B8);
-
- // Lock the surface
- D3DLOCKED_RECT lock;
- ::RECT winRect;
- winRect.left = rect.left();
- winRect.right = rect.right();
- winRect.top = rect.top();
- winRect.bottom = rect.bottom();
- if (surface->LockRect (&lock, &winRect, D3DLOCK_READONLY) == D3D_OK)
- {
- // Line count
- uint8 *dest = &(bitmap.getPixels ()[0]);
- uint i;
- for (i=0; iUnlockRect ();
- }
- }
- }
-
- surface->Release();
- }
- }
-}
-
-// ***************************************************************************
-
-IDirect3DSurface9 * CDriverD3D::getSurfaceTexture(ITexture * text)
-{
- if(!text)
- {
- if(!_BackBuffer)
- {
- updateRenderVariables ();
- _DeviceInterface->GetRenderTarget (0, &_BackBuffer);
- }
- nlassert(_BackBuffer);
- return _BackBuffer;
- }
-
- if(text->TextureDrvShare==NULL || text->TextureDrvShare->DrvTexture.getPtr()==NULL)
- {
- text->setRenderTarget(true);
- setupTexture(*text);
- }
- CTextureDrvInfosD3D* rdvInfosD3D = (NLMISC::safe_cast(text->TextureDrvShare->DrvTexture.getPtr()));
-
- IDirect3DTexture9 * texture = rdvInfosD3D->Texture2d;
- nlassert(texture);
-
- IDirect3DSurface9 * surface;
- HRESULT hr = texture->GetSurfaceLevel(0, &surface);
- nlassert(hr==D3D_OK);
-
- return surface;
-}
-
-void CDriverD3D::getDirect3DRect(NLMISC::CRect &rect, RECT & d3dRect)
-{
- d3dRect.left = rect.left();
- d3dRect.top = rect.top();
- d3dRect.right = rect.right();
- d3dRect.bottom = rect.bottom();
-
- uint32 w, h;
- getWindowSize(w, h);
-
- if(d3dRect.top>(sint32)h)
- d3dRect.top = h;
-
- if(d3dRect.right>(sint32)w)
- d3dRect.right = w;
-
- if(d3dRect.bottom<0)
- d3dRect.bottom = 0;
-
- if(d3dRect.left<0)
- d3dRect.left = 0;
-}
-
-bool CDriverD3D::stretchRect(ITexture * srcText, NLMISC::CRect &srcRect, ITexture * destText, NLMISC::CRect &destRect)
-{
- H_AUTO_D3D(CDriverD3D_stretchRect);
- if (_DeviceInterface)
- {
- IDirect3DSurface9 * srcSurface = getSurfaceTexture(srcText);
- IDirect3DSurface9 * destSurface = getSurfaceTexture(destText);
-
- D3DTEXTUREFILTERTYPE filterType = D3DTEXF_LINEAR;
-
- RECT srcD3DRect;
- RECT destD3DRect;
- getDirect3DRect(srcRect, srcD3DRect);
- getDirect3DRect(destRect, destD3DRect);
-
- HRESULT hr = _DeviceInterface->StretchRect(srcSurface, &srcD3DRect, destSurface, &destD3DRect, filterType);
-
- srcSurface->Release();
- destSurface->Release();
-
- return (hr==D3D_OK);
- }
-
- return false;
-}
-
-// ***************************************************************************
-
-bool CDriverD3D::supportBloomEffect() const
-{
- return supportVertexProgram(CVertexProgram::nelvp);
-}
-
-// ***************************************************************************
-
-bool CDriverD3D::supportNonPowerOfTwoTextures() const
-{
- return _NonPowerOfTwoTexturesSupported;
-}
-
-// ***************************************************************************
-
-bool CDriverD3D::fillBuffer (NLMISC::CBitmap &bitmap)
-{
- H_AUTO_D3D(CDriverD3D_fillBuffer);
- bool result = false;
- if (_DeviceInterface)
- {
- // Resize the bitmap
- const uint lineCount = _CurrentMode.Height;
- const uint width = _CurrentMode.Width;
- if ((bitmap.getWidth() == width) && (bitmap.getHeight() == lineCount))
- {
- // Lock the back buffer
- IDirect3DSurface9 *surface;
- if (_DeviceInterface->GetBackBuffer (0, 0, D3DBACKBUFFER_TYPE_MONO, &surface) == D3D_OK)
- {
- // Surface desc
- D3DSURFACE_DESC desc;
- if (surface->GetDesc(&desc) == D3D_OK)
- {
- // 32 bits format supported
- if ((desc.Format == D3DFMT_R8G8B8) ||
- (desc.Format == D3DFMT_A8R8G8B8) ||
- (desc.Format == D3DFMT_X8R8G8B8) ||
- (desc.Format == D3DFMT_A8B8G8R8) ||
- (desc.Format == D3DFMT_X8B8G8R8))
- {
- // Invert RGBA ?
- bool invertRGBA = (desc.Format == D3DFMT_R8G8B8) || (desc.Format == D3DFMT_A8R8G8B8) || (desc.Format == D3DFMT_X8R8G8B8);
-
- // Lock the surface
- D3DLOCKED_RECT lock;
- ::RECT winRect;
- winRect.left = 0;
- winRect.right = width;
- winRect.top = 0;
- winRect.bottom = lineCount;
- if (surface->LockRect (&lock, &winRect, 0) == D3D_OK)
- {
- // Line count
- uint8 *dest = &(bitmap.getPixels ()[0]);
- uint i;
- for (i=0; iUnlockRect ();
- result = true;
- }
- }
- }
-
- surface->Release();
- }
- }
- }
- return result;
-}
-
-// ***************************************************************************
-
-void CDriverD3D::setSwapVBLInterval(uint interval)
-{
- H_AUTO_D3D(CDriverD3D_setSwapVBLInterval);
- if (_Interval != interval)
- {
- _Interval = interval;
-
- // Must do a reset because the vsync parameter is choosed in the D3DPRESENT structure
- if (_DeviceInterface)
- reset (_CurrentMode);
- }
-}
-
-// ***************************************************************************
-
-uint CDriverD3D::getSwapVBLInterval()
-{
- H_AUTO_D3D(CDriverD3D_getSwapVBLInterval);
- return _Interval;
-}
-
-// ***************************************************************************
-void CDriverD3D::finish()
-{
- // TODO : actually do not wait until everythin is rendered
- H_AUTO_D3D(CDriverD3D_finish);
- // Flush now
- //nldebug("EndScene");
- endScene();
- //nldebug("BeginScene");
- beginScene();
-}
-
-// ***************************************************************************
-void CDriverD3D::flush()
-{
- H_AUTO_D3D(CDriverD3D_finish);
- // Flush now
- //nldebug("EndScene");
- endScene();
- //nldebug("BeginScene");
- beginScene();
-}
-
-// ***************************************************************************
-
-bool CDriverD3D::setMonitorColorProperties (const CMonitorColorProperties &properties)
-{
- /*
- H_AUTO_D3D(CDriverD3D_setMonitorColorProperties);
- // The ramp
- D3DGAMMARAMP ramp;
-
- // For each composant
- uint c;
- for( c=0; c<3; c++ )
- {
- WORD *table = (c==0)?ramp.red:(c==1)?ramp.green:ramp.blue;
- uint i;
- for( i=0; i<256; i++ )
- {
- // Floating value
- float value = (float)i / 256;
-
- // Contrast
- value = (float) max (0.0f, (value-0.5f) * (float) pow (3.f, properties.Contrast[c]) + 0.5f );
-
- // Gamma
- value = (float) pow (value, (properties.Gamma[c]>0) ? 1 - 3 * properties.Gamma[c] / 4 : 1 - properties.Gamma[c] );
-
- // Luminosity
- value = value + properties.Luminosity[c] / 2.f;
- table[i] = min (65535, max (0, (int)(value * 65535)));
- }
- }
-
- // Set the ramp
- _DeviceInterface->SetGammaRamp (0, D3DSGR_NO_CALIBRATION, &ramp);
- return true;
- */
-
- // TODO nico
- // It would be better to apply the gamma ramp only to the window and not to the whole desktop when playing in windowed mode.
- // This require to switch to D3D 9.0c which has a flag for that purpose in the 'Present' function.
- // Currently the SetGammaRamp only works in fullscreen mode, so we rely to the classic 'SetDeviceGammaRamp' instead.
- HDC dc = CreateDCW (L"DISPLAY", NULL, NULL, NULL);
- if (dc)
- {
- // The ramp
- WORD ramp[256*3];
-
- // For each composant
- uint c;
- for( c=0; c<3; c++ )
- {
- uint i;
- for( i=0; i<256; i++ )
- {
- // Floating value
- float value = (float)i / 256;
-
- // Contrast
- value = (float) max (0.0f, (value-0.5f) * (float) pow (3.f, properties.Contrast[c]) + 0.5f );
-
- // Gamma
- value = (float) pow (value, (properties.Gamma[c]>0) ? 1 - 3 * properties.Gamma[c] / 4 : 1 - properties.Gamma[c] );
-
- // Luminosity
- value = value + properties.Luminosity[c] / 2.f;
- ramp[i+(c<<8)] = (WORD)min (65535, max (0, (int)(value * 65535)));
- }
- }
-
- // Set the ramp
- bool result = SetDeviceGammaRamp (dc, ramp) != FALSE;
-
- // Release the DC
- ReleaseDC (NULL, dc);
-
- // Returns result
- return result;
- }
- else
- {
- nlwarning ("(CDriverD3D::setMonitorColorProperties): can't create DC");
- return false;
- }
-
-}
-// ***************************************************************************
-
-// ****************************************************************************
-bool CDriverD3D::supportEMBM() const
-{
- H_AUTO_D3D(CDriverD3D_supportEMBM);
- return _EMBMSupported;
-}
-
-// ****************************************************************************
-bool CDriverD3D::isEMBMSupportedAtStage(uint stage) const
-{
- H_AUTO_D3D(CDriverD3D_isEMBMSupportedAtStage);
- // we assume EMBM is supported at all stages except the last one
- return stage < _NbNeLTextureStages - 1;
-}
-
-// ****************************************************************************
-void CDriverD3D::setEMBMMatrix(const uint stage, const float mat[4])
-{
- H_AUTO_D3D(CDriverD3D_setEMBMMatrix);
- nlassert(stage < _NbNeLTextureStages - 1);
- SetTextureStageState(stage, D3DTSS_BUMPENVMAT00, (DWORD &) mat[0]);
- SetTextureStageState(stage, D3DTSS_BUMPENVMAT01, (DWORD &) mat[1]);
- SetTextureStageState(stage, D3DTSS_BUMPENVMAT10, (DWORD &) mat[2]);
- SetTextureStageState(stage, D3DTSS_BUMPENVMAT11, (DWORD &) mat[3]);
-}
-
-// ***************************************************************************
-bool CDriverD3D::supportOcclusionQuery() const
-{
- H_AUTO_D3D(CDriverD3D_supportOcclusionQuery);
- return _OcclusionQuerySupported;
-}
-
-// ***************************************************************************
-IOcclusionQuery *CDriverD3D::createOcclusionQuery()
-{
- H_AUTO_D3D(CDriverD3D_createOcclusionQuery);
- nlassert(_OcclusionQuerySupported);
- nlassert(_DeviceInterface);
- IDirect3DQuery9 *query;
- if (_DeviceInterface->CreateQuery(D3DQUERYTYPE_OCCLUSION, &query) != D3D_OK) return NULL;
- COcclusionQueryD3D *oqd3d = new COcclusionQueryD3D;
- oqd3d->Driver = this;
- oqd3d->Query = query;
- oqd3d->VisibleCount = 0;
- oqd3d->OcclusionType = IOcclusionQuery::NotAvailable;
- oqd3d->QueryIssued = false;
- oqd3d->WasLost = false;
- _OcclusionQueryList.push_front(oqd3d);
- oqd3d->Iterator = _OcclusionQueryList.begin();
- return oqd3d;
-}
-
-// ***************************************************************************
-void CDriverD3D::deleteOcclusionQuery(IOcclusionQuery *oq)
-{
- H_AUTO_D3D(CDriverD3D_deleteOcclusionQuery);
- if (!oq) return;
- COcclusionQueryD3D *oqd3d = NLMISC::safe_cast(oq);
- nlassert((CDriverD3D *) oqd3d->Driver == this); // should come from the same driver
- oqd3d->Driver = NULL;
- if (oqd3d->Query)
- {
- oqd3d->Query->Release();
- oqd3d->Query = NULL;
- }
- _OcclusionQueryList.erase(oqd3d->Iterator);
- if (oqd3d == _CurrentOcclusionQuery)
- {
- _CurrentOcclusionQuery = NULL;
- }
- delete oqd3d;
-}
-
-// ***************************************************************************
-void COcclusionQueryD3D::begin()
-{
- H_AUTO_D3D(COcclusionQueryD3D_begin);
- if (!Query) return; // Lost device
- nlassert(Driver);
- nlassert(Driver->_CurrentOcclusionQuery == NULL); // only one query at a time
- Query->Issue(D3DISSUE_BEGIN);
- Driver->_CurrentOcclusionQuery = this;
- OcclusionType = NotAvailable;
- QueryIssued = false;
- WasLost = false;
-}
-
-// ***************************************************************************
-void COcclusionQueryD3D::end()
-{
- H_AUTO_D3D(COcclusionQueryD3D_end);
- if (!Query) return; // Lost device
- nlassert(Driver);
- nlassert(Driver->_CurrentOcclusionQuery == this); // only one query at a time
- if (!WasLost)
- {
- Query->Issue(D3DISSUE_END);
- }
- Driver->_CurrentOcclusionQuery = NULL;
- QueryIssued = true;
-}
-
-// ***************************************************************************
-IOcclusionQuery::TOcclusionType COcclusionQueryD3D::getOcclusionType()
-{
- if (!Query || WasLost) return QueryIssued ? Occluded : NotAvailable;
- H_AUTO_D3D(COcclusionQueryD3D_getOcclusionType);
- nlassert(Driver);
- nlassert(Query);
- nlassert(Driver->_CurrentOcclusionQuery != this); // can't query result between a begin/end pair!
- if (OcclusionType == NotAvailable)
- {
- DWORD numPix;
- if (Query->GetData(&numPix, sizeof(DWORD), 0) == S_OK)
- {
- OcclusionType = numPix != 0 ? NotOccluded : Occluded;
- VisibleCount = (uint) numPix;
- }
- }
- return OcclusionType;
-}
-
-// ***************************************************************************
-uint COcclusionQueryD3D::getVisibleCount()
-{
- if (!Query || WasLost) return 0;
- H_AUTO_D3D(COcclusionQueryD3D_getVisibleCount);
- nlassert(Driver);
- nlassert(Query);
- nlassert(Driver->_CurrentOcclusionQuery != this); // can't query result between a begin/end pair!
- if (getOcclusionType() == NotAvailable) return 0;
- return VisibleCount;
-}
-
-// ***************************************************************************
-bool CDriverD3D::supportWaterShader() const
-{
- H_AUTO_D3D(CDriverD3D_supportWaterShader);
- return _PixelShaderVersion >= D3DPS_VERSION(1, 1);
-}
-
-// ***************************************************************************
-void CDriverD3D::setCullMode(TCullMode cullMode)
-{
- H_AUTO_D3D(CDriver3D_cullMode);
-#ifdef NL_D3D_USE_RENDER_STATE_CACHE
- NL_D3D_CACHE_TEST(CacheTest_CullMode, cullMode != _CullMode)
-#endif
- {
- if (_InvertCullMode)
- {
- setRenderState(D3DRS_CULLMODE, _CullMode == CCW ? D3DCULL_CW : D3DCULL_CCW);
- }
- else
- {
- setRenderState(D3DRS_CULLMODE, _CullMode == CCW ? D3DCULL_CCW : D3DCULL_CW);
- }
- _CullMode = cullMode;
- }
-}
-
-// ***************************************************************************
-IDriver::TCullMode CDriverD3D::getCullMode() const
-{
- H_AUTO_D3D(CDriver3D_CDriverD3D);
- return _CullMode;
-}
-
-// ***************************************************************************
-void CDriverD3D::enableStencilTest(bool enable)
-{
- H_AUTO_D3D(CDriver3D_CDriverD3D);
-
- _CurStencilTest = enable;
- setRenderState(D3DRS_STENCILENABLE, enable?TRUE:FALSE);
-}
-
-// ***************************************************************************
-bool CDriverD3D::isStencilTestEnabled() const
-{
- H_AUTO_D3D(CDriver3D_CDriverD3D);
- return _CurStencilTest?TRUE:FALSE;
-}
-
-// ***************************************************************************
-void CDriverD3D::stencilFunc(TStencilFunc stencilFunc, int ref, uint mask)
-{
- H_AUTO_D3D(CDriver3D_CDriverD3D);
-
- switch(stencilFunc)
- {
- case IDriver::never: _CurStencilFunc=D3DCMP_NEVER; break;
- case IDriver::less: _CurStencilFunc=D3DCMP_LESS; break;
- case IDriver::lessequal: _CurStencilFunc=D3DCMP_LESSEQUAL; break;
- case IDriver::equal: _CurStencilFunc=D3DCMP_EQUAL; break;
- case IDriver::notequal: _CurStencilFunc=D3DCMP_NOTEQUAL; break;
- case IDriver::greaterequal: _CurStencilFunc=D3DCMP_GREATEREQUAL; break;
- case IDriver::greater: _CurStencilFunc=D3DCMP_GREATER; break;
- case IDriver::always: _CurStencilFunc=D3DCMP_ALWAYS; break;
- default: nlstop;
- }
-
- _CurStencilRef = (DWORD)ref;
- _CurStencilMask = (DWORD)mask;
- setRenderState(D3DRS_STENCILFUNC, _CurStencilFunc);
- setRenderState(D3DRS_STENCILREF, _CurStencilRef);
- setRenderState(D3DRS_STENCILMASK, _CurStencilMask);
-}
-
-// ***************************************************************************
-void CDriverD3D::stencilOp(TStencilOp fail, TStencilOp zfail, TStencilOp zpass)
-{
- H_AUTO_D3D(CDriver3D_CDriverD3D);
-
- switch(fail)
- {
- case IDriver::keep: _CurStencilOpFail=D3DSTENCILOP_KEEP; break;
- case IDriver::zero: _CurStencilOpFail=D3DSTENCILOP_ZERO; break;
- case IDriver::replace: _CurStencilOpFail=D3DSTENCILOP_REPLACE; break;
- case IDriver::incr: _CurStencilOpFail=D3DSTENCILOP_INCR; break;
- case IDriver::decr: _CurStencilOpFail=D3DSTENCILOP_DECR; break;
- case IDriver::invert: _CurStencilOpFail=D3DSTENCILOP_INVERT; break;
- default: nlstop;
- }
-
- switch(zfail)
- {
- case IDriver::keep: _CurStencilOpZFail=D3DSTENCILOP_KEEP; break;
- case IDriver::zero: _CurStencilOpZFail=D3DSTENCILOP_ZERO; break;
- case IDriver::replace: _CurStencilOpZFail=D3DSTENCILOP_REPLACE; break;
- case IDriver::incr: _CurStencilOpZFail=D3DSTENCILOP_INCR; break;
- case IDriver::decr: _CurStencilOpZFail=D3DSTENCILOP_DECR; break;
- case IDriver::invert: _CurStencilOpZFail=D3DSTENCILOP_INVERT; break;
- default: nlstop;
- }
-
- switch(zpass)
- {
- case IDriver::keep: _CurStencilOpZPass=D3DSTENCILOP_KEEP; break;
- case IDriver::zero: _CurStencilOpZPass=D3DSTENCILOP_ZERO; break;
- case IDriver::replace: _CurStencilOpZPass=D3DSTENCILOP_REPLACE; break;
- case IDriver::incr: _CurStencilOpZPass=D3DSTENCILOP_INCR; break;
- case IDriver::decr: _CurStencilOpZPass=D3DSTENCILOP_DECR; break;
- case IDriver::invert: _CurStencilOpZPass=D3DSTENCILOP_INVERT; break;
- default: nlstop;
- }
-
- setRenderState(D3DRS_STENCILFAIL, _CurStencilOpFail);
- setRenderState(D3DRS_STENCILZFAIL, _CurStencilOpZFail);
- setRenderState(D3DRS_STENCILPASS, _CurStencilOpZPass);
-}
-
-// ***************************************************************************
-void CDriverD3D::stencilMask(uint mask)
-{
- H_AUTO_D3D(CDriver3D_CDriverD3D);
-
- _CurStencilWriteMask = (DWORD)mask;
- setRenderState (D3DRS_STENCILWRITEMASK, _CurStencilWriteMask);
-}
-
-// volatile bool preciseStateProfile = false;
-// ***************************************************************************
-void CDriverD3D::CRenderState::apply(CDriverD3D *driver)
-{
- H_AUTO_D3D(CDriverD3D_CRenderState);
- /*if (!preciseStateProfile)
- {*/
- driver->_DeviceInterface->SetRenderState (StateID, Value);
- /*
- }
- else
- {
- switch(StateID)
- {
- case D3DRS_ZENABLE: { H_AUTO_D3D(D3DRS_ZENABLE); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_FILLMODE: { H_AUTO_D3D(D3DRS_FILLMODE); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_SHADEMODE: { H_AUTO_D3D(D3DRS_SHADEMODE); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_ZWRITEENABLE: { H_AUTO_D3D(D3DRS_ZWRITEENABLE); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_ALPHATESTENABLE: { H_AUTO_D3D(D3DRS_ALPHATESTENABLE); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_LASTPIXEL: { H_AUTO_D3D(D3DRS_LASTPIXEL); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_SRCBLEND: { H_AUTO_D3D(D3DRS_SRCBLEND); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_DESTBLEND: { H_AUTO_D3D(D3DRS_DESTBLEND); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_CULLMODE: { H_AUTO_D3D(D3DRS_CULLMODE); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_ZFUNC: { H_AUTO_D3D(D3DRS_ZFUNC); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_ALPHAREF: { H_AUTO_D3D(D3DRS_ALPHAREF); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_ALPHAFUNC: { H_AUTO_D3D(D3DRS_ALPHAFUNC); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_DITHERENABLE: { H_AUTO_D3D(D3DRS_DITHERENABLE); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_ALPHABLENDENABLE: { H_AUTO_D3D(D3DRS_ALPHABLENDENABLE); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_FOGENABLE: { H_AUTO_D3D(D3DRS_FOGENABLE); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_SPECULARENABLE: { H_AUTO_D3D(D3DRS_SPECULARENABLE); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_FOGCOLOR: { H_AUTO_D3D(D3DRS_FOGCOLOR); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_FOGTABLEMODE: { H_AUTO_D3D(D3DRS_FOGTABLEMODE); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_FOGSTART: { H_AUTO_D3D(D3DRS_FOGSTART); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_FOGEND: { H_AUTO_D3D(D3DRS_FOGEND); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_FOGDENSITY: { H_AUTO_D3D(D3DRS_FOGDENSITY); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_RANGEFOGENABLE: { H_AUTO_D3D(D3DRS_RANGEFOGENABLE); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_STENCILENABLE: { H_AUTO_D3D(D3DRS_STENCILENABLE); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_STENCILFAIL: { H_AUTO_D3D(D3DRS_STENCILFAIL); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_STENCILZFAIL: { H_AUTO_D3D(D3DRS_STENCILZFAIL); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_STENCILPASS: { H_AUTO_D3D(D3DRS_STENCILPASS); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_STENCILFUNC: { H_AUTO_D3D(D3DRS_STENCILFUNC); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_STENCILREF: { H_AUTO_D3D(D3DRS_STENCILREF); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_STENCILMASK: { H_AUTO_D3D(D3DRS_STENCILMASK); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_STENCILWRITEMASK: { H_AUTO_D3D(D3DRS_STENCILWRITEMASK); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_TEXTUREFACTOR: { H_AUTO_D3D(D3DRS_TEXTUREFACTOR); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_WRAP0: { H_AUTO_D3D(D3DRS_WRAP0); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_WRAP1: { H_AUTO_D3D(D3DRS_WRAP1); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_WRAP2: { H_AUTO_D3D(D3DRS_WRAP2); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_WRAP3: { H_AUTO_D3D(D3DRS_WRAP3); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_WRAP4: { H_AUTO_D3D(D3DRS_WRAP4); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_WRAP5: { H_AUTO_D3D(D3DRS_WRAP5); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_WRAP6: { H_AUTO_D3D(D3DRS_WRAP6); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_WRAP7: { H_AUTO_D3D(D3DRS_WRAP7); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_CLIPPING: { H_AUTO_D3D(D3DRS_CLIPPING); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_LIGHTING: { H_AUTO_D3D(D3DRS_LIGHTING); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_AMBIENT: { H_AUTO_D3D(D3DRS_AMBIENT); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_FOGVERTEXMODE: { H_AUTO_D3D(D3DRS_FOGVERTEXMODE); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_COLORVERTEX: { H_AUTO_D3D(D3DRS_COLORVERTEX); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_LOCALVIEWER: { H_AUTO_D3D(D3DRS_LOCALVIEWER); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_NORMALIZENORMALS: { H_AUTO_D3D(D3DRS_NORMALIZENORMALS); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_DIFFUSEMATERIALSOURCE: { H_AUTO_D3D(D3DRS_DIFFUSEMATERIALSOURCE); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_SPECULARMATERIALSOURCE: { H_AUTO_D3D(D3DRS_SPECULARMATERIALSOURCE); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_AMBIENTMATERIALSOURCE: { H_AUTO_D3D(D3DRS_AMBIENTMATERIALSOURCE); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_EMISSIVEMATERIALSOURCE: { H_AUTO_D3D(D3DRS_EMISSIVEMATERIALSOURCE); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_VERTEXBLEND: { H_AUTO_D3D(D3DRS_VERTEXBLEND); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_CLIPPLANEENABLE: { H_AUTO_D3D(D3DRS_CLIPPLANEENABLE); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_POINTSIZE: { H_AUTO_D3D(D3DRS_POINTSIZE); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_POINTSIZE_MIN: { H_AUTO_D3D(D3DRS_POINTSIZE_MIN); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_POINTSPRITEENABLE: { H_AUTO_D3D(D3DRS_POINTSPRITEENABLE); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_POINTSCALEENABLE: { H_AUTO_D3D(D3DRS_POINTSCALEENABLE); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_POINTSCALE_A: { H_AUTO_D3D(D3DRS_POINTSCALE_A); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_POINTSCALE_B: { H_AUTO_D3D(D3DRS_POINTSCALE_B); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_POINTSCALE_C: { H_AUTO_D3D(D3DRS_POINTSCALE_C); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_MULTISAMPLEANTIALIAS: { H_AUTO_D3D(D3DRS_MULTISAMPLEANTIALIAS); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_MULTISAMPLEMASK: { H_AUTO_D3D(D3DRS_MULTISAMPLEMASK); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_PATCHEDGESTYLE: { H_AUTO_D3D(D3DRS_PATCHEDGESTYLE); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_DEBUGMONITORTOKEN: { H_AUTO_D3D(D3DRS_DEBUGMONITORTOKEN); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_POINTSIZE_MAX: { H_AUTO_D3D(D3DRS_POINTSIZE_MAX); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_INDEXEDVERTEXBLENDENABLE: { H_AUTO_D3D(D3DRS_INDEXEDVERTEXBLENDENABLE); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_COLORWRITEENABLE: { H_AUTO_D3D(D3DRS_COLORWRITEENABLE); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_TWEENFACTOR: { H_AUTO_D3D(D3DRS_TWEENFACTOR); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_BLENDOP: { H_AUTO_D3D(D3DRS_BLENDOP); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_POSITIONDEGREE: { H_AUTO_D3D(D3DRS_POSITIONDEGREE); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_NORMALDEGREE: { H_AUTO_D3D(D3DRS_NORMALDEGREE); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_SCISSORTESTENABLE: { H_AUTO_D3D(D3DRS_SCISSORTESTENABLE); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_SLOPESCALEDEPTHBIAS: { H_AUTO_D3D(D3DRS_SLOPESCALEDEPTHBIAS); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_ANTIALIASEDLINEENABLE: { H_AUTO_D3D(D3DRS_ANTIALIASEDLINEENABLE); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_MINTESSELLATIONLEVEL: { H_AUTO_D3D(D3DRS_MINTESSELLATIONLEVEL); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_MAXTESSELLATIONLEVEL: { H_AUTO_D3D(D3DRS_MAXTESSELLATIONLEVEL); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_ADAPTIVETESS_X: { H_AUTO_D3D(D3DRS_ADAPTIVETESS_X); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_ADAPTIVETESS_Y: { H_AUTO_D3D(D3DRS_ADAPTIVETESS_Y); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_ADAPTIVETESS_Z: { H_AUTO_D3D(D3DRS_ADAPTIVETESS_Z); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_ADAPTIVETESS_W: { H_AUTO_D3D(D3DRS_ADAPTIVETESS_W); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_ENABLEADAPTIVETESSELLATION: { H_AUTO_D3D(D3DRS_ENABLEADAPTIVETESSELLATION); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_TWOSIDEDSTENCILMODE: { H_AUTO_D3D(D3DRS_TWOSIDEDSTENCILMODE); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_CCW_STENCILFAIL: { H_AUTO_D3D(D3DRS_CCW_STENCILFAIL); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_CCW_STENCILZFAIL: { H_AUTO_D3D(D3DRS_CCW_STENCILZFAIL); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_CCW_STENCILPASS: { H_AUTO_D3D(D3DRS_CCW_STENCILPASS); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_CCW_STENCILFUNC: { H_AUTO_D3D(D3DRS_CCW_STENCILFUNC); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_COLORWRITEENABLE1: { H_AUTO_D3D(D3DRS_COLORWRITEENABLE1); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_COLORWRITEENABLE2: { H_AUTO_D3D(D3DRS_COLORWRITEENABLE2); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_COLORWRITEENABLE3: { H_AUTO_D3D(D3DRS_COLORWRITEENABLE3); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_BLENDFACTOR: { H_AUTO_D3D(D3DRS_BLENDFACTOR); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_SRGBWRITEENABLE: { H_AUTO_D3D(D3DRS_SRGBWRITEENABLE); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_DEPTHBIAS: { H_AUTO_D3D(D3DRS_DEPTHBIAS); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_WRAP8: { H_AUTO_D3D(D3DRS_WRAP8); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_WRAP9: { H_AUTO_D3D(D3DRS_WRAP9); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_WRAP10: { H_AUTO_D3D(D3DRS_WRAP10); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_WRAP11: { H_AUTO_D3D(D3DRS_WRAP11); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_WRAP12: { H_AUTO_D3D(D3DRS_WRAP12); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_WRAP13: { H_AUTO_D3D(D3DRS_WRAP13); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_WRAP14: { H_AUTO_D3D(D3DRS_WRAP14); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_WRAP15: { H_AUTO_D3D(D3DRS_WRAP15); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_SEPARATEALPHABLENDENABLE: { H_AUTO_D3D(D3DRS_SEPARATEALPHABLENDENABLE); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_SRCBLENDALPHA: { H_AUTO_D3D(D3DRS_SRCBLENDALPHA); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_DESTBLENDALPHA: { H_AUTO_D3D(D3DRS_DESTBLENDALPHA); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- case D3DRS_BLENDOPALPHA: { H_AUTO_D3D(D3DRS_BLENDOPALPHA); driver->_DeviceInterface->SetRenderState(StateID, Value); } break;
- }
- }
- */
-}
-
-
-// ***************************************************************************
-void CDriverD3D::CTextureState::apply(CDriverD3D *driver)
-{
- H_AUTO_D3D(CDriverD3D_CTextureState);
- if (Value != DeviceValue)
- {
- driver->_DeviceInterface->SetTextureStageState (StageID, StateID, Value);
- DeviceValue = Value;
- }
-}
-
-// ***************************************************************************
-void CDriverD3D::CTextureIndexState::apply(CDriverD3D *driver)
-{
- H_AUTO_D3D(CDriverD3D_CTextureIndexState);
- if (TexGen)
- driver->setTextureState (StageID, D3DTSS_TEXCOORDINDEX, TexGenMode);
- else
- driver->setTextureState (StageID, D3DTSS_TEXCOORDINDEX, UVChannel);
-}
-
-// ***************************************************************************
-void CDriverD3D::CTexturePtrState::apply(CDriverD3D *driver)
-{
- H_AUTO_D3D(CDriverD3D_CTexturePtrState);
- driver->_DeviceInterface->SetTexture (StageID, Texture);
-}
-
-// ***************************************************************************
-void CDriverD3D::CVertexProgramPtrState::apply(CDriverD3D *driver)
-{
- H_AUTO_D3D(CDriverD3D_CVertexProgramPtrState);
- driver->_DeviceInterface->SetVertexShader(VertexProgram);
-}
-
-// ***************************************************************************
-void CDriverD3D::CPixelShaderPtrState::apply(CDriverD3D *driver)
-{
- H_AUTO_D3D(CDriverD3D_CPixelShaderPtrState);
- if (!driver->_PixelProgram) return;
- driver->_DeviceInterface->SetPixelShader(PixelShader);
-}
-
-// ***************************************************************************
-void CDriverD3D::CVertexProgramConstantState::apply(CDriverD3D *driver)
-{
- H_AUTO_D3D(CDriverD3D_CVertexProgramConstantState);
- switch (ValueType)
- {
- case CVertexProgramConstantState::Float:
- driver->_DeviceInterface->SetVertexShaderConstantF (StateID, (float*)Values, 1);
- break;
- case CVertexProgramConstantState::Int:
- driver->_DeviceInterface->SetVertexShaderConstantI (StateID, (int*)Values, 1);
- break;
- }
-}
-
-// ***************************************************************************
-void CDriverD3D::CPixelShaderConstantState::apply(CDriverD3D *driver)
-{
- H_AUTO_D3D(CDriverD3D_CPixelShaderConstantState);
- switch (ValueType)
- {
- case CPixelShaderConstantState::Float:
- driver->_DeviceInterface->SetPixelShaderConstantF (StateID, (float*)Values, 1);
- break;
- case CPixelShaderConstantState::Int:
- driver->_DeviceInterface->SetPixelShaderConstantI (StateID, (int*)Values, 1);
- break;
- }
-}
-
-// ***************************************************************************
-void CDriverD3D::CSamplerState::apply(CDriverD3D *driver)
-{
- H_AUTO_D3D(CDriverD3D_CSamplerState);
- driver->_DeviceInterface->SetSamplerState (SamplerID, StateID, Value);
-}
-
-// ***************************************************************************
-void CDriverD3D::CMatrixState::apply(CDriverD3D *driver)
-{
- H_AUTO_D3D(CDriverD3D_CMatrixState);
- driver->_DeviceInterface->SetTransform (TransformType, &Matrix);
-}
-
-// ***************************************************************************
-void CDriverD3D::CVBState::apply(CDriverD3D *driver)
-{
- H_AUTO_D3D(CDriverD3D_CVBState);
- if (VertexBuffer)
- {
- driver->_DeviceInterface->SetStreamSource (0, VertexBuffer, Offset, Stride);
- // Fix for radeon 7xxx & bad vertex layout
- if (driver->inlGetNumTextStages() == 3) // If there are 3 stages this is a Radeon 7xxx
- {
- if (ColorOffset != 0 && driver->_VertexDeclCache.EnableVertexColor)
- {
- driver->_DeviceInterface->SetStreamSource (1, VertexBuffer, Offset + ColorOffset, Stride);
- }
- else
- {
- driver->_DeviceInterface->SetStreamSource (1, NULL, 0, 0);
- }
- }
- }
-}
-// ***************************************************************************
-void CDriverD3D::CIBState::apply(CDriverD3D *driver)
-{
- H_AUTO_D3D(CDriverD3D_CIBState);
- if (IndexBuffer)
- {
- driver->_DeviceInterface->SetIndices (IndexBuffer);
- }
-}
-
-// ***************************************************************************
-void CDriverD3D::CVertexDeclState::apply(CDriverD3D *driver)
-{
- H_AUTO_D3D(CDriverD3D_CVertexDeclState);
- if (Decl)
- {
- if (!EnableVertexColor && DeclAliasDiffuseToSpecular && driver->inlGetNumTextStages() == 3)
- {
- // Fix for radeon 7xxx -> if vertex color is not used it should not be present in the vertex declaration (example : lighted material + vertex color but, no vertexColorLighted)
- nlassert(DeclNoDiffuse);
- driver->_DeviceInterface->SetVertexDeclaration (DeclNoDiffuse);
- }
- else
- if (AliasDiffuseToSpecular)
- {
- nlassert(DeclAliasDiffuseToSpecular);
- driver->_DeviceInterface->SetVertexDeclaration (DeclAliasDiffuseToSpecular);
- }
- else
- {
- nlassert(Decl);
- driver->_DeviceInterface->SetVertexDeclaration (Decl);
- }
- }
-}
-
-// ***************************************************************************
-void CDriverD3D::CLightState::apply(CDriverD3D *driver)
-{
- H_AUTO_D3D(CDriverD3D_CLightState);
- // Enable state modified ?
- {
- H_AUTO_D3D(CDriverD3D_CLightStateEnabled);
- if (EnabledTouched)
- driver->_DeviceInterface->LightEnable (LightIndex, Enabled);
- }
- {
- H_AUTO_D3D(CDriverD3D_CLightStateSetup);
- // Light enabled ?
- if (Enabled)
- {
- if (SettingsTouched)
- {
- // New position
- Light.Position.x -= driver->_PZBCameraPos.x;
- Light.Position.y -= driver->_PZBCameraPos.y;
- Light.Position.z -= driver->_PZBCameraPos.z;
- driver->_DeviceInterface->SetLight (LightIndex, &Light);
- SettingsTouched = false;
- }
- }
- // Clean
- EnabledTouched = false;
- }
-}
-
-// ***************************************************************************
-void CDriverD3D::CRenderTargetState::apply(CDriverD3D *driver)
-{
- H_AUTO_D3D(CDriverD3D_CRenderTargetState);
- driver->_DeviceInterface->SetRenderTarget (0, Target);
- driver->setupViewport(driver->_Viewport);
- driver->setupScissor(driver->_Scissor);
-}
-
-// ***************************************************************************
-void CDriverD3D::CMaterialState::apply(CDriverD3D *driver)
-{
- H_AUTO_D3D(CDriverD3D_CMaterialState);
- driver->_DeviceInterface->SetMaterial(&Current);
-}
-
-// ***************************************************************************
-void CDriverD3D::beginDialogMode()
-{
- if (_FullScreen && _HWnd)
- ShowWindow(_HWnd, SW_MINIMIZE);
-}
-
-// ***************************************************************************
-void CDriverD3D::endDialogMode()
-{
- if (_FullScreen && _HWnd)
- ShowWindow(_HWnd, SW_MAXIMIZE);
-}
-
-bool CDriverD3D::clipRect(NLMISC::CRect &rect)
-{
- // Clip the wanted rectangle with window.
- uint32 width, height;
- getWindowSize(width, height);
-
- sint32 xr=rect.right() ,yr=rect.bottom();
-
- clamp((sint32&)rect.X, (sint32)0, (sint32)width);
- clamp((sint32&)rect.Y, (sint32)0, (sint32)height);
- clamp((sint32&)xr, (sint32)rect.X, (sint32)width);
- clamp((sint32&)yr, (sint32)rect.Y, (sint32)height);
- rect.Width= xr-rect.X;
- rect.Height= yr-rect.Y;
-
- return rect.Width>0 && rect.Height>0;
-}
-
-void CDriverD3D::getZBuffer(std::vector &zbuffer)
-{
- H_AUTO_D3D(CDriverD3D_getZBuffer);
-
- CRect rect(0, 0);
- getWindowSize(rect.Width, rect.Height);
- getZBufferPart(zbuffer, rect);
-}
-
-void CDriverD3D::getZBufferPart (std::vector &zbuffer, NLMISC::CRect &rect)
-{
- zbuffer.clear();
-
- IDirect3DSurface9 *surface;
- if (SUCCEEDED(_DeviceInterface->GetDepthStencilSurface(&surface)))
- {
- if (clipRect(rect))
- {
- RECT winRect;
- winRect.left = rect.left();
- winRect.right = rect.right();
- winRect.top = rect.top();
- winRect.bottom = rect.bottom();
-
- // Lock the surface
- D3DLOCKED_RECT lock;
- if (SUCCEEDED(surface->LockRect (&lock, &winRect, D3DLOCK_READONLY)))
- {
- zbuffer.resize(rect.Width*rect.Height);
-
- // Surface desc
- D3DSURFACE_DESC desc;
- if (SUCCEEDED(surface->GetDesc(&desc)))
- {
- const uint8* pBits = (uint8*)lock.pBits;
-
- for(uint y=0; y::max();
- }
- }
- else if (desc.Format == D3DFMT_D16_LOCKABLE)
- {
- uint16* pRow = (uint16*)(pBits + lock.Pitch * y);
- while(offset != end)
- {
- uint16 value = *pRow++;
- zbuffer[offset++] = (float)value / (float)std::numeric_limits::max();
- }
- }
- }
- }
-
- surface->UnlockRect ();
- }
- }
-
- surface->Release();
- }
-}
-
-
-void CDriverD3D::findNearestFullscreenVideoMode()
-{
- if(_CurrentMode.Windowed)
- return;
-
- std::vector modes;
- if(getModes(modes))
- {
- sint32 nbPixels = _CurrentMode.Width * _CurrentMode.Height;
- sint32 minError = nbPixels;
- uint bestMode = (uint)modes.size();
- for(uint i=0; i < modes.size(); i++)
- {
- if(!modes[i].Windowed)
- {
- if(modes[i].Width==_CurrentMode.Width && modes[i].Height==_CurrentMode.Height)
- {
- // ok we found the perfect mode
- return;
- }
- sint32 currentPixels = modes[i].Width * modes[i].Height;
- sint32 currentError = abs(nbPixels - currentPixels);
- if(currentError < minError)
- {
- minError = currentError;
- bestMode = i;
- }
- }
- }
- if(bestMode != modes.size())
- {
- nlwarning("The video mode %dx%d doesn't exist, use the nearest mode %dx%d", _CurrentMode.Width, _CurrentMode.Height, modes[bestMode].Width, modes[bestMode].Height);
- _CurrentMode.Width = modes[bestMode].Width;
- _CurrentMode.Height = modes[bestMode].Height;
- }
- }
-}
-bool CDriverD3D::copyTextToClipboard(const ucstring &text)
-{
- return _EventEmitter.copyTextToClipboard(text);
-}
-
-bool CDriverD3D::pasteTextFromClipboard(ucstring &text)
-{
- return _EventEmitter.pasteTextFromClipboard(text);
-}
-
-bool CDriverD3D::convertBitmapToIcon(const NLMISC::CBitmap &bitmap, HICON &icon, uint iconWidth, uint iconHeight, uint iconDepth, const NLMISC::CRGBA &col, sint hotSpotX, sint hotSpotY, bool cursor)
-{
- CBitmap src = bitmap;
- // resample bitmap if necessary
- if (src.getWidth() != iconWidth || src.getHeight() != iconHeight)
- {
- src.resample(iconWidth, iconHeight);
- }
- CBitmap colorBm;
- colorBm.resize(iconWidth, iconHeight, CBitmap::RGBA);
- const CRGBA *srcColorPtr = (CRGBA *) &(src.getPixels()[0]);
- const CRGBA *srcColorPtrLast = srcColorPtr + (iconWidth * iconHeight);
- CRGBA *destColorPtr = (CRGBA *) &(colorBm.getPixels()[0]);
- static volatile uint8 alphaThreshold = 127;
- do
- {
- destColorPtr->modulateFromColor(*srcColorPtr, col);
- std::swap(destColorPtr->R, destColorPtr->B);
- ++ srcColorPtr;
- ++ destColorPtr;
- }
- while (srcColorPtr != srcColorPtrLast);
- //
- HBITMAP colorHbm = NULL;
- HBITMAP maskHbm = NULL;
- //
- if (iconDepth == 16)
- {
- std::vector colorBm16(iconWidth * iconHeight);
- const CRGBA *src32 = (const CRGBA *) &colorBm.getPixels(0)[0];
-
- for (uint k = 0; k < colorBm16.size(); ++k)
- {
- colorBm16[k] = ((uint16)(src32[k].R&0xf8)>>3) | ((uint16)(src32[k].G&0xfc)<<3) | ((uint16)(src32[k].B & 0xf8)<<8);
- }
-
- colorHbm = CreateBitmap(iconWidth, iconHeight, 1, 16, &colorBm16[0]);
- std::vector bitMask((iconWidth * iconHeight + 7) / 8, 0);
-
- for (uint k = 0;k < colorBm16.size(); ++k)
- {
- if (src32[k].A <= 120)
- {
- bitMask[k / 8] |= (0x80 >> (k & 7));
- }
- }
-
- maskHbm = CreateBitmap(iconWidth, iconHeight, 1, 1, &bitMask[0]);
- }
- else
- {
- colorHbm = CreateBitmap(iconWidth, iconHeight, 1, 32, &colorBm.getPixels(0)[0]);
- maskHbm = CreateBitmap(iconWidth, iconHeight, 1, 32, &colorBm.getPixels(0)[0]);
- }
-
- ICONINFO iconInfo;
- iconInfo.fIcon = cursor ? FALSE:TRUE;
- iconInfo.xHotspot = (DWORD) hotSpotX;
- iconInfo.yHotspot = (DWORD) hotSpotY;
- iconInfo.hbmMask = maskHbm;
- iconInfo.hbmColor = colorHbm;
-
- if (colorHbm && maskHbm)
- {
- icon = CreateIconIndirect(&iconInfo);
- }
-
- //
- if (colorHbm) DeleteObject(colorHbm);
- if (maskHbm) DeleteObject(maskHbm);
-
- return true;
-}
-
-} // NL3D
diff --git a/code/nel/src/3d/driver/direct3d/driver_direct3d.def b/code/nel/src/3d/driver/direct3d/driver_direct3d.def
deleted file mode 100644
index e52ed712d..000000000
--- a/code/nel/src/3d/driver/direct3d/driver_direct3d.def
+++ /dev/null
@@ -1,3 +0,0 @@
-EXPORTS
- NL3D_createIDriverInstance
- NL3D_interfaceVersion
\ No newline at end of file
diff --git a/code/nel/src/3d/driver/direct3d/driver_direct3d.h b/code/nel/src/3d/driver/direct3d/driver_direct3d.h
deleted file mode 100644
index a4d9dbaeb..000000000
--- a/code/nel/src/3d/driver/direct3d/driver_direct3d.h
+++ /dev/null
@@ -1,2883 +0,0 @@
-// NeL - MMORPG Framework
-// Copyright (C) 2010 Winch Gate Property Limited
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Affero General Public License as
-// published by the Free Software Foundation, either version 3 of the
-// License, or (at your option) any later version.
-//
-// This program 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 Affero General Public License for more details.
-//
-// You should have received a copy of the GNU Affero General Public License
-// along with this program. If not, see .
-
-#ifndef NL_DRIVER_DIRECT3D_H
-#define NL_DRIVER_DIRECT3D_H
-
-
-#include "nel/misc/types_nl.h"
-
-// NeL includes
-#include "nel/misc/matrix.h"
-#include "nel/misc/smart_ptr.h"
-#include "nel/misc/rgba.h"
-#include "nel/misc/event_emitter.h"
-#include "nel/misc/bit_set.h"
-#include "nel/misc/heap_memory.h"
-#include "nel/misc/event_emitter_multi.h"
-#include "nel/misc/time_nl.h"
-#include "nel/misc/hierarchical_timer.h"
-#include "nel/misc/win_event_emitter.h"
-#include "nel/3d/viewport.h"
-#include "nel/3d/scissor.h"
-#include "nel/3d/driver.h"
-#include "nel/3d/material.h"
-#include "nel/3d/vertex_buffer.h"
-#include "nel/3d/index_buffer.h"
-#include "nel/3d/ptr_set.h"
-#include "nel/3d/texture_cube.h"
-#include "nel/3d/occlusion_query.h"
-#include "nel/3d/vertex_program_parse.h"
-#include "nel/3d/light.h"
-//
-#include
-
-typedef HCURSOR nlCursor;
-#define EmptyCursor NULL
-
-
-// *** DEBUG MACRO
-
-// Define this to activate the debug mode (default is undefined)
-//#define NL_DEBUG_D3D
-
-// Define this to enable the render state caching (default is defined)
-#define NL_D3D_USE_RENDER_STATE_CACHE
-
-// allows to enable / disable cache test at runtime (for debug)
-//#define NL_D3D_RUNTIME_DEBUG_CACHE_TEST
-#ifdef NL_D3D_RUNTIME_DEBUG_CACHE_TEST
- #define NL_D3D_CACHE_TEST(label, cond) if (!_CacheTest[label] || (cond))
-#else
- #define NL_D3D_CACHE_TEST(label, cond) if (cond)
-#endif
-
-
-// Define this to disable hardware vertex program (default is undefined)
-//#define NL_DISABLE_HARDWARE_VERTEX_PROGAM
-
-// Define this to disable hardware pixel shaders program (default is undefined)
-//#define NL_DISABLE_HARDWARE_PIXEL_SHADER
-
-// Define this to disable hardware vertex array AGP (default is undefined)
-//#define NL_DISABLE_HARDWARE_VERTEX_ARRAY_AGP
-
-// Define this to force the texture stage count (default is undefined)
-//#define NL_FORCE_TEXTURE_STAGE_COUNT 2
-
-// Define this to force the use of pixel shader in the normal shaders (default is undefined)
-//#define NL_FORCE_PIXEL_SHADER_USE_FOR_NORMAL_SHADERS
-
-// Define this to enable profiling by the NV Perf HUD tool (default is undefined)
-//#define NL_D3D_USE_NV_PERF_HUD
-
-// Define this to enable profiling of driver functions (default is undefined).
-//#define NL_PROFILE_DRIVER_D3D
-
-
-
-#ifdef NL_PROFILE_DRIVER_D3D
- #define H_AUTO_D3D(label) H_AUTO(label)
-#else
- #define H_AUTO_D3D(label)
-#endif
-
-class CFpuRestorer
-{
-public:
- CFpuRestorer() { _FPControlWord = _controlfp(0, 0); }
- ~CFpuRestorer()
- {
- _controlfp(_FPControlWord, ~0);
- }
-private:
- unsigned int _FPControlWord;
-};
-
-class CFpuChecker
-{
-public:
- CFpuChecker(const char *label) { _FPControlWord = _controlfp(0, 0); _Label = label; }
- ~CFpuChecker()
- {
- unsigned int newFP = _controlfp(0, 0);
- if ((newFP & (_MCW_DN | _MCW_IC | _MCW_RC | _MCW_PC)) != (_FPControlWord & (_MCW_DN | _MCW_IC | _MCW_RC | _MCW_PC)))
- {
- nlwarning(_Label);
- nlassert(0);
- }
- }
-private:
- const char *_Label;
- unsigned int _FPControlWord;
-};
-
-
-
-
-inline bool operator==(const D3DCOLORVALUE &lhs, const D3DCOLORVALUE &rhs)
-{
- return lhs.r == rhs.r && lhs.g == rhs.g && lhs.b == rhs.b && lhs.a == rhs.a;
-}
-inline bool operator!=(const D3DCOLORVALUE &lhs, const D3DCOLORVALUE &rhs)
-{
- return !(lhs == rhs);
-}
-
-
-
-
-
-// ***************************************************************************
-
-namespace NL3D
-{
-
-
-
-const uint MAX_NUM_QUADS = 32767; // max number of quads in a single draw call
-
-using NLMISC::CMatrix;
-using NLMISC::CVector;
-
-class CDriverD3D;
-class CTextureDrvInfosD3D;
-class COcclusionQueryD3D;
-class CVolatileVertexBuffer;
-class CVolatileIndexBuffer;
-
-typedef std::list TOcclusionQueryList;
-
-// ***************************************************************************
-class COcclusionQueryD3D : public IOcclusionQuery
-{
-public:
- IDirect3DQuery9 *Query;
- NLMISC::CRefPtr Driver; // owner driver
- TOcclusionQueryList::iterator Iterator; // iterator in owner driver list of queries
- TOcclusionType OcclusionType; // current type of occlusion
- uint VisibleCount; // number of samples that passed the test
- bool QueryIssued;
- bool WasLost; // tells that query was lost, so calls to end() will have not effects (there's no matching begin)
- // From IOcclusionQuery
- virtual void begin();
- virtual void end();
- virtual TOcclusionType getOcclusionType();
- virtual uint getVisibleCount();
-};
-
-
-using NLMISC::CRefCount;
-
-
-class IDriver;
-class CDriverD3D;
-
-// List typedef.
-class IShaderDrvInfos;
-typedef std::list TShaderDrvInfoPtrList;
-typedef TShaderDrvInfoPtrList::iterator ItShaderDrvInfoPtrList;
-
-/**
- * Interface for shader driver infos.
- */
-class IShaderDrvInfos : public CRefCount
-{
-private:
- CDriverD3D *_Driver;
- ItShaderDrvInfoPtrList _DriverIterator;
-
-public:
- IShaderDrvInfos(CDriverD3D *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 CD3DShaderFX
-{
-public:
- CD3DShaderFX();
- ~CD3DShaderFX();
-
- // 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 _DrvInfo;
-private:
- // The shader
- std::string _Text;
- // The shader name
- std::string _Name;
-};
-
-
-
-// ***************************************************************************
-class CTextureDrvInfosD3D : public ITextureDrvInfos
-{
-public:
- /*
- ANY DATA ADDED HERE MUST BE SWAPPED IN swapTextureHandle() !!
- */
-
- // The texture
- LPDIRECT3DBASETEXTURE9 Texture;
- IDirect3DTexture9 *Texture2d;
- IDirect3DCubeTexture9 *TextureCube;
-
- // The texture format and size
- D3DFORMAT DestFormat;
- uint Width;
- uint Height;
-
- // This is the owner driver.
- CDriverD3D *_Driver;
-
- // Is the internal format of the texture is a compressed one?
- bool SrcCompressed;
- bool IsCube;
-
- // Is a render target ?
- bool RenderTarget;
-
- // Mipmap levels
- uint8 Levels;
- uint8 FirstMipMap;
-
- // This is the computed size of what memory this texture take.
- uint32 TextureMemory;
-
- // The current wrap modes assigned to the texture.
- D3DTEXTUREADDRESS WrapS;
- D3DTEXTUREADDRESS WrapT;
- D3DTEXTUREFILTERTYPE MagFilter;
- D3DTEXTUREFILTERTYPE MinFilter;
- D3DTEXTUREFILTERTYPE MipFilter;
-
- CTextureDrvInfosD3D(IDriver *drv, ItTexDrvInfoPtrMap it, CDriverD3D *drvGl, bool renderTarget);
- ~CTextureDrvInfosD3D();
- virtual uint getTextureMemoryUsed() const {return TextureMemory;}
-};
-
-
-
-// ***************************************************************************
-class CVertexProgamDrvInfosD3D : public IProgramDrvInfos
-{
-public:
-
- // The shader
- IDirect3DVertexShader9 *Shader;
-
- CVertexProgamDrvInfosD3D(IDriver *drv, ItGPUPrgDrvInfoPtrList it);
- ~CVertexProgamDrvInfosD3D();
-
- virtual uint getUniformIndex(const char *name) const
- {
- std::map::const_iterator it = ParamIndices.find(name);
- if (it != ParamIndices.end()) return it->second;
- return std::numeric_limits::max();
- };
-
- std::map ParamIndices;
-};
-
-
-// ***************************************************************************
-class CPixelProgramDrvInfosD3D : public IProgramDrvInfos
-{
-public:
-
- // The shader
- IDirect3DPixelShader9 *Shader;
-
- CPixelProgramDrvInfosD3D(IDriver *drv, ItGPUPrgDrvInfoPtrList it);
- ~CPixelProgramDrvInfosD3D();
-
- virtual uint getUniformIndex(const char *name) const
- {
- std::map::const_iterator it = ParamIndices.find(name);
- if (it != ParamIndices.end()) return it->second;
- return std::numeric_limits::max();
- };
-
- std::map ParamIndices;
-};
-
-
-// ***************************************************************************
-
-class CVertexDeclaration
-{
-public:
- // The human readable values
- D3DVERTEXELEMENT9 VertexElements[CVertexBuffer::NumValue+1];
-
- // The driver pointer
- IDirect3DVertexDeclaration9 *VertexDecl;
-};
-
-
-// ***************************************************************************
-class CVBDrvInfosD3D : public IVBDrvInfos
-{
-public:
- IDirect3DVertexDeclaration9 *VertexDecl;
- IDirect3DVertexDeclaration9 *VertexDeclAliasDiffuseToSpecular;
- IDirect3DVertexDeclaration9 *VertexDeclNoDiffuse;
- uint ColorOffset; // Fix for Radeon 7xxx series -> see remarks in CDriverD3D::createVertexDeclaration
-
-
- IDirect3DVertexBuffer9 *VertexBuffer;
- uint Offset; // Vertex buffer offset
- bool UseVertexColor:1;
- bool Hardware:1;
- bool Volatile:1; // Volatile vertex buffer
- bool VolatileRAM:1;
- uint8 Stride:8;
- uint VolatileLockTime; // Volatile vertex buffer
- DWORD Usage;
- CVolatileVertexBuffer *VolatileVertexBuffer;
- CDriverD3D *Driver;
- #ifdef NL_DEBUG
- bool Locked;
- #endif
-
- CVBDrvInfosD3D(CDriverD3D *drv, ItVBDrvInfoPtrList it, CVertexBuffer *vb);
- virtual ~CVBDrvInfosD3D();
- virtual uint8 *lock (uint first, uint last, bool readOnly);
- virtual void unlock (uint first, uint last);
-};
-
-
-
-// ***************************************************************************
-
-class CIBDrvInfosD3D : public IIBDrvInfos
-{
-public:
- IDirect3DIndexBuffer9 *IndexBuffer;
- uint Offset; // Index buffer offset
- bool Volatile:1; // Volatile index buffer
- bool VolatileRAM:1;
- uint VolatileLockTime; // Volatile index buffer
- CVolatileIndexBuffer *VolatileIndexBuffer;
- CDriverD3D *Driver;
- std::vector RamVersion; // If device doesn't support 32 bit indexes, works in ram (unless it a 16 bit index buffer)
- CIBDrvInfosD3D(CDriverD3D *drv, ItIBDrvInfoPtrList it, CIndexBuffer *ib);
- virtual ~CIBDrvInfosD3D();
- virtual void *lock (uint first, uint last, bool readOnly);
- virtual void unlock (uint first, uint last);
-};
-
-// ***************************************************************************
-
-class CShaderDrvInfosD3D : public IShaderDrvInfos
-{
-public:
- enum
- {
- MaxShaderTexture=8,
- };
-
-
- ID3DXEffect *Effect;
- bool Validated;
-
- // Texture handles
- D3DXHANDLE TextureHandle[MaxShaderTexture];
-
- // Color handles
- D3DXHANDLE ColorHandle[MaxShaderTexture];
-
- // Factor handles
- D3DXHANDLE FactorHandle[MaxShaderTexture];
-
- // Scalar handles
- D3DXHANDLE ScalarFloatHandle[MaxShaderTexture];
-
- CShaderDrvInfosD3D(CDriverD3D *drv, ItShaderDrvInfoPtrList it);
- virtual ~CShaderDrvInfosD3D();
-};
-
-
-// ***************************************************************************
-
-// Normal shader description
-class CNormalShaderDesc
-{
-public:
- CNormalShaderDesc ()
- {
- H_AUTO_D3D(CNormalShaderDesc_CNormalShaderDesc);
- memset (this, 0, sizeof(CNormalShaderDesc));
- }
- ~CNormalShaderDesc ()
- {
- if (PixelShader)
- PixelShader->Release();
- }
- bool StageUsed[IDRV_MAT_MAXTEXTURES];
- uint32 TexEnvMode[IDRV_MAT_MAXTEXTURES];
-
- bool operator==(const CNormalShaderDesc &other) const
- {
- uint i;
- for (i=0; i Allocator;
-};
-
-// record of a single .fx pass
-class CFXPassRecord
-{
-public:
- void apply(class CDriverD3D &drv);
- ~CFXPassRecord();
- std::vector States;
-};
-
-
-template
-class CFXInputValue
-{
-public:
- T Value;
- bool Set;
- CFXInputValue() : Set(false) {}
- void reset();
- bool operator==(const CFXInputValue &other)
- {
- if (!Set) return !(other.Set);
- return (Value == other.Value) != 0;
- }
-};
-
-class CFXInputParams
-{
-public:
- enum { MaxNumParams = CShaderDrvInfosD3D::MaxShaderTexture };
- CFXInputValue Textures[MaxNumParams];
- CFXInputValue Colors[MaxNumParams];
- CFXInputValue Vectors[MaxNumParams];
- CFXInputValue Floats[MaxNumParams];
- bool Touched;
-public:
- CFXInputParams() { Touched = true; }
- void setTexture(uint index, LPDIRECT3DBASETEXTURE9 value)
- {
- nlassert(index < MaxNumParams);
- if (!Textures[index].Set || value != Textures[index].Value)
- {
- Textures[index].Value = value;
- Textures[index].Set = true;
- Touched = true;
- }
- }
- void setColor(uint index, DWORD value)
- {
- nlassert(index < MaxNumParams);
- if (!Colors[index].Set || value != Colors[index].Value)
- {
- Colors[index].Value = value;
- Colors[index].Set = true;
- Touched = true;
- }
- }
- void setVector(uint index, const D3DXVECTOR4 &value)
- {
- nlassert(index < MaxNumParams);
- if (!Vectors[index].Set || value != Vectors[index].Value)
- {
- Vectors[index].Value = value;
- Vectors[index].Set = true;
- Touched = true;
- }
- }
- void setFloat(uint index, FLOAT value)
- {
- nlassert(index < MaxNumParams);
- if (!Floats[index].Set || value != Floats[index].Value)
- {
- Floats[index].Value = value;
- Floats[index].Set = true;
- Touched = true;
- }
- }
- //
- /*
- bool operator==(const CFXInputParams &other)
- {
- return std::equal(Textures, Textures + CShaderDrvInfosD3D::MaxShaderTexture, other.Textures) &&
- std::equal(Vectors, Vectors + CShaderDrvInfosD3D::MaxShaderTexture, other.Vectors) &&
- std::equal(Colors, Colors + CShaderDrvInfosD3D::MaxShaderTexture, other.Colors) &&
- std::equal(Floats, Floats + CShaderDrvInfosD3D::MaxShaderTexture, other.Floats);
- }
- */
- void reset()
- {
- for(uint k = 0; k < MaxNumParams; ++k)
- {
- Textures[k].Set = false;
- Colors[k].Set = false;
- Vectors[k].Set = false;
- Floats[k].Set = false;
- }
- Touched = true;
- }
-};
-
-// .fx cache based on input parameters
-class CFXCache
-{
-public:
- // Input parameters
- CFXInputParams Params;
- // cache for .fx states
- std::vector Passes;
- uint Steadyness;
- uint NumPasses;
-public:
- CFXCache() : Steadyness(0) {}
- void begin(CShaderDrvInfosD3D *si, class CDriverD3D *driver);
- void applyPass(class CDriverD3D &drv, CShaderDrvInfosD3D *si, uint passIndex);
- void end(CShaderDrvInfosD3D *si);
- void reset();
- void setConstants(CShaderDrvInfosD3D *si);
-};
-
-
-
-// optimisation of an effect 2
-class CFXPassRecorder : public ID3DXEffectStateManager
-{
-public:
- CFXPassRecord *Target;
- class CDriverD3D *Driver;
-public:
- CFXPassRecorder() : Target(NULL), Driver(NULL) {}
- HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, LPVOID *ppvObj);
- ULONG STDMETHODCALLTYPE AddRef(VOID);
- ULONG STDMETHODCALLTYPE Release(VOID);
- HRESULT STDMETHODCALLTYPE LightEnable(DWORD Index, BOOL Enable);
- HRESULT STDMETHODCALLTYPE SetFVF(DWORD FVF);
- HRESULT STDMETHODCALLTYPE SetLight(DWORD Index, CONST D3DLIGHT9* pLight);
- HRESULT STDMETHODCALLTYPE SetMaterial(CONST D3DMATERIAL9* pMaterial);
- HRESULT STDMETHODCALLTYPE SetNPatchMode(FLOAT nSegments);
- HRESULT STDMETHODCALLTYPE SetPixelShader(LPDIRECT3DPIXELSHADER9 pShader);
- HRESULT STDMETHODCALLTYPE SetPixelShaderConstantB(UINT StartRegister, CONST BOOL* pConstantData, UINT RegisterCount);
- HRESULT STDMETHODCALLTYPE SetPixelShaderConstantF(UINT StartRegister, CONST FLOAT* pConstantData, UINT RegisterCount);
- HRESULT STDMETHODCALLTYPE SetPixelShaderConstantI(UINT StartRegister, CONST INT* pConstantData, UINT RegisterCount);
- HRESULT STDMETHODCALLTYPE SetRenderState(D3DRENDERSTATETYPE State, DWORD Value);
- HRESULT STDMETHODCALLTYPE SetSamplerState(DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value);
- HRESULT STDMETHODCALLTYPE SetTexture (DWORD Stage, LPDIRECT3DBASETEXTURE9 pTexture);
- HRESULT STDMETHODCALLTYPE SetTextureStageState(DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value);
- HRESULT STDMETHODCALLTYPE SetTransform(D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix);
- HRESULT STDMETHODCALLTYPE SetVertexShader(LPDIRECT3DVERTEXSHADER9 pShader);
- HRESULT STDMETHODCALLTYPE SetVertexShaderConstantB(UINT StartRegister, CONST BOOL* pConstantData, UINT RegisterCount);
- HRESULT STDMETHODCALLTYPE SetVertexShaderConstantF(UINT StartRegister, CONST FLOAT* pConstantData, UINT RegisterCount);
- HRESULT STDMETHODCALLTYPE SetVertexShaderConstantI(UINT StartRegister, CONST INT* pConstantData, UINT RegisterCount);
-};
-
-
-// ***************************************************************************
-struct CMaterialDrvInfosD3D : public IMaterialDrvInfos
-{
-public:
- D3DMATERIAL9 Material;
- D3DCOLOR UnlightedColor;
- BOOL SpecularEnabled;
- D3DBLEND SrcBlend;
- D3DBLEND DstBlend;
- D3DCMPFUNC ZComp;
- DWORD AlphaRef;
- D3DTEXTUREOP ColorOp[IDRV_MAT_MAXTEXTURES];
- DWORD ColorArg0[IDRV_MAT_MAXTEXTURES];
- DWORD ColorArg1[IDRV_MAT_MAXTEXTURES];
- DWORD ColorArg2[IDRV_MAT_MAXTEXTURES];
- uint NumColorArg[IDRV_MAT_MAXTEXTURES];
- uint NumAlphaArg[IDRV_MAT_MAXTEXTURES];
- D3DTEXTUREOP AlphaOp[IDRV_MAT_MAXTEXTURES];
- DWORD AlphaArg0[IDRV_MAT_MAXTEXTURES];
- DWORD AlphaArg1[IDRV_MAT_MAXTEXTURES];
- DWORD AlphaArg2[IDRV_MAT_MAXTEXTURES];
- D3DCOLOR ConstantColor[IDRV_MAT_MAXTEXTURES];
- DWORD TexGen[IDRV_MAT_MAXTEXTURES];
- IDirect3DPixelShader9 *PixelShader;
- IDirect3DPixelShader9 *PixelShaderUnlightedNoVertexColor;
- bool ActivateSpecularWorldTexMT[IDRV_MAT_MAXTEXTURES];
- bool ActivateInvViewModelTexMT[IDRV_MAT_MAXTEXTURES];
- bool VertexColorLighted;
- bool NeedsConstantForDiffuse; // Must use TFactor if not vertex color in the vertex buffer
- bool MultipleConstantNoPixelShader; // Multiple constant are possibly needed to setup the material. This flag is set only if the device has no pixel shaders
- // In this case diffuse color will be emulated by using an unlighted material with ambient
- bool MultiplePerStageConstant; // Are there more than one per-stage constant in the material ?
- uint8 ConstantIndex; // Index of the constant color to use (when only one constant color is needed and NeedsConstantForDiffuse == false);
- uint8 ConstantIndex2; // stage at which the 2nd constant is used (for emulation without pixel shaders)
-
- CRGBA Constant2; // value of the 2nd constant being used (for emulation without pixel shaders)
-
- uint NumUsedTexStages; // Last number of textures that were set in the material
- // Tex Env are only built for stages at which textures are set so if the number of used texture
- // change they must be rebuilt
-
- // Relevant parts of the pixel pipe for normal shader
- bool RGBPipe[IDRV_MAT_MAXTEXTURES];
- bool AlphaPipe[IDRV_MAT_MAXTEXTURES];
-
- CFXCache *FXCache;
-
- CMaterialDrvInfosD3D(IDriver *drv, ItMatDrvInfoPtrList it) : IMaterialDrvInfos(drv, it)
- {
- H_AUTO_D3D(CMaterialDrvInfosD3D_CMaterialDrvInfosD3D);
- PixelShader = NULL;
- PixelShaderUnlightedNoVertexColor = NULL;
- std::fill(RGBPipe, RGBPipe + IDRV_MAT_MAXTEXTURES, true);
- std::fill(AlphaPipe, AlphaPipe + IDRV_MAT_MAXTEXTURES, true);
- FXCache = NULL;
- NumUsedTexStages = 0;
- }
- ~CMaterialDrvInfosD3D()
- {
- delete FXCache;
- }
- void buildTexEnv (uint stage, const CMaterial::CTexEnv &env, bool textured);
-
-};
-
-
-//
-
-// ***************************************************************************
-
-/* Volatile buffers.
- *
- * The volatile buffer system is a double buffer allocated during the render pass by objects that needs
- * a temporary buffer to render vertex or indexes. Each lock allocates a buffer region
- * and locks it with the NOOVERWRITE flag. Locks are not blocked. The buffer is reset at each frame begin.
- * There is a double buffer to take benefit of the "over swapbuffer" parallelisme.
- */
-
-// ***************************************************************************
-
-class CVolatileVertexBuffer
-{
-public:
- CVolatileVertexBuffer();
- ~CVolatileVertexBuffer();
-
- CDriverD3D *Driver;
- IDirect3DVertexBuffer9 *VertexBuffer;
- uint Size;
- CVertexBuffer::TLocation Location;
- uint CurrentIndex;
- uint MaxSize;
- bool Locked;
-
- /* size is in bytes */
- void init (CVertexBuffer::TLocation location, uint size, uint maxSize, CDriverD3D *driver);
- void release ();
-
- // Runtime buffer access, no-blocking lock.
- void *lock (uint size, uint stride, uint &offset);
- void unlock ();
-
- // Runtime reset (called at the beginning of the frame rendering), blocking lock here.
- void reset ();
-};
-
-// ***************************************************************************
-
-class CVolatileIndexBuffer
-{
-public:
- CVolatileIndexBuffer();
- ~CVolatileIndexBuffer();
-
- CDriverD3D *Driver;
- IDirect3DIndexBuffer9 *IndexBuffer;
- uint Size;
- CIndexBuffer::TLocation Location;
- // current position in bytes!
- uint CurrentIndex;
- uint MaxSize;
- bool Locked;
- CIndexBuffer::TFormat Format;
-
- /* size is in bytes */
- void init (CIndexBuffer::TLocation location, uint sizeInBytes, uint maxSize, CDriverD3D *driver, CIndexBuffer::TFormat format);
- void release ();
-
- // Runtime buffer access, no-blocking lock. Re
- void *lock (uint size, uint &offset);
- void unlock ();
-
- // Runtime reset (called at the beginning of the frame rendering), blocking lock here.
- void reset ();
-};
-
-
-
-// ***************************************************************************
-
-class CDriverD3D : public IDriver, public ID3DXEffectStateManager
-{
-public:
-
- enum
- {
- CacheTest_CullMode = 0,
- CacheTest_RenderState = 1,
- CacheTest_TextureState = 2,
- CacheTest_TextureIndexMode = 3,
- CacheTest_TextureIndexUV = 4,
- CacheTest_Texture = 5,
- CacheTest_VertexProgram = 6,
- CacheTest_PixelShader = 7,
- CacheTest_VertexProgramConstant = 8,
- CacheTest_PixelShaderConstant = 9,
- CacheTest_SamplerState = 10,
- CacheTest_VertexBuffer = 11,
- CacheTest_IndexBuffer = 12,
- CacheTest_VertexDecl = 13,
- CacheTest_Matrix = 14,
- CacheTest_RenderTarget = 15,
- CacheTest_MaterialState = 16,
- CacheTest_DepthRange = 17,
- CacheTest_Count
- };
-
- // Some constants
- enum
- {
- MaxLight=8,
- MaxRenderState=256,
- MaxTextureState=36,
- MaxTexture=8,
- MaxSamplerState=16,
- MaxSampler=8,
-
- MatrixStateRemap = 24,
- MaxMatrixState=32,
- MaxVertexProgramConstantState=96,
- MaxPixelShaderConstantState=96,
- };
-
- // Prefered pixel formats
- enum
- {
- // Number of pixel format choice for each pixel format
- FinalPixelFormatChoice = 5,
- };
-
- // Construction / destruction
- CDriverD3D();
- virtual ~CDriverD3D();
-
- virtual bool isLost() const { return _Lost; }
- // ***************************************************************************
- // Implementation
- // see nel\src\3d\driver.h
- // ***************************************************************************
-
- // Mode initialisation, requests
- virtual bool init (uintptr_t windowIcon = 0, emptyProc exitFunc = 0);
- virtual bool setDisplay(nlWindow wnd, const GfxMode& mode, bool show, bool resizeable) throw(EBadDisplay);
- virtual bool release();
- virtual bool setMode(const GfxMode& mode);
- virtual bool getModes(std::vector &modes);
- virtual bool getCurrentScreenMode(GfxMode &mode);
- virtual void beginDialogMode();
- virtual void endDialogMode();
- virtual bool activate();
- virtual bool isActive ();
- virtual bool initVertexBufferHard(uint agpMem, uint vramMem);
-
- // Windows interface
- virtual nlWindow getDisplay();
- virtual emptyProc getWindowProc();
- virtual NLMISC::IEventEmitter *getEventEmitter();
- virtual void getWindowSize (uint32 &width, uint32 &height);
- virtual void getWindowPos (sint32 &x, sint32 &y);
- virtual uint8 getBitPerPixel ();
-
- /// Set the title of the NeL window
- virtual void setWindowTitle(const ucstring &title);
-
- /// Set icon(s) of the NeL window
- virtual void setWindowIcon(const std::vector &bitmaps);
-
- /// Set the position of the NeL window
- virtual void setWindowPos(sint32 x, sint32 y);
-
- /// Show or hide the NeL window
- virtual void showWindow(bool show);
-
- // Driver parameters
- virtual void disableHardwareVertexProgram();
- virtual void disableHardwarePixelProgram();
- virtual void disableHardwareIndexArrayAGP();
- virtual void disableHardwareVertexArrayAGP();
- virtual void disableHardwareTextureShader();
- virtual void forceDXTCCompression(bool dxtcComp);
- virtual void setAnisotropicFilter(sint filter);
- virtual uint getAnisotropicFilter() const;
- virtual uint getAnisotropicFilterMaximum() const;
- virtual void forceTextureResize(uint divisor);
-
- // Driver information
- virtual uint getNumAdapter() const;
- virtual bool getAdapter(uint adapter, CAdapter &desc) const;
- virtual bool setAdapter(uint adapter);
- virtual uint32 getAvailableVertexAGPMemory ();
- virtual uint32 getAvailableVertexVRAMMemory ();
- virtual uint getNbTextureStages() const;
- virtual void getNumPerStageConstant(uint &lightedMaterial, uint &unlightedMaterial) const;
- virtual bool supportVertexBufferHard() const;
- virtual bool supportVolatileVertexBuffer() const;
- virtual bool supportIndexBufferHard() const;
- // todo hulud d3d vertex buffer hard
- virtual bool slowUnlockVertexBufferHard() const {return false;};
- virtual uint getMaxVerticesByVertexBufferHard() const;
- virtual uint32 getImplementationVersion () const;
- virtual const char* getDriverInformation ();
- virtual const char* getVideocardInformation ();
- virtual sint getTotalVideoMemory () const;
- virtual CVertexBuffer::TVertexColorType getVertexColorFormat() const;
-
- // Textures
- virtual bool isTextureExist(const ITexture&tex);
- virtual bool setupTexture (ITexture& tex);
- virtual bool setupTextureEx (ITexture& tex, bool bUpload, bool &bAllUploaded, bool bMustRecreateSharedTexture= false);
- virtual bool uploadTexture (ITexture& tex, NLMISC::CRect& rect, uint8 nNumMipMap);
- // todo hulud d3d texture
- virtual bool uploadTextureCube (ITexture& /* tex */, NLMISC::CRect& /* rect */, uint8 /* nNumMipMap */, uint8 /* nNumFace */) {return false;};
-
- // Material
- virtual bool setupMaterial(CMaterial& mat);
-
- virtual bool supportCloudRenderSinglePass () const;
-
- // Buffer
- virtual bool clear2D(CRGBA rgba);
- virtual bool clearZBuffer(float zval=1);
- virtual bool clearStencilBuffer(float stencilval=0);
- virtual void setColorMask (bool bRed, bool bGreen, bool bBlue, bool bAlpha);
- virtual bool swapBuffers();
- virtual void getBuffer (CBitmap &bitmap); // Only 32 bits back buffer supported
- virtual void setDepthRange(float znear, float zfar);
- virtual void getDepthRange(float &znear, float &zfar) const;
-
- virtual void getZBuffer (std::vector &zbuffer);
- virtual void getBufferPart (CBitmap &bitmap, NLMISC::CRect &rect);
-
- // return true if driver support Bloom effect.
- virtual bool supportBloomEffect() const;
-
- // return true if driver support non-power of two textures
- virtual bool supportNonPowerOfTwoTextures() const;
-
- // copy the first texture in a second one of different dimensions
- virtual bool stretchRect (ITexture * srcText, NLMISC::CRect &srcRect, ITexture * destText, NLMISC::CRect &destRect); // Only 32 bits back buffer supported
- virtual bool isTextureRectangle(ITexture * /* tex */) const {return false;}
- IDirect3DSurface9* getSurfaceTexture(ITexture * text);
- void getDirect3DRect(NLMISC::CRect &rect, RECT & d3dRect);
-
- // todo hulud d3d buffers
- virtual void getZBufferPart (std::vector &zbuffer, NLMISC::CRect &rect);
- virtual bool setRenderTarget (ITexture *tex, uint32 x, uint32 y, uint32 width, uint32 height, uint32 mipmapLevel, uint32 cubeFace);
- virtual ITexture *getRenderTarget() const;
- virtual bool copyTargetToTexture (ITexture *tex, uint32 offsetx, uint32 offsety, uint32 x, uint32 y, uint32 width,
- uint32 height, uint32 mipmapLevel);
- virtual bool textureCoordinateAlternativeMode() const { return true; };
- virtual bool getRenderTargetSize (uint32 &width, uint32 &height);
- virtual bool fillBuffer (CBitmap &bitmap);
-
- // Performances
- virtual void startSpecularBatch();
- virtual void endSpecularBatch();
- virtual void setSwapVBLInterval(uint interval);
- virtual uint getSwapVBLInterval();
- virtual void swapTextureHandle(ITexture &tex0, ITexture &tex1);
- virtual uintptr_t getTextureHandle(const ITexture&tex);
-
- // Matrix, viewport and frustum
- virtual void setFrustum(float left, float right, float bottom, float top, float znear, float zfar, bool perspective = true);
- virtual void setFrustumMatrix(CMatrix &frust);
- virtual CMatrix getFrustumMatrix();
- virtual float getClipSpaceZMin() const { return 0.f; }
- virtual void setupViewMatrix(const CMatrix& mtx);
- virtual void setupViewMatrixEx(const CMatrix& mtx, const CVector &cameraPos);
- virtual void setupModelMatrix(const CMatrix& mtx);
- virtual CMatrix getViewMatrix() const;
- virtual void forceNormalize(bool normalize);
- virtual bool isForceNormalize() const;
- virtual void setupScissor (const class CScissor& scissor);
- virtual void setupViewport (const class CViewport& viewport);
- virtual void getViewport(CViewport &viewport);
-
- // Vertex buffers
- virtual bool activeVertexBuffer(CVertexBuffer& VB);
-
- // Index buffers
- virtual bool activeIndexBuffer(CIndexBuffer& IB);
-
- // UV
- virtual void mapTextureStageToUV(uint stage, uint uv);
-
- // Indexed primitives
- virtual bool renderLines(CMaterial& mat, uint32 firstIndex, uint32 nlines);
- virtual bool renderTriangles(CMaterial& Mat, uint32 firstIndex, uint32 ntris);
- virtual bool renderSimpleTriangles(uint32 firstTri, uint32 ntris);
- // Indexed primitives with index offset
- virtual bool renderLinesWithIndexOffset(CMaterial& mat, uint32 firstIndex, uint32 nlines, uint indexOffset);
- virtual bool renderTrianglesWithIndexOffset(CMaterial& mat, uint32 firstIndex, uint32 ntris, uint indexOffset);
- virtual bool renderSimpleTrianglesWithIndexOffset(uint32 firstIndex, uint32 ntris, uint indexOffset);
- // Unindexed primitives with index offset
- virtual bool renderRawPoints(CMaterial& Mat, uint32 startIndex, uint32 numPoints);
- virtual bool renderRawLines(CMaterial& Mat, uint32 startIndex, uint32 numLines);
- virtual bool renderRawTriangles(CMaterial& Mat, uint32 startIndex, uint32 numTris);
- virtual bool renderRawQuads(CMaterial& Mat, uint32 startIndex, uint32 numQuads);
- //
- virtual void setPolygonMode (TPolygonMode mode);
- virtual void finish();
- virtual void flush();
-
- // Profile
- virtual void profileRenderedPrimitives(CPrimitiveProfile &pIn, CPrimitiveProfile &pOut);
- virtual uint32 profileAllocatedTextureMemory();
- virtual uint32 profileSetupedMaterials() const;
- virtual uint32 profileSetupedModelMatrix() const;
- virtual void enableUsedTextureMemorySum (bool enable);
- virtual uint32 getUsedTextureMemory() const;
- virtual void startProfileVBHardLock();
- virtual void endProfileVBHardLock(std::vector &result);
- virtual void profileVBHardAllocation(std::vector &result);
- virtual void startProfileIBLock();
- virtual void endProfileIBLock(std::vector &result);
- virtual void profileIBAllocation(std::vector &result);
- //virtual void profileIBAllocation(std::vector &result);
-
- // Misc
- virtual TMessageBoxId systemMessageBox (const char* message, const char* title, TMessageBoxType type=okType, TMessageBoxIcon icon=noIcon);
- virtual uint64 getSwapBufferCounter() const { return _SwapBufferCounter; }
-
- // Inputs
- virtual void showCursor (bool b);
- virtual void setMousePos(float x, float y);
- virtual void setCapture (bool b);
-
- // see if system cursor is currently captured
- virtual bool isSystemCursorCaptured();
-
- // Add a new cursor (name is case unsensitive)
- virtual void addCursor(const std::string &name, const NLMISC::CBitmap &bitmap);
-
- // Display a cursor from its name (case unsensitive)
- virtual void setCursor(const std::string &name, NLMISC::CRGBA col, uint8 rot, sint hotSpotX, sint hotSpotY, bool forceRebuild = false);
-
- // Change default scale for all cursors
- virtual void setCursorScale(float scale);
-
- // Lights
- virtual uint getMaxLight () const;
- virtual void setLight (uint8 num, const CLight& light);
- virtual void enableLight (uint8 num, bool enable=true);
- virtual void setLightMapDynamicLight (bool enable, const CLight& light);
- // todo hulud d3d light
- virtual void setPerPixelLightingLight(CRGBA /* diffuse */, CRGBA /* specular */, float /* shininess */) {}
- virtual void setAmbientColor (CRGBA color);
-
- // Fog
- virtual bool fogEnabled();
- virtual void enableFog(bool enable);
- virtual void setupFog(float start, float end, CRGBA color);
- virtual float getFogStart() const;
- virtual float getFogEnd() const;
- virtual CRGBA getFogColor() const;
-
- // Texture addressing modes
- // todo hulud d3d adressing mode
- virtual bool supportTextureShaders() const {return false;};
- virtual bool supportMADOperator() const;
- // todo hulud d3d adressing mode
- virtual bool supportWaterShader() const;
- // todo hulud d3d adressing mode
- virtual bool supportTextureAddrMode(CMaterial::TTexAddressingMode /* mode */) const {return false;};
- // todo hulud d3d adressing mode
- virtual void setMatrix2DForTextureOffsetAddrMode(const uint /* stage */, const float /* mat */[4]) {}
-
- // EMBM support
- virtual bool supportEMBM() const;
- virtual bool isEMBMSupportedAtStage(uint stage) const;
- virtual void setEMBMMatrix(const uint stage, const float mat[4]);
- virtual bool supportPerPixelLighting(bool /* specular */) const {return false;};
-
- // index offset support
- virtual bool supportIndexOffset() const { return true; /* always supported with D3D driver */ }
-
- // Blend
- virtual bool supportBlendConstantColor() const;
- virtual void setBlendConstantColor(NLMISC::CRGBA col);
- virtual NLMISC::CRGBA getBlendConstantColor() const;
-
- // Monitor properties
- virtual bool setMonitorColorProperties (const CMonitorColorProperties &properties);
-
- // Polygon smoothing
- virtual void enablePolygonSmoothing(bool smooth);
- virtual bool isPolygonSmoothingEnabled() const;
-
- // Material multipass
- virtual sint beginMaterialMultiPass();
- virtual void setupMaterialPass(uint pass);
- virtual void endMaterialMultiPass();
-
-
-
-
-
-
- /// \name Vertex Program
- // @{
-
- // Order of preference
- // - activeVertexProgram
- // - CMaterial pass[n] VP (uses activeVertexProgram, but does not override if one already set by code)
- // - default generic VP that mimics fixed pipeline / no VP with fixed pipeline
-
- /**
- * Does the driver supports vertex program, but emulated by CPU ?
- */
- virtual bool isVertexProgramEmulated() const;
-
- /** Return true if the driver supports the specified vertex program profile.
- */
- virtual bool supportVertexProgram(CVertexProgram::TProfile profile) const;
-
- /** Compile the given vertex program, return if successful.
- * If a vertex program was set active before compilation,
- * the state of the active vertex program is undefined behaviour afterwards.
- */
- virtual bool compileVertexProgram(CVertexProgram *program);
-
- /** Set the active vertex program. This will override vertex programs specified in CMaterial render calls.
- * Also used internally by setupMaterial(CMaterial) when getVertexProgram returns NULL.
- * The vertex program is activated immediately.
- */
- virtual bool activeVertexProgram(CVertexProgram *program);
- // @}
-
-
-
- /// \name Pixel Program
- // @{
-
- // Order of preference
- // - activePixelProgram
- // - CMaterial pass[n] PP (uses activePixelProgram, but does not override if one already set by code)
- // - PP generated from CMaterial (uses activePixelProgram, but does not override if one already set by code)
-
- /** Return true if the driver supports the specified pixel program profile.
- */
- virtual bool supportPixelProgram(CPixelProgram::TProfile profile) const;
-
- /** Compile the given pixel program, return if successful.
- * If a pixel program was set active before compilation,
- * the state of the active pixel program is undefined behaviour afterwards.
- */
- virtual bool compilePixelProgram(CPixelProgram *program);
-
- /** Set the active pixel program. This will override pixel programs specified in CMaterial render calls.
- * Also used internally by setupMaterial(CMaterial) when getPixelProgram returns NULL.
- * The pixel program is activated immediately.
- */
- virtual bool activePixelProgram(CPixelProgram *program);
- // @}
-
-
-
- /// \name Geometry Program
- // @{
-
- // Order of preference
- // - activeGeometryProgram
- // - CMaterial pass[n] PP (uses activeGeometryProgram, but does not override if one already set by code)
- // - none
-
- /** Return true if the driver supports the specified pixel program profile.
- */
- virtual bool supportGeometryProgram(CGeometryProgram::TProfile profile) const { return false; }
-
- /** Compile the given pixel program, return if successful.
- * If a pixel program was set active before compilation,
- * the state of the active pixel program is undefined behaviour afterwards.
- */
- virtual bool compileGeometryProgram(CGeometryProgram *program) { return false; }
-
- /** Set the active pixel program. This will override pixel programs specified in CMaterial render calls.
- * Also used internally by setupMaterial(CMaterial) when getGeometryProgram returns NULL.
- * The pixel program is activated immediately.
- */
- virtual bool activeGeometryProgram(CGeometryProgram *program) { return false; }
- // @}
-
-
-
- /// \name Program parameters
- // @{
- // Set parameters
- virtual void setUniform1f(TProgram program, uint index, float f0);
- virtual void setUniform2f(TProgram program, uint index, float f0, float f1);
- virtual void setUniform3f(TProgram program, uint index, float f0, float f1, float f2);
- virtual void setUniform4f(TProgram program, uint index, float f0, float f1, float f2, float f3);
- virtual void setUniform1i(TProgram program, uint index, sint32 i0);
- virtual void setUniform2i(TProgram program, uint index, sint32 i0, sint32 i1);
- virtual void setUniform3i(TProgram program, uint index, sint32 i0, sint32 i1, sint32 i2);
- virtual void setUniform4i(TProgram program, uint index, sint32 i0, sint32 i1, sint32 i2, sint32 i3);
- virtual void setUniform1ui(TProgram program, uint index, uint32 ui0);
- virtual void setUniform2ui(TProgram program, uint index, uint32 ui0, uint32 ui1);
- virtual void setUniform3ui(TProgram program, uint index, uint32 ui0, uint32 ui1, uint32 ui2);
- virtual void setUniform4ui(TProgram program, uint index, uint32 ui0, uint32 ui1, uint32 ui2, uint32 ui3);
- virtual void setUniform3f(TProgram program, uint index, const NLMISC::CVector& v);
- virtual void setUniform4f(TProgram program, uint index, const NLMISC::CVector& v, float f3);
- virtual void setUniform4f(TProgram program, uint index, const NLMISC::CRGBAF& rgba);
- virtual void setUniform4x4f(TProgram program, uint index, const NLMISC::CMatrix& m);
- virtual void setUniform4fv(TProgram program, uint index, size_t num, const float *src);
- virtual void setUniform4iv(TProgram program, uint index, size_t num, const sint32 *src);
- virtual void setUniform4uiv(TProgram program, uint index, size_t num, const uint32 *src);
- // Set builtin parameters
- virtual void setUniformMatrix(TProgram program, uint index, TMatrix matrix, TTransform transform);
- virtual void setUniformFog(TProgram program, uint index);
- // Set feature parameters
- virtual bool setUniformDriver(TProgram program); // set all driver-specific features params (based on program->features->DriverFlags)
- virtual bool setUniformMaterial(TProgram program, CMaterial &material); // set all material-specific feature params (based on program->features->MaterialFlags)
- virtual void setUniformParams(TProgram program, CGPUProgramParams ¶ms); // set all user-provided params from the storage
- virtual bool isUniformProgramState() { return false; }
- // @}
-
-
-
-
-
- virtual void enableVertexProgramDoubleSidedColor(bool doubleSided);
- virtual bool supportVertexProgramDoubleSidedColor() const;
-
- // Occlusion query
- virtual bool supportOcclusionQuery() const;
- virtual IOcclusionQuery *createOcclusionQuery();
- virtual void deleteOcclusionQuery(IOcclusionQuery *oq);
-
-
-
- /** Shader implementation
- *
- * Shader can assume this states are setuped:
- * TextureTransformFlags[n] = DISABLE;
- * TexCoordIndex[n] = n;
- * ColorOp[n] = DISABLE;
- * AlphaOp[n] = DISABLE;
- */
- bool activeShader(CD3DShaderFX *shd);
-
- // Bench
- virtual void startBench (bool wantStandardDeviation = false, bool quick = false, bool reset = true);
- virtual void endBench ();
- virtual void displayBench (class NLMISC::CLog *log);
-
-
- virtual void setCullMode(TCullMode cullMode);
- virtual TCullMode getCullMode() const;
-
- virtual void enableStencilTest(bool enable);
- virtual bool isStencilTestEnabled() const;
- virtual void stencilFunc(TStencilFunc stencilFunc, int ref, uint mask);
- virtual void stencilOp(TStencilOp fail, TStencilOp zfail, TStencilOp zpass);
- virtual void stencilMask(uint mask);
-
- uint32 getMaxVertexIndex() const { return _MaxVertexIndex; }
-
- // *** Inline info
- uint inlGetNumTextStages() const { return _NbNeLTextureStages; }
-
-//private:
-public:
-
- // Hardware render variables, like matrices, render states
- struct CRenderVariable
- {
- CRenderVariable()
- {
- NextModified = NULL;
- Modified = false;
- }
-
- // Type of render state
- enum
- {
- RenderState = 0,
- TextureState,
- TextureIndexState,
- TexturePtrState,
- VertexProgramPtrState,
- PixelShaderPtrState,
- VertexProgramConstantState,
- PixelShaderConstantState,
- SamplerState,
- MatrixState,
- VBState,
- IBState,
- VertexDecl,
- LightState,
- RenderTargetState,
- } Type;
- CRenderVariable *NextModified;
- bool Modified;
- virtual void apply(CDriverD3D *driver) = 0;
- };
-
- // Render state
- struct CRenderState : public CRenderVariable
- {
- CRenderState()
- {
- Type = RenderState;
- Value= 0;
- ValueSet = false;
- }
- D3DRENDERSTATETYPE StateID;
- DWORD Value;
- bool ValueSet;
- virtual void apply(CDriverD3D *driver);
- };
-
- // Render texture state
- struct CTextureState : public CRenderVariable
- {
- CTextureState()
- {
- Type = TextureState;
- DeviceValue = 0xcccccccc;
- }
- DWORD StageID;
- D3DTEXTURESTAGESTATETYPE StateID;
- DWORD Value;
- DWORD DeviceValue;
- virtual void apply(CDriverD3D *driver);
- };
-
-
- // Render texture index state
- struct CTextureIndexState : public CRenderVariable
- {
- CTextureIndexState()
- {
- Type = TextureIndexState;
- }
- DWORD StageID;
- DWORD TexGenMode;
- DWORD UVChannel;
- bool TexGen;
- virtual void apply(CDriverD3D *driver);
- };
-
- // Render texture
- struct CTexturePtrState : public CRenderVariable
- {
- CTexturePtrState()
- {
- Type = TexturePtrState;
- Texture = NULL;
- }
- DWORD StageID;
- LPDIRECT3DBASETEXTURE9 Texture;
- virtual void apply(CDriverD3D *driver);
- };
-
- // Render texture
- struct CVertexProgramPtrState : public CRenderVariable
- {
- CVertexProgramPtrState()
- {
- Type = VertexProgramPtrState;
- VertexProgram = NULL;
- }
- LPDIRECT3DVERTEXSHADER9 VertexProgram;
- // for debug
- const CVertexProgram *VP;
- virtual void apply(CDriverD3D *driver);
- };
-
- // Render texture
- struct CPixelShaderPtrState : public CRenderVariable
- {
- CPixelShaderPtrState()
- {
- Type = PixelShaderPtrState;
- PixelShader = NULL;
- }
- LPDIRECT3DPIXELSHADER9 PixelShader;
- virtual void apply(CDriverD3D *driver);
- };
-
- // Vertex buffer constants state
- struct CVertexProgramConstantState : public CRenderVariable
- {
- CVertexProgramConstantState()
- {
- Type = VertexProgramConstantState;
- }
- enum
- {
- Float= 0,
- Int,
- Undef,
- } ValueType;
- uint StateID;
- DWORD Values[4];
- virtual void apply(CDriverD3D *driver);
- };
-
- // Pixel shader constants state
- struct CPixelShaderConstantState : public CRenderVariable
- {
- CPixelShaderConstantState()
- {
- Type = PixelShaderConstantState;
- }
- enum
- {
- Float= 0,
- Int,
- Undef,
- } ValueType;
- uint StateID;
- DWORD Values[4];
- virtual void apply(CDriverD3D *driver);
- };
-
- // Render sampler state
- struct CSamplerState : public CRenderVariable
- {
- CSamplerState()
- {
- Type = SamplerState;
- }
- DWORD SamplerID;
- D3DSAMPLERSTATETYPE StateID;
- DWORD Value;
- virtual void apply(CDriverD3D *driver);
- };
-
- // Render matrix
- struct CMatrixState : public CRenderVariable
- {
- CMatrixState()
- {
- Type = MatrixState;
- }
- D3DTRANSFORMSTATETYPE TransformType;
- D3DXMATRIX Matrix;
- virtual void apply(CDriverD3D *driver);
- };
-
- // Render vertex buffer
- struct CVBState : public CRenderVariable
- {
- CVBState()
- {
- Type = VBState;
- VertexBuffer = NULL;
- ColorOffset = 0;
- }
- IDirect3DVertexBuffer9 *VertexBuffer;
- UINT Offset;
- UINT Stride;
- CVertexBuffer::TPreferredMemory PrefferedMemory;
- DWORD Usage; // d3d vb usage
- uint ColorOffset; // Fix for Radeon 7xxx series (see remark in CDriverD3D::createVertexDeclaration)
- virtual void apply(CDriverD3D *driver);
- };
-
- // Render index buffer
- struct CIBState : public CRenderVariable
- {
- CIBState()
- {
- Type = IBState;
- IndexBuffer = NULL;
- }
- IDirect3DIndexBuffer9 *IndexBuffer;
- virtual void apply(CDriverD3D *driver);
- };
-
- // Render vertex decl
- struct CVertexDeclState : public CRenderVariable
- {
- CVertexDeclState()
- {
- Type = VertexDecl;
- Decl = NULL;
- DeclAliasDiffuseToSpecular = NULL;
- DeclNoDiffuse = NULL;
- Stride= 0;
- AliasDiffuseToSpecular = false;
- EnableVertexColor = false;
- }
- IDirect3DVertexDeclaration9 *Decl;
- IDirect3DVertexDeclaration9 *DeclAliasDiffuseToSpecular;
- IDirect3DVertexDeclaration9 *DeclNoDiffuse;
- uint Stride;
- bool AliasDiffuseToSpecular;
- bool EnableVertexColor;
- virtual void apply(CDriverD3D *driver);
- };
-
- // Render vertex buffer
- struct CLightState : public CRenderVariable
- {
- CLightState()
- {
- Type = LightState;
- Enabled = false;
- SettingsTouched = false;
- EnabledTouched = true;
- Light.Type = D3DLIGHT_POINT;
- Light.Range = 1;
- Light.Falloff = 1;
- Light.Position.x = 0;
- Light.Position.y = 0;
- Light.Position.z = 0;
- Light.Direction.x = 1;
- Light.Direction.y = 0;
- Light.Direction.z = 0;
- Light.Attenuation0 = 1;
- Light.Attenuation1 = 1;
- Light.Attenuation2 = 1;
- Light.Theta = 0;
- Light.Phi = 0;
- }
- uint8 LightIndex;
- bool SettingsTouched;
- bool EnabledTouched;
- bool Enabled;
- D3DLIGHT9 Light;
- virtual void apply(CDriverD3D *driver);
- };
-
- // Render target
- struct CRenderTargetState : public CRenderVariable
- {
- CRenderTargetState()
- {
- Type = RenderTargetState;
- Target = NULL;
- Texture = NULL;
- Level = 0;
- CubeFace = 0;
- }
- IDirect3DSurface9 *Target;
- ITexture *Texture;
- uint8 Level;
- uint8 CubeFace;
- virtual void apply(CDriverD3D *driver);
- };
-
- // material state
- struct CMaterialState : public CRenderVariable
- {
- CMaterialState()
- {
- //Current.Power = -1.f;
- Current.Diffuse.r = Current.Diffuse.g = Current.Diffuse.b = Current.Diffuse.a = 0.f;
- Current.Ambient.r = Current.Ambient.g = Current.Ambient.b = Current.Ambient.a = 0.f;
- Current.Specular.r = Current.Specular.g = Current.Specular.b = Current.Specular.a = 0.f;
- Current.Emissive.r = Current.Emissive.g = Current.Emissive.b = Current.Emissive.a = 0.f;
- Current.Power = 0.f;
- }
- D3DMATERIAL9 Current;
- virtual void apply(CDriverD3D *driver);
- };
-
-
- // Friends
- friend void D3DWndProc(CDriverD3D *driver, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
- friend class CTextureDrvInfosD3D;
- friend class CVBDrvInfosD3D;
- friend class CIBDrvInfosD3D;
- friend class CVolatileVertexBuffer;
- friend class CVolatileIndexBuffer;
-
- // Init render states
- void initRenderVariables();
-
- // Reset render states
- void resetRenderVariables();
-
- // Replace all arguments of color / alpha operators in the pixel pipe with the given value
- void replaceAllArgument(DWORD from, DWORD to, DWORD blendOpFrom);
-
- // Replace all arguments of color / alpha operators in the pixel pipe at the given stage with the given value
- void replaceAllArgumentAtStage(uint stage, DWORD from, DWORD to, DWORD blendOpFrom);
- void replaceAllRGBArgumentAtStage(uint stage, DWORD from, DWORD to, DWORD blendOpFrom);
- void replaceAllAlphaArgumentAtStage(uint stage, DWORD from, DWORD to, DWORD blendOpFrom);
-
- // Replace a the given color / alpha op
- void replaceArgumentAtStage(D3DTEXTURESTAGESTATETYPE state, DWORD stage, DWORD from, DWORD to);
-
- // Setup lighting & material so that it produces the given constant color (useful to simulate a per stage constant using diffuse)
- void setupConstantDiffuseColorFromLightedMaterial(D3DCOLOR color);
-
- // Update all modified render states, reset current material
- void updateRenderVariables();
-
- // Update all modified render states, assume current material is still alive
- void updateRenderVariablesInternal();
-
- // Reset the driver, release the lost resources
- bool reset (const GfxMode& mode);
-
- // Handle window size change
- bool handlePossibleSizeChange();
-
-public:
- // Touch a render variable
- inline void touchRenderVariable (CRenderVariable *renderVariable)
- {
- // Modified ?
- if (!renderVariable->Modified)
- {
- // Link to modified states
- renderVariable->NextModified = _ModifiedRenderState;
- _ModifiedRenderState = renderVariable;
- renderVariable->Modified = true;
- }
- }
-
-
-
- // Access render states
- inline void setRenderState (D3DRENDERSTATETYPE renderState, DWORD value)
- {
- H_AUTO_D3D(CDriverD3D_setRenderState);
- #ifdef NL_DEBUG
- nlassert (_DeviceInterface);
- nlassert (renderStateTexture);
- setSamplerState (stage, D3DSAMP_ADDRESSU, d3dtext->WrapS);
- setSamplerState (stage, D3DSAMP_ADDRESSV, d3dtext->WrapT);
- setSamplerState (stage, D3DSAMP_MAGFILTER, d3dtext->MagFilter);
- setSamplerState (stage, D3DSAMP_MINFILTER, d3dtext->MinFilter);
- setSamplerState (stage, D3DSAMP_MIPFILTER, d3dtext->MipFilter);
- setSamplerState (stage, D3DSAMP_MAXANISOTROPY, _AnisotropicFilter);
-
- // Profile, log the use of this texture
- if (_SumTextureMemoryUsed)
- {
- // Insert the pointer of this texture
- _TextureUsed.insert (d3dtext);
- }
- }
-
- // Access vertex program
- inline void setVertexProgram (LPDIRECT3DVERTEXSHADER9 vertexProgram, const CVertexProgram *vp)
- {
- H_AUTO_D3D(CDriverD3D_setVertexProgram);
- nlassert (_DeviceInterface);
-
- // Ref on the state
-#ifdef NL_D3D_USE_RENDER_STATE_CACHE
- NL_D3D_CACHE_TEST(CacheTest_VertexProgram, _VertexProgramCache.VertexProgram != vertexProgram)
-#endif // NL_D3D_USE_RENDER_STATE_CACHE
- {
- _VertexProgramCache.VertexProgram = vertexProgram;
- _VertexProgramCache.VP = vp;
- touchRenderVariable (&_VertexProgramCache);
- }
- }
-
- // Access pixel shader
- inline void setPixelShader (LPDIRECT3DPIXELSHADER9 pixelShader)
- {
- H_AUTO_D3D(CDriverD3D_setPixelShader);
- nlassert (_DeviceInterface);
-
- // Ref on the state
-#ifdef NL_D3D_USE_RENDER_STATE_CACHE
- NL_D3D_CACHE_TEST(CacheTest_PixelShader, _PixelShaderCache.PixelShader != pixelShader)
-#endif // NL_D3D_USE_RENDER_STATE_CACHE
- {
- _PixelShaderCache.PixelShader = pixelShader;
- touchRenderVariable (&_PixelShaderCache);
- }
- }
-
- // Access vertex program constant
- inline void setVertexProgramConstant (uint index, const float *values)
- {
- H_AUTO_D3D(CDriverD3D_setVertexProgramConstant);
- nlassert (_DeviceInterface);
- nlassert (index=256)
- return (D3DTRANSFORMSTATETYPE)(MatrixStateRemap + type - 256);
- else
- return (uint)type;
- }
- inline void setMatrix (D3DTRANSFORMSTATETYPE type, const D3DXMATRIX &matrix)
- {
- H_AUTO_D3D(CDriverD3D_setMatrix);
- nlassert (_DeviceInterface);
-
- // Remap high matrices indexes
- type = (D3DTRANSFORMSTATETYPE)remapMatrixIndex (type);
- nlassert ((int)type<(int)MaxMatrixState);
-
- CMatrixState &theMatrix = _MatrixCache[type];
-#ifdef NL_D3D_USE_RENDER_STATE_CACHE
- bool doUpdate = (matrix._11 != theMatrix.Matrix._11) ||
- (matrix._12 != theMatrix.Matrix._12) ||
- (matrix._13 != theMatrix.Matrix._13) ||
- (matrix._14 != theMatrix.Matrix._14) ||
- (matrix._21 != theMatrix.Matrix._21) ||
- (matrix._22 != theMatrix.Matrix._22) ||
- (matrix._23 != theMatrix.Matrix._23) ||
- (matrix._24 != theMatrix.Matrix._24) ||
- (matrix._31 != theMatrix.Matrix._31) ||
- (matrix._32 != theMatrix.Matrix._32) ||
- (matrix._33 != theMatrix.Matrix._33) ||
- (matrix._34 != theMatrix.Matrix._34) ||
- (matrix._41 != theMatrix.Matrix._41) ||
- (matrix._42 != theMatrix.Matrix._42) ||
- (matrix._43 != theMatrix.Matrix._43) ||
- (matrix._44 != theMatrix.Matrix._44);
- NL_D3D_CACHE_TEST(CacheTest_Matrix, doUpdate)
-#endif // NL_D3D_USE_RENDER_STATE_CACHE
- {
- theMatrix.Matrix = matrix;
- touchRenderVariable (&theMatrix);
- }
- }
-
- // Access texture states
- inline void setRenderTarget (IDirect3DSurface9 *target, ITexture *texture, uint8 level, uint8 cubeFace)
- {
- H_AUTO_D3D(CDriverD3D_setRenderTarget);
- nlassert (_DeviceInterface);
-
- // Ref on the state
-#ifdef NL_D3D_USE_RENDER_STATE_CACHE
- NL_D3D_CACHE_TEST(CacheTest_RenderTarget, _RenderTarget.Target != target)
-#endif // NL_D3D_USE_RENDER_STATE_CACHE
- {
- _RenderTarget.Target = target;
- _RenderTarget.Texture = texture;
- _RenderTarget.Level = level;
- _RenderTarget.CubeFace = cubeFace;
-
- touchRenderVariable (&_RenderTarget);
-
- _ScissorTouched = true;
- }
- }
-
-
-public:
- void setMaterialState(const D3DMATERIAL9 &material)
- {
- H_AUTO_D3D(setMaterialState);
-#ifdef NL_D3D_USE_RENDER_STATE_CACHE
- bool update = material.Power != _MaterialState.Current.Power ||
- material.Ambient != _MaterialState.Current.Ambient ||
- material.Emissive != _MaterialState.Current.Emissive ||
- material.Diffuse != _MaterialState.Current.Diffuse ||
- material.Specular != _MaterialState.Current.Specular;
- NL_D3D_CACHE_TEST(CacheTest_MaterialState, update)
-#endif
- {
- _MaterialState.Current = material;
- touchRenderVariable(&_MaterialState);
- }
- }
-
-
-
-
- // Get the d3dtext mirror of an existing setuped texture.
- static inline CTextureDrvInfosD3D* getTextureD3D(ITexture& tex)
- {
- H_AUTO_D3D(CDriverD3D_getTextureD3D);
- CTextureDrvInfosD3D* d3dtex;
- d3dtex= (CTextureDrvInfosD3D*)(ITextureDrvInfos*)(tex.TextureDrvShare->DrvTexture);
- return d3dtex;
- }
-
- // Get the d3dtext mirror of an existing setuped pixel program.
- static inline CPixelProgramDrvInfosD3D* getPixelProgramD3D(CPixelProgram& pixelProgram)
- {
- H_AUTO_D3D(CDriverD3D_getPixelProgramD3D);
- CPixelProgramDrvInfosD3D* d3dPixelProgram;
- d3dPixelProgram = (CPixelProgramDrvInfosD3D*)(IProgramDrvInfos*)(pixelProgram.m_DrvInfo);
- return d3dPixelProgram;
- }
-
- // Get the d3dtext mirror of an existing setuped vertex program.
- static inline CVertexProgamDrvInfosD3D* getVertexProgramD3D(CVertexProgram& vertexProgram)
- {
- H_AUTO_D3D(CDriverD3D_getVertexProgramD3D);
- CVertexProgamDrvInfosD3D* d3dVertexProgram;
- d3dVertexProgram = (CVertexProgamDrvInfosD3D*)(IProgramDrvInfos*)(vertexProgram.m_DrvInfo);
- return d3dVertexProgram;
- }
-
- // *** Init helper
-
- bool isDepthFormatOk(UINT adapter, D3DDEVTYPE rasterizer, D3DFORMAT DepthFormat, D3DFORMAT AdapterFormat, D3DFORMAT BackBufferFormat);
- bool isTextureFormatOk(UINT adapter, D3DDEVTYPE rasterizer, D3DFORMAT TextureFormat, D3DFORMAT AdapterFormat);
- bool fillPresentParameter (D3DPRESENT_PARAMETERS ¶meters, D3DFORMAT &adapterFormat, const GfxMode& mode, const D3DDISPLAYMODE &adapterMode);
-
- // *** Texture helper
-
- D3DFORMAT getD3DDestTextureFormat (ITexture& tex);
- // Generates the texture, degades it, creates / resizes the d3d surface. Don't fill the surface.
- bool generateD3DTexture (ITexture& tex, bool textureDegradation, D3DFORMAT &destFormat, D3DFORMAT &srcFormat, bool &cube);
- // Return the memory used by the surface described iwith the parameters
- uint32 computeTextureMemoryUsage (uint width, uint height, uint levels, D3DFORMAT destFormat, bool cube);
- // Upload a texture part
- bool uploadTextureInternal (ITexture& tex, NLMISC::CRect& rect, uint8 destMipmap, uint8 srcMipmap, D3DFORMAT destFormat, D3DFORMAT srcFormat);
-
- // *** Matrix helper
-
- // Update _D3DModelView and _D3DModelViewProjection matrices. Call this if the model, the projection or the view matrix are modified
- void updateMatrices ();
- // Update the projection matrix. Call this if the driver resolution, the viewport or the frustum changes.
- void updateProjectionMatrix ();
-
- // *** Vertex buffer helper
-
- // Create a vertex declaration
- bool createVertexDeclaration (uint16 vertexFormat, const uint8 *typeArray,
- IDirect3DVertexDeclaration9 **vertexDecl,
- uint &colorOffset,
- bool aliasDiffuseToSpecular,
- bool bypassDiffuse,
- uint *stride = NULL
- );
-
- // *** Index buffer helper
-
- // *** Multipass helpers
-
- void initInternalShaders();
- void releaseInternalShaders();
- bool setShaderTexture (uint textureHandle, ITexture *texture, CFXCache *cache);
-
- bool validateShader(CD3DShaderFX *shader);
-
- void activePass (uint pass)
- {
- H_AUTO_D3D(CDriverD3D_activePass);
- if (_CurrentShader)
- {
- CShaderDrvInfosD3D *drvInfo = static_cast((IShaderDrvInfos*)_CurrentShader->_DrvInfo);
- if (_CurrentMaterialInfo->FXCache)
- {
- nlassert(_CurrentMaterialInfo);
- _CurrentMaterialInfo->FXCache->applyPass(*this, drvInfo, pass);
- }
- else
- {
-#if (DIRECT3D_VERSION >= 0x0900) && (D3D_SDK_VERSION >= 32)
- drvInfo->Effect->BeginPass (pass);
- drvInfo->Effect->EndPass ();
-#else
- drvInfo->Effect->Pass (pass);
-#endif
- }
- }
-
- // Update render states
- updateRenderVariablesInternal();
- }
-
- void beginMultiPass ()
- {
- H_AUTO_D3D(CDriverD3D_beginMultiPass);
- if (_CurrentShader)
- {
- // Does the shader validated ?
- validateShader(_CurrentShader);
-
- // Init default state value
- uint i;
- for (i=0; i((IShaderDrvInfos*)_CurrentShader->_DrvInfo);
- if (_CurrentMaterialInfo->FXCache)
- {
- nlassert(_CurrentMaterialInfo);
- _CurrentMaterialInfo->FXCache->begin(drvInfo, this);
- }
- else
- {
- drvInfo->Effect->Begin (&_CurrentShaderPassCount, D3DXFX_DONOTSAVESTATE|D3DXFX_DONOTSAVESHADERSTATE);
- }
- }
- else
- // No shader setuped
- _CurrentShaderPassCount = 1;
- }
-
- void endMultiPass ()
- {
- H_AUTO_D3D(CDriverD3D_endMultiPass);
- if (_CurrentShader)
- {
- CShaderDrvInfosD3D *drvInfo = static_cast((IShaderDrvInfos*)_CurrentShader->_DrvInfo);
- if (_CurrentMaterialInfo->FXCache)
- {
- _CurrentMaterialInfo->FXCache->end(drvInfo);
- }
- else
- {
- drvInfo->Effect->End ();
- }
- }
- }
-
- // render helpers
- bool renderPrimitives(D3DPRIMITIVETYPE primitiveType, uint numVertexPerPrim, CMaterial& mat, uint firstVertex, uint32 nPrims);
- bool renderIndexedPrimitives(D3DPRIMITIVETYPE primitiveType, uint numVertexPerPrim, CMaterial& mat, uint32 firstIndex, uint32 nPrims, uint indexOffset = 0);
- bool renderSimpleIndexedPrimitives(D3DPRIMITIVETYPE primitiveType, uint numVertexPerPrim, uint32 firstIndex, uint32 nPrims, uint indexOffset = 0);
- void convertToIndices16(uint firstIndex, uint numIndices);
-
- // Returns true if this material needs a constant color for the diffuse component
- static bool needsConstantForDiffuse (CMaterial &mat);
-
- /* Returns true if this normal needs constant. If true, numConstant is the number of needed constants, firstConstant is the first
- constants needed. */
- static bool needsConstants (uint &numConstant, uint &firstConstant, uint &secondConstant, CMaterial &mat);
-
- // For normal shader, compute part of the pipeline that are worth setting
- // For example : if alpha output if not used (no alpha test or blend), then the alpha part won't be set at all
- static void computeRelevantTexEnv(CMaterial &mat, bool rgbPipe[IDRV_MAT_MAXTEXTURES], bool alphaPipe[IDRV_MAT_MAXTEXTURES]);
-
- // Build a pixel shader for normal shader
- IDirect3DPixelShader9 *buildPixelShader (const CNormalShaderDesc &normalShaderDesc, bool unlightedNoVertexColor);
-
-
- // Notify all the shaders drivers info that a device has been lost
- void notifyAllShaderDrvOfLostDevice();
- // Notify all the shaders drivers info that a device has been reset
- void notifyAllShaderDrvOfResetDevice();
-
- // *** Debug helpers
-
- void setDebugMaterial();
-
- // ** From ID3DXEffectStateManager
-public:
- HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, LPVOID *ppvObj);
- ULONG STDMETHODCALLTYPE AddRef(VOID);
- ULONG STDMETHODCALLTYPE Release(VOID);
- HRESULT STDMETHODCALLTYPE LightEnable(DWORD Index, BOOL Enable);
- HRESULT STDMETHODCALLTYPE SetFVF(DWORD FVF);
- HRESULT STDMETHODCALLTYPE SetLight(DWORD Index, CONST D3DLIGHT9* pLight);
- HRESULT STDMETHODCALLTYPE SetMaterial(CONST D3DMATERIAL9* pMaterial);
- HRESULT STDMETHODCALLTYPE SetNPatchMode(FLOAT nSegments);
- HRESULT STDMETHODCALLTYPE SetPixelShader(LPDIRECT3DPIXELSHADER9 pShader);
- HRESULT STDMETHODCALLTYPE SetPixelShaderConstantB(UINT StartRegister, CONST BOOL* pConstantData, UINT RegisterCount);
- HRESULT STDMETHODCALLTYPE SetPixelShaderConstantF(UINT StartRegister, CONST FLOAT* pConstantData, UINT RegisterCount);
- HRESULT STDMETHODCALLTYPE SetPixelShaderConstantI(UINT StartRegister, CONST INT* pConstantData, UINT RegisterCount);
- HRESULT STDMETHODCALLTYPE SetRenderState(D3DRENDERSTATETYPE State, DWORD Value);
- HRESULT STDMETHODCALLTYPE SetSamplerState(DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value);
- HRESULT STDMETHODCALLTYPE SetTexture (DWORD Stage, LPDIRECT3DBASETEXTURE9 pTexture);
- HRESULT STDMETHODCALLTYPE SetTextureStageState(DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value);
- HRESULT STDMETHODCALLTYPE SetTransform(D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix);
- HRESULT STDMETHODCALLTYPE SetVertexShader(LPDIRECT3DVERTEXSHADER9 pShader);
- HRESULT STDMETHODCALLTYPE SetVertexShaderConstantB(UINT StartRegister, CONST BOOL* pConstantData, UINT RegisterCount);
- HRESULT STDMETHODCALLTYPE SetVertexShaderConstantF(UINT StartRegister, CONST FLOAT* pConstantData, UINT RegisterCount);
- HRESULT STDMETHODCALLTYPE SetVertexShaderConstantI(UINT StartRegister, CONST INT* pConstantData, UINT RegisterCount);
-private:
-
- void findNearestFullscreenVideoMode();
-
- TShaderDrvInfoPtrList _ShaderDrvInfos;
-
- // Windows
- std::string _WindowClass;
- HWND _HWnd;
- sint32 _WindowX;
- sint32 _WindowY;
- bool _DestroyWindow;
- bool _Maximized;
- bool _HandlePossibleSizeChangeNextSize;
- GfxMode _CurrentMode;
- uint _Interval;
- bool _FullScreen;
-
- // cursors
- enum TColorDepth { ColorDepth16 = 0, ColorDepth32, ColorDepthCount };
-
- TColorDepth _ColorDepth;
- std::string _CurrName;
- NLMISC::CRGBA _CurrCol;
- uint8 _CurrRot;
- uint _CurrHotSpotX;
- uint _CurrHotSpotY;
- float _CursorScale;
-
- nlCursor _DefaultCursor;
-
- bool _AlphaBlendedCursorSupported;
- bool _AlphaBlendedCursorSupportRetrieved;
-
- class CCursor
- {
- public:
- NLMISC::CBitmap Src;
- TColorDepth ColorDepth;
- uint OrigHeight;
- float HotspotScale;
- uint HotspotOffsetX;
- uint HotspotOffsetY;
- sint HotSpotX;
- sint HotSpotY;
- nlCursor Cursor;
- NLMISC::CRGBA Col;
- uint8 Rot;
-#if defined(NL_OS_UNIX) && !defined(NL_OS_MAC)
- Display *Dpy;
-#endif
- public:
- CCursor();
- ~CCursor();
- CCursor& operator= (const CCursor& from);
-
- void reset();
- };
-
- struct CStrCaseUnsensitiveCmp
- {
- bool operator()(const std::string &lhs, const std::string &rhs) const
- {
- return NLMISC::nlstricmp(lhs, rhs) < 0;
- }
- };
-
- typedef std::map TCursorMap;
-
- TCursorMap _Cursors;
-
- // Directx
- uint32 _Adapter;
- D3DDEVTYPE _Rasterizer;
- LPDIRECT3D9 _D3D;
-public:
- IDirect3DDevice9 *_DeviceInterface;
-private:
-
- // Events
- NLMISC::CEventEmitterMulti _EventEmitter; // this can contains a win emitter and eventually a direct input emitter
-
- // Some matrices (Local -> Model -> World -> Screen)
-public:
- CVector _PZBCameraPos;
-private:
- CMatrix _UserModelMtx;
- CMatrix _UserViewMtx;
-public:
- CViewport _Viewport;
-private:
- D3DVIEWPORT9 _D3DViewport;
-public:
- CScissor _Scissor;
-private:
- float _OODeltaZ; // Backup znear and zfar
- D3DXMATRIX _D3DSpecularWorldTex; // World (as in NeL) to model matrix.
- D3DXMATRIX _D3DModelView; // Local to world (as in D3D) matrix.
- D3DXMATRIX _D3DModelViewProjection; // Local to screen (as in D3D) matrix.
- D3DXMATRIX _D3DInvModelView; // World (as in DX) to local matrix.
- bool _ForceNormalize;
- bool _FrustumPerspective;
- bool _InvertCullMode;
- bool _DoubleSided;
- float _FrustumLeft;
- float _FrustumRight;
- float _FrustumTop;
- float _FrustumBottom;
- float _FrustumZNear;
- float _FrustumZFar;
- float _FogStart;
- float _FogEnd;
-
- // Vertex memory available
- uint32 _AGPMemoryAllocated;
- uint32 _VRAMMemoryAllocated;
-
- // Textures caps
- D3DFORMAT _PreferedTextureFormat[ITexture::UploadFormatCount];
- uint _ForceTextureResizePower;
- bool _ForceDXTCCompression:1;
- bool _TextureCubeSupported;
- bool _VertexProgram;
- bool _PixelProgram;
- uint16 _PixelProgramVersion;
- bool _DisableHardwareVertexProgram;
- bool _DisableHardwarePixelProgram;
- bool _DisableHardwareVertexArrayAGP;
- bool _DisableHardwareIndexArrayAGP;
- bool _DisableHardwarePixelShader;
- bool _MADOperatorSupported;
- bool _EMBMSupported;
- bool _CubbedMipMapSupported;
- bool _IsGeforce;
- bool _NonPowerOfTwoTexturesSupported;
- uint _MaxAnisotropy;
- bool _AnisotropicMinSupported;
- bool _AnisotropicMagSupported;
- bool _AnisotropicMinCubeSupported;
- bool _AnisotropicMagCubeSupported;
- uint _NbNeLTextureStages; // Number of texture stage for NeL (max IDRV_MAT_MAXTEXTURES)
- uint _MaxVerticesByVertexBufferHard;
- uint _MaxLight;
- uint32 _PixelShaderVersion;
- uint32 _MaxPrimitiveCount;
- uint32 _MaxVertexIndex;
- uint _MaxNumPerStageConstantLighted;
- uint _MaxNumPerStageConstantUnlighted;
-
- // Profiling
- CPrimitiveProfile _PrimitiveProfileIn;
- CPrimitiveProfile _PrimitiveProfileOut;
- uint32 _AllocatedTextureMemory;
- uint32 _NbSetupMaterialCall;
- uint32 _NbSetupModelMatrixCall;
- bool _SumTextureMemoryUsed;
- std::set _TextureUsed;
-
- // VBHard Lock Profiling
- struct CVBHardProfile
- {
- NLMISC::CRefPtr VBHard;
- NLMISC::TTicks AccumTime;
- // true if the VBHard was not always the same for the same chronogical place.
- bool Change;
- CVBHardProfile()
- {
- AccumTime= 0;
- Change= false;
- }
- };
-
- // Index buffer lock profiling
- struct CIBProfile
- {
- NLMISC::CRefPtr IB;
- NLMISC::TTicks AccumTime;
- // true if the VBHard was not always the same for the same chronogical place.
- bool Change;
- CIBProfile()
- {
- AccumTime= 0;
- Change= false;
- }
- };
-
- // The vb hard Profiles in chronogical order.
- bool _VBHardProfiling;
- std::vector _VBHardProfiles;
- uint _CurVBHardLockCount;
- uint _NumVBHardProfileFrame;
- void appendVBHardLockProfile(NLMISC::TTicks time, CVertexBuffer *vb);
-
- // The index buffer profile in chronogical order.
- bool _IBProfiling;
- std::vector _IBProfiles;
- uint _CurIBLockCount;
- uint _NumIBProfileFrame;
-public:
- NLMISC::TTicks _VolatileIBLockTime;
- NLMISC::TTicks _VolatileVBLockTime;
-private:
- void appendIBLockProfile(NLMISC::TTicks time, CIndexBuffer *ib);
-
- // VBHard profile
- std::set _VertexBufferHardSet;
-
- // The render variables
-public:
- CRenderState _RenderStateCache[MaxRenderState];
- CTextureState _TextureStateCache[MaxTexture][MaxTextureState];
- CTextureIndexState _TextureIndexStateCache[MaxTexture];
- CTexturePtrState _TexturePtrStateCache[MaxTexture];
- CSamplerState _SamplerStateCache[MaxSampler][MaxSamplerState];
- CMatrixState _MatrixCache[MaxMatrixState];
- CVertexProgramPtrState _VertexProgramCache;
- CPixelShaderPtrState _PixelShaderCache;
- CVertexProgramConstantState _VertexProgramConstantCache[MaxVertexProgramConstantState];
- CPixelShaderConstantState _PixelShaderConstantCache[MaxPixelShaderConstantState];
- CVertexDeclState _VertexDeclCache;
- CLightState _LightCache[MaxLight];
- CRenderTargetState _RenderTarget;
- CMaterialState _MaterialState;
-private:
-
- // last activation of vertex buffer / index buffer
- NLMISC::CRefPtr _LastIndexBufferInfo;
-
- // Vertex buffer cache
- CVBState _VertexBufferCache;
- uint _VertexBufferSize;
- uint _VertexBufferOffset;
-public:
- bool _UseVertexColor;
-private:
-
- // Index buffer cache
- CIBState _IndexBufferCache;
- uint _IndexBufferOffset; // Current index buffer offset
- CIndexBuffer::TFormat _CurrIndexBufferFormat; // updated at call to activeIndexBuffer
-
- // The last vertex buffer needs vertex color
- bool _FogEnabled;
-
- NLMISC::CRefPtr _VertexProgramUser;
- NLMISC::CRefPtr _PixelProgramUser;
-
- // *** Internal resources
-
- // Current render pass
- uint _CurrentRenderPass;
-
-
- // Volatile double buffers
- CVolatileVertexBuffer *_VolatileVertexBufferRAM[2];
- CVolatileVertexBuffer *_VolatileVertexBufferAGP[2];
- CVolatileIndexBuffer *_VolatileIndexBuffer16RAM[2];
- CVolatileIndexBuffer *_VolatileIndexBuffer16AGP[2];
- CVolatileIndexBuffer *_VolatileIndexBuffer32RAM[2];
- CVolatileIndexBuffer *_VolatileIndexBuffer32AGP[2];
-
- // Special 16 bit index buffer for quads
- IDirect3DIndexBuffer9 *_QuadIB;
-
- // Vertex declaration list
- std::list _VertexDeclarationList;
-
- // Pixel shader list
- std::list _NormalPixelShaders[2];
-
- // Quad indexes
- CIndexBuffer _QuadIndexes;
- CIndexBuffer _QuadIndexesAGP;
-
- // The last setuped shader
- CD3DShaderFX *_CurrentShader;
- UINT _CurrentShaderPassCount;
-public:
- struct CTextureRef
- {
- CRefPtr NeLTexture;
- LPDIRECT3DBASETEXTURE9 D3DTexture;
- };
- const std::vector &getCurrentShaderTextures() const { return _CurrentShaderTextures; }
-private:
- std::vector _CurrentShaderTextures;
-
- // The last material setuped
- CMaterial *_CurrentMaterial;
-public:
- CMaterialDrvInfosD3D *_CurrentMaterialInfo;
-private:
-
- // Optim: To not test change in Materials states if just texture has changed. Very useful for landscape.
- uint32 _MaterialAllTextureTouchedFlag;
-
- // The modified render variables list
- CRenderVariable *_ModifiedRenderState;
-
- // Internal shaders
- CD3DShaderFX _ShaderLightmap0;
- CD3DShaderFX _ShaderLightmap1;
- CD3DShaderFX _ShaderLightmap2;
- CD3DShaderFX _ShaderLightmap3;
- CD3DShaderFX _ShaderLightmap4;
- CD3DShaderFX _ShaderLightmap0Blend;
- CD3DShaderFX _ShaderLightmap1Blend;
- CD3DShaderFX _ShaderLightmap2Blend;
- CD3DShaderFX _ShaderLightmap3Blend;
- CD3DShaderFX _ShaderLightmap4Blend;
- CD3DShaderFX _ShaderLightmap0X2;
- CD3DShaderFX _ShaderLightmap1X2;
- CD3DShaderFX _ShaderLightmap2X2;
- CD3DShaderFX _ShaderLightmap3X2;
- CD3DShaderFX _ShaderLightmap4X2;
- CD3DShaderFX _ShaderLightmap0BlendX2;
- CD3DShaderFX _ShaderLightmap1BlendX2;
- CD3DShaderFX _ShaderLightmap2BlendX2;
- CD3DShaderFX _ShaderLightmap3BlendX2;
- CD3DShaderFX _ShaderLightmap4BlendX2;
- CD3DShaderFX _ShaderCloud;
- CD3DShaderFX _ShaderWaterNoDiffuse;
- CD3DShaderFX _ShaderWaterDiffuse;
-
-
- // Backup frame buffer
- IDirect3DSurface9 *_BackBuffer;
-
- // Static bitmap buffer to convert rgba to bgra
- static std::vector _TempBuffer;
-
- // Version of the driver. Not the interface version!! Increment when implementation of the driver change.
- static const uint32 ReleaseVersion;
-
- uint64 _SwapBufferCounter;
-
- // occlusion query
- bool _OcclusionQuerySupported;
- TOcclusionQueryList _OcclusionQueryList;
-
- // depth range
- float _DepthRangeNear;
- float _DepthRangeFar;
- //
- bool _ScissorTouched;
- uint8 _CurrentUVRouting[MaxTexture];
- bool _MustRestoreLight;
- D3DXMATRIX _D3DMatrixIdentity;
- DWORD _FogColor;
- uint _AnisotropicFilter;
-
- // stencil buffer
- bool _CurStencilTest;
- DWORD _CurStencilFunc;
- DWORD _CurStencilRef;
- DWORD _CurStencilMask;
- DWORD _CurStencilOpFail;
- DWORD _CurStencilOpZFail;
- DWORD _CurStencilOpZPass;
- DWORD _CurStencilWriteMask;
-
-public:
-
- // private, for access by COcclusionQueryD3D
- COcclusionQueryD3D *_CurrentOcclusionQuery;
-
- // *** Lightmap Dynamic Light
- // For Lightmap Dynamic Lighting
- CLight _LightMapDynamicLight;
- bool _LightMapDynamicLightEnabled;
- bool _LightMapDynamicLightDirty;
- CMaterial::TShader _CurrentMaterialSupportedShader;
- // this is the backup of standard lighting (cause GL states may be modified by Lightmap Dynamic Lighting)
- CLight _UserLight0;
- bool _UserLightEnable[MaxLight];
- // methods to enable / disable DX light, without affecting _LightMapDynamicLight*, or _UserLight0*
- void setLightInternal(uint8 num, const CLight& light);
- void enableLightInternal(uint8 num, bool enable);
- // on/off Lights for LightMap mode: only the first light is enabled in lightmap mode
- void setupLightMapDynamicLighting(bool enable);
-
- TCullMode _CullMode;
-
- bool _Lost;
- bool _SceneBegun;
-
- WORD _DesktopGammaRamp[256 * 3];
- bool _DesktopGammaRampValid;
-
- // for debug only
- static bool _CacheTest[CacheTest_Count];
-
- static std::vector _QuadIndices; // tmp : quads indices -> to allow support of quads on devices that don't have 32 bit indices
-
- // reset an index buffer and force it to be reallocated
- void deleteIndexBuffer(CIBDrvInfosD3D *ib);
- // Build 16 bit index buffer for quad
- bool buildQuadIndexBuffer();
-
- // Test if cursor is in the client area. always true when software cursor is used and window visible
- // (displayed in software when DirectInput is used)
- bool isSystemCursorInClientArea();
-
- // Check if RGBA cursors are supported
- bool isAlphaBlendedCursorSupported();
-
- // Update cursor appearance
- void updateCursor(bool forceRebuild = false);
-
- // Create default cursors
- void createCursors();
-
- // Release all cursors
- void releaseCursors();
-
- // Convert a NLMISC::CBitmap to nlCursor
- bool convertBitmapToCursor(const NLMISC::CBitmap &bitmap, nlCursor &cursor, uint iconWidth, uint iconHeight, uint iconDepth, const NLMISC::CRGBA &col, sint hotSpotX, sint hotSpotY);
-
- // build a cursor from src, src should have the same size that the hardware cursor
- // or a assertion is thrown
- nlCursor buildCursor(const NLMISC::CBitmap &src, NLMISC::CRGBA col, uint8 rot, sint hotSpotX, sint hotSpotY);
-
- // reset the cursor shape to the system arrow
- void setSystemArrow();
-
- bool convertBitmapToIcon(const NLMISC::CBitmap &bitmap, HICON &icon, uint iconWidth, uint iconHeight, uint iconDepth, const NLMISC::CRGBA &col = NLMISC::CRGBA::White, sint hotSpotX = 0, sint hotSpotY = 0, bool cursor = false);
-
- virtual bool copyTextToClipboard(const ucstring &text);
- virtual bool pasteTextFromClipboard(ucstring &text);
-
-public:
- #ifdef NL_DEBUG
- std::set _LockedBuffers;
- #endif
-
- emptyProc ExitFunc;
-
- bool beginScene()
- {
- nlassert(!_SceneBegun);
- if (_DeviceInterface->BeginScene() != D3D_OK) return false;
- _SceneBegun = true;
- return true;
- }
-
- bool endScene()
- {
- nlassert(_SceneBegun);
- if (_DeviceInterface->EndScene() != D3D_OK) return false;
- _SceneBegun = false;
- return true;
- }
-
- bool hasSceneBegun() const { return _SceneBegun; }
-
- // Clip the wanted rectangle with window. return true if rect is not NULL.
- bool clipRect(NLMISC::CRect &rect);
-
- friend class IShaderDrvInfos;
-
- void removeShaderDrvInfoPtr(ItShaderDrvInfoPtrList shaderIt);
-
-};
-
-#define NL_D3DCOLOR_RGBA(rgba) (D3DCOLOR_ARGB(rgba.A,rgba.R,rgba.G,rgba.B))
-#define D3DCOLOR_NL_RGBA(rgba) (NLMISC::CRGBA((uint8)((rgba>>16)&0xff), (uint8)((rgba>>8)&0xff), (uint8)(rgba&0xff), (uint8)((rgba>>24)&0xff)))
-#define NL_D3DCOLORVALUE_RGBA(dest,rgba) \
- dest.a=(float)rgba.A*(1.f/255.f);dest.r=(float)rgba.R*(1.f/255.f);dest.g=(float)rgba.G*(1.f/255.f);dest.b=(float)rgba.B*(1.f/255.f);
-#define NL_D3D_MATRIX(d3d_mt,nl_mt) \
- { const float *nl_mt_ptr = nl_mt.get(); \
- d3d_mt._11 = nl_mt_ptr[0]; \
- d3d_mt._21 = nl_mt_ptr[4]; \
- d3d_mt._31 = nl_mt_ptr[8]; \
- d3d_mt._41 = nl_mt_ptr[12]; \
- d3d_mt._12 = nl_mt_ptr[1]; \
- d3d_mt._22 = nl_mt_ptr[5]; \
- d3d_mt._32 = nl_mt_ptr[9]; \
- d3d_mt._42 = nl_mt_ptr[13]; \
- d3d_mt._13 = nl_mt_ptr[2]; \
- d3d_mt._23 = nl_mt_ptr[6]; \
- d3d_mt._33 = nl_mt_ptr[10]; \
- d3d_mt._43 = nl_mt_ptr[14]; \
- d3d_mt._14 = nl_mt_ptr[3]; \
- d3d_mt._24 = nl_mt_ptr[7]; \
- d3d_mt._34 = nl_mt_ptr[11]; \
- d3d_mt._44 = nl_mt_ptr[15]; }
-// build matrix for texture 2D transform (special case in D3D)
-#define NL_D3D_TEX2D_MATRIX(d3d_mt,nl_mt) \
- { const float *nl_mt_ptr = nl_mt.get(); \
- d3d_mt._11 = nl_mt_ptr[0]; \
- d3d_mt._12 = nl_mt_ptr[1]; \
- d3d_mt._13 = nl_mt_ptr[3]; \
- d3d_mt._14 = 0.f; \
- d3d_mt._21 = nl_mt_ptr[4]; \
- d3d_mt._22 = nl_mt_ptr[5]; \
- d3d_mt._23 = nl_mt_ptr[7]; \
- d3d_mt._24 = 0.f; \
- d3d_mt._31 = nl_mt_ptr[12]; \
- d3d_mt._32 = nl_mt_ptr[13]; \
- d3d_mt._33 = nl_mt_ptr[15]; \
- d3d_mt._34 = 0.f; \
- d3d_mt._41 = 0.f; \
- d3d_mt._42 = 0.f; \
- d3d_mt._43 = 0.f; \
- d3d_mt._44 = 1.f; }
-
-
-
-
-
-
-#define NL_D3DVECTOR_VECTOR(dest,vect) dest.x=(vect).x;dest.y=(vect).y;dest.z=(vect).z;
-#define FTODW(f) (*((DWORD*)&(f)))
-#define D3DCOLOR_FLOATS(floats,rgba) {floats[0]=(float)((rgba>>16)&0xff) * (1.f/255.f);floats[1]=(float)((rgba>>8)&0xff) * (1.f/255.f);\
- floats[2]=(float)(rgba&0xff) * (1.f/255.f);floats[3]=(float)((rgba>>24)&0xff) * (1.f/255.f);}
-#define NL_FLOATS(floats,rgba) {floats[0] = (float)rgba.R * (1.f/255.f);floats[1] = (float)rgba.G * (1.f/255.f);\
- floats[2] = (float)rgba.B * (1.f/255.f);floats[3] = (float)rgba.A * (1.f/255.f);}
-
-// ***************************************************************************
-// nbPixels is pixel count, not a byte count !
-inline void copyRGBA2BGRA (uint32 *dest, const uint32 *src, uint nbPixels)
-{
- H_AUTO_D3D(CDriverD3D_copyRGBA2BGRA);
- while (nbPixels != 0)
- {
- register uint32 color = *src;
- *dest = (color & 0xff00ff00) | ((color&0xff)<<16) | ((color&0xff0000)>>16);
- dest++;
- src++;
- nbPixels--;
- }
-}
-
-
-// ***************************************************************************
-// set a D3DCOLORVALUE
-inline void setColor(D3DCOLORVALUE &dest, float r, float g, float b, float a)
-{
- dest.r = r;
- dest.g = g;
- dest.b = b;
- dest.a = a;
-}
-
-// ***************************************************************************
-// set a D3DCOLORVALUE from & D3DCOLOR
-inline void setColor(D3DCOLORVALUE &dest, const D3DCOLOR &src)
-{
- dest.r = (1.f / 255.f) * ((src >> 16) & 0xff);
- dest.g = (1.f / 255.f) * ((src >> 8) & 0xff);
- dest.b = (1.f / 255.f) * (src & 0xff);
- dest.a = (1.f / 255.f) * (src >> 24);
-}
-
-// ***************************************************************************
-// set a D3DCOLORVALUE from a CRGBA
-inline void setColor(D3DCOLORVALUE &dest, const NLMISC::CRGBA &src)
-{
- dest.r = (1.f / 255.f) * src.R;
- dest.g = (1.f / 255.f) * src.G;
- dest.b = (1.f / 255.f) * src.B;
- dest.a = (1.f / 255.f) * src.A;
-}
-
-// ***************************************************************************
-void fillQuadIndexes (uint16 *indexes, uint first, uint last);
-
-} // NL3D
-
-#ifndef NL_STATIC
-extern HINSTANCE HInstDLL;
-#endif
-
-#endif // NL_DRIVER_DIRECT3D_H
diff --git a/code/nel/src/3d/driver/direct3d/driver_direct3d_index.cpp b/code/nel/src/3d/driver/direct3d/driver_direct3d_index.cpp
deleted file mode 100644
index d7ee84303..000000000
--- a/code/nel/src/3d/driver/direct3d/driver_direct3d_index.cpp
+++ /dev/null
@@ -1,515 +0,0 @@
-// NeL - MMORPG Framework
-// Copyright (C) 2010 Winch Gate Property Limited
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Affero General Public License as
-// published by the Free Software Foundation, either version 3 of the
-// License, or (at your option) any later version.
-//
-// This program 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 Affero General Public License for more details.
-//
-// You should have received a copy of the GNU Affero General Public License
-// along with this program. If not, see .
-
-#include "stddirect3d.h"
-
-#include "nel/3d/index_buffer.h"
-#include "nel/3d/light.h"
-#include "nel/misc/rect.h"
-#include "nel/3d/viewport.h"
-#include "nel/3d/scissor.h"
-#include "nel/3d/u_driver.h"
-
-#include "driver_direct3d.h"
-
-#ifdef DEBUG_NEW
-#define new DEBUG_NEW
-#endif
-
-using namespace std;
-using namespace NLMISC;
-
-namespace NL3D
-{
-
-// ***************************************************************************
-
-CIBDrvInfosD3D::CIBDrvInfosD3D(CDriverD3D *drv, ItIBDrvInfoPtrList it, CIndexBuffer *ib) : IIBDrvInfos(drv, it, ib)
-{
- H_AUTO_D3D(CIBDrvInfosD3D_CIBDrvInfosD3D)
- Driver = drv;
- IndexBuffer = NULL;
- VolatileIndexBuffer = NULL;
-
-}
-
-// ***************************************************************************
-
-uint indexCount=0;
-
-CIBDrvInfosD3D::~CIBDrvInfosD3D()
-{
- H_AUTO_D3D(CIBDrvInfosD3D_CIBDrvInfosD3DDtor);
- // Restore non resident memory
- if (IndexBufferPtr)
- {
- IndexBufferPtr->setLocation(CIndexBuffer::NotResident);
- IndexBufferPtr= NULL;
- }
-
- // release index buffer
- if (IndexBuffer && !Volatile)
- {
- if (Driver)
- {
- if (Driver->_IndexBufferCache.IndexBuffer == IndexBuffer)
- {
- Driver->_IndexBufferCache.IndexBuffer = NULL;
- Driver->touchRenderVariable(&Driver->_IndexBufferCache);
- }
- }
- indexCount--;
- IndexBuffer->Release();
- }
-}
-
-// ***************************************************************************
-
-void *CIBDrvInfosD3D::lock (uint first, uint last, bool readOnly)
-{
- H_AUTO_D3D(CIBDrvInfosD3D_lock);
- nlassert (first != last);
- CDriverD3D *driver = static_cast(_Driver);
-
- if (driver->getMaxVertexIndex() <= 0xffff && getFormat() != CIndexBuffer::Indices16)
- {
- nlassert(getFormat() == CIndexBuffer::Indices32);
- // 32-bit index not supported -> uses RAM mirror
- nlassert(!RamVersion.empty());
- return &RamVersion[0];
- }
- else
- {
- if (Volatile)
- {
- // Lock the good buffer
- CVolatileIndexBuffer **buffer = NULL;
- if (getFormat() == CIndexBuffer::Indices16)
- {
- buffer = VolatileRAM ? (&driver->_VolatileIndexBuffer16RAM[driver->_CurrentRenderPass&1]):(&driver->_VolatileIndexBuffer16AGP[driver->_CurrentRenderPass&1]);
- }
- else if (getFormat() == CIndexBuffer::Indices32)
- {
- buffer = VolatileRAM ? (&driver->_VolatileIndexBuffer32RAM[driver->_CurrentRenderPass&1]):(&driver->_VolatileIndexBuffer32AGP[driver->_CurrentRenderPass&1]);
- }
- else
- {
- nlassert(0);
- }
- void *ptr = (*buffer)->lock ((last-first)*getIndexNumBytes(), Offset);
- if (!ptr)
- {
- // buffer full, swap them
- CVolatileIndexBuffer **bufferOther;
- if (getFormat() == CIndexBuffer::Indices16)
- {
- bufferOther = VolatileRAM ? (&driver->_VolatileIndexBuffer16RAM[(driver->_CurrentRenderPass + 1) &1]):(&driver->_VolatileIndexBuffer16AGP[(driver->_CurrentRenderPass + 1 ) &1]);
- }
- else
- {
- bufferOther = VolatileRAM ? (&driver->_VolatileIndexBuffer32RAM[(driver->_CurrentRenderPass + 1) &1]):(&driver->_VolatileIndexBuffer32AGP[(driver->_CurrentRenderPass + 1 ) &1]);
- }
- std::swap(*buffer, *bufferOther);
- (*buffer)->reset();
- ptr = (*buffer)->lock ((last-first)*getIndexNumBytes(), Offset);
- nlassert(ptr);
- }
- nlassert(!VolatileIndexBuffer);
- VolatileIndexBuffer = *buffer;
- IndexBuffer = (*buffer)->IndexBuffer;
- ptr = (uint8 *) ptr - first * getIndexNumBytes();
-
- // Current lock time
- VolatileLockTime = driver->_CurrentRenderPass;
-
- // Touch the index buffer
- driver->touchRenderVariable (&driver->_IndexBufferCache);
-
- return ptr;
- }
- else
- {
- nlassert (IndexBuffer);
- // Lock Profile?
- TTicks beforeLock = 0;
- if(driver->_IBProfiling /*&& Hardware*/)
- {
- beforeLock= CTime::getPerformanceTime();
- }
- void *pbData;
- HRESULT result = IndexBuffer->Lock ( first*getIndexNumBytes(), (last-first)*getIndexNumBytes(), &pbData, readOnly?D3DLOCK_READONLY:0);
- nlassert(result == D3D_OK);
- // Lock Profile?
- if(driver->_IBProfiling /*&& Hardware*/)
- {
- TTicks afterLock;
- afterLock= CTime::getPerformanceTime();
- driver->appendIBLockProfile(afterLock-beforeLock, IndexBufferPtr);
- }
- if (result == D3D_OK) return pbData;
- }
- }
- return NULL;
-}
-
-// ***************************************************************************
-
-void CIBDrvInfosD3D::unlock (uint /* first */, uint /* last */)
-{
- H_AUTO_D3D(CIBDrvInfosD3D_unlock)
- CDriverD3D *driver = static_cast(_Driver);
- if (driver->getMaxVertexIndex() > 0xffff || getFormat() == CIndexBuffer::Indices16)
- {
- if (Volatile)
- {
- nlassert(VolatileIndexBuffer);
- VolatileIndexBuffer->unlock ();
- VolatileIndexBuffer = NULL;
- }
- else
- {
- if (IndexBuffer) IndexBuffer->Unlock ();
- }
- }
-}
-
-// ***************************************************************************
-
-DWORD RemapIndexBufferUsage[CIndexBuffer::LocationCount]=
-{
- D3DUSAGE_DYNAMIC, // RAMResident
- D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY, // AGPResident
- D3DUSAGE_WRITEONLY, // VRAMResident
- 0, // Not used
-};
-
-// ***************************************************************************
-
-D3DPOOL RemapIndexBufferPool[CIndexBuffer::LocationCount]=
-{
- D3DPOOL_SYSTEMMEM, // RAMResident
- D3DPOOL_DEFAULT, // AGPResident
- D3DPOOL_DEFAULT, // VRAMResident
- D3DPOOL_DEFAULT, // Not used
-};
-
-// ***************************************************************************
-
-bool CDriverD3D::activeIndexBuffer(CIndexBuffer& IB)
-{
- H_AUTO_D3D(CDriverD3D_activeIndexBuffer)
-
- // Must not be locked
- nlassert (!IB.isLocked());
-
- // Must not be empty
- if (IB.capacity() == 0)
- return false;
-
- const bool touched = (IB.getTouchFlags() & (CIndexBuffer::TouchedReserve|CIndexBuffer::TouchedIndexFormat)) != 0;
- CIBDrvInfosD3D *info = static_cast(static_cast(IB.DrvInfos));
-
- // Volatile buffers must be filled at each pass (exception if emulated)
- if (_MaxVertexIndex > 0xffff)
- {
- nlassertex (!info || !info->Volatile || IB.getKeepLocalMemory() || (info->VolatileLockTime == _CurrentRenderPass), ("Volatile buffers must be filled at each pass"));
- }
-
- // Build the driver info
- if (touched)
- {
- // Delete previous index buffer info
- if (IB.DrvInfos)
- {
- delete IB.DrvInfos;
- nlassert (IB.DrvInfos == NULL);
- }
-
- // Rebuild it
- _IBDrvInfos.push_front (NULL);
- ItIBDrvInfoPtrList ite = _IBDrvInfos.begin();
- info = new CIBDrvInfosD3D(this, ite, &IB);
- *ite = info;
- // Create the index buffer
- const uint size = (uint)IB.capacity();
- uint preferredMemory = 0;
- if (_DisableHardwareIndexArrayAGP)
- {
- preferredMemory = CIndexBuffer::RAMResident;
- info->Volatile = false;
- }
- else
- {
- switch (IB.getPreferredMemory ())
- {
- case CIndexBuffer::RAMPreferred:
- preferredMemory = CIndexBuffer::RAMResident;
- info->Volatile = false;
- break;
- case CIndexBuffer::AGPPreferred:
- preferredMemory = CIndexBuffer::AGPResident;
- info->Volatile = false;
- break;
- case CIndexBuffer::StaticPreferred:
- if (getStaticMemoryToVRAM())
- preferredMemory = CIndexBuffer::VRAMResident;
- else
- preferredMemory = CIndexBuffer::AGPResident;
- info->Volatile = false;
- break;
- case CIndexBuffer::RAMVolatile:
- preferredMemory = CIndexBuffer::RAMResident;
- info->Volatile = true;
- break;
- case CIndexBuffer::AGPVolatile:
- preferredMemory = CIndexBuffer::AGPResident;
- info->Volatile = true;
- break;
- }
- }
-
- // if 32 bit index not supported, the index buffer will be reformated so return a RAM mirror
- // Real index buffer will be allocated if indices are not modified (e.g a single lock is used to update the content)
- if (_MaxVertexIndex <= 0xffff && IB.getFormat() == CIndexBuffer::Indices32)
- {
- info->RamVersion.resize(size);
- info->IndexBuffer = NULL;
- }
- else
- {
- // Volatile index buffer
- if (info->Volatile)
- {
- nlassert (info->IndexBuffer == NULL);
- info->VolatileRAM = preferredMemory == CIndexBuffer::RAMResident;
- }
- else
- {
- // Offset will be 0
- info->Offset = 0;
- bool success = false;
- do
- {
- success = _DeviceInterface->CreateIndexBuffer(size*IB.getIndexNumBytes(),
- RemapIndexBufferUsage[preferredMemory],
- IB.getFormat() == CIndexBuffer::Indices32 ? D3DFMT_INDEX32 : D3DFMT_INDEX16,
- RemapIndexBufferPool[preferredMemory],
- &(info->IndexBuffer), NULL) == D3D_OK;
-
- if (success)
- break;
- }
- while (preferredMemory--);
- if (!success)
- return false;
- ++indexCount;
- }
- // Force the vertex buffer update
- touchRenderVariable (&_IndexBufferCache);
- }
- // Release the local index buffer
- IB.DrvInfos = info;
- IB.setLocation((CIndexBuffer::TLocation)preferredMemory);
- }
-
- // Set the current index buffer
- nlassert (info);
- _LastIndexBufferInfo = info;
-
- // Fill the buffer if in local memory
- IB.fillBuffer ();
-
- _CurrIndexBufferFormat = IB.getFormat();
-
- // Set the index buffer
- if (_MaxVertexIndex > 0xffff || IB.getFormat() == CIndexBuffer::Indices16)
- {
- setIndexBuffer (info->IndexBuffer, info->Offset);
- }
- return true;
-}
-
-// ***************************************************************************
-
-bool CDriverD3D::supportIndexBufferHard() const
-{
- H_AUTO_D3D(CDriverD3D_supportIndexBufferHard);
- return !_DisableHardwareIndexArrayAGP;
-}
-
-// ***************************************************************************
-
-void CDriverD3D::disableHardwareIndexArrayAGP()
-{
- H_AUTO_D3D(CDriverD3D_disableHardwareIndexArrayAGP)
- _DisableHardwareIndexArrayAGP = true;
-}
-
-// ***************************************************************************
-// CVolatileIndexBuffer
-// ***************************************************************************
-
-CVolatileIndexBuffer::CVolatileIndexBuffer()
-{
- H_AUTO_D3D(CVolatileIndexBuffer_CVolatileIndexBuffer);
- IndexBuffer = NULL;
- Locked = false;
-}
-
-// ***************************************************************************
-
-CVolatileIndexBuffer::~CVolatileIndexBuffer()
-{
- H_AUTO_D3D(CVolatileIndexBuffer_CVolatileIndexBufferDtor);
- release ();
-}
-
-// ***************************************************************************
-
-void CVolatileIndexBuffer::release ()
-{
- H_AUTO_D3D(CVolatileIndexBuffer_release);
- if (IndexBuffer)
- IndexBuffer->Release();
- IndexBuffer = NULL;
-}
-
-// ***************************************************************************
-void CVolatileIndexBuffer::init (CIndexBuffer::TLocation location, uint sizeInBytes, uint maxSize, CDriverD3D *driver, CIndexBuffer::TFormat format)
-{
- H_AUTO_D3D(CVolatileIndexBuffer_init);
- release();
- if (maxSize < sizeInBytes) maxSize = sizeInBytes;
-
- // Init the buffer
- Location = location;
- Size = sizeInBytes;
- MaxSize = maxSize;
- Driver = driver;
-
- nlassert(format == CIndexBuffer::Indices16 || format == CIndexBuffer::Indices32);
- if (format == CIndexBuffer::Indices32)
- {
- // device must support 32 bits indices
- nlassert(driver->_MaxVertexIndex > 0xffff);
- }
- D3DFORMAT d3dFormat = format == CIndexBuffer::Indices16 ? D3DFMT_INDEX16 : D3DFMT_INDEX32;
-
- // Allocate the vertex buffer
- if (Driver->_DeviceInterface->CreateIndexBuffer(sizeInBytes, RemapIndexBufferUsage[location],
- d3dFormat, RemapIndexBufferPool[location], &IndexBuffer, NULL) != D3D_OK)
- {
- // Location in RAM must not failed
- nlassert (location != CIndexBuffer::RAMResident);
-
- // Allocate in RAM
- nlverify (Driver->_DeviceInterface->CreateIndexBuffer(sizeInBytes, RemapIndexBufferUsage[CIndexBuffer::RAMResident],
- d3dFormat, RemapIndexBufferPool[CIndexBuffer::RAMResident], &IndexBuffer, NULL) != D3D_OK);
- Location = CIndexBuffer::RAMResident;
- }
- Format = format;
-}
-
-
-
-
-// ***************************************************************************
-void *CVolatileIndexBuffer::lock (uint size, uint &offset)
-{
- nlassertex(!Locked, ("Volatile buffer usage should follow an atomic lock/unlock/render sequence"));
- H_AUTO_D3D(CVolatileIndexBuffer_lock);
- /* If not enough room to allocate this buffer, resise the buffer to Size+Size/2 but do not reset CurrentIndex
- * to be sure the buffer will be large enough next pass. */
-
- // Enough room for this index ?
- if (CurrentIndex+size > Size)
- {
- if (CurrentIndex+size > MaxSize && CurrentIndex != 0)
- {
- return NULL; // max size exceeded -> can reallocate only if we are at start of block
- }
- // No, reallocate
- init (Location, std::max (std::min(Size+Size/2, MaxSize), CurrentIndex+size), MaxSize, Driver, Format);
- }
- // Lock Profile?
- TTicks beforeLock = 0;
- if(Driver->_IBProfiling /*&& Hardware*/)
- {
- beforeLock= CTime::getPerformanceTime();
- }
- // Lock the buffer, noblocking lock here if not the first allocation since a reset
- VOID *pbData;
- if (CurrentIndex==0)
- {
- nlverify (IndexBuffer->Lock (0, size, &pbData, 0) == D3D_OK);
- }
- else
- {
- nlverify (IndexBuffer->Lock (CurrentIndex, size, &pbData, D3DLOCK_NOOVERWRITE) == D3D_OK);
- }
- if(Driver->_IBProfiling /*&& Hardware*/)
- {
- TTicks afterLock;
- afterLock= CTime::getPerformanceTime();
- Driver->_VolatileIBLockTime += afterLock - beforeLock;
- }
-
- // Old buffer position
- offset = CurrentIndex / (Format == CIndexBuffer::Indices32 ? sizeof(uint32) : sizeof(uint16));
-
- // New buffer position
- CurrentIndex += size;
- Locked = true;
- return pbData;
-}
-
-// ***************************************************************************
-
-void CVolatileIndexBuffer::unlock ()
-{
- H_AUTO_D3D(CVolatileIndexBuffer_unlock);
- nlassertex(Locked, ("Volatile buffer usage should follow an atomic lock/unlock/render sequence"));
- nlverify (IndexBuffer->Unlock () == D3D_OK);
- Locked = false;
-}
-
-// ***************************************************************************
-void CVolatileIndexBuffer::reset ()
-{
- H_AUTO_D3D(CVolatileIndexBuffer_reset);
- CurrentIndex = 0;
-}
-
-// ***************************************************************************
-bool CDriverD3D::buildQuadIndexBuffer()
-{
- // this code will becomes useless when 16 bits buffer are really supported
- nlassert(!_QuadIB);
- uint numQuads = std::min(MAX_NUM_QUADS, (uint) (_MaxPrimitiveCount * 2)); // 2 primitives for each quads
- HRESULT r = _DeviceInterface->CreateIndexBuffer(sizeof(uint16) * 6 * numQuads, D3DUSAGE_DYNAMIC, D3DFMT_INDEX16, D3DPOOL_SYSTEMMEM, &_QuadIB, NULL);
- if (r != D3D_OK) return false;
- void *datas;
- r = _QuadIB->Lock(0, sizeof(uint16) * 6 * numQuads, &datas, 0);
- if (r != D3D_OK) return false;
- fillQuadIndexes((uint16 *) datas, 0, 6 * numQuads);
- _QuadIB->Unlock();
- return true;
-}
-
-
-// ***************************************************************************
-
-} // NL3D
diff --git a/code/nel/src/3d/driver/direct3d/driver_direct3d_inputs.cpp b/code/nel/src/3d/driver/direct3d/driver_direct3d_inputs.cpp
deleted file mode 100644
index d26741faf..000000000
--- a/code/nel/src/3d/driver/direct3d/driver_direct3d_inputs.cpp
+++ /dev/null
@@ -1,475 +0,0 @@
-// NeL - MMORPG Framework
-// Copyright (C) 2010 Winch Gate Property Limited
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Affero General Public License as
-// published by the Free Software Foundation, either version 3 of the
-// License, or (at your option) any later version.
-//
-// This program 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 Affero General Public License for more details.
-//
-// You should have received a copy of the GNU Affero General Public License
-// along with this program. If not, see .
-
-#include "stddirect3d.h"
-#include "driver_direct3d.h"
-
-#ifdef DEBUG_NEW
-#define new DEBUG_NEW
-#endif
-
-using namespace std;
-using namespace NLMISC;
-
-namespace NL3D
-{
-
-// *************************************************************************************
-CDriverD3D::CCursor::CCursor() : ColorDepth(CDriverD3D::ColorDepth32),
- OrigHeight(32),
- HotspotScale(1.f),
- HotspotOffsetX(0),
- HotspotOffsetY(0),
- HotSpotX(0),
- HotSpotY(0),
- Cursor(EmptyCursor),
- Col(CRGBA::White),
- Rot(0)
-{
-}
-
-// *************************************************************************************
-CDriverD3D::CCursor::~CCursor()
-{
- reset();
-}
-
-// *************************************************************************************
-void CDriverD3D::CCursor::reset()
-{
- if (Cursor != EmptyCursor)
- {
- DestroyIcon(Cursor);
- }
-}
-
-// *************************************************************************************
-CDriverD3D::CCursor& CDriverD3D::CCursor::operator= (const CDriverD3D::CCursor& from)
-{
- if (&from == this)
- return *this;
- Src = from.Src; // requires more than a surface copy
- OrigHeight = from.OrigHeight;
- HotspotScale = from.HotspotScale;
- HotspotOffsetX = from.HotspotOffsetX;
- HotspotOffsetY = from.HotspotOffsetY;
- HotSpotX = from.HotSpotX;
- HotSpotY = from.HotSpotY;
- Cursor = from.Cursor;
- Col = from.Col;
- Rot = from.Rot;
- return *this;
-}
-
-// *************************************************************************************
-bool CDriverD3D::isAlphaBlendedCursorSupported()
-{
- if (!_AlphaBlendedCursorSupportRetrieved)
- {
- // Support starts with windows 2000 (not only from XP as seen in most docs)
- // NB : Additionnaly, could query D3D caps to know if
- // color hardware cursor is supported, not only emulated,
- // but can't be sure that using the win32 api 'SetCursor' uses the same resources
- // So far, seems to be supported on any modern card used by the game anyway ...
- OSVERSIONINFO osvi;
- osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
- if (GetVersionEx(&osvi))
- {
- _AlphaBlendedCursorSupported = (osvi.dwMajorVersion >= 5);
- }
-
- _AlphaBlendedCursorSupportRetrieved = true;
- }
-
- return _AlphaBlendedCursorSupported;
-}
-
-// *************************************************************************************
-void CDriverD3D::addCursor(const std::string &name, const NLMISC::CBitmap &cursorBitmap)
-{
- if (!isAlphaBlendedCursorSupported()) return;
-
- nlassert(cursorBitmap.getWidth() != 0);
- nlassert(cursorBitmap.getHeight() != 0);
-
- // find used part base on alpha, to avoid too much shrinking
- const CRGBA *pixels = (const CRGBA *) &cursorBitmap.getPixels()[0];
- uint minX, maxX, minY, maxY;
- uint width = cursorBitmap.getWidth();
- uint height = cursorBitmap.getHeight();
- //
- minX = 0;
- for (uint x = 0; x < width; ++x)
- {
- bool stop = false;
- minX = x;
- for (uint y = 0; y < height; ++y)
- {
- if(pixels[x + y * width].A != 0)
- {
- stop = true;
- break;
- }
- }
- if (stop) break;
- }
- //
- maxX = width - 1;
- for (sint x = width - 1; x >= 0; --x)
- {
- bool stop = false;
- maxX = (uint) x;
- for (uint y = 0; y < height; ++y)
- {
- if(pixels[x + y * width].A != 0)
- {
- stop = true;
- break;
- }
- }
- if (stop) break;
- }
- //
- minY = 0;
- for (uint y = 0; y < height; ++y)
- {
- bool stop = false;
- minY = y;
- for (uint x = 0; x < width; ++x)
- {
- if(pixels[x + y * width].A != 0)
- {
- stop = true;
- break;
- }
- }
- if (stop) break;
- }
- //
- maxY = height - 1;
- for (sint y = height - 1; y >= 0; --y)
- {
- bool stop = false;
- maxY = (uint) y;
- for (uint x = 0; x < width; ++x)
- {
- if(pixels[x + y * width].A != 0)
- {
- stop = true;
- break;
- }
- }
- if (stop) break;
- }
- //
- CCursor &curs = _Cursors[name];
- curs = CCursor(); // erase possible previous cursor
-
- uint destWidth = GetSystemMetrics(SM_CXCURSOR);
- uint destHeight = GetSystemMetrics(SM_CYCURSOR);
-
- // build a square bitmap
- uint tmpSize = std::max(maxX - minX + 1, maxY - minY + 1);
- curs.Src.resize(tmpSize, tmpSize);
- // blit at top left corner
- curs.Src.blit(cursorBitmap, minX, minY, maxX - minX + 1, maxY - minY + 1, 0, 0);
-
- curs.OrigHeight = cursorBitmap.getHeight();
- curs.HotspotOffsetX = minX;
- curs.HotspotOffsetY = minY;
- //
- curs.HotspotScale = _CursorScale;
- clamp(curs.HotspotScale, 0.f, 1.f);
- // first resampling, same for all cursors
- tmpSize = (uint) (tmpSize * curs.HotspotScale);
- if (tmpSize == 0) tmpSize = 1;
-
- if (curs.HotspotScale < 1.f)
- {
- curs.Src.resample(tmpSize, tmpSize);
- }
-
- // shrink if necessary
- if (tmpSize > destWidth || tmpSize > destHeight) // need to shrink ?
- {
- // constraint proportions
- curs.HotspotScale *= std::min(float(destWidth) / tmpSize, float(destHeight) / tmpSize);
- curs.Src.resample(destWidth, destHeight);
- }
- else
- {
- CBitmap final;
- final.resize(destWidth, destHeight);
- final.blit(&curs.Src, 0, 0);
- curs.Src.swap(final);
- }
-
- if (name == _CurrName)
- {
- updateCursor();
- }
-}
-
-// *************************************************************************************
-void CDriverD3D::createCursors()
-{
- _DefaultCursor = LoadCursor(NULL, IDC_ARROW);
-}
-
-// *************************************************************************************
-void CDriverD3D::releaseCursors()
-{
- SetClassLongPtr(_HWnd, GCLP_HCURSOR, 0);
-
- _Cursors.clear();
-}
-
-// *************************************************************************************
-void CDriverD3D::updateCursor(bool forceRebuild)
-{
- setCursor(_CurrName, _CurrCol, _CurrRot, _CurrHotSpotX, _CurrHotSpotY, forceRebuild);
-}
-
-// *************************************************************************************
-void CDriverD3D::setCursor(const std::string &name, NLMISC::CRGBA col, uint8 rot, sint hotSpotX, sint hotSpotY, bool forceRebuild)
-{
- // don't update cursor if it's hidden or if custom cursors are not suppported
- if (!isAlphaBlendedCursorSupported() || _CurrName == "none") return;
-
- _CurrName = name;
- _CurrCol = col;
- _CurrRot = rot;
- _CurrHotSpotX = hotSpotX;
- _CurrHotSpotY = hotSpotY;
-
- // cursor has to be changed next time
- if (_CurrName.empty()) return;
-
- if (rot > 3) rot = 3; // same than 'CViewRenderer::drawRotFlipBitmapTiled
-
- TCursorMap::iterator it = _Cursors.find(name);
-
- nlCursor cursorHandle = _DefaultCursor;
-
- if (it != _Cursors.end())
- {
- // Update cursor if modified or not already built
- CCursor &curs = it->second;
- hotSpotX = (sint) (curs.HotspotScale * (hotSpotX - curs.HotspotOffsetX));
- hotSpotY = (sint) (curs.HotspotScale * ((curs.OrigHeight - hotSpotY) - curs.HotspotOffsetY));
- if (curs.Cursor == EmptyCursor ||
- curs.HotSpotX != hotSpotX ||
- curs.HotSpotY != hotSpotY ||
- curs.Col != col ||
- curs.Rot != rot ||
- curs.ColorDepth != _ColorDepth ||
- forceRebuild
- )
- {
- curs.reset();
- curs.Cursor = buildCursor(curs.Src, col, rot, hotSpotX, hotSpotY);
- curs.Col = col;
- curs.Rot = rot;
- curs.HotSpotX = hotSpotX;
- curs.HotSpotY = hotSpotY;
- curs.ColorDepth = _ColorDepth;
- }
- cursorHandle = curs.Cursor ? curs.Cursor : _DefaultCursor;
- }
-
- if (isSystemCursorInClientArea() || isSystemCursorCaptured() || forceRebuild)
- {
-// if (CInputHandlerManager::getInstance()->hasFocus())
- {
- ::SetCursor(cursorHandle);
- SetClassLongPtr(_HWnd, GCLP_HCURSOR, (LONG_PTR) cursorHandle); // set default mouse icon to the last one
- }
- }
-
-}
-
-// *************************************************************************************
-void CDriverD3D::setCursorScale(float scale)
-{
- _CursorScale = scale;
-}
-
-// *************************************************************************************
-nlCursor CDriverD3D::buildCursor(const CBitmap &src, NLMISC::CRGBA col, uint8 rot, sint hotSpotX, sint hotSpotY)
-{
- nlassert(isAlphaBlendedCursorSupported());
-
- uint mouseW = GetSystemMetrics(SM_CXCURSOR);
- uint mouseH = GetSystemMetrics(SM_CYCURSOR);
-
- CBitmap rotSrc = src;
- if (rot > 3) rot = 3; // mimic behavior of 'CViewRenderer::drawRotFlipBitmapTiled' (why not rot & 3 ??? ...)
- switch(rot)
- {
- case 0: break;
- case 1: rotSrc.rot90CW(); break;
- case 2: rotSrc.rot90CW(); rotSrc.rot90CW(); break;
- case 3: rotSrc.rot90CCW(); break;
- }
-
- // create a cursor from bitmap
- nlCursor result = NULL;
- convertBitmapToCursor(rotSrc, result, mouseW, mouseH, _ColorDepth == ColorDepth16 ? 16:32, col, hotSpotX, hotSpotY);
- return result;
-}
-
-
-// *************************************************************************************
-void CDriverD3D::setSystemArrow()
-{
- H_AUTO_D3D(CDriverD3D_setSystemArrow);
-
- if (isSystemCursorInClientArea() || isSystemCursorCaptured())
- {
- SetCursor(_DefaultCursor);
- }
-
- // set default mouse icon to the default one
- SetClassLongPtr(_HWnd, GCLP_HCURSOR, (LONG_PTR) _DefaultCursor);
-}
-
-// ***************************************************************************
-void CDriverD3D::showCursor(bool b)
-{
- H_AUTO_D3D(CDriverD3D_showCursor);
-
- if (_HWnd == EmptyWindow)
- return;
-
- if (b)
- {
- // update current hardware icon to avoid to have the plain arrow
- updateCursor(true);
-
- while (ShowCursor(b) < 0)
- ;
- }
- else
- {
- while (ShowCursor(b) >= 0)
- ;
- }
-}
-
-// ***************************************************************************
-void CDriverD3D::setMousePos(float x, float y)
-{
- H_AUTO_D3D(CDriverD3D_setMousePos);
-
- if (_HWnd == EmptyWindow)
- return;
-
- // convert position size from float to pixels
- sint x1 = (sint)((float)_CurrentMode.Width*x);
- sint y1 = (sint)((float)_CurrentMode.Height*(1.0f-y));
-
- // NeL window coordinate to MSWindows coordinates
- POINT pt;
- pt.x = x1;
- pt.y = y1;
- ClientToScreen (_HWnd, &pt);
- SetCursorPos(pt.x, pt.y);
-}
-
-// ***************************************************************************
-void CDriverD3D::setCapture (bool b)
-{
- H_AUTO_D3D(CDriverD3D_setCapture);
-
- if (b && isSystemCursorInClientArea() && !isSystemCursorCaptured())
- {
- SetCapture(_HWnd);
- }
- else if (!b && isSystemCursorCaptured())
- {
- // if hardware mouse and not in client area, then force to update its aspect by updating its pos
- if (!isSystemCursorInClientArea())
- {
- // force update
- showCursor(true);
- }
-
- ReleaseCapture();
- }
-}
-
-// ***************************************************************************
-bool CDriverD3D::isSystemCursorInClientArea()
-{
- if (_FullScreen /* || !IsMouseCursorHardware() */)
- {
- return IsWindowVisible(_HWnd) != FALSE;
- }
- else
- {
- POINT cursPos;
- // the mouse should be in the client area of the window
- if (!GetCursorPos(&cursPos))
- {
- return false;
- }
- HWND wnd = WindowFromPoint(cursPos);
- if (wnd != _HWnd)
- {
- return false; // not the same window
- }
- // want that the mouse be in the client area
- RECT clientRect;
- if (!GetClientRect(_HWnd, &clientRect))
- {
- return false;
- }
- POINT tl, br;
- tl.x = clientRect.left;
- tl.y = clientRect.top;
- br.x = clientRect.right;
- br.y = clientRect.bottom;
- if (!ClientToScreen(_HWnd, &tl))
- {
- return false;
- }
- if (!ClientToScreen(_HWnd, &br))
- {
- return false;
- }
- if ((cursPos.x < tl.x) || (cursPos.x >= br.x) || (cursPos.y < tl.y) || (cursPos.y >= br.y))
- {
- return false;
- }
- }
-
- return true;
-}
-
-// ***************************************************************************
-bool CDriverD3D::isSystemCursorCaptured()
-{
- H_AUTO_D3D(CDriverD3D_isSystemCursorCaptured);
-
- return GetCapture() == _HWnd;
-}
-
-bool CDriverD3D::convertBitmapToCursor(const NLMISC::CBitmap &bitmap, nlCursor &cursor, uint iconWidth, uint iconHeight, uint iconDepth, const NLMISC::CRGBA &col, sint hotSpotX, sint hotSpotY)
-{
- return convertBitmapToIcon(bitmap, cursor, iconWidth, iconHeight, iconDepth, col, hotSpotX, hotSpotY, true);
-}
-
-} // NL3D
diff --git a/code/nel/src/3d/driver/direct3d/driver_direct3d_light.cpp b/code/nel/src/3d/driver/direct3d/driver_direct3d_light.cpp
deleted file mode 100644
index f68caab3a..000000000
--- a/code/nel/src/3d/driver/direct3d/driver_direct3d_light.cpp
+++ /dev/null
@@ -1,213 +0,0 @@
-// NeL - MMORPG Framework
-// Copyright (C) 2010 Winch Gate Property Limited
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Affero General Public License as
-// published by the Free Software Foundation, either version 3 of the
-// License, or (at your option) any later version.
-//
-// This program 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 Affero General Public License for more details.
-//
-// You should have received a copy of the GNU Affero General Public License
-// along with this program. If not, see .
-
-#include "stddirect3d.h"
-
-#include "nel/3d/vertex_buffer.h"
-#include "nel/3d/light.h"
-#include "nel/3d/index_buffer.h"
-#include "nel/misc/rect.h"
-#include "nel/3d/viewport.h"
-#include "nel/3d/scissor.h"
-#include "nel/3d/u_driver.h"
-
-#include "driver_direct3d.h"
-
-#ifdef DEBUG_NEW
-#define new DEBUG_NEW
-#endif
-
-using namespace std;
-using namespace NLMISC;
-
-namespace NL3D
-{
-
-// ***************************************************************************
-const D3DLIGHTTYPE RemapLightTypeNeL2D3D[3]=
-{
- D3DLIGHT_DIRECTIONAL, // CLight::DirectionalLight
- D3DLIGHT_POINT, // CLight::PointLight
- D3DLIGHT_SPOT, // CLight::SpotLight
-};
-
-
-// ***************************************************************************
-void CDriverD3D::setLight (uint8 index, const CLight &light)
-{
- H_AUTO_D3D(CDriverD3D_setLight);
- // bkup real light, for lightmap dynamic lighting purpose
- if(index==0)
- {
- _UserLight0= light;
- // because the D3D setup change, must dirt lightmap rendering
- _LightMapDynamicLightDirty= true;
- }
-
- setLightInternal(index, light);
-}
-
-
-// ***************************************************************************
-void CDriverD3D::enableLight (uint8 index, bool enable)
-{
- H_AUTO_D3D(CDriverD3D_enableLight);
- // User call => set the User flag
- if(index
-// Copyright (C) 2010 Winch Gate Property Limited
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Affero General Public License as
-// published by the Free Software Foundation, either version 3 of the
-// License, or (at your option) any later version.
-//
-// This program 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 Affero General Public License for more details.
-//
-// You should have received a copy of the GNU Affero General Public License
-// along with this program. If not, see .
-
-#include "stddirect3d.h"
-
-#include "nel/3d/vertex_buffer.h"
-#include "nel/3d/light.h"
-#include "nel/3d/index_buffer.h"
-#include "nel/3d/texture_bump.h"
-#include "nel/misc/rect.h"
-#include "nel/3d/viewport.h"
-#include "nel/3d/scissor.h"
-#include "nel/3d/u_driver.h"
-
-#include "driver_direct3d.h"
-
-#ifdef DEBUG_NEW
-#define new DEBUG_NEW
-#endif
-
-using namespace std;
-using namespace NLMISC;
-
-
-
-
-namespace NL3D
-{
-
-// ***************************************************************************
-
-const D3DBLEND RemapBlendTypeNeL2D3D[CMaterial::blendCount]=
-{
- D3DBLEND_ONE, // one
- D3DBLEND_ZERO, // zero
- D3DBLEND_SRCALPHA, // srcalpha
- D3DBLEND_INVSRCALPHA, // invsrcalpha
- D3DBLEND_SRCCOLOR, // srccolor
- D3DBLEND_INVSRCCOLOR, // invsrccolor
- D3DBLEND_ONE, // blendConstantColor
- D3DBLEND_ONE, // blendConstantInvColor
- D3DBLEND_ONE, // blendConstantAlpha
- D3DBLEND_ONE, // blendConstantInvAlpha
-};
-
-// ***************************************************************************
-
-const D3DCMPFUNC RemapZFuncTypeNeL2D3D[CMaterial::zfuncCount]=
-{
- D3DCMP_ALWAYS, // always
- D3DCMP_NEVER, // never
- D3DCMP_EQUAL, // equal
- D3DCMP_NOTEQUAL, // notequal
- D3DCMP_LESS, // less
- D3DCMP_LESSEQUAL, // lessequal
- D3DCMP_GREATER, // greater
- D3DCMP_GREATEREQUAL,// greaterequal
-};
-
-// ***************************************************************************
-
-// For stage 0 only
-const D3DTEXTUREOP RemapTexOpType0NeL2D3D[CMaterial::TexOperatorCount]=
-{
- D3DTOP_SELECTARG1, // Replace
- D3DTOP_MODULATE, // Modulate
- D3DTOP_ADD, // Add
- D3DTOP_ADDSIGNED, // AddSigned
- D3DTOP_BLENDTEXTUREALPHA, // InterpolateTexture
- D3DTOP_BLENDDIFFUSEALPHA, // InterpolatePrevious
- D3DTOP_BLENDDIFFUSEALPHA, // InterpolateDiffuse
- D3DTOP_LERP, // InterpolateConstant
- D3DTOP_BUMPENVMAP, // EMBM
- D3DTOP_MULTIPLYADD // MAD
-};
-
-// ***************************************************************************
-
-const D3DTEXTUREOP RemapTexOpTypeNeL2D3D[CMaterial::TexOperatorCount]=
-{
- D3DTOP_SELECTARG1, // Replace
- D3DTOP_MODULATE, // Modulate
- D3DTOP_ADD, // Add
- D3DTOP_ADDSIGNED, // AddSigned
- D3DTOP_BLENDTEXTUREALPHA, // InterpolateTexture
- D3DTOP_BLENDCURRENTALPHA, // InterpolatePrevious
- D3DTOP_BLENDDIFFUSEALPHA, // InterpolateDiffuse
- D3DTOP_LERP, // InterpolateConstant
- D3DTOP_BUMPENVMAP, // EMBM
- D3DTOP_MULTIPLYADD // MAD
-};
-
-const uint OpNumArg[CMaterial::TexOperatorCount] =
-{
- 1, // Replace
- 2, // Modulate
- 2, // Add
- 2, // AddSigned
- 2, // InterpolateTexture
- 2, // InterpolatePrevious
- 2, // InterpolateDiffuse
- 3, // InterpolateConstant
- 2, // EMBM
- 3 // MAD
-};
-
-
-// ***************************************************************************
-
-// For stage 0 only
-const DWORD RemapTexArg0NeL2D3D[CMaterial::TexSourceCount]=
-{
- D3DTA_TEXTURE, // Texture
- D3DTA_DIFFUSE, // Previous
- D3DTA_DIFFUSE, // Diffuse
- D3DTA_TFACTOR, // todo hulud constant color D3DTA_CONSTANT, // Constant
-};
-
-// ***************************************************************************
-
-const DWORD RemapTexArgNeL2D3D[CMaterial::TexSourceCount]=
-{
- D3DTA_TEXTURE, // Texture
- D3DTA_CURRENT, // Previous
- D3DTA_DIFFUSE, // Diffuse
- D3DTA_TFACTOR, // todo hulud constant color D3DTA_CONSTANT, // Constant
-};
-
-// ***************************************************************************
-const DWORD RemapTexOpArgTypeNeL2D3D[CMaterial::TexOperandCount]=
-{
- 0, // SrcColor
- D3DTA_COMPLEMENT, // InvSrcColor
- D3DTA_ALPHAREPLICATE, // SrcAlpha
- D3DTA_ALPHAREPLICATE|D3DTA_COMPLEMENT, // InvSrcAlpha
-};
-
-
-// ***************************************************************************
-
-const DWORD RemapTexArg0TypeNeL2D3D[CMaterial::TexOperatorCount]=
-{
- D3DTA_TFACTOR, // todo hulud constant color D3DTA_CONSTANT, // Replace not used
- D3DTA_TFACTOR, // todo hulud constant color D3DTA_CONSTANT, // Modulate not used
- D3DTA_TFACTOR, // todo hulud constant color D3DTA_CONSTANT, // Add not used
- D3DTA_TFACTOR, // todo hulud constant color D3DTA_CONSTANT, // AddSigned not used
- D3DTA_TFACTOR, // todo hulud constant color D3DTA_CONSTANT, // InterpolateTexture not used
- D3DTA_TFACTOR, // todo hulud constant color D3DTA_CONSTANT, // InterpolatePrevious not used
- D3DTA_TFACTOR, // todo hulud constant color D3DTA_CONSTANT, // InterpolateDiffuse not used
- D3DTA_TFACTOR|D3DTA_ALPHAREPLICATE, // todo hulud constant color D3DTA_CONSTANT|D3DTA_ALPHAREPLICATE, // InterpolateConstant
- D3DTA_TFACTOR, // todo hulud constant color D3DTA_CONSTANT, // EMBM not used
- D3DTA_TFACTOR // todo hulud constant color D3DTA_CONSTANT // MAD
-};
-
-// ***************************************************************************
-
-const DWORD RemapTexGenTypeNeL2D3D[CMaterial::numTexCoordGenMode]=
-{
- D3DTSS_TCI_SPHEREMAP, // TexCoordGenReflect
- D3DTSS_TCI_CAMERASPACEPOSITION, // TexCoordGenObjectSpace, not supported
- D3DTSS_TCI_CAMERASPACEPOSITION, // TexCoordGenEyeSpace
-};
-
-// ***************************************************************************
-
-const DWORD RemapTexGenCubeTypeNeL2D3D[CMaterial::numTexCoordGenMode]=
-{
- D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR, // TexCoordGenReflect
- D3DTSS_TCI_CAMERASPACEPOSITION, // TexCoordGenObjectSpace, not supported
- D3DTSS_TCI_CAMERASPACEPOSITION, // TexCoordGenEyeSpace
-};
-
-// ***************************************************************************
-
-void CMaterialDrvInfosD3D::buildTexEnv (uint stage, const CMaterial::CTexEnv &env, bool textured)
-{
- H_AUTO_D3D(CMaterialDrvInfosD3D_buildTexEnv)
- if (textured)
- {
- // The source operator pointer
- const DWORD *srcOp = (stage==0)?RemapTexArg0NeL2D3D:RemapTexArgNeL2D3D;
-
- ColorOp[stage] = ((stage==0)?RemapTexOpType0NeL2D3D:RemapTexOpTypeNeL2D3D)[env.Env.OpRGB];
- NumColorArg[stage] = OpNumArg[env.Env.OpRGB];
- if (env.Env.OpRGB == CMaterial::Mad)
- {
- ColorArg2[stage] = srcOp[env.Env.SrcArg0RGB];
- ColorArg2[stage] |= RemapTexOpArgTypeNeL2D3D[env.Env.OpArg0RGB];
- ColorArg1[stage] = srcOp[env.Env.SrcArg1RGB];
- ColorArg1[stage] |= RemapTexOpArgTypeNeL2D3D[env.Env.OpArg1RGB];
- ColorArg0[stage] = srcOp[env.Env.SrcArg2RGB];
- ColorArg0[stage] |= RemapTexOpArgTypeNeL2D3D[env.Env.OpArg2RGB];
- }
- else
- {
- // Only used for InterpolateConstant
- ColorArg0[stage] = RemapTexArg0TypeNeL2D3D[env.Env.OpRGB];
- ColorArg1[stage] = srcOp[env.Env.SrcArg0RGB];
- ColorArg1[stage] |= RemapTexOpArgTypeNeL2D3D[env.Env.OpArg0RGB];
- ColorArg2[stage] = srcOp[env.Env.SrcArg1RGB];
- ColorArg2[stage] |= RemapTexOpArgTypeNeL2D3D[env.Env.OpArg1RGB];
- }
- AlphaOp[stage] = ((stage==0)?RemapTexOpType0NeL2D3D:RemapTexOpTypeNeL2D3D)[env.Env.OpAlpha];
- NumAlphaArg[stage] = OpNumArg[env.Env.OpAlpha];
- if (env.Env.OpAlpha == CMaterial::Mad)
- {
- AlphaArg2[stage] = srcOp[env.Env.SrcArg0Alpha];
- AlphaArg2[stage] |= RemapTexOpArgTypeNeL2D3D[env.Env.OpArg0Alpha];
- AlphaArg1[stage] = srcOp[env.Env.SrcArg1Alpha];
- AlphaArg1[stage] |= RemapTexOpArgTypeNeL2D3D[env.Env.OpArg1Alpha];
- AlphaArg0[stage] = srcOp[env.Env.SrcArg2Alpha];
- AlphaArg0[stage] |= RemapTexOpArgTypeNeL2D3D[env.Env.OpArg2Alpha];
- }
- else
- {
- // Only used for InterpolateConstant
- AlphaArg0[stage] = RemapTexArg0TypeNeL2D3D[env.Env.OpAlpha];
- AlphaArg1[stage] = srcOp[env.Env.SrcArg0Alpha];
- AlphaArg1[stage] |= RemapTexOpArgTypeNeL2D3D[env.Env.OpArg0Alpha];
- AlphaArg2[stage] = srcOp[env.Env.SrcArg1Alpha];
- AlphaArg2[stage] |= RemapTexOpArgTypeNeL2D3D[env.Env.OpArg1Alpha];
- }
- ConstantColor[stage] = NL_D3DCOLOR_RGBA(env.ConstantColor);
- }
- else
- {
- // The stage is disabled, active only the lighting
- ColorOp[stage] = D3DTOP_SELECTARG1;
- DWORD opSrc = D3DTA_DIFFUSE;
- ColorArg0[stage] = opSrc;
- ColorArg1[stage] = opSrc;
- ColorArg2[stage] = opSrc;
- AlphaOp[stage] = D3DTOP_SELECTARG1;
- AlphaArg0[stage] = opSrc;
- AlphaArg1[stage] = opSrc;
- AlphaArg2[stage] = opSrc;
- ConstantColor[stage] = NL_D3DCOLOR_RGBA(CRGBA::White);
- NumColorArg[stage] = 1;
- NumAlphaArg[stage] = 1;
- }
-}
-
-
-// ***************************************************************************
-static inline DWORD replaceDiffuseWithConstant(DWORD value)
-{
- if ((value & D3DTA_SELECTMASK) == D3DTA_DIFFUSE)
- {
- return (value & ~D3DTA_SELECTMASK) | D3DTA_TFACTOR;
- }
- return value;
-}
-
-
-
-
-// helpers to set shaders parameters
-
-// Set a color in the shader
-static inline void setShaderParam(CMaterialDrvInfosD3D *pShader, uint index, INT value)
-{
- nlassert(pShader->FXCache);
- pShader->FXCache->Params.setColor(index, value);
-}
-
-// Set a color
-static inline void setShaderParam(CMaterialDrvInfosD3D *pShader, uint index, CRGBA color)
-{
- nlassert(pShader->FXCache);
- float values[4];
- NL_FLOATS(values, color);
- pShader->FXCache->Params.setVector(index, D3DXVECTOR4(values[0], values[1], values[2], values[3]));
-}
-
-
-// Set a float value in the shader
-static inline void setShaderParam(CMaterialDrvInfosD3D *pShader, uint index, FLOAT value)
-{
- nlassert(pShader->FXCache);
- pShader->FXCache->Params.setFloat(index, value);
-}
-
-
-// Set a vector of floats
-static inline void setShaderParam(CMaterialDrvInfosD3D *pShader, uint index, float vector[4])
-{
- nlassert(pShader->FXCache); \
- pShader->FXCache->Params.setVector(index, D3DXVECTOR4(vector[0], vector[1], vector[2], vector[3]));
-}
-
-// ***************************************************************************
-bool CDriverD3D::setupMaterial(CMaterial &mat)
-{
- H_AUTO_D3D(CDriverD3D_setupMaterial)
- CMaterialDrvInfosD3D* pShader;
-
- // Stats
- _NbSetupMaterialCall++;
-
- // Max texture
- const uint maxTexture = inlGetNumTextStages();
-
- // Update material
- uint32 touched=mat.getTouched();
-
- // No shader ?
- if (!mat._MatDrvInfo)
- {
- // Insert into driver list. (so it is deleted when driver is deleted).
- ItMatDrvInfoPtrList it= _MatDrvInfos.insert(_MatDrvInfos.end(), (NL3D::IMaterialDrvInfos*)NULL);
-
- *it = mat._MatDrvInfo = new CMaterialDrvInfosD3D(this, it);
-
- // Must create all OpenGL shader states.
- touched = IDRV_TOUCHED_ALL;
- }
- pShader = static_cast((IMaterialDrvInfos*)(mat._MatDrvInfo));
-
- // Now we can get the supported shader from the cache.
- CMaterial::TShader matShader = _PixelProgramUser ? CMaterial::Program : mat.getShader();
-
- if (_CurrentMaterialSupportedShader != CMaterial::Normal)
- {
- // because of multipass, some shader need to disable fog
- // restore fog here
- if(_FogEnabled && _FogColor != _RenderStateCache[D3DRS_FOGCOLOR].Value)
- {
- // restore fog
- setRenderState(D3DRS_FOGCOLOR, _FogColor);
- }
- }
- {
- H_AUTO_D3D(CDriverD3D_setupMaterial_light)
- // if the shader has changed since last time
- if(matShader != _CurrentMaterialSupportedShader)
- {
- // if current shader is normal shader, then must restore uv routing, because it may have been changed by a previous shader (such as lightmap)
- if (matShader == CMaterial::Normal)
- {
- for(uint k = 0; k < MaxTexture; ++k)
- {
- setTextureIndexUV (k, _CurrentUVRouting[k]);
- }
- }
- // if old was lightmap, restore standard lighting
- if(_CurrentMaterialSupportedShader==CMaterial::LightMap)
- {
- _MustRestoreLight = true;
- }
-
- // if new is lightmap, setup dynamic lighting
- if(matShader==CMaterial::LightMap)
- {
- setupLightMapDynamicLighting(true);
- _MustRestoreLight = false;
- }
- }
- if (mat.isLighted() && _MustRestoreLight)
- {
- setupLightMapDynamicLighting(false);
- _MustRestoreLight = false;
- }
- // setup the global
- _CurrentMaterialSupportedShader= matShader;
- }
-
-
- {
- // count number of tex stages
- uint numUsedTexStages = 0;
- for(numUsedTexStages = 0; numUsedTexStages < IDRV_MAT_MAXTEXTURES; ++numUsedTexStages)
- {
- if (mat.getTexture(uint8(numUsedTexStages)) == NULL) break;
- }
-
- H_AUTO_D3D(CDriverD3D_setupMaterial_touchupdate)
- if (pShader->NumUsedTexStages != numUsedTexStages)
- {
- touched |= IDRV_TOUCHED_TEXENV;
- }
- // Something to setup ?
- if (touched)
- {
- if (touched & IDRV_TOUCHED_SHADER)
- {
- delete pShader->FXCache;
- pShader->FXCache = NULL;
- // See if material actually needs a fx cache
- if (mat.getShader() != CMaterial::Specular && mat.getShader() != CMaterial::Normal)
- {
- pShader->FXCache = new CFXCache;
- }
- }
- /* Exception: if only Textures are modified in the material, no need to "Bind OpenGL States", or even to test
- for change, because textures are activated alone, see below.
- No problem with delete/new problem (see below), because in this case, IDRV_TOUCHED_ALL is set (see above).
- */
- // If any flag is set (but a flag of texture).
- if(touched & (~_MaterialAllTextureTouchedFlag))
- {
- // Convert Material to driver shader.
- if (touched & IDRV_TOUCHED_BLENDFUNC)
- {
- pShader->SrcBlend = RemapBlendTypeNeL2D3D[mat.getSrcBlend()];
- pShader->DstBlend = RemapBlendTypeNeL2D3D[mat.getDstBlend()];
- }
- if (touched & IDRV_TOUCHED_ZFUNC)
- {
- pShader->ZComp = RemapZFuncTypeNeL2D3D[mat.getZFunc()];
- }
- if (touched & IDRV_TOUCHED_LIGHTING)
- {
- // Lighted material ?
- if (mat.isLighted())
- {
- // Setup the color
- NL_D3DCOLORVALUE_RGBA(pShader->Material.Diffuse, mat.getDiffuse());
- NL_D3DCOLORVALUE_RGBA(pShader->Material.Ambient, mat.getAmbient());
- NL_D3DCOLORVALUE_RGBA(pShader->Material.Emissive, mat.getEmissive());
-
- // Specular
- CRGBA spec = mat.getSpecular();
- if (spec != CRGBA::Black)
- {
- NL_D3DCOLORVALUE_RGBA(pShader->Material.Specular, spec);
- pShader->SpecularEnabled = TRUE;
- pShader->Material.Power = mat.getShininess();
- }
- else
- setRenderState (D3DRS_SPECULARENABLE, FALSE);
- }
- else
- {
- // No specular
- pShader->SpecularEnabled = FALSE;
- }
- }
- if (touched & IDRV_TOUCHED_COLOR)
- {
- // Setup the color
- pShader->UnlightedColor = NL_D3DCOLOR_RGBA(mat.getColor());
- }
- if (touched & IDRV_TOUCHED_ALPHA_TEST_THRE)
- {
- float alphaRef = (float)floor(mat.getAlphaTestThreshold() * 255.f + 0.5f);
- clamp (alphaRef, 0.f, 255.f);
- pShader->AlphaRef = (DWORD)alphaRef;
- }
- if (touched & IDRV_TOUCHED_SHADER)
- {
- // todo hulud d3d material shaders
- // Get shader. Fallback to other shader if not supported.
- // pShader->SupportedShader= getSupportedShader(mat.getShader());
- }
- if (touched & IDRV_TOUCHED_TEXENV)
- {
- // Build the tex env cache.
- // Do not do it for Lightmap and per pixel lighting , because done in multipass in a very special fashion.
- // This avoid the useless multiple change of texture states per lightmapped object.
- // Don't do it also for Specular because the EnvFunction and the TexGen may be special.
- if(matShader == CMaterial::Normal)
- {
- uint stage;
- for(stage=0 ; stagebuildTexEnv (stage, mat._TexEnvs[stage], mat.getTexture(uint8(stage)) != NULL);
- }
- }
- }
- if (touched & (IDRV_TOUCHED_TEXGEN|IDRV_TOUCHED_ALLTEX))
- {
- uint stage;
- for(stage=0 ; stageActivateSpecularWorldTexMT[stage] = false;
- pShader->ActivateInvViewModelTexMT[stage] = false;
-
- // Build the tex env
- ITexture *text= mat.getTexture(uint8(stage));
- if (text && text->isTextureCube())
- {
- if (mat.getTexCoordGen(stage))
- {
- // Texture cube
- pShader->TexGen[stage] = RemapTexGenCubeTypeNeL2D3D[mat.getTexCoordGenMode (stage)];
-
- // Texture matrix
- pShader->ActivateSpecularWorldTexMT[stage] = mat.getTexCoordGenMode (stage) == CMaterial::TexCoordGenReflect;
- }
- else
- {
- pShader->TexGen[stage] = mat.getTexCoordGen(stage);
- }
- }
- else
- {
- if (mat.getTexCoordGen(stage))
- {
- pShader->TexGen[stage] = RemapTexGenTypeNeL2D3D[mat.getTexCoordGenMode (stage)];
-
- // Texture matrix
- pShader->ActivateInvViewModelTexMT[stage] = mat.getTexCoordGenMode (stage) == CMaterial::TexCoordGenObjectSpace;
- }
- else
- {
- pShader->TexGen[stage] = mat.getTexCoordGen(stage);
- }
- }
- }
- }
-
- // Does this material needs a pixel shader ?
- if (touched & (IDRV_TOUCHED_TEXENV|IDRV_TOUCHED_BLEND|IDRV_TOUCHED_ALPHA_TEST))
- {
- std::fill(pShader->RGBPipe, pShader->RGBPipe + IDRV_MAT_MAXTEXTURES, true);
- std::fill(pShader->AlphaPipe, pShader->AlphaPipe + IDRV_MAT_MAXTEXTURES, true);
-
- pShader->MultipleConstantNoPixelShader = false;
- pShader->MultiplePerStageConstant = false;
- pShader->VertexColorLighted = mat.getLightedVertexColor();
- bool _needPixelShader = false;
- pShader->ConstantIndex = 0xff;
- pShader->ConstantIndex2 = 0xff;
- if (matShader == CMaterial::Normal)
- {
- // Need of constants ?
- uint numConstants;
- uint firstConstant;
- uint secondConstant;
- needsConstants (numConstants, firstConstant, secondConstant, mat);
-
- pShader->ConstantIndex = uint8(firstConstant);
- pShader->ConstantIndex2 = uint8(secondConstant);
-
- // Need a constant color for the diffuse component ?
- pShader->NeedsConstantForDiffuse = needsConstantForDiffuse (mat);
-
- // Need pixel shader ?
- #ifndef NL_FORCE_PIXEL_SHADER_USE_FOR_NORMAL_SHADERS
- _needPixelShader = (numConstants > 1) || ((numConstants==1) && pShader->NeedsConstantForDiffuse);
- #else // NL_FORCE_PIXEL_SHADER_USE_FOR_NORMAL_SHADERS
- _needPixelShader = true;
- #endif // NL_FORCE_PIXEL_SHADER_USE_FOR_NORMAL_SHADERS
- if (_needPixelShader)
- {
- // The shader description
- CNormalShaderDesc normalShaderDesc;
-
- // Setup descriptor
- uint stage;
- for(stage=0 ; stage<(uint)maxTexture; stage++)
- {
- // Stage used ?
- normalShaderDesc.StageUsed[stage] = mat.getTexture (uint8(stage)) != NULL;
- normalShaderDesc.TexEnvMode[stage] = mat.getTexEnvMode(uint8(stage));
- }
-
- if (_PixelProgram)
- {
- #ifdef NL_DEBUG_D3D
- // Check, should not occur
- nlassertex (_PixelShader, ("STOP : no pixel shader available. Can't render this material."));
- #endif // NL_DEBUG_D3D
-
- // Build the pixel shader
- pShader->PixelShader = buildPixelShader (normalShaderDesc, false);
- if (!mat.isLighted())
- pShader->PixelShaderUnlightedNoVertexColor = buildPixelShader (normalShaderDesc, true);
- else
- pShader->PixelShaderUnlightedNoVertexColor = NULL;
- }
- else
- {
- // Possible configurations are :
- // unlighted, 1 constant diffuse + 1 per stage constant
- // unlighted, 2 constants (second constant emulated with material emissive + diffuse), possibly with vertex color (aliased to specular)
-
- // If there are no pixel shader then we're likely to have three stage or less
- pShader->MultipleConstantNoPixelShader = true;
- pShader->MultiplePerStageConstant = numConstants > 1;
- #ifdef NL_DEBUG
- nlassert(numConstants <= 2);
- #endif
- if (secondConstant != 0xffffffff)
- {
- pShader->Constant2 = mat.getTexConstantColor(secondConstant);
- }
- pShader->PixelShader = NULL;
- pShader->PixelShaderUnlightedNoVertexColor = NULL;
- // compute relevant parts of the pipeline
- computeRelevantTexEnv(mat, pShader->RGBPipe, pShader->AlphaPipe);
- }
- }
- else
- {
- // compute relevant parts of the pipeline
- computeRelevantTexEnv(mat, pShader->RGBPipe, pShader->AlphaPipe);
- }
- }
- else
- {
- // Other shaders
- pShader->MultipleConstantNoPixelShader = false;
- pShader->NeedsConstantForDiffuse = false;
- }
-
- if (!_needPixelShader)
- {
- // Remove the old one
- pShader->PixelShader = NULL;
- pShader->PixelShaderUnlightedNoVertexColor = NULL;
- pShader->MultipleConstantNoPixelShader = 0;
- }
- }
-
- // Since modified, must rebind all D3D states. And do this also for the delete/new problem.
- /* If an old material is deleted, _CurrentMaterial is invalid. But this is grave only if a new
- material is created, with the same pointer (bad luck). Since an newly allocated material always
- pass here before use, we are sure to avoid any problems.
- */
- _CurrentMaterial= NULL;
- }
-
- // Optimize: reset all flags at the end.
- mat.clearTouched(0xFFFFFFFF);
- pShader->NumUsedTexStages = numUsedTexStages;
- }
- }
-
-
- {
- H_AUTO_D3D(CDriverD3D_setupMaterial_bindTexture)
- // 2. Setup / Bind Textures.
- //==========================
- // Must setup textures each frame. (need to test if touched).
- // Must separate texture setup and texture activation in 2 "for"...
- // because setupTexture() may disable all stage.
-
- if (matShader == CMaterial::Normal
- || ((matShader == CMaterial::Program) && (_PixelProgramUser->features().MaterialFlags & CProgramFeatures::TextureStages))
- )
- {
- uint stage;
- for(stage=0 ; stagefeatures().MaterialFlags & CProgramFeatures::TextureStages))
- )
- {
- uint stage;
- for(stage=0 ; stagePixelShader == NULL)
- {
- if (pShader->RGBPipe[stage])
- {
- setTextureState (stage, D3DTSS_COLOROP, pShader->ColorOp[stage]);
- setTextureState (stage, D3DTSS_COLORARG1, pShader->ColorArg1[stage]);
- if (pShader->NumColorArg[stage] > 1)
- {
- setTextureState (stage, D3DTSS_COLORARG2, pShader->ColorArg2[stage]);
- if (pShader->NumColorArg[stage] > 2)
- {
- setTextureState (stage, D3DTSS_COLORARG0, pShader->ColorArg0[stage]);
- }
- }
- }
- if (pShader->AlphaPipe[stage])
- {
- setTextureState (stage, D3DTSS_ALPHAOP, pShader->AlphaOp[stage]);
- setTextureState (stage, D3DTSS_ALPHAARG1, pShader->AlphaArg1[stage]);
- if (pShader->NumAlphaArg[stage] > 1)
- {
- setTextureState (stage, D3DTSS_ALPHAARG2, pShader->AlphaArg2[stage]);
- if (pShader->NumAlphaArg[stage] > 2)
- {
- setTextureState (stage, D3DTSS_ALPHAARG0, pShader->AlphaArg0[stage]);
- }
- }
- }
- // If there is one constant and the tfactor is not needed for diffuse, use the tfactor as constant
- if (pShader->ConstantIndex == stage)
- setRenderState (D3DRS_TEXTUREFACTOR, pShader->ConstantColor[stage]);
- }
- else
- {
- float colors[4];
- D3DCOLOR_FLOATS (colors, pShader->ConstantColor[stage]);
- setPixelShaderConstant (stage, colors);
- }
- }
-
- // Set texture generator state
- setTextureIndexMode (stage, pShader->TexGen[stage]!=D3DTSS_TCI_PASSTHRU, pShader->TexGen[stage]);
-
- // Need user matrix ?
- bool needUserMtx = mat.isUserTexMatEnabled(stage);
- D3DXMATRIX userMtx;
- if (needUserMtx)
- {
- // If tex gen mode is used, or a cube texture is used, then use the matrix 'as it'.
- // Must build a 3x3 matrix for 2D texture coordinates in D3D (which is kind of weird ...)
- if (pShader->TexGen[stage] != D3DTSS_TCI_PASSTHRU || (mat.getTexture(uint8(stage)) && mat.getTexture(uint8(stage))->isTextureCube()))
- {
- NL_D3D_MATRIX(userMtx, mat.getUserTexMat(stage));
- }
- else
- {
- const CMatrix &m = mat.getUserTexMat(stage);
- NL_D3D_TEX2D_MATRIX(userMtx, m);
- }
- }
-
- // Need cubic texture coord generator ?
- if (pShader->ActivateSpecularWorldTexMT[stage])
- {
- // Set the driver matrix
- setTextureState (stage, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT3);
- if (!needUserMtx)
- setMatrix ((D3DTRANSFORMSTATETYPE)(D3DTS_TEXTURE0+stage), _D3DSpecularWorldTex);
- else
- {
- D3DXMatrixMultiply (&userMtx, &_D3DSpecularWorldTex, &userMtx);
- setMatrix ((D3DTRANSFORMSTATETYPE)(D3DTS_TEXTURE0+stage), userMtx);
- }
- }
- else if (pShader->ActivateInvViewModelTexMT[stage])
- {
- // Set the driver matrix
- setTextureState (stage, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT3);
- if (!needUserMtx)
- setMatrix ((D3DTRANSFORMSTATETYPE)(D3DTS_TEXTURE0+stage), _D3DInvModelView);
- else
- {
- D3DXMatrixMultiply (&userMtx, &_D3DInvModelView, &userMtx);
- setMatrix ((D3DTRANSFORMSTATETYPE)(D3DTS_TEXTURE0+stage), userMtx);
- }
- }
- else
- {
- if (_NbNeLTextureStages == 3)
- {
- // Fix for Radeon 7xxx
- // In some situation, texture transform stays enabled after a material change, so enable it all the
- // time and use identity matrix instead of the D3DTTFF_DISABLE flag
- setTextureState (stage, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT3);
- setMatrix ((D3DTRANSFORMSTATETYPE)(D3DTS_TEXTURE0+stage), needUserMtx ? userMtx : _D3DMatrixIdentity);
- }
- else
- {
- // Set the driver matrix
- if (needUserMtx)
- {
- setTextureState (stage, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT3);
- setMatrix ((D3DTRANSFORMSTATETYPE)(D3DTS_TEXTURE0+stage), userMtx);
- }
- else
- {
- setTextureState (stage, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);
- }
- }
- }
- if (!text && stage == 0) break;
- }
- }
- }
-
- if (_CurrentMaterial != &mat)
- {
- // Material has changed ?
- // Restore fog state to its current value
- {
- H_AUTO_D3D(CDriverD3D_setupMaterial_updateFog)
- setRenderState (D3DRS_FOGENABLE, _FogEnabled?TRUE:FALSE);
- }
-
- // Flags
- const uint32 flags = mat.getFlags();
-
- // Two sided
- _DoubleSided = (flags&IDRV_MAT_DOUBLE_SIDED)!=0;
-
- {
- H_AUTO_D3D(CDriverD3D_setupMaterial_handleBackSide)
- // Handle backside
- if (_CullMode == CCW)
- {
- setRenderState (D3DRS_CULLMODE, _DoubleSided?D3DCULL_NONE:_InvertCullMode?D3DCULL_CCW:D3DCULL_CW);
- }
- else
- {
- setRenderState (D3DRS_CULLMODE, _DoubleSided?D3DCULL_NONE:_InvertCullMode?D3DCULL_CW:D3DCULL_CCW);
- }
- }
-
-
- bool blend = (flags&IDRV_MAT_BLEND) != 0;
- {
- H_AUTO_D3D(CDriverD3D_setupMaterial_updateBlend)
- // Active states
- if (blend)
- {
- setRenderState (D3DRS_ALPHABLENDENABLE, TRUE);
- setRenderState (D3DRS_SRCBLEND, pShader->SrcBlend);
- setRenderState (D3DRS_DESTBLEND, pShader->DstBlend);
- }
- else
- setRenderState (D3DRS_ALPHABLENDENABLE, FALSE);
-
- // Alpha test
- if (flags&IDRV_MAT_ALPHA_TEST)
- {
- setRenderState (D3DRS_ALPHATESTENABLE, TRUE);
- setRenderState (D3DRS_ALPHAREF, pShader->AlphaRef);
- setRenderState (D3DRS_ALPHAFUNC, D3DCMP_GREATER);
- }
- else
- setRenderState (D3DRS_ALPHATESTENABLE, FALSE);
- }
-
- {
- H_AUTO_D3D(CDriverD3D_setupMaterial_updateZBuffer)
- // Z buffer
- setRenderState (D3DRS_ZWRITEENABLE, (flags&IDRV_MAT_ZWRITE)?TRUE:FALSE);
- setRenderState (D3DRS_ZFUNC, pShader->ZComp);
- float flt = mat.getZBias () * _OODeltaZ;
- setRenderState (D3DRS_DEPTHBIAS, FTODW(flt));
- }
-
- {
- H_AUTO_D3D(CDriverD3D_setupMaterial_updateLighting)
- // Active lighting
- if (mat.isLighted())
- {
- setRenderState (D3DRS_LIGHTING, TRUE);
- setMaterialState(pShader->Material);
- }
- else
- {
- setRenderState (D3DRS_LIGHTING, FALSE);
-
- // Set pixel shader unlighted color ?
- if (pShader->PixelShader)
- {
- float colors[4];
- D3DCOLOR_FLOATS(colors,pShader->UnlightedColor);
- setPixelShaderConstant (5, colors);
- }
- }
- setRenderState (D3DRS_SPECULARENABLE, pShader->SpecularEnabled);
- }
-
- {
- H_AUTO_D3D(CDriverD3D_setupMaterial_updateVertexColorLighted)
- // Active vertex color if not lighted or vertex color forced
- if (mat.isLightedVertexColor ())
- {
- setRenderState (D3DRS_COLORVERTEX, TRUE);
-
- setRenderState (D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_COLOR1);
- }
- else
- {
- setRenderState (D3DRS_COLORVERTEX, FALSE);
- setRenderState (D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL);
- }
- }
-
- {
- H_AUTO_D3D(CDriverD3D_setupMaterial_disableFog)
- // Disable fog if dest blend is ONE
- if (blend && (pShader->DstBlend == D3DBLEND_ONE))
- {
- setRenderState (D3DRS_FOGENABLE, FALSE);
- }
- }
-
- // Set the good shader
- switch (matShader)
- {
- case CMaterial::Normal:
- {
- H_AUTO_D3D(CDriverD3D_setupMaterial_setupNormalshader)
- // No shader
- activeShader (NULL);
-
- /* If unlighted trick is needed, set the shader later */
- if (!pShader->NeedsConstantForDiffuse && _PixelProgram)
- setPixelShader (pShader->PixelShader);
- }
- break;
- case CMaterial::LightMap:
- {
- H_AUTO_D3D(CDriverD3D_setupMaterial_setupLightmapShader)
- setPixelShader (NULL);
- static const uint32 RGBMaskPacked = CRGBA(255,255,255,0).getPacked();
-
- if (_NbNeLTextureStages == 3)
- {
- touchRenderVariable(&_MaterialState);
- }
-
- // if the dynamic lightmap light has changed since the last render (should not happen), resetup
- // normal way is that setupLightMapDynamicLighting() is called at begin of setupMaterial() if shader different from prec
- if(_LightMapDynamicLightDirty)
- setupLightMapDynamicLighting(true);
-
- // Count the lightmaps
- uint lightmap;
- uint lightmapCount = 0;
- uint lightmapMask = 0;
- for(lightmap=0 ; lightmap<(sint)mat._LightMaps.size() ; lightmap++)
- {
- if (mat._LightMaps[lightmap].Factor.getPacked() & RGBMaskPacked)
- {
- lightmapCount++;
- lightmapMask |= 1<FXCache))
- return false;
-
- // Get the effect
- nlassert (_CurrentShader);
- CShaderDrvInfosD3D *shaderInfo = static_cast((IShaderDrvInfos*)_CurrentShader->_DrvInfo);
-// ID3DXEffect *effect = shaderInfo->Effect;
-
-
- // Set the ambiant for 8Bit Light Compression
- {
- // Sum ambiant of all active lightmaps.
- uint32 r=0;
- uint32 g=0;
- uint32 b=0;
- for(lightmap=0 ; lightmap<(sint)mat._LightMaps.size() ; lightmap++)
- {
- if (lightmapMask & (1<>7))) >>8;
- g+= ((uint32)ambFactor.G * ((uint32)lmcAmb.G+(lmcAmb.G>>7))) >>8;
- b+= ((uint32)ambFactor.B * ((uint32)lmcAmb.B+(lmcAmb.B>>7))) >>8;
- }
- }
- r= std::min(r, (uint32)255);
- g= std::min(g, (uint32)255);
- b= std::min(b, (uint32)255);
- CRGBA lmcAmbient((uint8)r,(uint8)g,(uint8)b,255);
-
- // Set into FX shader
- setShaderParam(pShader, 0, (INT) NL_D3DCOLOR_RGBA(lmcAmbient));
- if (shaderInfo->FactorHandle[0])
- {
- setShaderParam(pShader, 0, lmcAmbient);
- }
- }
-
-
- // Set the lightmaps
- lightmapCount = 0;
- for(lightmap=0 ; lightmap<(sint)mat._LightMaps.size() ; lightmap++)
- {
- if (lightmapMask & (1<FXCache))
- return false;
-
- // Get the lightmap color factor, and mul by lmcDiffuse compression
- CRGBA lmapFactor = mat._LightMaps[lightmap].Factor;
- CRGBA lmcDiff= mat._LightMaps[lightmap].LMCDiffuse;
- lmapFactor.R = (uint8)(((uint32)lmapFactor.R * ((uint32)lmcDiff.R+(lmcDiff.R>>7))) >>8);
- lmapFactor.G = (uint8)(((uint32)lmapFactor.G * ((uint32)lmcDiff.G+(lmcDiff.G>>7))) >>8);
- lmapFactor.B = (uint8)(((uint32)lmapFactor.B * ((uint32)lmcDiff.B+(lmcDiff.B>>7))) >>8);
- lmapFactor.A = 255;
-
- // Set the lightmap color factor into shader
- setShaderParam(pShader, lightmapCount+1, (INT) NL_D3DCOLOR_RGBA(lmapFactor));
- if (shaderInfo->FactorHandle[lightmapCount+1])
- {
- setShaderParam(pShader, lightmapCount+1, lmapFactor);
- }
- lightmapCount++;
- }
- }
- }
- break;
- case CMaterial::Specular:
- {
- H_AUTO_D3D(CDriverD3D_setupMaterial_setupSpecularShader)
- // No shader
- activeShader (NULL);
- setPixelShader (NULL);
-
- // Setup the texture
- ITexture *texture = mat.getTexture(0);
- if (!texture || !setupTexture (*texture))
- return false;
- setTexture (0, texture);
-
- // Setup the texture
- texture = mat.getTexture(1);
- if (!texture || !setupTexture (*texture))
- return false;
- setTexture (1, texture);
-
- // Set the driver matrix
- if (texture->isTextureCube())
- {
- setTextureIndexMode (1, true, D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR);
- setTextureState (1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT3);
- setMatrix ((D3DTRANSFORMSTATETYPE)(D3DTS_TEXTURE0+1), _D3DSpecularWorldTex);
- }
-
- setRenderState (D3DRS_LIGHTING, mat.isLighted()?TRUE:FALSE);
- setRenderState (D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL);
- setTextureState (0, D3DTSS_COLOROP, D3DTOP_MODULATE);
- setTextureState (0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
- setTextureState (0, D3DTSS_COLORARG2, D3DTA_TEXTURE);
- setTextureState (0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
- setTextureState (0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
- setTextureState (1, D3DTSS_COLOROP, D3DTOP_MULTIPLYADD);
- setTextureState (1, D3DTSS_COLORARG0, D3DTA_CURRENT);
- setTextureState (1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
- setTextureState (1, D3DTSS_COLORARG2, D3DTA_CURRENT|D3DTA_ALPHAREPLICATE);
- setTextureState (1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
- setTextureState (1, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);
-
- }
- break;
- case CMaterial::Cloud:
- {
- H_AUTO_D3D(CDriverD3D_setupMaterial_setupCloudShader)
- activeShader (&_ShaderCloud);
-
- // Get the shader
- nlassert (_CurrentShader);
-// CShaderDrvInfosD3D *shaderInfo = static_cast((IShaderDrvInfos*)_CurrentShader->_DrvInfo);
-
- // Set the constant
-// ID3DXEffect *effect = shaderInfo->Effect;
- CRGBA color = mat.getColor();
- color.R = 255;
- color.G = 255;
- color.B = 255;
- setShaderParam(pShader, 0, color);
-
- // Set the texture
- if (!setShaderTexture (0, mat.getTexture(0), pShader->FXCache) || !setShaderTexture (1, mat.getTexture(1), pShader->FXCache))
- return false;
- }
- break;
- case CMaterial::Water:
- {
- H_AUTO_D3D(CDriverD3D_setupMaterial_setupWaterShader)
- activeShader(mat.getTexture(3) ? &_ShaderWaterDiffuse : &_ShaderWaterNoDiffuse);
- // Get the shader
- nlassert (_CurrentShader);
-// CShaderDrvInfosD3D *shaderInfo = static_cast((IShaderDrvInfos*)_CurrentShader->_DrvInfo);
- // Set the textures
- if (_PixelShaderVersion >= D3DPS_VERSION(1, 4))
- {
- ITexture *tex = mat.getTexture(0);
- if (tex)
- {
- tex->setUploadFormat(ITexture::RGBA8888);
-// if (tex->isBumpMap())
-// {
-// CTextureBump *tb = static_cast(tex);
-// }
- setupTexture(*tex);
- setShaderTexture (0, tex, pShader->FXCache);
- }
- }
- ITexture *tex = mat.getTexture(1);
- if (tex)
- {
- if (_PixelShaderVersion < D3DPS_VERSION(1, 4))
- {
- tex->setUploadFormat(ITexture::DsDt);
-// if (tex->isBumpMap())
-// {
-// CTextureBump *tb = static_cast(tex);
-// }
- }
- else
- {
- tex->setUploadFormat(ITexture::RGBA8888);
-// if (tex->isBumpMap())
-// {
-// CTextureBump *tb = static_cast(tex);
-// }
- }
- setupTexture(*tex);
- setShaderTexture (1, tex, pShader->FXCache);
- }
- //
- tex = mat.getTexture(2);
- if (tex)
- {
- setupTexture(*tex);
- setShaderTexture (2, tex, pShader->FXCache);
- }
- tex = mat.getTexture(3);
- if (tex)
- {
- setupTexture(*tex);
- setShaderTexture (3, tex, pShader->FXCache);
- }
-
- // Set the constants
-// ID3DXEffect *effect = shaderInfo->Effect;
- if (_PixelShaderVersion < D3DPS_VERSION(2, 0))
- {
- if (_PixelShaderVersion < D3DPS_VERSION(1, 4))
- {
- if (mat.getTexture(1) && mat.getTexture(1)->isBumpMap())
- {
- float factor = NLMISC::safe_cast(mat.getTexture(1))->getNormalizationFactor();
- setShaderParam(pShader, 0, factor);
- }
- else
- {
- setShaderParam(pShader, 0, 1.f);
- }
- }
- else
- {
- if (mat.getTexture(0) && mat.getTexture(0)->isBumpMap())
- {
- float factor = NLMISC::safe_cast(mat.getTexture(0))->getNormalizationFactor();
- float cst[4] = { factor, factor, factor, 0.f };
- setShaderParam(pShader, 0, cst);
- }
- else
- {
- float cst[4] = { 1.f, 1.f, 1.f, 0.f };
- setShaderParam(pShader, 0, cst);
- }
- //
- if (mat.getTexture(1) && mat.getTexture(1)->isBumpMap())
- {
- float factor = NLMISC::safe_cast(mat.getTexture(1))->getNormalizationFactor();
- float cst[4] = { factor, factor, factor, 0.f };
- setShaderParam(pShader, 1, cst);
- }
- else
- {
- float cst[4] = { 1.f, 1.f, 1.f, 0.f };
- setShaderParam(pShader, 1, cst);
- }
- }
- }
- else
- {
- // setup the constant
- if (mat.getTexture(0) && mat.getTexture(0)->isBumpMap())
- {
- float factor = 0.25f * NLMISC::safe_cast(mat.getTexture(0))->getNormalizationFactor();
- float bmScale[4] = { -1.f * factor, -1.f * factor, 2.f * factor, 0.f };
- setShaderParam(pShader, 0, bmScale);
- }
- else
- {
- float bmScale[4] = { -1.f, -1.f, 2.f, 0.f };
- setShaderParam(pShader, 0, bmScale);
- }
- // setup the constant
- if (mat.getTexture(1) && mat.getTexture(1)->isBumpMap())
- {
- float factor = NLMISC::safe_cast(mat.getTexture(1))->getNormalizationFactor();
- float bmScale[4] = { -1.f * factor, -1.f * factor, 2.f * factor, 0.f };
- setShaderParam(pShader, 1, bmScale);
- }
- else
- {
- float bmScale[4] = { -1.f, -1.f, 2.f, 0.f };
- setShaderParam(pShader, 1, bmScale);
- }
- }
- }
- // CMaterial::Water
- }
-
- // New material setuped
- _CurrentMaterial = &mat;
-
- // Update variables
- _CurrentMaterialInfo = pShader;
- }
-
- return true;
-}
-
-// ***************************************************************************
-// Add one set to another
-static void add(std::set &dest, const std::set &toAdd)
-{
- for (std::set::const_iterator it = toAdd.begin(); it != toAdd.end(); ++it)
- {
- dest.insert(*it);
- }
-}
-
-
-// ***************************************************************************
-bool CDriverD3D::needsConstants (uint &numConstant, uint &firstConstant, uint &secondConstant, CMaterial &mat)
-{
- H_AUTO_D3D(CDriverD3D_needsConstants)
- firstConstant = 0xffffffff;
- secondConstant = 0xffffffff;
- // Of course std::set could be avoided, but much simpler that way
- std::set rgbPipe[2]; // constant used to compute the rgb component
- std::set alphaPipe[2]; // constant used to compute the alpha component
- for (uint i=0; i= 0)
- {
- rgbPipe[currStage] = rgbUsed;
- alphaPipe[currStage] = alphaUsed;
- bool newAlphaUsed = false;
- bool newRGBUsed = false;
- CMaterial::CTexEnv texEnv;
- texEnv.EnvPacked = mat.getTexEnvMode(currStage);
- // test for rgb propagate
- if (rgbUsed)
- {
- if (texEnv.Env.OpRGB == CMaterial::InterpolatePrevious)
- {
- newAlphaUsed = true;
- }
- for(uint l = 0; l < OpNumArg[texEnv.Env.OpRGB]; ++l)
- {
- if (texEnv.getColorArg(l) == CMaterial::Previous ||
- (currStage != 0 && texEnv.getColorArg(l) == CMaterial::Texture && mat.getTexEnvOpRGB(currStage - 1) == CMaterial::EMBM)
- )
- {
- if (texEnv.getColorOperand(l) == CMaterial::SrcColor || texEnv.getColorOperand(l) == CMaterial::InvSrcColor)
- {
- newRGBUsed = true;
- }
- if (texEnv.getColorOperand(l) == CMaterial::SrcAlpha || texEnv.getColorOperand(l) == CMaterial::InvSrcAlpha)
- {
- newAlphaUsed = true;
- }
- }
- }
- }
- // test for alpha propagate
- if (alphaUsed)
- {
- if (texEnv.Env.OpAlpha == CMaterial::InterpolatePrevious)
- {
- newAlphaUsed = true;
- }
- for(uint l = 0; l < OpNumArg[texEnv.Env.OpAlpha]; ++l)
- {
- if (texEnv.getAlphaArg(l) == CMaterial::Previous ||
- (currStage != 0 && texEnv.getAlphaArg(l) == CMaterial::Texture && mat.getTexEnvOpRGB(currStage - 1) == CMaterial::EMBM)
- )
- {
- if (texEnv.getAlphaOperand(l) == CMaterial::SrcAlpha || texEnv.getAlphaOperand(l) == CMaterial::InvSrcAlpha)
- {
- newAlphaUsed = true;
- }
- }
- }
- }
- alphaUsed = newAlphaUsed;
- rgbUsed = newRGBUsed;
-
- -- currStage;
- }
-}
-
-
-// ***************************************************************************
-
-const char *RemapPSInstructions[CMaterial::TexOperatorCount]=
-{
- "mov", // Replace
- "mul", // Modulate
- "add", // Add
- "add", // AddSigned
- "lrp", // InterpolateTexture
- "lrp", // InterpolatePrevious
- "lrp", // InterpolateDiffuse
- "lrp", // InterpolateConstant
- "bem", // EMBM
- "mad" // MAD
-};
-
-// ***************************************************************************
-
-const char *RemapPSThirdArguments[CMaterial::TexOperatorCount][2]=
-{
- {"", ""}, // Replace
- {"", ""}, // Modulate
- {"", ""}, // Add
- {"", ""}, // AddSigned
- {"t", "t"}, // InterpolateTexture
- {"r0", "r0"}, // InterpolatePrevious
- {"v0", "c5"}, // InterpolateDiffuse
- {"c", "c"}, // InterpolateConstant
- {"", ""}, // EMBM
- {"", ""} // MAD (not used)
-};
-
-// ***************************************************************************
-
-// Only for stage 0
-const char *RemapPSThirdArguments0[CMaterial::TexOperatorCount][2]=
-{
- {"", ""}, // Replace
- {"", ""}, // Modulate
- {"", ""}, // Add
- {"", ""}, // AddSigned
- {"t", "t"}, // InterpolateTexture
- {"v0", "c5"}, // InterpolatePrevious
- {"v0", "c5"}, // InterpolateDiffuse
- {"c", "c"}, // InterpolateConstant
- {"", ""}, // EMBM
- {"", ""} // MAD (not used)
-};
-
-// ***************************************************************************
-
-const char *RemapPSSecondRegisterModificator[CMaterial::TexOperatorCount]=
-{
- "", // Replace
- "", // Modulate
- "", // Add
- "_bias", // AddSigned
- "", // InterpolateTexture
- "", // InterpolatePrevious
- "", // InterpolateDiffuse
- "", // InterpolateConstant
- "", // EMBM
- "" // MAD
-};
-
-// ***************************************************************************
-
-const char *RemapPSArguments[CMaterial::TexOperatorCount][2]=
-{
- {"t", "t"}, // Texture
- {"r0", "r0"}, // Previous
- {"v0", "c5"}, // Diffuse
- {"c", "c"}, // Constant
-};
-
-// ***************************************************************************
-
-// Only for stage 0
-const char *RemapPSArguments0[CMaterial::TexOperatorCount][2]=
-{
- {"t", "t"}, // Texture
- {"v0", "c5"}, // Previous
- {"v0", "c5"}, // Diffuse
- {"c", "c"}, // Constant
-};
-
-// ***************************************************************************
-
-void buildColorOperation (string &dest, const char *prefix, const char *destSizzle, uint stage, CMaterial::TTexOperator &op, CMaterial::TTexSource src0, CMaterial::TTexSource src1, CMaterial::TTexSource src2, CMaterial::TTexOperand &op0, CMaterial::TTexOperand &op1, CMaterial::TTexOperand &op2, bool unlightedNoVertexColor)
-{
- H_AUTO_D3D(buildColorOperation)
- // Refix
- dest += prefix;
-
- // RGB operation
- dest += RemapPSInstructions[op];
-
- // Destination argument
- dest += " r0";
- dest += destSizzle;
-
- // Need a third argument ?
- if (op != CMaterial::Mad)
- {
- const char *remapPSThirdArguments = ((stage==0)?RemapPSThirdArguments0:RemapPSThirdArguments)[op][(uint)unlightedNoVertexColor];
- if (remapPSThirdArguments[0] != 0)
- {
- dest += ", ";
- dest += remapPSThirdArguments;
-
- // Need stage postfix ?
- if ((op == CMaterial::InterpolateTexture) || (op == CMaterial::InterpolateConstant))
- dest += toString (stage);
-
- // Add alpha swizzle
- dest += ".w";
- }
- }
-
- // First argument
- dest += ", ";
-
- // Inverted ?
- if ((op0 == CMaterial::InvSrcColor) || (op0 == CMaterial::InvSrcAlpha))
- dest += "1-";
-
- // The first operator argument
- dest += ((stage==0)?RemapPSArguments0:RemapPSArguments)[src0][(uint)unlightedNoVertexColor];
-
- // Need stage postfix ?
- if ((src0 == CMaterial::Texture) || (src0 == CMaterial::Constant))
- dest += toString (stage);
-
- // Need alpha ?
- if ((op0 == CMaterial::SrcAlpha) || (op0 == CMaterial::InvSrcAlpha))
- dest += ".w";
-
- if (op != CMaterial::Replace)
- {
- dest += ", ";
-
- // Inverted ?
- if ((op1 == CMaterial::InvSrcColor) || (op1 == CMaterial::InvSrcAlpha))
- dest += "1-";
-
- dest += ((stage==0)?RemapPSArguments0:RemapPSArguments)[src1][(uint)unlightedNoVertexColor];
-
- // Second register modifier
- dest += RemapPSSecondRegisterModificator[op];
-
- // Need stage postfix ?
- if ((src1 == CMaterial::Texture) || (src1 == CMaterial::Constant))
- dest += toString (stage);
-
- // Need alpha ?
- if ((op1 == CMaterial::SrcAlpha) || (op1 == CMaterial::InvSrcAlpha))
- dest += ".w";
- }
-
- if (op == CMaterial::Mad)
- {
- dest += ", ";
-
- // Inverted ?
- if ((op2 == CMaterial::InvSrcColor) || (op2 == CMaterial::InvSrcAlpha))
- dest += "1-";
-
- dest += ((stage==0)?RemapPSArguments0:RemapPSArguments)[src2][(uint)unlightedNoVertexColor];
-
- // Second register modifier
- dest += RemapPSSecondRegisterModificator[op];
-
- // Need stage postfix ?
- if ((src2 == CMaterial::Texture) || (src2 == CMaterial::Constant))
- dest += toString (stage);
-
- // Need alpha ?
- if ((op2 == CMaterial::SrcAlpha) || (op2 == CMaterial::InvSrcAlpha))
- dest += ".w";
- }
-
- // End
- dest += ";\n";
-}
-
-// ***************************************************************************
-
-IDirect3DPixelShader9 *CDriverD3D::buildPixelShader (const CNormalShaderDesc &normalShaderDesc, bool unlightedNoVertexColor)
-{
- H_AUTO_D3D(CDriverD3D_buildPixelShader)
- static string shaderText;
- shaderText = "ps_1_1;\n";
-
- // Look for a shader already created
- std::list &normalPixelShaders = _NormalPixelShaders[(uint)unlightedNoVertexColor];
- std::list::iterator ite = normalPixelShaders.begin();
- while (ite != normalPixelShaders.end())
- {
- if (normalShaderDesc == *ite)
- {
- // Good one
- return (*ite).PixelShader;
- }
- ite++;
- }
-
- // For each state, texture lookup
- uint i;
- for (i=0; iCreatePixelShader((DWORD*)pShader->GetBufferPointer(), &shader) == D3D_OK)
- normalPixelShaders.back().PixelShader = shader;
- else
- normalPixelShaders.back().PixelShader = NULL;
- }
- else
- {
- nlwarning ("Can't assemble pixel shader:");
- nlwarning ((const char*)pErrorMsgs->GetBufferPointer());
- normalPixelShaders.back().PixelShader = NULL;
- }
-
- return normalPixelShaders.back().PixelShader;
-}
-
-// ***************************************************************************
-
-void CDriverD3D::startSpecularBatch()
-{
- /* Not used in direct3d, use normal caching */
-}
-
-// ***************************************************************************
-
-void CDriverD3D::endSpecularBatch()
-{
- /* Not used in direct3d, use normal caching */
-}
-
-// ***************************************************************************
-
-bool CDriverD3D::supportBlendConstantColor() const
-{
- /* Not supported in D3D */
- return false;
-};
-
-// ***************************************************************************
-
-void CDriverD3D::setBlendConstantColor(NLMISC::CRGBA /* col */)
-{
- /* Not supported in D3D */
-};
-
-// ***************************************************************************
-
-NLMISC::CRGBA CDriverD3D::getBlendConstantColor() const
-{
- /* Not supported in D3D */
- return CRGBA::White;
-};
-
-// ***************************************************************************
-
-void CDriverD3D::enablePolygonSmoothing(bool /* smooth */)
-{
- /* Not supported in D3D */
-}
-
-// ***************************************************************************
-
-bool CDriverD3D::isPolygonSmoothingEnabled() const
-{
- /* Not supported in D3D */
- return false;
-}
-
-// ***************************************************************************
-
-sint CDriverD3D::beginMaterialMultiPass()
-{
- H_AUTO_D3D(CDriverD3D_beginMaterialMultiPass)
- beginMultiPass ();
- return _CurrentShaderPassCount;
-}
-
-// ***************************************************************************
-
-void CDriverD3D::setupMaterialPass(uint pass)
-{
- H_AUTO_D3D(CDriver3D_setupMaterialPass);
- activePass (pass);
-}
-
-// ***************************************************************************
-
-void CDriverD3D::endMaterialMultiPass()
-{
- H_AUTO_D3D(CDriver3D_endMaterialMultiPass);
- endMultiPass ();
-}
-
-// ***************************************************************************
-
-bool CDriverD3D::supportCloudRenderSinglePass () const
-{
- H_AUTO_D3D(CDriver3D_supportCloudRenderSinglePass);
- return _PixelProgram;
-}
-
-// ***************************************************************************
-
-void CDriverD3D::getNumPerStageConstant(uint &lightedMaterial, uint &unlightedMaterial) const
-{
- lightedMaterial = _MaxNumPerStageConstantLighted;
- unlightedMaterial = _MaxNumPerStageConstantUnlighted;
-}
-
-
-
-} // NL3D
diff --git a/code/nel/src/3d/driver/direct3d/driver_direct3d_matrix.cpp b/code/nel/src/3d/driver/direct3d/driver_direct3d_matrix.cpp
deleted file mode 100644
index 6e7520fb7..000000000
--- a/code/nel/src/3d/driver/direct3d/driver_direct3d_matrix.cpp
+++ /dev/null
@@ -1,445 +0,0 @@
-// NeL - MMORPG Framework
-// Copyright (C) 2010 Winch Gate Property Limited
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Affero General Public License as
-// published by the Free Software Foundation, either version 3 of the
-// License, or (at your option) any later version.
-//
-// This program 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 Affero General Public License for more details.
-//
-// You should have received a copy of the GNU Affero General Public License
-// along with this program. If not, see .
-
-#include "stddirect3d.h"
-
-#include "nel/3d/vertex_buffer.h"
-#include "nel/3d/light.h"
-#include "nel/3d/index_buffer.h"
-#include "nel/misc/rect.h"
-#include "nel/3d/viewport.h"
-#include "nel/3d/scissor.h"
-#include "nel/3d/u_driver.h"
-
-#include "driver_direct3d.h"
-
-#ifdef DEBUG_NEW
-#define new DEBUG_NEW
-#endif
-
-using namespace std;
-using namespace NLMISC;
-
-namespace NL3D
-{
-
-// ***************************************************************************
-
-void CDriverD3D::updateMatrices ()
-{
- H_AUTO_D3D(CDriver3D_updateMatrices );
- // Update view model matrix
- D3DXMatrixMultiply (&_D3DModelView, &(_MatrixCache[remapMatrixIndex (D3DTS_WORLD)].Matrix), &(_MatrixCache[remapMatrixIndex (D3DTS_VIEW)].Matrix));
-
- // Update view model projection matrix
- _D3DModelViewProjection = _D3DModelView;
- D3DXMatrixMultiply (&_D3DModelViewProjection, &_D3DModelViewProjection, &(_MatrixCache[remapMatrixIndex (D3DTS_PROJECTION)].Matrix));
-
- // Update the inverted view model matrix
- D3DXMatrixInverse (&_D3DInvModelView, NULL, &_D3DModelView);
-
- // Update the normalize state
- setRenderState (D3DRS_NORMALIZENORMALS, (_UserViewMtx.hasScalePart() || _UserModelMtx.hasScalePart() || _ForceNormalize)?TRUE:FALSE);
-}
-
-// ***************************************************************************
-
-void CDriverD3D::updateProjectionMatrix ()
-{
- H_AUTO_D3D(CDriver3D_updateProjectionMatrix );
- float left = _FrustumLeft;
- float right = _FrustumRight;
- float top = _FrustumTop;
- float bottom = _FrustumBottom;
-
- if (_RenderTarget.Texture)
- swap (bottom, top);
-
- // Get the render target size
- uint32 clientWidth;
- uint32 clientHeight;
- getRenderTargetSize (clientWidth, clientHeight);
-
- // In D3D, the center of the first screen pixel is [0.0,0.0]. Is NeL it is [0.5,0.5]
- const float addW = (right-left)/(2*(_Viewport.getWidth() * (float)clientWidth));
- const float addH = (bottom-top)/(2*(_Viewport.getHeight() * (float)clientHeight));
-
- left += addW;
- right += addW;
- top += addH;
- bottom += addH;
-
- D3DXMATRIX projection;
- if (_FrustumPerspective)
- {
- D3DXMatrixPerspectiveOffCenterLH (&projection, left, right, bottom, top, _FrustumZNear, _FrustumZFar);
- }
- else
- {
- D3DXMatrixOrthoOffCenterLH (&projection, left, right, bottom, top, _FrustumZNear, _FrustumZFar);
- }
- setMatrix (D3DTS_PROJECTION, projection);
-
- // Backup znear and zfar for zbias setup
- _OODeltaZ = 1 / (_FrustumZFar - _FrustumZNear);
-
- updateMatrices ();
-}
-
-// ***************************************************************************
-
-void CDriverD3D::setFrustum(float left, float right, float bottom, float top, float znear, float zfar, bool perspective)
-{
- H_AUTO_D3D(CDriverD3D_setFrustum)
- _FrustumLeft = left;
- _FrustumRight = right;
- _FrustumTop = top;
- _FrustumBottom = bottom;
- _FrustumZNear = znear;
- _FrustumZFar = zfar;
- _FrustumPerspective = perspective;
- updateProjectionMatrix ();
-}
-
-
-// ***************************************************************************
-
-void CDriverD3D::setFrustumMatrix(CMatrix &frustumMatrix)
-{
- H_AUTO_D3D(CDriverD3D_setFrustum)
-
- frustumMatrix.transpose();
- setMatrix (D3DTS_PROJECTION, D3DXMATRIX(frustumMatrix.get()));
-}
-
-// ***************************************************************************
-
-CMatrix CDriverD3D::getFrustumMatrix()
-{
- H_AUTO_D3D(CDriverD3D_getFrustum)
-
- CMatrix frustumMatrix;
- frustumMatrix.set((float *)_MatrixCache[D3DTS_PROJECTION].Matrix.m);
- frustumMatrix.transpose();
-
- return frustumMatrix;
-}
-
-// ***************************************************************************
-
-void CDriverD3D::setupViewMatrix(const CMatrix& mtx)
-{
- H_AUTO_D3D(CDriverD3D_setupViewMatrix)
- // Remember the view matrix
- _UserViewMtx= mtx;
- _PZBCameraPos= CVector::Null;
-
- // Set the driver matrix
- D3DXMATRIX view;
- NL_D3D_MATRIX (view, mtx);
-
- // Pass to directx matrix basis
- swap (view._12, view._13);
- swap (view._22, view._23);
- swap (view._32, view._33);
- swap (view._42, view._43);
-
- setMatrix (D3DTS_VIEW, view);
-
- // Set the spacular matrix
- CMatrix specularTex;
- specularTex = mtx;
- specularTex.setPos(CVector(0.0f,0.0f,0.0f));
- specularTex.invert();
- NL_D3D_MATRIX (_D3DSpecularWorldTex, specularTex);
-
- updateMatrices ();
-}
-
-// ***************************************************************************
-
-void CDriverD3D::setupViewMatrixEx(const CMatrix& mtx, const CVector &cameraPos)
-{
- H_AUTO_D3D(CDriverD3D_setupViewMatrixEx)
- // Remeber the view matrix
- _UserViewMtx= mtx;
- _PZBCameraPos= cameraPos;
-
- // Set the driver matrix
- D3DXMATRIX view;
- NL_D3D_MATRIX (view, mtx);
-
- // Pass to directx matrix basis
- swap (view._12, view._13);
- swap (view._22, view._23);
- swap (view._32, view._33);
- swap (view._42, view._43);
-
- // Reset the viewMtx position.
- view._41 = 0;
- view._42 = 0;
- view._43 = 0;
-
- setMatrix (D3DTS_VIEW, view);
-
- // Set the spacular matrix
- CMatrix specularTex;
- specularTex = mtx;
- NL_D3D_MATRIX (_D3DSpecularWorldTex, specularTex);
- swap (_D3DSpecularWorldTex._12, _D3DSpecularWorldTex._13);
- swap (_D3DSpecularWorldTex._22, _D3DSpecularWorldTex._23);
- swap (_D3DSpecularWorldTex._32, _D3DSpecularWorldTex._33);
- swap (_D3DSpecularWorldTex._42, _D3DSpecularWorldTex._43);
- _D3DSpecularWorldTex._41 = 0;
- _D3DSpecularWorldTex._42 = 0;
- _D3DSpecularWorldTex._43 = 0;
-
- D3DXMatrixInverse ( &_D3DSpecularWorldTex, NULL, &_D3DSpecularWorldTex);
- swap (_D3DSpecularWorldTex._12, _D3DSpecularWorldTex._13);
- swap (_D3DSpecularWorldTex._22, _D3DSpecularWorldTex._23);
- swap (_D3DSpecularWorldTex._32, _D3DSpecularWorldTex._33);
- swap (_D3DSpecularWorldTex._42, _D3DSpecularWorldTex._43);
-
- updateMatrices ();
-}
-
-// ***************************************************************************
-
-void CDriverD3D::setupModelMatrix(const CMatrix& mtx)
-{
- H_AUTO_D3D(CDriverD3D_setupModelMatrix)
- // Stats
- _NbSetupModelMatrixCall++;
-
- // Remeber the model matrix
- _UserModelMtx= mtx;
-
- D3DXMATRIX world;
- NL_D3D_MATRIX (world, mtx);
-
- // Remove from position the camera position
- world._41 -= _PZBCameraPos.x;
- world._42 -= _PZBCameraPos.y;
- world._43 -= _PZBCameraPos.z;
-
- setMatrix (D3DTS_WORLD, world);
-
- updateMatrices ();
-}
-
-// ***************************************************************************
-
-CMatrix CDriverD3D::getViewMatrix() const
-{
- H_AUTO_D3D(CDriverD3D_getViewMatrix)
- return _UserViewMtx;
-}
-
-// ***************************************************************************
-
-void CDriverD3D::forceNormalize(bool normalize)
-{
- H_AUTO_D3D(CDriverD3D_forceNormalize)
- _ForceNormalize = normalize;
- updateMatrices ();
-}
-
-// ***************************************************************************
-
-bool CDriverD3D::isForceNormalize() const
-{
- H_AUTO_D3D(CDriverD3D_isForceNormalize)
- return _RenderStateCache[D3DRS_NORMALIZENORMALS].Value != FALSE;
-}
-
-
-
-// ***************************************************************************
-
-void CDriverD3D::setupScissor (const class CScissor& scissor)
-{
- H_AUTO_D3D(CDriverD3D_setupScissor )
- if (!_ScissorTouched &&
- _Scissor.X == scissor.X &&
- _Scissor.Y == scissor.Y &&
- _Scissor.Width == scissor.Width &&
- _Scissor.Height == scissor.Height
- ) return;
- nlassert (_DeviceInterface);
-
- // Get viewport
- _ScissorTouched = false;
- float x= scissor.X;
- float width= scissor.Width;
- float height= scissor.Height;
-
- if(x==0 && x==0 && width==1 && height==1)
- {
- setRenderState (D3DRS_SCISSORTESTENABLE, FALSE);
- }
- else
- {
-
- float y= scissor.Y;
-
- if (_HWnd)
- {
- // Get the render target size
- uint32 clientWidth;
- uint32 clientHeight;
- getRenderTargetSize (clientWidth, clientHeight);
-
- // Setup d3d scissor
-
- RECT rect;
- rect.left=(int)floor((float)clientWidth * x + 0.5f);
- clamp (rect.left, 0, (int)clientWidth);
- if (_RenderTarget.Texture)
- rect.top=(int)floor((float)clientHeight* y + 0.5f);
- else
- rect.top=(int)floor((float)clientHeight* (1-y-height) + 0.5f);
- clamp (rect.top, 0, (int)clientHeight);
-
- rect.right=(int)floor((float)clientWidth * (x+width) + 0.5f );
- clamp (rect.right, 0, (int)clientWidth);
- if (_RenderTarget.Texture)
- rect.bottom=(int)floor((float)clientHeight* (y+height) + 0.5f);
- else
- rect.bottom=(int)floor((float)clientHeight* (1-y) + 0.5f);
- clamp (rect.bottom, 0, (int)clientHeight);
-
- {
- H_AUTO_D3D(CDriverD3D_setupScissorDevice )
- _DeviceInterface->SetScissorRect (&rect);
- }
- setRenderState (D3DRS_SCISSORTESTENABLE, TRUE);
-
- }
- }
-
- // Backup the scissor
- _Scissor = scissor;
-}
-
-// ***************************************************************************
-
-void CDriverD3D::setupViewport (const class CViewport& viewport)
-{
- H_AUTO_D3D(CDriverD3D_setupViewport )
- if (_HWnd == NULL)
- return;
-
- // Get the render target size
- uint32 clientWidth;
- uint32 clientHeight;
- getRenderTargetSize (clientWidth, clientHeight);
-
- // Get viewport
- float x;
- float y;
- float width;
- float height;
- viewport.getValues (x, y, width, height);
-
- // Get integer values
- int ix=(int)((float)clientWidth*x);
- clamp (ix, 0, (int)clientWidth);
- int iy;
- if (_RenderTarget.Texture)
- iy=(int)((float)clientHeight*y);
- else
- iy=(int)((float)clientHeight*(1.f-(y+height)));
- clamp (iy, 0, (int)clientHeight);
- int iwidth=(int)((float)clientWidth*width);
- clamp (iwidth, 0, (int)clientWidth-ix);
- int iheight=(int)((float)clientHeight*height);
- clamp (iheight, 0, (int)clientHeight-iy);
-
- // Setup D3D viewport
- _D3DViewport.X = ix;
- _D3DViewport.Y = iy;
- _D3DViewport.Width = iwidth;
- _D3DViewport.Height = iheight;
- _D3DViewport.MinZ = _DepthRangeNear;
- _D3DViewport.MaxZ = _DepthRangeFar;
- _DeviceInterface->SetViewport (&_D3DViewport);
-
- // Backup the viewport
- _Viewport = viewport;
-
- updateProjectionMatrix ();
-}
-
-// ***************************************************************************
-void CDriverD3D::setDepthRange(float znear, float zfar)
-{
- H_AUTO_D3D(CDriverD3D_setDepthRange)
- nlassert(znear != zfar);
- if (_HWnd == NULL)
- return;
-#ifdef NL_D3D_USE_RENDER_STATE_CACHE
- NL_D3D_CACHE_TEST(CacheTest_DepthRange, znear != _DepthRangeNear || zfar != _DepthRangeFar)
-#endif
- {
- _DepthRangeNear = znear;
- _DepthRangeFar = zfar;
- _D3DViewport.MinZ = _DepthRangeNear;
- _D3DViewport.MaxZ = _DepthRangeFar;
- _DeviceInterface->SetViewport (&_D3DViewport);
- }
-}
-
-// ***************************************************************************
-void CDriverD3D::getDepthRange(float &znear, float &zfar) const
-{
- H_AUTO_D3D(CDriverD3D_getDepthRange)
- znear = _DepthRangeNear;
- zfar = _DepthRangeFar;
-}
-
-// ***************************************************************************
-
-void CDriverD3D::getViewport(CViewport &viewport)
-{
- H_AUTO_D3D(CDriverD3D_getViewport)
- viewport = _Viewport;
-}
-
-// ***************************************************************************
-
-
-} // NL3D
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
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
deleted file mode 100644
index 7d79eb1a7..000000000
--- a/code/nel/src/3d/driver/direct3d/driver_direct3d_pixel_program.cpp
+++ /dev/null
@@ -1,157 +0,0 @@
-/** \file driver_direct3d_pixel_program.cpp
- * Direct 3d driver implementation
- *
- * $Id: driver_direct3d_pixel_program.cpp,v 1.1.2.4 2007/07/09 15:26:35 legallo Exp $
- *
- * \todo manage better the init/release system (if a throw occurs in the init, we must release correctly the driver)
- */
-
-/* Copyright, 2000 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 "stddirect3d.h"
-
-#include "driver_direct3d.h"
-
-#ifdef DEBUG_NEW
-#define new DEBUG_NEW
-#endif
-
-using namespace std;
-using namespace NLMISC;
-
-namespace NL3D
-{
-
-// ***************************************************************************
-
-CPixelProgramDrvInfosD3D::CPixelProgramDrvInfosD3D(IDriver *drv, ItGPUPrgDrvInfoPtrList it) : IProgramDrvInfos (drv, it)
-{
- H_AUTO_D3D(CPixelProgramDrvInfosD3D_CPixelProgamDrvInfosD3D)
- Shader = NULL;
-}
-
-// ***************************************************************************
-
-CPixelProgramDrvInfosD3D::~CPixelProgramDrvInfosD3D()
-{
- H_AUTO_D3D(CPixelProgramDrvInfosD3D_CPixelProgramDrvInfosD3DDtor)
- if (Shader)
- Shader->Release();
-}
-
-// ***************************************************************************
-
-bool CDriverD3D::supportPixelProgram (CPixelProgram::TProfile profile) const
-{
- H_AUTO_D3D(CDriverD3D_supportPixelProgram_profile)
- return ((profile & 0xFFFF0000) == 0xD9020000)
- && (_PixelProgramVersion >= (uint16)(profile & 0x0000FFFF));
-}
-
-// ***************************************************************************
-
-bool CDriverD3D::compilePixelProgram(CPixelProgram *program)
-{
- // Program setuped ?
- if (program->m_DrvInfo==NULL)
- {
- // Find a supported pixel program profile
- IProgram::CSource *source = NULL;
- for (uint i = 0; i < program->getSourceNb(); ++i)
- {
- if (supportPixelProgram(program->getSource(i)->Profile))
- {
- source = program->getSource(i);
- }
- }
- if (!source)
- {
- nlwarning("No supported source profile for pixel program");
- return false;
- }
-
- _GPUPrgDrvInfos.push_front (NULL);
- ItGPUPrgDrvInfoPtrList itPix = _GPUPrgDrvInfos.begin();
- CPixelProgramDrvInfosD3D *drvInfo;
- *itPix = drvInfo = new CPixelProgramDrvInfosD3D(this, itPix);
-
- // Create a driver info structure
- program->m_DrvInfo = *itPix;
-
- LPD3DXBUFFER pShader;
- LPD3DXBUFFER pErrorMsgs;
- if (D3DXAssembleShader(source->SourcePtr, source->SourceLen, NULL, NULL, 0, &pShader, &pErrorMsgs) == D3D_OK)
- {
- if (_DeviceInterface->CreatePixelShader((DWORD*)pShader->GetBufferPointer(), &(getPixelProgramD3D(*program)->Shader)) != D3D_OK)
- return false;
- }
- else
- {
- nlwarning ("Can't assemble pixel program:");
- nlwarning ((const char*)pErrorMsgs->GetBufferPointer());
- return false;
- }
-
- // Set parameters for assembly programs
- drvInfo->ParamIndices = source->ParamIndices;
-
- // Build the feature info
- program->buildInfo(source);
- }
-
- return true;
-}
-
-// ***************************************************************************
-
-bool CDriverD3D::activePixelProgram(CPixelProgram *program)
-{
- H_AUTO_D3D(CDriverD3D_activePixelProgram )
- if (_DisableHardwarePixelProgram)
- return false;
-
- // Set the pixel program
- if (program)
- {
- if (!CDriverD3D::compilePixelProgram(program)) return false;
-
- CPixelProgramDrvInfosD3D *info = static_cast((IProgramDrvInfos*)program->m_DrvInfo);
- _PixelProgramUser = program;
- setPixelShader(info->Shader);
- }
- else
- {
- setPixelShader(NULL);
- _PixelProgramUser = NULL;
- }
-
- return true;
-}
-
-// ***************************************************************************
-
-void CDriverD3D::disableHardwarePixelProgram()
-{
- H_AUTO_D3D(CDriverD3D_disableHardwarePixelProgram)
- _DisableHardwarePixelProgram = true;
- _PixelProgram = false;
-}
-
-} // NL3D
diff --git a/code/nel/src/3d/driver/direct3d/driver_direct3d_profile.cpp b/code/nel/src/3d/driver/direct3d/driver_direct3d_profile.cpp
deleted file mode 100644
index b574fff54..000000000
--- a/code/nel/src/3d/driver/direct3d/driver_direct3d_profile.cpp
+++ /dev/null
@@ -1,358 +0,0 @@
-// NeL - MMORPG Framework
-// Copyright (C) 2010 Winch Gate Property Limited
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Affero General Public License as
-// published by the Free Software Foundation, either version 3 of the
-// License, or (at your option) any later version.
-//
-// This program 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 Affero General Public License for more details.
-//
-// You should have received a copy of the GNU Affero General Public License
-// along with this program. If not, see .
-
-#include "stddirect3d.h"
-
-#include "driver_direct3d.h"
-#include "nel/misc/hierarchical_timer.h"
-
-#ifdef DEBUG_NEW
-#define new DEBUG_NEW
-#endif
-
-using namespace std;
-using namespace NLMISC;
-
-namespace NL3D
-{
-
-// ***************************************************************************
-
-void CDriverD3D::profileRenderedPrimitives(CPrimitiveProfile &pIn, CPrimitiveProfile &pOut)
-{
- pIn= _PrimitiveProfileIn;
- pOut= _PrimitiveProfileOut;
-}
-
-// ***************************************************************************
-
-uint32 CDriverD3D::profileAllocatedTextureMemory()
-{
- return _AllocatedTextureMemory;
-}
-
-// ***************************************************************************
-
-uint32 CDriverD3D::profileSetupedMaterials() const
-{
- return _NbSetupMaterialCall;
-}
-
-// ***************************************************************************
-
-uint32 CDriverD3D::profileSetupedModelMatrix() const
-{
- return _NbSetupModelMatrixCall;
-}
-
-// ***************************************************************************
-
-void CDriverD3D::enableUsedTextureMemorySum (bool enable)
-{
- if (enable)
- nlinfo ("PERFORMANCE INFO: enableUsedTextureMemorySum has been set to true in CDriverD3D\n");
- _SumTextureMemoryUsed=enable;
-}
-
-// ***************************************************************************
-
-uint32 CDriverD3D::getUsedTextureMemory() const
-{
- // Sum memory used
- uint32 memory=0;
-
- // For each texture used
- set::const_iterator ite=_TextureUsed.begin();
- while (ite!=_TextureUsed.end())
- {
- // Get the d3d texture
- CTextureDrvInfosD3D* d3dtext;
- d3dtext= (*ite);
-
- // Sum the memory used by this texture
- memory+=d3dtext->TextureMemory;
-
- // Next texture
- ite++;
- }
-
- // Return the count
- return memory;
-}
-
-// ***************************************************************************
-void CDriverD3D::startProfileVBHardLock()
-{
- if(_VBHardProfiling)
- return;
-
- // start
- _VBHardProfiles.clear();
- _VBHardProfiles.reserve(50);
- _VBHardProfiling= true;
- _CurVBHardLockCount= 0;
- _NumVBHardProfileFrame= 0;
- _VolatileVBLockTime = 0;
-}
-
-// ***************************************************************************
-
-void CDriverD3D::endProfileVBHardLock(std::vector &result)
-{
- if(!_VBHardProfiling)
- return;
-
- // Fill infos.
- result.clear();
- result.resize(_VBHardProfiles.size() + 2);
- float total= 0;
- for(uint i=0;i<_VBHardProfiles.size();i++)
- {
- const uint tmpSize= 256;
- char tmp[tmpSize];
- CVBHardProfile &vbProf= _VBHardProfiles[i];
- const char *vbName;
- if(vbProf.VBHard && !vbProf.VBHard->getName().empty())
- {
- vbName= vbProf.VBHard->getName().c_str();
- }
- else
- {
- vbName= "????";
- }
- // Display in ms.
- float timeLock= (float)CTime::ticksToSecond(vbProf.AccumTime)*1000 / max(_NumVBHardProfileFrame,1U);
- smprintf(tmp, tmpSize, "%16s%c: %2.3f ms", vbName, vbProf.Change?'*':' ', timeLock );
- total+= timeLock;
-
- result[i]= tmp;
- }
- result[_VBHardProfiles.size()]= toString("Total: %2.3f", total);
-// float volatileVBTimeLock = (float)CTime::ticksToSecond(_VolatileVBLockTime)*1000 / max(_NumVBHardProfileFrame,1U);
- result[_VBHardProfiles.size() + 1]= toString("Volatile Vertex Buffer lock time = %2.3f", _VolatileVBLockTime);
-
- // clear.
- _VBHardProfiling= false;
- contReset(_VBHardProfiles);
-}
-
-// ***************************************************************************
-
-void CDriverD3D::appendVBHardLockProfile(NLMISC::TTicks time, CVertexBuffer *vb)
-{
- // must allocate a new place?
- if(_CurVBHardLockCount>=_VBHardProfiles.size())
- {
- _VBHardProfiles.resize(_VBHardProfiles.size()+1);
- // set the original VBHard
- _VBHardProfiles[_CurVBHardLockCount].VBHard= vb;
- }
-
- // Accumulate.
- _VBHardProfiles[_CurVBHardLockCount].AccumTime+= time;
- // if change of VBHard for this chrono place
- if(_VBHardProfiles[_CurVBHardLockCount].VBHard != vb)
- {
- // flag, and set new
- _VBHardProfiles[_CurVBHardLockCount].VBHard= vb;
- _VBHardProfiles[_CurVBHardLockCount].Change= true;
- }
-
- // next!
- _CurVBHardLockCount++;
-}
-
-// ***************************************************************************
-void CDriverD3D::startProfileIBLock()
-{
- if(_IBProfiling)
- return;
-
- // start
- _IBProfiles.clear();
- _IBProfiles.reserve(50);
- _IBProfiling= true;
- _CurIBLockCount= 0;
- _NumIBProfileFrame= 0;
- _VolatileIBLockTime = 0;
-}
-
-// ***************************************************************************
-
-void CDriverD3D::endProfileIBLock(std::vector &result)
-{
- if(!_IBProfiling)
- return;
-
- // Fill infos.
- result.clear();
- result.resize(_IBProfiles.size() + 2);
- float total= 0;
- for(uint i=0;i<_IBProfiles.size();i++)
- {
- const uint tmpSize= 256;
- char tmp[tmpSize];
- CIBProfile &ibProf= _IBProfiles[i];
- const char *ibName;
- if(ibProf.IB && !ibProf.IB->getName().empty())
- {
- ibName= ibProf.IB->getName().c_str();
- }
- else
- {
- ibName= "????";
- }
- // Display in ms.
- float timeLock= (float)CTime::ticksToSecond(ibProf.AccumTime)*1000 / max(_NumIBProfileFrame,1U);
- smprintf(tmp, tmpSize, "%16s%c: %2.3f ms", ibName, ibProf.Change?'*':' ', timeLock );
- total+= timeLock;
-
- result[i]= tmp;
- }
- result[_IBProfiles.size()]= toString("Total: %2.3f", total);
- float volatileIBTimeLock = (float)CTime::ticksToSecond(_VolatileIBLockTime)*1000 / max(_NumIBProfileFrame,1U);
- result[_IBProfiles.size() + 1]= toString("Volatile Index Buffer lock time = %2.3f", volatileIBTimeLock);
- nlwarning("IB lock time = %2.3f", total);
- nlwarning("Volatile IB lock time = %2.3f", volatileIBTimeLock);
-
- // clear.
- _IBProfiling= false;
- contReset(_IBProfiles);
-}
-
-// ***************************************************************************
-
-void CDriverD3D::appendIBLockProfile(NLMISC::TTicks time, CIndexBuffer *ib)
-{
- // must allocate a new place?
- if(_CurIBLockCount>=_IBProfiles.size())
- {
- _IBProfiles.resize(_IBProfiles.size()+1);
- _IBProfiles[_CurIBLockCount].IB= ib;
- }
-
- // Accumulate.
- _IBProfiles[_CurIBLockCount].AccumTime+= time;
- // if change of VBHard for this chrono place
- if(_IBProfiles[_CurIBLockCount].IB != ib)
- {
- // flag, and set new
- _IBProfiles[_CurIBLockCount].IB= ib;
- _IBProfiles[_CurIBLockCount].Change= true;
- }
-
- // next!
- _CurIBLockCount++;
-}
-
-// ***************************************************************************
-void CDriverD3D::profileVBHardAllocation(std::vector &result)
-{
- result.clear();
- result.reserve(1000);
- result.push_back(toString("Memory Allocated: %4d Ko in AGP / %4d Ko in VRAM",
- getAvailableVertexAGPMemory()/1000, getAvailableVertexVRAMMemory()/1000 ));
- result.push_back(toString("Num VBHard: %d", _VertexBufferHardSet.size()));
-
- uint totalMemUsed= 0;
- set::iterator it;
- for(it= _VertexBufferHardSet.begin(); it!=_VertexBufferHardSet.end(); it++)
- {
- CVBDrvInfosD3D *vbHard= *it;
- if(vbHard)
- {
- uint vSize= vbHard->VertexBufferPtr->getVertexSize();
- uint numVerts= vbHard->VertexBufferPtr->getNumVertices();
- totalMemUsed+= vSize*numVerts;
- }
- }
- result.push_back(toString("Mem Used: %4d Ko", totalMemUsed/1000) );
-
- for(it= _VertexBufferHardSet.begin(); it!=_VertexBufferHardSet.end(); it++)
- {
- CVBDrvInfosD3D *vbHard= *it;
- if(vbHard)
- {
- uint vSize= vbHard->VertexBufferPtr->getVertexSize();
- uint numVerts= vbHard->VertexBufferPtr->getNumVertices();
- result.push_back(toString(" %16s: %4d ko (format: %d / numVerts: %d)",
- vbHard->VertexBufferPtr->getName().c_str(), vSize*numVerts/1000, vSize, numVerts ));
- }
- }
-}
-
-// ***************************************************************************
-void CDriverD3D::profileIBAllocation(std::vector &result)
-{
- result.clear();
- result.reserve(1000);
- result.push_back(toString("Memory Allocated: %4d Ko in AGP / %4d Ko in VRAM",
- getAvailableVertexAGPMemory()/1000, getAvailableVertexVRAMMemory()/1000 ));
- result.push_back(toString("Num Index buffers : %d", _IBDrvInfos.size()));
-
- uint totalMemUsed= 0;
- for(TIBDrvInfoPtrList::iterator it = _IBDrvInfos.begin(); it != _IBDrvInfos.end(); ++it)
- {
- CIBDrvInfosD3D *ib = NLMISC::safe_cast(*it);
- if(ib)
- {
- uint numIndex= ib->IndexBufferPtr->getNumIndexes();
- totalMemUsed+= sizeof(uint32)*numIndex;
- }
- }
- result.push_back(toString("Mem Used: %4d Ko", totalMemUsed/1000) );
-
- for(TIBDrvInfoPtrList::iterator it = _IBDrvInfos.begin(); it != _IBDrvInfos.end(); ++it)
- {
- CIBDrvInfosD3D *ib = NLMISC::safe_cast(*it);
- if(ib)
- {
- uint numIndex= ib->IndexBufferPtr->getNumIndexes();
- result.push_back(toString(" %16s: %4d ko ",
- ib->IndexBufferPtr->getName().c_str(), sizeof(uint32) * numIndex));
- }
- }
-}
-
-// ***************************************************************************
-
-void CDriverD3D::startBench (bool wantStandardDeviation, bool quick, bool reset)
-{
- CHTimer::startBench (wantStandardDeviation, quick, reset);
-}
-
-// ***************************************************************************
-
-void CDriverD3D::endBench ()
-{
- CHTimer::endBench ();
-}
-
-// ***************************************************************************
-
-void CDriverD3D::displayBench (class NLMISC::CLog *log)
-{
- // diplay
- CHTimer::displayHierarchicalByExecutionPathSorted(log, CHTimer::TotalTime, true, 48, 2);
- CHTimer::displayHierarchical(log, true, 48, 2);
- CHTimer::displayByExecutionPath(log, CHTimer::TotalTime);
- CHTimer::display(log, CHTimer::TotalTime);
- CHTimer::display(log, CHTimer::TotalTimeWithoutSons);
-}
-
-// ***************************************************************************
-
-} // NL3D
diff --git a/code/nel/src/3d/driver/direct3d/driver_direct3d_render.cpp b/code/nel/src/3d/driver/direct3d/driver_direct3d_render.cpp
deleted file mode 100644
index 6b9d2ce0c..000000000
--- a/code/nel/src/3d/driver/direct3d/driver_direct3d_render.cpp
+++ /dev/null
@@ -1,468 +0,0 @@
-// NeL - MMORPG Framework
-// Copyright (C) 2010 Winch Gate Property Limited
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Affero General Public License as
-// published by the Free Software Foundation, either version 3 of the
-// License, or (at your option) any later version.
-//
-// This program 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 Affero General Public License for more details.
-//
-// You should have received a copy of the GNU Affero General Public License
-// along with this program. If not, see .
-
-#include "stddirect3d.h"
-
-#include "nel/3d/vertex_buffer.h"
-#include "nel/3d/light.h"
-#include "nel/3d/index_buffer.h"
-#include "nel/misc/rect.h"
-#include "nel/misc/fast_mem.h"
-#include "nel/3d/viewport.h"
-#include "nel/3d/scissor.h"
-#include "nel/3d/u_driver.h"
-
-#include "driver_direct3d.h"
-
-#ifdef DEBUG_NEW
-#define new DEBUG_NEW
-#endif
-
-using namespace std;
-using namespace NLMISC;
-
-
-
-
-namespace NL3D
-{
-
-
-
-
-// convert 32 bit indices to 16 bit indices on devices that don't have 32 bit indices
-// ***************************************************************************
-void CDriverD3D::convertToIndices16(uint firstIndex, uint numIndices)
-{
- nlassert(numIndices > 0);
- // Lock the good buffer
- uint offset;
- CVolatileIndexBuffer *&buffer = _VolatileIndexBuffer16RAM[_CurrentRenderPass&1];
- uint16 *ptr = (uint16*)buffer->lock (numIndices*sizeof(uint16), offset);
- if (!ptr)
- {
- // index buffer full, swap with other buffer
- CVolatileIndexBuffer *&bufferOther = _VolatileIndexBuffer16RAM[(_CurrentRenderPass + 1) &1];
- std::swap(buffer, bufferOther);
- buffer->reset();
- ptr = (uint16*)buffer->lock (numIndices*sizeof(uint16), offset);
- }
- const uint32 *currIndex = &_LastIndexBufferInfo->RamVersion[firstIndex];
- const uint32 *indexEnd = currIndex + numIndices;
- do
- {
- #ifdef NL_DEBUG
- nlassertex(*currIndex < _MaxVertexIndex, ("In this implementation, only 16 bit indices are supported"));
- #endif
- *ptr++ = (uint16&) (*currIndex++);
- }
- while (currIndex != indexEnd);
- buffer->unlock();
- setIndexBuffer(buffer->IndexBuffer, offset);
-}
-
-// ***************************************************************************
-#ifndef NL_DEBUG
- inline
-#endif
-bool CDriverD3D::renderPrimitives(D3DPRIMITIVETYPE primitiveType, uint /* numVertexPerPrim */, CMaterial& mat, uint firstVertex, uint32 nPrims)
-{
- // Setup material
- if ( !setupMaterial(mat) )
- return false;
- if (nPrims == 0)
- return false;
- nlassertex(nPrims < _MaxPrimitiveCount, ("Number of max primitive at each calls limited in this implementation on current hradware"));
- if (_VertexBufferCache.VertexBuffer)
- {
- uint pass;
- beginMultiPass ();
- for (pass=0; pass<_CurrentShaderPassCount; pass++)
- {
- // Active the pass
- activePass (pass);
- HRESULT r = _DeviceInterface->DrawPrimitive (primitiveType, firstVertex + _VertexBufferOffset, nPrims);
- nlassert(r == D3D_OK);
- }
- endMultiPass ();
- }
- return true;
-}
-
-
-
-
-// ***************************************************************************
-#ifndef NL_DEBUG
- inline
-#endif
-bool CDriverD3D::renderIndexedPrimitives(D3DPRIMITIVETYPE primitiveType, uint numVertexPerPrim, CMaterial& mat, uint32 firstIndex, uint32 nPrims, uint indexOffset /*= 0*/)
-{
- // Setup material
- if ( !setupMaterial(mat) )
- return false;
- if (nPrims == 0)
- return false;
- nlassertex(nPrims < _MaxPrimitiveCount, ("Number of max primitive at each calls limited in this implementation on current hardware"));
- nlassert(_CurrIndexBufferFormat != CIndexBuffer::IndicesUnknownFormat);
- if (_MaxVertexIndex <= 0xffff && _CurrIndexBufferFormat == CIndexBuffer::Indices32)
- {
- convertToIndices16(firstIndex, numVertexPerPrim * nPrims);
- firstIndex = 0;
- }
- if (_VertexBufferCache.VertexBuffer && _IndexBufferCache.IndexBuffer)
- {
- uint pass;
- beginMultiPass ();
- for (pass=0; pass< _CurrentShaderPassCount; pass++)
- {
- // Active the pass
- activePass (pass);
- // NB : indexOffset is actually a constant added to each index in the current index buffer (actually may be implemented
- // by moving vertex pointer in the driver ...), whereas _IndexBufferOffset+firstIndex gives an offset into the index buffer
- HRESULT r = _DeviceInterface->DrawIndexedPrimitive (primitiveType, _VertexBufferOffset + indexOffset, 0, _VertexBufferSize,
- firstIndex+_IndexBufferOffset, nPrims);
- nlassert(r == D3D_OK);
-
- }
- endMultiPass ();
- }
- return true;
-}
-
-// ***************************************************************************
-#ifndef NL_DEBUG
- inline
-#endif
-bool CDriverD3D::renderSimpleIndexedPrimitives(D3DPRIMITIVETYPE primitiveType, uint numVertexPerPrim, uint32 firstIndex, uint32 nPrims, uint indexOffset /*= 0*/)
-{
- if (nPrims == 0)
- return false;
- nlassertex(nPrims < _MaxPrimitiveCount, ("Number of max primitive at each calls limited in this implementation on current hardware"));
- nlassert(_CurrIndexBufferFormat != CIndexBuffer::IndicesUnknownFormat);
- if (_MaxVertexIndex <= 0xffff && _CurrIndexBufferFormat == CIndexBuffer::Indices32)
- {
- convertToIndices16(firstIndex, numVertexPerPrim * nPrims);
- firstIndex = 0;
- }
- if (_VertexBufferCache.VertexBuffer && _IndexBufferCache.IndexBuffer)
- {
- updateRenderVariablesInternal();
- //fixVB(nPrims, numVertexPerPrim);
- // NB : indexOffset is actually a constant added to each index in the current index buffer (actually may be implemented
- // by moving vertex pointer in the driver ...), whereas _IndexBufferOffset+firstIndex gives an offset into the index buffer
- HRESULT r = _DeviceInterface->DrawIndexedPrimitive (primitiveType, _VertexBufferOffset + indexOffset, 0, _VertexBufferSize,
- firstIndex+_IndexBufferOffset, nPrims);
- nlassert(r == D3D_OK);
- }
- return true;
-}
-
-// ***************************************************************************
-
-bool CDriverD3D::renderLines(CMaterial& mat, uint32 firstIndex, uint32 nlines)
-{
- H_AUTO_D3D(CDriverD3D_renderLines)
- if (!renderIndexedPrimitives(D3DPT_LINELIST, 2, mat, firstIndex, nlines)) return false;
- // Stats
- _PrimitiveProfileIn.NLines += nlines;
- _PrimitiveProfileOut.NLines += nlines*_CurrentShaderPassCount;
-
- return true;
-}
-
-
-// ***************************************************************************
-
-bool CDriverD3D::renderTriangles(CMaterial& mat, uint32 firstIndex, uint32 ntris)
-{
- H_AUTO_D3D(CDriverD3D_renderTriangles)
- if (!renderIndexedPrimitives(D3DPT_TRIANGLELIST, 3, mat, firstIndex, ntris)) return false;
- // Stats
- _PrimitiveProfileIn.NTriangles += ntris;
- _PrimitiveProfileOut.NTriangles += ntris*_CurrentShaderPassCount;
- return true;
-}
-
-// ***************************************************************************
-
-bool CDriverD3D::renderSimpleTriangles(uint32 firstIndex, uint32 ntris)
-{
- H_AUTO_D3D(CDriverD3D_renderSimpleTriangles)
- nlassert (ntris != 0);
- nlassert (_VertexBufferCache.VertexBuffer);
- nlassert (_IndexBufferCache.IndexBuffer);
- if (!renderSimpleIndexedPrimitives(D3DPT_TRIANGLELIST, 3, firstIndex, ntris)) return false;
- // Stats
- _PrimitiveProfileIn.NTriangles += ntris;
- _PrimitiveProfileOut.NTriangles += ntris;
-
- return true;
-}
-
-// ***************************************************************************
-bool CDriverD3D::renderLinesWithIndexOffset(CMaterial& mat, uint32 firstIndex, uint32 nlines, uint indexOffset)
-{
- H_AUTO_D3D(CDriverD3D_renderLinesWithIndexOffset)
- if (!renderIndexedPrimitives(D3DPT_LINELIST, 2, mat, firstIndex, nlines, indexOffset)) return false;
- // Stats
- _PrimitiveProfileIn.NLines += nlines;
- _PrimitiveProfileOut.NLines += nlines*_CurrentShaderPassCount;
- return true;
-}
-
-// ***************************************************************************
-bool CDriverD3D::renderTrianglesWithIndexOffset(CMaterial& mat, uint32 firstIndex, uint32 ntris, uint indexOffset)
-{
- H_AUTO_D3D(CDriverD3D_renderTrianglesWithIndexOffset)
- if (!renderIndexedPrimitives(D3DPT_TRIANGLELIST, 3, mat, firstIndex, ntris, indexOffset)) return false;
- // Stats
- _PrimitiveProfileIn.NTriangles += ntris;
- _PrimitiveProfileOut.NTriangles += ntris*_CurrentShaderPassCount;
- return true;
-}
-
-// ***************************************************************************
-bool CDriverD3D::renderSimpleTrianglesWithIndexOffset(uint32 firstIndex, uint32 ntris, uint indexOffset)
-{
- H_AUTO_D3D(CDriverD3D_renderSimpleTrianglesWithIndexOffset)
- nlassert (ntris != 0);
- nlassert (_VertexBufferCache.VertexBuffer);
- nlassert (_IndexBufferCache.IndexBuffer);
- if (!renderSimpleIndexedPrimitives(D3DPT_TRIANGLELIST, 3, firstIndex, ntris, indexOffset)) return false;
- // Stats
- _PrimitiveProfileIn.NTriangles += ntris;
- _PrimitiveProfileOut.NTriangles += ntris;
-
- return true;
-}
-
-// ***************************************************************************
-bool CDriverD3D::renderRawPoints(CMaterial& mat, uint32 firstIndex, uint32 numPoints)
-{
- H_AUTO_D3D(CDriverD3D_renderRawPoints);
- if (!renderPrimitives(D3DPT_POINTLIST, 1, mat, firstIndex, numPoints))
- // Stats
- _PrimitiveProfileIn.NPoints += numPoints;
- _PrimitiveProfileOut.NPoints += numPoints*_CurrentShaderPassCount;
- return true;
-}
-
-// ***************************************************************************
-bool CDriverD3D::renderRawLines(CMaterial& mat, uint32 firstIndex, uint32 numLines)
-{
- H_AUTO_D3D(CDriverD3D_renderRawLines);
- if (!renderPrimitives(D3DPT_LINELIST, 2, mat, firstIndex, numLines)) return false;
- // Stats
- _PrimitiveProfileIn.NLines += numLines;
- _PrimitiveProfileOut.NLines += numLines*_CurrentShaderPassCount;
-
- return true;
-}
-
-// ***************************************************************************
-
-bool CDriverD3D::renderRawTriangles(CMaterial& mat, uint32 firstIndex, uint32 numTris)
-{
- H_AUTO_D3D(CDriverD3D_renderRawTriangles)
- if (!renderPrimitives(D3DPT_TRIANGLELIST, 3, mat, 3 * firstIndex, numTris)) return false;
- // Stats
- _PrimitiveProfileIn.NTriangles += numTris;
- _PrimitiveProfileOut.NTriangles += numTris*_CurrentShaderPassCount;
-
- return true;
-}
-
-// ***************************************************************************
-// 32 bits version
-void fillQuadIndexes (uint32 *indexes, uint first, uint last)
-{
- H_AUTO_D3D(fillQuadIndexes)
- uint firstQuad = (first / 6) * 4;
- for (;firstSetRenderState (D3DRS_ALPHABLENDENABLE, FALSE);
- _DeviceInterface->SetRenderState (D3DRS_SRCBLEND, D3DBLEND_ONE);
- _DeviceInterface->SetRenderState (D3DRS_DESTBLEND, D3DBLEND_ZERO);
- _DeviceInterface->SetRenderState (D3DRS_ALPHATESTENABLE, FALSE);
- _DeviceInterface->SetRenderState (D3DRS_ALPHAREF, 128);
- _DeviceInterface->SetRenderState (D3DRS_ALPHAFUNC, D3DCMP_GREATER);
- _DeviceInterface->SetRenderState (D3DRS_LIGHTING, FALSE);
- _DeviceInterface->SetRenderState (D3DRS_TEXTUREFACTOR, NL_D3DCOLOR_RGBA(CRGBA(255,0,255,255)));
- _DeviceInterface->SetRenderState (D3DRS_CULLMODE, D3DCULL_CW);
- _DeviceInterface->SetRenderState (D3DRS_COLORVERTEX, FALSE);
- _DeviceInterface->SetRenderState (D3DRS_ZWRITEENABLE, TRUE);
- _DeviceInterface->SetRenderState (D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
- _DeviceInterface->SetRenderState (D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL);
- _DeviceInterface->SetRenderState (D3DRS_SPECULARMATERIALSOURCE, D3DMCS_MATERIAL);
- _DeviceInterface->SetRenderState (D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL);
- _DeviceInterface->SetRenderState (D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_MATERIAL);
- _DeviceInterface->SetTexture (0, NULL);
- _DeviceInterface->SetTexture (1, NULL);
- _DeviceInterface->SetTexture (2, NULL);
- _DeviceInterface->SetTexture (3, NULL);
- _DeviceInterface->SetTexture (4, NULL);
- _DeviceInterface->SetTexture (5, NULL);
- _DeviceInterface->SetTexture (6, NULL);
- _DeviceInterface->SetTexture (7, NULL);
- _DeviceInterface->SetTextureStageState (0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
- _DeviceInterface->SetTextureStageState (0, D3DTSS_COLORARG0, D3DTA_TFACTOR);
- _DeviceInterface->SetTextureStageState (0, D3DTSS_COLORARG1, D3DTA_TFACTOR);
- _DeviceInterface->SetTextureStageState (0, D3DTSS_COLORARG2, D3DTA_TFACTOR);
- _DeviceInterface->SetTextureStageState (0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
- _DeviceInterface->SetTextureStageState (0, D3DTSS_ALPHAARG0, D3DTA_TFACTOR);
- _DeviceInterface->SetTextureStageState (0, D3DTSS_ALPHAARG1, D3DTA_TFACTOR);
- _DeviceInterface->SetTextureStageState (0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR);
- // _DeviceInterface->SetTextureStageState (0, D3DTSS_CONSTANT, 0x0);
- uint i;
- for (i=1; i<8; i++)
- {
- _DeviceInterface->SetTextureStageState (i, D3DTSS_COLOROP, D3DTOP_DISABLE);
- _DeviceInterface->SetTextureStageState (i, D3DTSS_COLORARG0, D3DTA_TFACTOR);
- _DeviceInterface->SetTextureStageState (i, D3DTSS_COLORARG1, D3DTA_TFACTOR);
- _DeviceInterface->SetTextureStageState (i, D3DTSS_COLORARG2, D3DTA_TFACTOR);
- _DeviceInterface->SetTextureStageState (i, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
- _DeviceInterface->SetTextureStageState (i, D3DTSS_ALPHAARG0, D3DTA_TFACTOR);
- _DeviceInterface->SetTextureStageState (i, D3DTSS_ALPHAARG1, D3DTA_TFACTOR);
- _DeviceInterface->SetTextureStageState (i, D3DTSS_ALPHAARG2, D3DTA_TFACTOR);
- // _DeviceInterface->SetTextureStageState (i, D3DTSS_CONSTANT, 0x0);
- }
-}
-
-
-// ***************************************************************************
-bool CDriverD3D::renderRawQuads(CMaterial& mat, uint32 startIndex, uint32 numQuads)
-{
- H_AUTO_D3D(CDriverD3D_renderRawQuads)
- if (numQuads == 0) return false;
- else
- if (_VertexBufferCache.VertexBuffer)
- {
- // Num of indexes needed
- const uint numQuadsNeeded = numQuads*6;
- nlassert(numQuads < MAX_NUM_QUADS); // this limitation should suffice for now
- {
- if (_MaxVertexIndex <= 0xffff)
- {
- nlassert(_QuadIB);
- setIndexBuffer(_QuadIB, 0);
- _CurrIndexBufferFormat = CIndexBuffer::Indices16; // must set the format because we don't call activeIndexBuffer
- }
- else
- {
- const uint IB_RESIZE_STRIDE = 6 * 256;
- nlctassert(IB_RESIZE_STRIDE % 6 == 0);
- // Need to resize the quad indexes array ?
- if (_QuadIndexes.getNumIndexes() < numQuadsNeeded)
- {
- // Resize it
- uint32 numIndexResize = IB_RESIZE_STRIDE * ((numQuadsNeeded + (IB_RESIZE_STRIDE - 1)) / IB_RESIZE_STRIDE);
- _QuadIndexes.setFormat(NL_DEFAULT_INDEX_BUFFER_FORMAT);
- _QuadIndexes.setNumIndexes(numIndexResize); // snap to nearest size
- // Fill the index buffer in VRAM
- CIndexBufferReadWrite iba;
- _QuadIndexes.lock (iba);
- if (_QuadIndexes.getFormat() == CIndexBuffer::Indices32)
- {
- fillQuadIndexes ((uint32 *) iba.getPtr(), 0, numIndexResize);
- }
- else
- {
- fillQuadIndexes ((uint16 *) iba.getPtr(), 0, numIndexResize);
- }
- }
- activeIndexBuffer (_QuadIndexes);
- }
- // Setup material
- if ( !setupMaterial(mat) )
- return false;
-
- uint pass;
- beginMultiPass ();
- for (pass=0; pass<_CurrentShaderPassCount; pass++)
- {
- // Active the pass
- activePass (pass);
- //fixVB(numQuads, 4);
- _DeviceInterface->DrawIndexedPrimitive (D3DPT_TRIANGLELIST, _VertexBufferOffset + startIndex, 0, numQuads * 4,
- 0, numQuads*2);
- }
- endMultiPass ();
- }
- }
-
- // Stats
- _PrimitiveProfileIn.NTriangles += numQuads*2;
- _PrimitiveProfileOut.NTriangles += numQuads*2*_CurrentShaderPassCount;
-
- return true;
-}
-
-// ***************************************************************************
-
-} // NL3D
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/code/nel/src/3d/driver/direct3d/driver_direct3d_shader.cpp b/code/nel/src/3d/driver/direct3d/driver_direct3d_shader.cpp
deleted file mode 100644
index 3f11f8bce..000000000
--- a/code/nel/src/3d/driver/direct3d/driver_direct3d_shader.cpp
+++ /dev/null
@@ -1,4011 +0,0 @@
-// NeL - MMORPG Framework
-// Copyright (C) 2010 Winch Gate Property Limited
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Affero General Public License as
-// published by the Free Software Foundation, either version 3 of the
-// License, or (at your option) any later version.
-//
-// This program 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 Affero General Public License for more details.
-//
-// You should have received a copy of the GNU Affero General Public License
-// along with this program. If not, see .
-
-#include "stddirect3d.h"
-
-#include "driver_direct3d.h"
-#include "nel/misc/path.h"
-#include "nel/misc/file.h"
-
-#ifdef DEBUG_NEW
-#define new DEBUG_NEW
-#endif
-
-using namespace std;
-using namespace NLMISC;
-
-namespace NL3D
-{
-
-
-// ***************************************************************************
-
-CD3DShaderFX::~CD3DShaderFX()
-{
- // Must kill the drv mirror of this shader.
- _DrvInfo.kill();
-}
-
-// ***************************************************************************
-
-CD3DShaderFX::CD3DShaderFX()
-{
- _ShaderChanged = true;
-}
-
-// ***************************************************************************
-
-void CD3DShaderFX::setText (const char *text)
-{
- _Text = text;
- _ShaderChanged = true;
-}
-
-// ***************************************************************************
-
-void CD3DShaderFX::setName (const char *name)
-{
- _Name = name;
- _ShaderChanged = true;
-}
-
-// ***************************************************************************
-
-bool CD3DShaderFX::loadShaderFile (const char *filename)
-{
- _Text.clear();
- // Lookup
- string _filename = NLMISC::CPath::lookup(filename, false, true, true);
- if (!_filename.empty())
- {
- // File length
- uint size = NLMISC::CFile::getFileSize (_filename);
- _Text.reserve (size+1);
-
- try
- {
- NLMISC::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 = NLMISC::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);
-}
-
-void CDriverD3D::removeShaderDrvInfoPtr(ItShaderDrvInfoPtrList shaderIt)
-{
- _ShaderDrvInfos.erase(shaderIt);
-}
-
-// mem allocator for state records
-std::allocator CStateRecord::Allocator;
-
-
-// ***************************************************************************
-// The state manager with cache
-// ***************************************************************************
-
-HRESULT CDriverD3D::QueryInterface(REFIID /* riid */, LPVOID * /* ppvObj */)
-{
- H_AUTO_D3D(CDriverD3D_QueryInterface)
- return D3D_OK;
-}
-
-// ***************************************************************************
-
-ULONG CDriverD3D::AddRef(VOID)
-{
- H_AUTO_D3D(CDriverD3D_AddRef)
- return 0;
-}
-
-// ***************************************************************************
-
-ULONG CDriverD3D::Release(VOID)
-{
- H_AUTO_D3D(CDriverD3D_Release)
- return 0;
-}
-
-// ***************************************************************************
-
-HRESULT CDriverD3D::LightEnable(DWORD Index, BOOL Enable)
-{
- H_AUTO_D3D(CDriverD3D_LightEnable)
- enableLight ((uint8)Index, Enable!=FALSE);
- return D3D_OK;
-}
-
-// ***************************************************************************
-
-HRESULT CDriverD3D::SetFVF(DWORD /* FVF */)
-{
- H_AUTO_D3D(CDriverD3D_SetFVF)
- // Not implemented
- return D3D_OK;
-}
-
-// ***************************************************************************
-
-HRESULT CDriverD3D::SetLight(DWORD Index, CONST D3DLIGHT9* pLight)
-{
- H_AUTO_D3D(CDriverD3D_SetLight)
- _LightCache[Index].Light = *pLight;
- touchRenderVariable (&_LightCache[Index]);
- return D3D_OK;
-}
-
-// ***************************************************************************
-
-HRESULT CDriverD3D::SetMaterial(CONST D3DMATERIAL9* pMaterial)
-{
- H_AUTO_D3D(CDriverD3D_SetMaterial)
- setMaterialState( *pMaterial );
- return D3D_OK;
-}
-
-// ***************************************************************************
-
-HRESULT CDriverD3D::SetNPatchMode(FLOAT /* nSegments */)
-{
- H_AUTO_D3D(CDriverD3D_SetNPatchMode)
- // Not implemented
- return D3D_OK;
-}
-
-// ***************************************************************************
-
-HRESULT CDriverD3D::SetPixelShader(LPDIRECT3DPIXELSHADER9 pShader)
-{
- H_AUTO_D3D(CDriverD3D_SetPixelShader)
- setPixelShader (pShader);
- return D3D_OK;
-}
-
-// ***************************************************************************
-
-HRESULT CDriverD3D::SetPixelShaderConstantB(UINT StartRegister, CONST BOOL* pConstantData, UINT RegisterCount)
-{
- H_AUTO_D3D(CDriverD3D_SetPixelShaderConstantB)
- uint i;
- for (i=0; iRelease();
-}
-
-// ***************************************************************************
-
-bool CDriverD3D::validateShader(CD3DShaderFX *shader)
-{
- H_AUTO_D3D(CDriverD3D_validateShader)
- CShaderDrvInfosD3D *shaderInfo = static_cast((IShaderDrvInfos*)shader->_DrvInfo);
-
- if (!shaderInfo->Validated)
- {
- // Choose the good method
- D3DXHANDLE hTechnique = NULL;
- D3DXHANDLE hCurrentTechnique = NULL;
- while (hTechnique == NULL)
- {
- if (shaderInfo->Effect->FindNextValidTechnique(hCurrentTechnique, &hCurrentTechnique) != D3D_OK)
- return false;
-
- // Info
-
-#ifdef NL_FORCE_TEXTURE_STAGE_COUNT
- D3DXTECHNIQUE_DESC desc;
- nlverify (shaderInfo->Effect->GetTechniqueDesc(hCurrentTechnique, &desc) == D3D_OK);
-
- // Check this is compatible
- const uint len = strlen(desc.Name);
- if (len)
- {
- char shaderStageCount = desc.Name[len-1];
- if ((shaderStageCount>='0') && (shaderStageCount<='9'))
- {
- uint stageCount = NL_FORCE_TEXTURE_STAGE_COUNT;
-
- if ((uint)(shaderStageCount-'0')<=stageCount)
- // The good technique
- hTechnique = hCurrentTechnique;
- }
- }
-#else // NL_FORCE_TEXTURE_STAGE_COUNT
- hTechnique = hCurrentTechnique;
-#endif // NL_FORCE_TEXTURE_STAGE_COUNT
-
-#ifdef NL_DEBUG_D3D
- {
- D3DXTECHNIQUE_DESC desc;
- nlverify (shaderInfo->Effect->GetTechniqueDesc(hCurrentTechnique, &desc) == D3D_OK);
- if (hTechnique)
- nlinfo ("Shader \"%s\" : use technique \"%s\" with %d passes.", shader->getName(), desc.Name, desc.Passes);
- }
-#endif // NL_DEBUG_D3D
- }
-
- // Set the technique
- shaderInfo->Effect->SetTechnique(hTechnique);
-
- // Set the state manager
- shaderInfo->Effect->SetStateManager (this);
-
- shaderInfo->Validated = true;
- }
- return true;
-}
-
-// ***************************************************************************
-
-bool CDriverD3D::activeShader(CD3DShaderFX *shd)
-{
- H_AUTO_D3D(CDriverD3D_activeShader)
- if (_DisableHardwarePixelShader)
- return false;
-
- // Clear current textures
- _CurrentShaderTextures.clear();
-
- // Shader has been changed ?
- if (shd && shd->_ShaderChanged)
- {
- // Remove old shader
- shd->_DrvInfo.kill();
-
- // Already setuped ?
- CShaderDrvInfosD3D *shaderInfo = static_cast((IShaderDrvInfos*)shd->_DrvInfo);
- if ( !shd->_DrvInfo )
- {
- // insert into driver list. (so it is deleted when driver is deleted).
- ItShaderDrvInfoPtrList it= _ShaderDrvInfos.insert(_ShaderDrvInfos.end(), (NL3D::IShaderDrvInfos*)NULL);
- // create and set iterator, for future deletion.
- shaderInfo = new CShaderDrvInfosD3D(this, it);
- *it= shd->_DrvInfo = shaderInfo;
- }
-
- // Assemble the shader
- LPD3DXBUFFER pErrorMsgs;
- HRESULT hr = D3DXCreateEffect(_DeviceInterface, shd->getText(), (UINT)strlen(shd->getText())+1, NULL, NULL, 0, NULL, &(shaderInfo->Effect), &pErrorMsgs);
- if (hr == D3D_OK)
- {
- // Get the texture handle
- uint i;
- for (i=0; iTextureHandle[i] = shaderInfo->Effect->GetParameterByName(NULL, name.c_str());
- name = "color" + toString (i);
- shaderInfo->ColorHandle[i] = shaderInfo->Effect->GetParameterByName(NULL, name.c_str());
- name = "factor" + toString (i);
- shaderInfo->FactorHandle[i] = shaderInfo->Effect->GetParameterByName(NULL, name.c_str());
- name = "scalarFloat" + toString (i);
- shaderInfo->ScalarFloatHandle[i] = shaderInfo->Effect->GetParameterByName(NULL, name.c_str());
- }
- }
- else
- {
- nlwarning ("Can't create shader '%s' (0x%x):", shd->getName(), hr);
- if (pErrorMsgs)
- nlwarning ((const char*)pErrorMsgs->GetBufferPointer());
- shd->_ShaderChanged = false;
- _CurrentShader = NULL;
- return false;
- }
-
- // Done
- shd->_ShaderChanged = false;
- }
-
- // Set the shader
- _CurrentShader = shd;
-
- return true;
-}
-
-
-static void setFX(CD3DShaderFX &s, const char *name, const char *prog, CDriverD3D *drv)
-{
- H_AUTO_D3D(setFX)
-
- s.setName(name);
- s.setText(prog);
- nlverify (drv->activeShader (&s));
-}
-
-#define setFx(a,b,c) { setFX(a, b, c, this); }
-
-static const char *CloudFx =
-" \n\
-texture texture0; \n\
-texture texture1; \n\
-float4 factor0; \n\
- \n\
-pixelshader two_stages_ps = asm \n\
-{ \n\
- ps_1_1; \n\
- tex t0; \n\
- tex t1; \n\
- lrp r0.w, v0, t0, t1; \n\
- mov r0.xyz, c0; \n\
- +mul r0.w, c0, r0; \n\
-}; \n\
- \n\
-technique two_stages_2 \n\
-{ \n\
- pass p0 \n\
- { \n\
- Texture[0] = ; \n\
- Texture[1] = ; \n\
- PixelShaderConstant[0] = ; \n\
- PixelShader = (two_stages_ps); \n\
- } \n\
-}; \n\
- \n\
-";
-
-static const char *Lightmap0Fx =
-" \n\
-texture texture0; \n\
- \n\
-float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
-float4 g_dyn_factor = { 1.0f, 1.0f, 1.0f, 1.0f }; \n\
- \n\
-technique one_stage_1 \n\
-{ \n\
- pass p0 \n\
- { \n\
- // do a standard lighting with the first light \n\
- Lighting = true; \n\
- MaterialEmissive= ; \n\
- MaterialAmbient= ; \n\
- MaterialDiffuse= ; \n\
- MaterialSpecular= ; \n\
- AlphaBlendEnable = false; \n\
- \n\
- Texture[0] = ; \n\
- ColorOp[0] = MODULATE; \n\
- ColorArg1[0] = TEXTURE; \n\
- ColorArg2[0] = DIFFUSE; \n\
- AlphaOp[0] = SELECTARG1; // for alpha test \n\
- AlphaArg1[0] = TEXTURE; \n\
- } \n\
-}; \n\
- \n\
-";
-
-static const char *Lightmap0blendFx =
-" \n\
-texture texture0; \n\
- \n\
-float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
-float4 g_dyn_factor = { 1.0f, 1.0f, 1.0f, 1.0f }; \n\
- \n\
-technique one_stage_1 \n\
-{ \n\
- pass p0 \n\
- { \n\
- // do a standard lighting with the first light \n\
- Lighting = true; \n\
- MaterialEmissive= ; \n\
- MaterialAmbient= ; \n\
- MaterialDiffuse= ; \n\
- MaterialSpecular= ; \n\
- AlphaBlendEnable = true; \n\
- SrcBlend = SRCALPHA; \n\
- DestBlend = INVSRCALPHA; \n\
- \n\
- Texture[0] = ; \n\
- ColorOp[0] = MODULATE; \n\
- ColorArg1[0] = TEXTURE; \n\
- ColorArg2[0] = DIFFUSE; \n\
- AlphaOp[0] = SELECTARG1; \n\
- AlphaArg1[0] = TEXTURE; \n\
- } \n\
-}; \n\
- \n\
-";
-
-static const char *Lightmap0blend_x2Fx =
-" \n\
-texture texture0; \n\
- \n\
-float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
-float4 g_dyn_factor = { 1.0f, 1.0f, 1.0f, 1.0f }; \n\
- \n\
-technique one_stage_1 \n\
-{ \n\
- pass p0 \n\
- { \n\
- // do a standard lighting with the first light \n\
- Lighting = true; \n\
- MaterialEmissive= ; \n\
- MaterialAmbient= ; \n\
- MaterialDiffuse= ; \n\
- MaterialSpecular= ; \n\
- AlphaBlendEnable = true; \n\
- SrcBlend = SRCALPHA; \n\
- DestBlend = INVSRCALPHA; \n\
- \n\
- Texture[0] = ; \n\
- ColorOp[0] = MODULATE; \n\
- ColorArg1[0] = TEXTURE; \n\
- ColorArg2[0] = DIFFUSE; \n\
- AlphaOp[0] = SELECTARG1; \n\
- AlphaArg1[0] = TEXTURE; \n\
- } \n\
-}; \n\
- \n\
-";
-
-static const char *Lightmap0_x2Fx =
-" \n\
-texture texture0; \n\
- \n\
-float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
-float4 g_dyn_factor = { 1.0f, 1.0f, 1.0f, 1.0f }; \n\
- \n\
-technique one_stage_1 \n\
-{ \n\
- pass p0 \n\
- { \n\
- // do a standard lighting with the first light \n\
- Lighting = true; \n\
- MaterialEmissive= ; \n\
- MaterialAmbient= ; \n\
- MaterialDiffuse= ; \n\
- MaterialSpecular= ; \n\
- AlphaBlendEnable = false; \n\
- \n\
- Texture[0] = ; \n\
- ColorOp[0] = MODULATE; \n\
- ColorArg1[0] = TEXTURE; \n\
- ColorArg2[0] = DIFFUSE; \n\
- AlphaOp[0] = SELECTARG1; // for alpha test \n\
- AlphaArg1[0] = TEXTURE; \n\
- } \n\
-}; \n\
- \n\
-";
-
-static const char *Lightmap1Fx =
-" \n\
-texture texture0; \n\
-texture texture1; \n\
-// Color0 is the Ambient Added to the lightmap (for Lightmap 8 bit compression)\n\
-// Other colors are the lightmap Factors for each lightmap \n\
-dword color0; \n\
-dword color1; \n\
-float4 factor0; \n\
-float4 factor1; \n\
- \n\
-float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
-float4 g_dyn_factor = { 1.0f, 1.0f, 1.0f, 1.0f }; \n\
- \n\
-technique two_stages_2 \n\
-{ \n\
- pass p0 \n\
- { \n\
- // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
- Lighting = true; \n\
- MaterialEmissive= ; \n\
- MaterialAmbient= ; \n\
- MaterialDiffuse= ; \n\
- MaterialSpecular= ; \n\
- AlphaBlendEnable = false; \n\
- \n\
- // the DiffuseTexture texture 0 is in last stage \n\
- TexCoordIndex[0] = 1; \n\
- TexCoordIndex[1] = 0; \n\
- Texture[0] = ; \n\
- Texture[1] = ; \n\
- TextureFactor = ; \n\
- ColorOp[0] = MULTIPLYADD; \n\
- ColorArg0[0] = DIFFUSE; \n\
- ColorArg1[0] = TFACTOR; \n\
- ColorArg2[0] = TEXTURE; \n\
- ColorOp[1] = MODULATE; \n\
- ColorArg1[1] = CURRENT; \n\
- ColorArg2[1] = TEXTURE; \n\
- AlphaOp[0] = SELECTARG1; \n\
- AlphaArg1[0] = TFACTOR; \n\
- AlphaOp[1] = SELECTARG1; // for alpha test \n\
- AlphaArg1[1] = TEXTURE; \n\
- } \n\
-}; \n\
- \n\
-";
-
-static const char *Lightmap1blendFx =
-" \n\
-texture texture0; \n\
-texture texture1; \n\
-// Color0 is the Ambient Added to the lightmap (for Lightmap 8 bit compression)\n\
-// Other colors are the lightmap Factors for each lightmap \n\
-dword color0; \n\
-dword color1; \n\
-float4 factor0; \n\
-float4 factor1; \n\
- \n\
-float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
-float4 g_dyn_factor = { 1.0f, 1.0f, 1.0f, 1.0f }; \n\
- \n\
-technique two_stages_2 \n\
-{ \n\
- pass p0 \n\
- { \n\
- // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
- Lighting = true; \n\
- MaterialEmissive= ; \n\
- MaterialAmbient= ; \n\
- MaterialDiffuse= ; \n\
- MaterialSpecular= ; \n\
- AlphaBlendEnable = true; \n\
- SrcBlend = SRCALPHA; \n\
- DestBlend = INVSRCALPHA; \n\
- \n\
- // the DiffuseTexture texture 0 is in last stage \n\
- TexCoordIndex[0] = 1; \n\
- TexCoordIndex[1] = 0; \n\
- Texture[0] = ; \n\
- Texture[1] = ; \n\
- TextureFactor = ; \n\
- ColorOp[0] = MULTIPLYADD; \n\
- ColorArg0[0] = DIFFUSE; \n\
- ColorArg1[0] = TFACTOR; \n\
- ColorArg2[0] = TEXTURE; \n\
- ColorOp[1] = MODULATE; \n\
- ColorArg1[1] = CURRENT; \n\
- ColorArg2[1] = TEXTURE; \n\
- // Alpha stage 0 unused \n\
- AlphaOp[0] = SELECTARG1; \n\
- AlphaArg1[0] = TFACTOR; \n\
- AlphaOp[1] = SELECTARG1; \n\
- AlphaArg1[1] = TEXTURE; \n\
- } \n\
-}; \n\
- \n\
-";
-
-static const char *Lightmap1blend_x2Fx =
-" \n\
-texture texture0; \n\
-texture texture1; \n\
-// Color0 is the Ambient Added to the lightmap (for Lightmap 8 bit compression)\n\
-// Other colors are the lightmap Factors for each lightmap \n\
-dword color0; \n\
-dword color1; \n\
-float4 factor0; \n\
-float4 factor1; \n\
- \n\
-float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
-// modulate the dyn light by 0.5, because of MODULATE2X \n\
-float4 g_dyn_factor = { 0.5f, 0.5f, 0.5f, 1.0f }; \n\
- \n\
-technique two_stages_2 \n\
-{ \n\
- pass p0 \n\
- { \n\
- // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
- Lighting = true; \n\
- MaterialEmissive= ; \n\
- MaterialAmbient= ; \n\
- MaterialDiffuse= ; \n\
- MaterialSpecular= ; \n\
- AlphaBlendEnable = true; \n\
- SrcBlend = SRCALPHA; \n\
- DestBlend = INVSRCALPHA; \n\
- \n\
- // the DiffuseTexture texture 0 is in last stage \n\
- TexCoordIndex[0] = 1; \n\
- TexCoordIndex[1] = 0; \n\
- Texture[0] = ; \n\
- Texture[1] = ; \n\
- TextureFactor = ; \n\
- ColorOp[0] = MULTIPLYADD; \n\
- ColorArg0[0] = DIFFUSE; \n\
- ColorArg1[0] = TFACTOR; \n\
- ColorArg2[0] = TEXTURE; \n\
- ColorOp[1] = MODULATE2X; \n\
- ColorArg1[1] = CURRENT; \n\
- ColorArg2[1] = TEXTURE; \n\
- // Alpha stage 0 unused \n\
- AlphaOp[0] = SELECTARG1; \n\
- AlphaArg1[0] = TFACTOR; \n\
- AlphaOp[1] = SELECTARG1; \n\
- AlphaArg1[1] = TEXTURE; \n\
- } \n\
-}; \n\
- \n\
-";
-
-static const char *Lightmap1_x2Fx =
-" \n\
-texture texture0; \n\
-texture texture1; \n\
-// Color0 is the Ambient Added to the lightmap (for Lightmap 8 bit compression)\n\
-// Other colors are the lightmap Factors for each lightmap \n\
-dword color0; \n\
-dword color1; \n\
-float4 factor0; \n\
-float4 factor1; \n\
- \n\
-float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
-// modulate the dyn light by 0.5, because of MODULATE2X \n\
-float4 g_dyn_factor = { 0.5f, 0.5f, 0.5f, 1.0f }; \n\
- \n\
-technique two_stages_2 \n\
-{ \n\
- pass p0 \n\
- { \n\
- // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
- Lighting = true; \n\
- MaterialEmissive= ; \n\
- MaterialAmbient= ; \n\
- MaterialDiffuse= ; \n\
- MaterialSpecular= ; \n\
- AlphaBlendEnable = false; \n\
- \n\
- // the DiffuseTexture texture 0 is in last stage \n\
- TexCoordIndex[0] = 1; \n\
- TexCoordIndex[1] = 0; \n\
- Texture[0] = ; \n\
- Texture[1] = ; \n\
- TextureFactor = ; \n\
- ColorOp[0] = MULTIPLYADD; \n\
- ColorArg0[0] = DIFFUSE; \n\
- ColorArg1[0] = TFACTOR; \n\
- ColorArg2[0] = TEXTURE; \n\
- ColorOp[1] = MODULATE2X; \n\
- ColorArg1[1] = CURRENT; \n\
- ColorArg2[1] = TEXTURE; \n\
- AlphaOp[0] = SELECTARG1; \n\
- AlphaArg1[0] = TFACTOR; \n\
- AlphaOp[1] = SELECTARG1; // for alpha test \n\
- AlphaArg1[1] = TEXTURE; \n\
- } \n\
-}; \n\
- \n\
-";
-
-static const char *Lightmap2Fx =
-" \n\
-texture texture0; \n\
-texture texture1; \n\
-texture texture2; \n\
-// Color0 is the Ambient Added to the lightmap (for Lightmap 8 bit compression)\n\
-// Other colors are the lightmap Factors for each lightmap \n\
-dword color0; \n\
-dword color1; \n\
-dword color2; \n\
-float4 factor0; \n\
-float4 factor1; \n\
-float4 factor2; \n\
- \n\
-float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
-float4 g_dyn_factor = { 1.0f, 1.0f, 1.0f, 1.0f }; \n\
- \n\
- \n\
-// **** 3 stages technique \n\
-pixelshader three_stages_ps = asm \n\
-{ \n\
- ps_1_1; \n\
- tex t0; \n\
- tex t1; \n\
- tex t2; \n\
- // multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
- mad r0.xyz, c1, t1, v0; \n\
- mad r0.xyz, c2, t2, r0; \n\
- mul r0.xyz, r0, t0; \n\
- +mov r0.w, t0; \n\
-}; \n\
- \n\
-technique three_stages_3 \n\
-{ \n\
- pass p0 \n\
- { \n\
- TexCoordIndex[2] = 1; \n\
- \n\
- // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
- Lighting = true; \n\
- MaterialEmissive= ; \n\
- MaterialAmbient= ; \n\
- MaterialDiffuse= ; \n\
- MaterialSpecular= ; \n\
- AlphaBlendEnable = false; \n\
- \n\
- Texture[0] = ; \n\
- Texture[1] = ; \n\
- Texture[2] = ; \n\
- PixelShaderConstant[1] = ; \n\
- PixelShaderConstant[2] = ; \n\
- PixelShader = (three_stages_ps); \n\
- } \n\
-} \n\
- \n\
-// **** 2 stages, no pixel shader technique \n\
-technique two_stages_2 \n\
-{ \n\
- pass p0 \n\
- { \n\
- // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
- Lighting = true; \n\
- MaterialEmissive= ; \n\
- MaterialAmbient= ; \n\
- MaterialDiffuse= ; \n\
- MaterialSpecular= ; \n\
- AlphaBlendEnable = false; \n\
- \n\
- // the DiffuseTexture texture 0 is in last stage \n\
- TexCoordIndex[0] = 1; \n\
- TexCoordIndex[1] = 0; \n\
- Texture[0] = ; \n\
- Texture[1] = ; \n\
- TextureFactor = ; \n\
- ColorOp[0] = MULTIPLYADD; \n\
- ColorArg0[0] = DIFFUSE; \n\
- ColorArg1[0] = TFACTOR; \n\
- ColorArg2[0] = TEXTURE; \n\
- ColorOp[1] = MODULATE; \n\
- ColorArg1[1] = CURRENT; \n\
- ColorArg2[1] = TEXTURE; \n\
- // Alpha stage 0 unused \n\
- AlphaOp[0] = SELECTARG1; \n\
- AlphaArg1[0] = TFACTOR; \n\
- AlphaOp[1] = SELECTARG1; // for alpha test \n\
- AlphaArg1[1] = TEXTURE; \n\
- } \n\
- pass p1 \n\
- { \n\
- FogColor = 0x00000000; // don't accumulate fog several times\n\
- Lighting = false; \n\
- AlphaBlendEnable = true; \n\
- SrcBlend = one; \n\
- DestBlend = one; \n\
- Texture[0] = ; \n\
- TextureFactor = ; \n\
- ColorOp[0] = MODULATE; \n\
- } \n\
-} \n\
- \n\
-";
-
-static const char *Lightmap2blendFx =
-" \n\
-texture texture0; \n\
-texture texture1; \n\
-texture texture2; \n\
-// Color0 is the Ambient Added to the lightmap (for Lightmap 8 bit compression)\n\
-// Other colors are the lightmap Factors for each lightmap \n\
-dword color0; \n\
-dword color1; \n\
-dword color2; \n\
-float4 factor0; \n\
-float4 factor1; \n\
-float4 factor2; \n\
- \n\
-float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
-float4 g_dyn_factor = { 1.0f, 1.0f, 1.0f, 1.0f }; \n\
- \n\
- \n\
-// **** 3 stages technique \n\
-pixelshader three_stages_ps = asm \n\
-{ \n\
- ps_1_1; \n\
- tex t0; \n\
- tex t1; \n\
- tex t2; \n\
- // multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
- mad r0.xyz, c1, t1, v0; \n\
- mad r0.xyz, c2, t2, r0; \n\
- mul r0.xyz, r0, t0; \n\
- +mov r0.w, t0; \n\
-}; \n\
- \n\
-technique three_stages_3 \n\
-{ \n\
- pass p0 \n\
- { \n\
- TexCoordIndex[2] = 1; \n\
- \n\
- // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
- Lighting = true; \n\
- MaterialEmissive= ; \n\
- MaterialAmbient= ; \n\
- MaterialDiffuse= ; \n\
- MaterialSpecular= ; \n\
- AlphaBlendEnable = true; \n\
- SrcBlend = srcalpha; \n\
- DestBlend = invsrcalpha; \n\
- \n\
- Texture[0] = ; \n\
- Texture[1] = ; \n\
- Texture[2] = ; \n\
- PixelShaderConstant[1] = ; \n\
- PixelShaderConstant[2] = ; \n\
- PixelShader = (three_stages_ps); \n\
- } \n\
-} \n\
- \n\
-// **** 2 stages, no pixel shader technique \n\
-technique two_stages_2 \n\
-{ \n\
- pass p0 \n\
- { \n\
- // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
- Lighting = true; \n\
- MaterialEmissive= ; \n\
- MaterialAmbient= ; \n\
- MaterialDiffuse= ; \n\
- MaterialSpecular= ; \n\
- AlphaBlendEnable = true; \n\
- SrcBlend = srcalpha; \n\
- DestBlend = invsrcalpha; \n\
- \n\
- // the DiffuseTexture texture 0 is in last stage \n\
- TexCoordIndex[0] = 1; \n\
- TexCoordIndex[1] = 0; \n\
- Texture[0] = ; \n\
- Texture[1] = ; \n\
- TextureFactor = ; \n\
- ColorOp[0] = MULTIPLYADD; \n\
- ColorArg0[0] = DIFFUSE; \n\
- ColorArg1[0] = TFACTOR; \n\
- ColorArg2[0] = TEXTURE; \n\
- ColorOp[1] = MODULATE; \n\
- ColorArg1[1] = CURRENT; \n\
- ColorArg2[1] = TEXTURE; \n\
- // Alpha stage 0 unused \n\
- AlphaOp[0] = SELECTARG1; \n\
- AlphaArg1[0] = TFACTOR; \n\
- AlphaOp[1] = SELECTARG1; \n\
- AlphaArg1[1] = TEXTURE; \n\
- } \n\
- pass p1 \n\
- { \n\
- FogColor = 0x00000000; // don't accumulate fog several times\n\
- Lighting = false; \n\
- DestBlend = one; \n\
- Texture[0] = ; \n\
- TextureFactor = ; \n\
- ColorOp[0] = MODULATE; \n\
- } \n\
-} \n\
- \n\
- \n\
-";
-
-static const char *Lightmap2blend_x2Fx =
-" \n\
-texture texture0; \n\
-texture texture1; \n\
-texture texture2; \n\
-// Color0 is the Ambient Added to the lightmap (for Lightmap 8 bit compression)\n\
-// Other colors are the lightmap Factors for each lightmap \n\
-dword color0; \n\
-dword color1; \n\
-dword color2; \n\
-float4 factor0; \n\
-float4 factor1; \n\
-float4 factor2; \n\
- \n\
-float4 g_black = { 0.0f, 0.0f, 0.0f, 1.0f }; \n\
-// modulate the dyn light by 0.5, because of MODULATE2X \n\
-float4 g_dyn_factor = { 0.5f, 0.5f, 0.5f, 1.0f }; \n\
- \n\
- \n\
-// **** 3 stages technique \n\
-pixelshader three_stages_ps = asm \n\
-{ \n\
- ps_1_1; \n\
- tex t0; \n\
- tex t1; \n\
- tex t2; \n\
- // multiply lightmap with factor, and add with LMCAmbient+DynamicLight term\n\
- mad r0.xyz, c1, t1, v0; \n\
- mad r0.xyz, c2, t2, r0; \n\
- mul_x2 r0.xyz, r0, t0; \n\
- mov r0.w, t0; \n\
-}; \n\
- \n\
-technique three_stages_3 \n\
-{ \n\
- pass p0 \n\
- { \n\
- TexCoordIndex[2] = 1; \n\
- \n\
- // Use Emissive For LMCAmbient, and diffuse for per vertex dynamic lighting\n\
- Lighting = true; \n\
- MaterialEmissive= ; \n\
- MaterialAmbient= ; \n\
- MaterialDiffuse= ; \n\
- MaterialSpecular= ; \n\
- AlphaBlendEnable = true; \n\
- SrcBlend = srcalpha; \n\
- DestBlend = invsrcalpha; \n\
- \n\
- Texture[0] = ; \n\
- Texture[1] =