Add Direct3D 8 implementation.
Bug swiftshader:5
Change-Id: I6aec7237f2db6222702e828a2b9dae1a1a6ac9af
Reviewed-on: https://swiftshader-review.googlesource.com/7191
Tested-by: Nicolas Capens <capn@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
diff --git a/src/D3D8/Capabilities.cpp b/src/D3D8/Capabilities.cpp
new file mode 100644
index 0000000..dd0ba20
--- /dev/null
+++ b/src/D3D8/Capabilities.cpp
@@ -0,0 +1,246 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "Capabilities.hpp"
+
+#include "Main/Config.hpp"
+
+namespace D3D8
+{
+ bool Capabilities::Surface::RenderTarget::R8G8B8 = false;
+ bool Capabilities::Surface::RenderTarget::R5G6B5 = true;
+ bool Capabilities::Surface::RenderTarget::X1R5G5B5 = true;
+ bool Capabilities::Surface::RenderTarget::A1R5G5B5 = true;
+ bool Capabilities::Surface::RenderTarget::A4R4G4B4 = true;
+ bool Capabilities::Surface::RenderTarget::R3G3B2 = false;
+ bool Capabilities::Surface::RenderTarget::A8R3G3B2 = false;
+ bool Capabilities::Surface::RenderTarget::X4R4G4B4 = true;
+ bool Capabilities::Surface::RenderTarget::A8R8G8B8 = true;
+ bool Capabilities::Surface::RenderTarget::X8R8G8B8 = true;
+ bool Capabilities::Surface::RenderTarget::A8B8G8R8 = true;
+ bool Capabilities::Surface::RenderTarget::X8B8G8R8 = true;
+ bool Capabilities::Surface::RenderTarget::G16R16 = true;
+ bool Capabilities::Surface::RenderTarget::A2B10G10R10 = true;
+
+ bool Capabilities::Surface::DepthStencil::D32 = true;
+ bool Capabilities::Surface::DepthStencil::D24S8 = true;
+ bool Capabilities::Surface::DepthStencil::D24X8 = true;
+ bool Capabilities::Surface::DepthStencil::D16 = true;
+
+ bool Capabilities::Surface::A8 = true;
+ bool Capabilities::Surface::R5G6B5 = true;
+ bool Capabilities::Surface::X1R5G5B5 = true;
+ bool Capabilities::Surface::A1R5G5B5 = true;
+ bool Capabilities::Surface::A4R4G4B4 = true;
+ bool Capabilities::Surface::R3G3B2 = true;
+ bool Capabilities::Surface::A8R3G3B2 = true;
+ bool Capabilities::Surface::X4R4G4B4 = true;
+ bool Capabilities::Surface::R8G8B8 = false;
+ bool Capabilities::Surface::X8R8G8B8 = true;
+ bool Capabilities::Surface::A8R8G8B8 = true;
+ bool Capabilities::Surface::X8B8G8R8 = true;
+ bool Capabilities::Surface::A8B8G8R8 = true;
+ bool Capabilities::Surface::P8 = false;
+ bool Capabilities::Surface::A8P8 = false;
+ bool Capabilities::Surface::G16R16 = true;
+ bool Capabilities::Surface::A2B10G10R10 = true;
+ bool Capabilities::Surface::DXT1 = S3TC_SUPPORT;
+ bool Capabilities::Surface::DXT2 = S3TC_SUPPORT;
+ bool Capabilities::Surface::DXT3 = S3TC_SUPPORT;
+ bool Capabilities::Surface::DXT4 = S3TC_SUPPORT;
+ bool Capabilities::Surface::DXT5 = S3TC_SUPPORT;
+ bool Capabilities::Surface::V8U8 = true;
+ bool Capabilities::Surface::L6V5U5 = true;
+ bool Capabilities::Surface::X8L8V8U8 = true;
+ bool Capabilities::Surface::Q8W8V8U8 = true;
+ bool Capabilities::Surface::V16U16 = true;
+ bool Capabilities::Surface::A2W10V10U10 = true;
+ bool Capabilities::Surface::L8 = true;
+ bool Capabilities::Surface::A4L4 = true;
+ bool Capabilities::Surface::A8L8 = true;
+
+ bool Capabilities::Volume::A8 = true;
+ bool Capabilities::Volume::R5G6B5 = true;
+ bool Capabilities::Volume::X1R5G5B5 = true;
+ bool Capabilities::Volume::A1R5G5B5 = true;
+ bool Capabilities::Volume::A4R4G4B4 = true;
+ bool Capabilities::Volume::R3G3B2 = true;
+ bool Capabilities::Volume::A8R3G3B2 = true;
+ bool Capabilities::Volume::X4R4G4B4 = true;
+ bool Capabilities::Volume::R8G8B8 = false;
+ bool Capabilities::Volume::X8R8G8B8 = true;
+ bool Capabilities::Volume::A8R8G8B8 = true;
+ bool Capabilities::Volume::X8B8G8R8 = true;
+ bool Capabilities::Volume::A8B8G8R8 = true;
+ bool Capabilities::Volume::P8 = false;
+ bool Capabilities::Volume::A8P8 = false;
+ bool Capabilities::Volume::G16R16 = true;
+ bool Capabilities::Volume::A2B10G10R10 = true;
+ bool Capabilities::Volume::DXT1 = S3TC_SUPPORT;
+ bool Capabilities::Volume::DXT2 = S3TC_SUPPORT;
+ bool Capabilities::Volume::DXT3 = S3TC_SUPPORT;
+ bool Capabilities::Volume::DXT4 = S3TC_SUPPORT;
+ bool Capabilities::Volume::DXT5 = S3TC_SUPPORT;
+ bool Capabilities::Volume::V8U8 = true;
+ bool Capabilities::Volume::L6V5U5 = true;
+ bool Capabilities::Volume::X8L8V8U8 = true;
+ bool Capabilities::Volume::Q8W8V8U8 = true;
+ bool Capabilities::Volume::V16U16 = true;
+ bool Capabilities::Volume::A2W10V10U10 = true;
+ bool Capabilities::Volume::L8 = true;
+ bool Capabilities::Volume::A4L4 = true;
+ bool Capabilities::Volume::A8L8 = true;
+
+ bool Capabilities::CubeMap::RenderTarget::R8G8B8 = false;
+ bool Capabilities::CubeMap::RenderTarget::R5G6B5 = true;
+ bool Capabilities::CubeMap::RenderTarget::X1R5G5B5 = true;
+ bool Capabilities::CubeMap::RenderTarget::A1R5G5B5 = true;
+ bool Capabilities::CubeMap::RenderTarget::A4R4G4B4 = true;
+ bool Capabilities::CubeMap::RenderTarget::R3G3B2 = false;
+ bool Capabilities::CubeMap::RenderTarget::A8R3G3B2 = false;
+ bool Capabilities::CubeMap::RenderTarget::X4R4G4B4 = true;
+ bool Capabilities::CubeMap::RenderTarget::A8R8G8B8 = true;
+ bool Capabilities::CubeMap::RenderTarget::X8R8G8B8 = true;
+ bool Capabilities::CubeMap::RenderTarget::A8B8G8R8 = true;
+ bool Capabilities::CubeMap::RenderTarget::X8B8G8R8 = true;
+ bool Capabilities::CubeMap::RenderTarget::G16R16 = true;
+ bool Capabilities::CubeMap::RenderTarget::A2B10G10R10 = true;
+
+ bool Capabilities::CubeMap::DepthStencil::D32 = false;
+ bool Capabilities::CubeMap::DepthStencil::D24S8 = false;
+ bool Capabilities::CubeMap::DepthStencil::D24X8 = false;
+ bool Capabilities::CubeMap::DepthStencil::D16 = false;
+
+ bool Capabilities::CubeMap::A8 = true;
+ bool Capabilities::CubeMap::R5G6B5 = true;
+ bool Capabilities::CubeMap::X1R5G5B5 = true;
+ bool Capabilities::CubeMap::A1R5G5B5 = true;
+ bool Capabilities::CubeMap::A4R4G4B4 = true;
+ bool Capabilities::CubeMap::R3G3B2 = true;
+ bool Capabilities::CubeMap::A8R3G3B2 = true;
+ bool Capabilities::CubeMap::X4R4G4B4 = true;
+ bool Capabilities::CubeMap::R8G8B8 = false;
+ bool Capabilities::CubeMap::X8R8G8B8 = true;
+ bool Capabilities::CubeMap::A8R8G8B8 = true;
+ bool Capabilities::CubeMap::X8B8G8R8 = true;
+ bool Capabilities::CubeMap::A8B8G8R8 = true;
+ bool Capabilities::CubeMap::P8 = false;
+ bool Capabilities::CubeMap::A8P8 = false;
+ bool Capabilities::CubeMap::G16R16 = true;
+ bool Capabilities::CubeMap::A2B10G10R10 = true;
+ bool Capabilities::CubeMap::DXT1 = S3TC_SUPPORT;
+ bool Capabilities::CubeMap::DXT2 = S3TC_SUPPORT;
+ bool Capabilities::CubeMap::DXT3 = S3TC_SUPPORT;
+ bool Capabilities::CubeMap::DXT4 = S3TC_SUPPORT;
+ bool Capabilities::CubeMap::DXT5 = S3TC_SUPPORT;
+ bool Capabilities::CubeMap::V8U8 = true;
+ bool Capabilities::CubeMap::L6V5U5 = true;
+ bool Capabilities::CubeMap::X8L8V8U8 = true;
+ bool Capabilities::CubeMap::Q8W8V8U8 = true;
+ bool Capabilities::CubeMap::V16U16 = true;
+ bool Capabilities::CubeMap::A2W10V10U10 = true;
+ bool Capabilities::CubeMap::L8 = true;
+ bool Capabilities::CubeMap::A4L4 = true;
+ bool Capabilities::CubeMap::A8L8 = true;
+
+ bool Capabilities::VolumeTexture::A8 = true;
+ bool Capabilities::VolumeTexture::R5G6B5 = true;
+ bool Capabilities::VolumeTexture::X1R5G5B5 = true;
+ bool Capabilities::VolumeTexture::A1R5G5B5 = true;
+ bool Capabilities::VolumeTexture::A4R4G4B4 = true;
+ bool Capabilities::VolumeTexture::R3G3B2 = true;
+ bool Capabilities::VolumeTexture::A8R3G3B2 = true;
+ bool Capabilities::VolumeTexture::X4R4G4B4 = true;
+ bool Capabilities::VolumeTexture::R8G8B8 = false;
+ bool Capabilities::VolumeTexture::X8R8G8B8 = true;
+ bool Capabilities::VolumeTexture::A8R8G8B8 = true;
+ bool Capabilities::VolumeTexture::X8B8G8R8 = true;
+ bool Capabilities::VolumeTexture::A8B8G8R8 = true;
+ bool Capabilities::VolumeTexture::P8 = false;
+ bool Capabilities::VolumeTexture::A8P8 = false;
+ bool Capabilities::VolumeTexture::G16R16 = true;
+ bool Capabilities::VolumeTexture::A2B10G10R10 = true;
+ bool Capabilities::VolumeTexture::DXT1 = S3TC_SUPPORT;
+ bool Capabilities::VolumeTexture::DXT2 = S3TC_SUPPORT;
+ bool Capabilities::VolumeTexture::DXT3 = S3TC_SUPPORT;
+ bool Capabilities::VolumeTexture::DXT4 = S3TC_SUPPORT;
+ bool Capabilities::VolumeTexture::DXT5 = S3TC_SUPPORT;
+ bool Capabilities::VolumeTexture::V8U8 = true;
+ bool Capabilities::VolumeTexture::L6V5U5 = true;
+ bool Capabilities::VolumeTexture::X8L8V8U8 = true;
+ bool Capabilities::VolumeTexture::Q8W8V8U8 = true;
+ bool Capabilities::VolumeTexture::V16U16 = true;
+ bool Capabilities::VolumeTexture::A2W10V10U10 = true;
+ bool Capabilities::VolumeTexture::L8 = true;
+ bool Capabilities::VolumeTexture::A4L4 = true;
+ bool Capabilities::VolumeTexture::A8L8 = true;
+
+ bool Capabilities::Texture::RenderTarget::R8G8B8 = false;
+ bool Capabilities::Texture::RenderTarget::R5G6B5 = true;
+ bool Capabilities::Texture::RenderTarget::X1R5G5B5 = true;
+ bool Capabilities::Texture::RenderTarget::A1R5G5B5 = true;
+ bool Capabilities::Texture::RenderTarget::A4R4G4B4 = true;
+ bool Capabilities::Texture::RenderTarget::R3G3B2 = false;
+ bool Capabilities::Texture::RenderTarget::A8R3G3B2 = false;
+ bool Capabilities::Texture::RenderTarget::X4R4G4B4 = true;
+ bool Capabilities::Texture::RenderTarget::A8R8G8B8 = true;
+ bool Capabilities::Texture::RenderTarget::X8R8G8B8 = true;
+ bool Capabilities::Texture::RenderTarget::A8B8G8R8 = true;
+ bool Capabilities::Texture::RenderTarget::X8B8G8R8 = true;
+ bool Capabilities::Texture::RenderTarget::G16R16 = true;
+ bool Capabilities::Texture::RenderTarget::A2B10G10R10 = true;
+
+ bool Capabilities::Texture::DepthStencil::D32 = false;
+ bool Capabilities::Texture::DepthStencil::D24S8 = false;
+ bool Capabilities::Texture::DepthStencil::D24X8 = false;
+ bool Capabilities::Texture::DepthStencil::D16 = false;
+
+ bool Capabilities::Texture::A8 = true;
+ bool Capabilities::Texture::R5G6B5 = true;
+ bool Capabilities::Texture::X1R5G5B5 = true;
+ bool Capabilities::Texture::A1R5G5B5 = true;
+ bool Capabilities::Texture::A4R4G4B4 = true;
+ bool Capabilities::Texture::R3G3B2 = true;
+ bool Capabilities::Texture::A8R3G3B2 = true;
+ bool Capabilities::Texture::X4R4G4B4 = true;
+ bool Capabilities::Texture::R8G8B8 = false;
+ bool Capabilities::Texture::X8R8G8B8 = true;
+ bool Capabilities::Texture::A8R8G8B8 = true;
+ bool Capabilities::Texture::X8B8G8R8 = true;
+ bool Capabilities::Texture::A8B8G8R8 = true;
+ bool Capabilities::Texture::P8 = false;
+ bool Capabilities::Texture::A8P8 = false;
+ bool Capabilities::Texture::G16R16 = true;
+ bool Capabilities::Texture::A2B10G10R10 = true;
+ bool Capabilities::Texture::DXT1 = S3TC_SUPPORT;
+ bool Capabilities::Texture::DXT2 = S3TC_SUPPORT;
+ bool Capabilities::Texture::DXT3 = S3TC_SUPPORT;
+ bool Capabilities::Texture::DXT4 = S3TC_SUPPORT;
+ bool Capabilities::Texture::DXT5 = S3TC_SUPPORT;
+ bool Capabilities::Texture::V8U8 = true;
+ bool Capabilities::Texture::L6V5U5 = true;
+ bool Capabilities::Texture::X8L8V8U8 = true;
+ bool Capabilities::Texture::Q8W8V8U8 = true;
+ bool Capabilities::Texture::V16U16 = true;
+ bool Capabilities::Texture::A2W10V10U10 = true;
+ bool Capabilities::Texture::L8 = true;
+ bool Capabilities::Texture::A4L4 = true;
+ bool Capabilities::Texture::A8L8 = true;
+
+ unsigned int pixelShaderVersion = D3DPS_VERSION(1, 4);
+ unsigned int vertexShaderVersion = D3DVS_VERSION(1, 1);
+
+ unsigned int textureMemory = 256 * 1024 * 1024;
+ unsigned int maxAnisotropy = 16;
+}
diff --git a/src/D3D8/Capabilities.hpp b/src/D3D8/Capabilities.hpp
new file mode 100644
index 0000000..4980e38
--- /dev/null
+++ b/src/D3D8/Capabilities.hpp
@@ -0,0 +1,313 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef D3D8_Capabilities_hpp
+#define D3D8_Capabilities_hpp
+
+#include <d3d8.h>
+
+namespace D3D8
+{
+ struct Capabilities
+ {
+ struct Surface
+ {
+ struct RenderTarget
+ {
+ static bool R8G8B8;
+ static bool R5G6B5;
+ static bool X1R5G5B5;
+ static bool A1R5G5B5;
+ static bool A4R4G4B4;
+ static bool R3G3B2;
+ static bool A8R3G3B2;
+ static bool X4R4G4B4;
+ static bool A8R8G8B8;
+ static bool X8R8G8B8;
+ static bool A8B8G8R8;
+ static bool X8B8G8R8;
+ // Integer HDR formats
+ static bool G16R16;
+ static bool A2B10G10R10;
+ };
+
+ struct DepthStencil
+ {
+ static bool D32;
+ static bool D24S8;
+ static bool D24X8;
+ static bool D16;
+ };
+
+ static bool A8;
+ static bool R5G6B5;
+ static bool X1R5G5B5;
+ static bool A1R5G5B5;
+ static bool A4R4G4B4;
+ static bool R3G3B2;
+ static bool A8R3G3B2;
+ static bool X4R4G4B4;
+ static bool R8G8B8;
+ static bool X8R8G8B8;
+ static bool A8R8G8B8;
+ static bool A8B8G8R8;
+ static bool X8B8G8R8;
+ // Paletted formats
+ static bool P8;
+ static bool A8P8;
+ // Integer HDR formats
+ static bool G16R16;
+ static bool A2B10G10R10;
+ // Compressed formats
+ static bool DXT1;
+ static bool DXT2;
+ static bool DXT3;
+ static bool DXT4;
+ static bool DXT5;
+ // Bump map formats
+ static bool V8U8;
+ static bool L6V5U5;
+ static bool X8L8V8U8;
+ static bool Q8W8V8U8;
+ static bool V16U16;
+ static bool A2W10V10U10;
+ // Luminance formats
+ static bool L8;
+ static bool A4L4;
+ static bool A8L8;
+ };
+
+ struct Volume
+ {
+ static bool A8;
+ static bool R5G6B5;
+ static bool X1R5G5B5;
+ static bool A1R5G5B5;
+ static bool A4R4G4B4;
+ static bool R3G3B2;
+ static bool A8R3G3B2;
+ static bool X4R4G4B4;
+ static bool R8G8B8;
+ static bool X8R8G8B8;
+ static bool A8R8G8B8;
+ static bool A8B8G8R8;
+ static bool X8B8G8R8;
+ // Paletted formats
+ static bool P8;
+ static bool A8P8;
+ // Integer HDR formats
+ static bool G16R16;
+ static bool A2B10G10R10;
+ // Compressed formats
+ static bool DXT1;
+ static bool DXT2;
+ static bool DXT3;
+ static bool DXT4;
+ static bool DXT5;
+ // Bump map formats
+ static bool V8U8;
+ static bool L6V5U5;
+ static bool X8L8V8U8;
+ static bool Q8W8V8U8;
+ static bool V16U16;
+ static bool A2W10V10U10;
+ // Luminance formats
+ static bool L8;
+ static bool A4L4;
+ static bool A8L8;
+ };
+
+ struct CubeMap
+ {
+ struct RenderTarget
+ {
+ static bool R8G8B8;
+ static bool R5G6B5;
+ static bool X1R5G5B5;
+ static bool A1R5G5B5;
+ static bool A4R4G4B4;
+ static bool R3G3B2;
+ static bool A8R3G3B2;
+ static bool X4R4G4B4;
+ static bool A8R8G8B8;
+ static bool X8R8G8B8;
+ static bool A8B8G8R8;
+ static bool X8B8G8R8;
+ // Integer HDR formats
+ static bool G16R16;
+ static bool A2B10G10R10;
+ };
+
+ struct DepthStencil
+ {
+ static bool D32;
+ static bool D24S8;
+ static bool D24X8;
+ static bool D16;
+ };
+
+ static bool A8;
+ static bool R5G6B5;
+ static bool X1R5G5B5;
+ static bool A1R5G5B5;
+ static bool A4R4G4B4;
+ static bool R3G3B2;
+ static bool A8R3G3B2;
+ static bool X4R4G4B4;
+ static bool R8G8B8;
+ static bool X8R8G8B8;
+ static bool A8R8G8B8;
+ static bool A8B8G8R8;
+ static bool X8B8G8R8;
+ // Paletted formats
+ static bool P8;
+ static bool A8P8;
+ // Integer HDR formats
+ static bool G16R16;
+ static bool A2B10G10R10;
+ // Compressed formats
+ static bool DXT1;
+ static bool DXT2;
+ static bool DXT3;
+ static bool DXT4;
+ static bool DXT5;
+ // Bump map formats
+ static bool V8U8;
+ static bool L6V5U5;
+ static bool X8L8V8U8;
+ static bool Q8W8V8U8;
+ static bool V16U16;
+ static bool A2W10V10U10;
+ // Luminance formats
+ static bool L8;
+ static bool A4L4;
+ static bool A8L8;
+ };
+
+ struct VolumeTexture
+ {
+ static bool A8;
+ static bool R5G6B5;
+ static bool X1R5G5B5;
+ static bool A1R5G5B5;
+ static bool A4R4G4B4;
+ static bool R3G3B2;
+ static bool A8R3G3B2;
+ static bool X4R4G4B4;
+ static bool R8G8B8;
+ static bool X8R8G8B8;
+ static bool A8R8G8B8;
+ static bool A8B8G8R8;
+ static bool X8B8G8R8;
+ // Paletted formats
+ static bool P8;
+ static bool A8P8;
+ // Integer HDR formats
+ static bool G16R16;
+ static bool A2B10G10R10;
+ // Compressed formats
+ static bool DXT1;
+ static bool DXT2;
+ static bool DXT3;
+ static bool DXT4;
+ static bool DXT5;
+ // Bump map formats
+ static bool V8U8;
+ static bool L6V5U5;
+ static bool X8L8V8U8;
+ static bool Q8W8V8U8;
+ static bool V16U16;
+ static bool A2W10V10U10;
+ // Luminance formats
+ static bool L8;
+ static bool A4L4;
+ static bool A8L8;
+ };
+
+ struct Texture
+ {
+ struct RenderTarget
+ {
+ static bool R8G8B8;
+ static bool R5G6B5;
+ static bool X1R5G5B5;
+ static bool A1R5G5B5;
+ static bool A4R4G4B4;
+ static bool R3G3B2;
+ static bool A8R3G3B2;
+ static bool X4R4G4B4;
+ static bool A8R8G8B8;
+ static bool X8R8G8B8;
+ static bool A8B8G8R8;
+ static bool X8B8G8R8;
+ // Integer HDR formats
+ static bool G16R16;
+ static bool A2B10G10R10;
+ };
+
+ struct DepthStencil
+ {
+ static bool D32;
+ static bool D24S8;
+ static bool D24X8;
+ static bool D16;
+ };
+
+ static bool A8;
+ static bool R5G6B5;
+ static bool X1R5G5B5;
+ static bool A1R5G5B5;
+ static bool A4R4G4B4;
+ static bool R3G3B2;
+ static bool A8R3G3B2;
+ static bool X4R4G4B4;
+ static bool R8G8B8;
+ static bool X8R8G8B8;
+ static bool A8R8G8B8;
+ static bool A8B8G8R8;
+ static bool X8B8G8R8;
+ // Paletted formats
+ static bool P8;
+ static bool A8P8;
+ // Integer HDR formats
+ static bool G16R16;
+ static bool A2B10G10R10;
+ // Compressed formats
+ static bool DXT1;
+ static bool DXT2;
+ static bool DXT3;
+ static bool DXT4;
+ static bool DXT5;
+ // Bump map formats
+ static bool V8U8;
+ static bool L6V5U5;
+ static bool X8L8V8U8;
+ static bool Q8W8V8U8;
+ static bool V16U16;
+ static bool A2W10V10U10;
+ // Luminance formats
+ static bool L8;
+ static bool A4L4;
+ static bool A8L8;
+ };
+ };
+
+ extern unsigned int pixelShaderVersion;
+ extern unsigned int vertexShaderVersion;
+
+ extern unsigned int textureMemory;
+ extern unsigned int maxAnisotropy;
+}
+
+#endif // D3D8_Capabilities_hpp
diff --git a/src/D3D8/D3D8.cpp b/src/D3D8/D3D8.cpp
new file mode 100644
index 0000000..307e48b
--- /dev/null
+++ b/src/D3D8/D3D8.cpp
@@ -0,0 +1,100 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "Direct3D8.hpp"
+
+#include "resource.h"
+
+#include <stdio.h>
+#include <assert.h>
+
+extern "C"
+{
+ HINSTANCE dllInstance;
+
+ int __stdcall DllMain(HINSTANCE instance, unsigned long reason, void *reserved)
+ {
+ dllInstance = instance;
+
+ switch(reason)
+ {
+ case DLL_PROCESS_DETACH:
+ break;
+ case DLL_PROCESS_ATTACH:
+ DisableThreadLibraryCalls(instance);
+ break;
+ case DLL_THREAD_ATTACH:
+ break;
+ case DLL_THREAD_DETACH:
+ break;
+ default:
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return FALSE;
+ }
+
+ return TRUE;
+ }
+
+ IDirect3D8 *__stdcall Direct3DCreate8(unsigned int version)
+ {
+ // D3D_SDK_VERSION check
+ if(version != 120 && // 8.0
+ version != 220) // 8.1
+ {
+ return 0;
+ }
+
+ #ifndef NDEBUG
+ FILE *file = fopen("debug.txt", "w"); // Clear debug log
+ fclose(file);
+ #endif
+
+ IDirect3D8 *device = new D3D8::Direct3D8(version, dllInstance);
+
+ if(device)
+ {
+ device->AddRef();
+ }
+
+ return device;
+ }
+
+ int __stdcall CheckFullscreen() // FIXME: __cdecl or __stdcall?
+ {
+ #ifndef NDEBUG
+ // ASSERT(false); // FIXME
+ #endif
+
+ return FALSE;
+ }
+
+ void __cdecl DebugSetMute(long mute) // FIXME: Return type
+ {
+ // ASSERT(false); // FIXME
+ }
+
+ int __stdcall ValidatePixelShader(long *shader, int x, int y, int z) // FIXME: __cdecl or __stdcall? // FIXME: Argument meanings
+ {
+ // ASSERT(false); // FIXME
+
+ return TRUE;
+ }
+
+ int __stdcall ValidateVertexShader(long *shader, int x, int y, int z) // FIXME: __cdecl or __stdcall? // FIXME: Argument meanings
+ {
+ // ASSERT(false); // FIXME
+
+ return TRUE;
+ }
+}
diff --git a/src/D3D8/D3D8.rc b/src/D3D8/D3D8.rc
new file mode 100644
index 0000000..fa0a3f7
--- /dev/null
+++ b/src/D3D8/D3D8.rc
@@ -0,0 +1,89 @@
+// Microsoft Visual C++ generated resource script.
+//
+#include "resource1.h"
+
+#define APSTUDIO_READONLY_SYMBOLS
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 2 resource.
+//
+#include "Windows.h"
+#include "../Common/Version.h"
+/////////////////////////////////////////////////////////////////////////////
+#undef APSTUDIO_READONLY_SYMBOLS
+
+/////////////////////////////////////////////////////////////////////////////
+// English (United States) resources
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
+#pragma code_page(1252)
+
+#ifdef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// TEXTINCLUDE
+//
+
+1 TEXTINCLUDE
+BEGIN
+ "resource1.h\0"
+END
+
+2 TEXTINCLUDE
+BEGIN
+ "#include ""afxres.h""\r\n"
+ "#include ""../Common/Version.h""\0"
+END
+
+3 TEXTINCLUDE
+BEGIN
+ "\0"
+END
+
+#endif // APSTUDIO_INVOKED
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Version
+//
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION MAJOR_VERSION,MINOR_VERSION,BUILD_VERSION,BUILD_REVISION
+ PRODUCTVERSION MAJOR_VERSION,MINOR_VERSION,BUILD_VERSION,BUILD_REVISION
+ FILEFLAGSMASK 0x1fL
+#ifdef _DEBUG
+ FILEFLAGS 0x9L
+#else
+ FILEFLAGS 0x8L
+#endif
+ FILEOS 0x4L
+ FILETYPE 0x2L
+ FILESUBTYPE 0x0L
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904b0"
+ BEGIN
+ VALUE "CompanyName", "Google Inc."
+ VALUE "FileDescription", "SwiftShader Direct3D 8 Renderer"
+ VALUE "FileVersion", VERSION_STRING
+ VALUE "InternalName", "D3D8"
+ VALUE "LegalCopyright", "Copyright (C) 2016 Google Inc."
+ VALUE "OriginalFilename", "d3d8.dll"
+ VALUE "PrivateBuild", REVISION_STRING
+ VALUE "ProductName", "SwiftShader Direct3D 8 Renderer"
+ VALUE "ProductVersion", VERSION_STRING
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x409, 1200
+ END
+END
+
+#endif // English (United States) resources
+/////////////////////////////////////////////////////////////////////////////
+
+
diff --git a/src/D3D8/D3D8.vcxproj b/src/D3D8/D3D8.vcxproj
new file mode 100644
index 0000000..2bb7bc2
--- /dev/null
+++ b/src/D3D8/D3D8.vcxproj
@@ -0,0 +1,282 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|Win32">
+ <Configuration>Debug</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Profile|Win32">
+ <Configuration>Profile</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>{F18D5ABF-CA3A-4B74-BDB2-4A1956C86F18}</ProjectGuid>
+ <Keyword>Win32Proj</Keyword>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <CharacterSet>NotSet</CharacterSet>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <PlatformToolset>v140</PlatformToolset>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <CharacterSet>NotSet</CharacterSet>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <PlatformToolset>v140</PlatformToolset>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <CharacterSet>NotSet</CharacterSet>
+ <WholeProgramOptimization>false</WholeProgramOptimization>
+ <PlatformToolset>v140</PlatformToolset>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ <Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC71.props" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ <Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC71.props" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ <Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC71.props" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup>
+ <_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Platform)\$(Configuration)\</OutDir>
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Platform)\$(Configuration)\</IntDir>
+ <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Platform)\$(Configuration)\</OutDir>
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">$(Platform)\$(Configuration)\</OutDir>
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Platform)\$(Configuration)\</IntDir>
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">$(Platform)\$(Configuration)\</IntDir>
+ <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
+ <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">false</LinkIncremental>
+ <IncludePath Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)\include\Direct3D;$(DXSDK_DIR)\Include;$(IncludePath)</IncludePath>
+ <IncludePath Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">$(SolutionDir)\include\Direct3D;$(DXSDK_DIR)\Include;$(IncludePath)</IncludePath>
+ <IncludePath Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)\include\Direct3D;$(DXSDK_DIR)\Include;$(IncludePath)</IncludePath>
+ <LibraryPath Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(DXSDK_DIR)Lib\x86;$(LibraryPath)</LibraryPath>
+ <LibraryPath Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">$(DXSDK_DIR)Lib\x86;$(LibraryPath)</LibraryPath>
+ <LibraryPath Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(DXSDK_DIR)Lib\x86;$(LibraryPath)</LibraryPath>
+ </PropertyGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ClCompile>
+ <Optimization>Disabled</Optimization>
+ <InlineFunctionExpansion>Default</InlineFunctionExpansion>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <FavorSizeOrSpeed>Neither</FavorSizeOrSpeed>
+ <OmitFramePointers>false</OmitFramePointers>
+ <AdditionalIncludeDirectories>..\;..\Main;..\Renderer;..\Shader;..\Common;..\SwiftAsm;..\libjpeg;..\SwiftShader;..\D3D9;..\Reactor;..\LLVM\include;..\LLVM\win32;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;D3D8DLL_EXPORTS;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <MinimalRebuild>true</MinimalRebuild>
+ <ExceptionHandling>
+ </ExceptionHandling>
+ <BasicRuntimeChecks>Default</BasicRuntimeChecks>
+ <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
+ <BufferSecurityCheck>false</BufferSecurityCheck>
+ <ForceConformanceInForLoopScope>true</ForceConformanceInForLoopScope>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <BrowseInformation>true</BrowseInformation>
+ <WarningLevel>Level3</WarningLevel>
+ <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+ <ForcedIncludeFiles>%(ForcedIncludeFiles)</ForcedIncludeFiles>
+ </ClCompile>
+ <Link>
+ <AdditionalDependencies>dxguid.lib;WS2_32.lib;comctl32.lib;user32.lib;gdi32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <OutputFile>$(OutDir)d3d8.dll</OutputFile>
+ <IgnoreSpecificDefaultLibraries>libci.lib;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
+ <ModuleDefinitionFile>d3d8.def</ModuleDefinitionFile>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <AssemblyDebug>true</AssemblyDebug>
+ <ProgramDatabaseFile>
+ </ProgramDatabaseFile>
+ <GenerateMapFile>true</GenerateMapFile>
+ <MapExports>true</MapExports>
+ <SubSystem>Windows</SubSystem>
+ <ImportLibrary>$(OutDir)D3D8.lib</ImportLibrary>
+ <TargetMachine>MachineX86</TargetMachine>
+ </Link>
+ <PostBuildEvent>
+ <Command>mkdir "$(SolutionDir)lib\$(Configuration)_$(Platform)\"
+copy "$(OutDir)d3d8.dll" "$(SolutionDir)lib\$(Configuration)_$(Platform)\"</Command>
+ </PostBuildEvent>
+ <ProjectReference>
+ <LinkLibraryDependencies>false</LinkLibraryDependencies>
+ </ProjectReference>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ClCompile>
+ <Optimization>Full</Optimization>
+ <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
+ <IntrinsicFunctions>false</IntrinsicFunctions>
+ <FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
+ <OmitFramePointers>true</OmitFramePointers>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <AdditionalIncludeDirectories>..\;..\Main;..\Renderer;..\Shader;..\Common;..\SwiftAsm;..\libjpeg;..\SwiftShader;..\D3D9;..\Reactor;..\LLVM\include;..\LLVM\win32;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;D3D8DLL_EXPORTS;_CRT_SECURE_NO_DEPRECATE;_SECURE_SCL=0;_HAS_EXCEPTIONS=0;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <ExceptionHandling>false</ExceptionHandling>
+ <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+ <BufferSecurityCheck>false</BufferSecurityCheck>
+ <ForceConformanceInForLoopScope>true</ForceConformanceInForLoopScope>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <ExpandAttributedSource>false</ExpandAttributedSource>
+ <WarningLevel>Level3</WarningLevel>
+ <DebugInformationFormat>
+ </DebugInformationFormat>
+ <ForcedIncludeFiles>%(ForcedIncludeFiles)</ForcedIncludeFiles>
+ <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>
+ <StringPooling>true</StringPooling>
+ <FloatingPointExceptions>false</FloatingPointExceptions>
+ </ClCompile>
+ <Link>
+ <AdditionalDependencies>dxguid.lib;WS2_32.lib;comctl32.lib;user32.lib;gdi32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <OutputFile>$(OutDir)d3d8.dll</OutputFile>
+ <IgnoreSpecificDefaultLibraries>libci.lib;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
+ <ModuleDefinitionFile>d3d8.def</ModuleDefinitionFile>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <SubSystem>Windows</SubSystem>
+ <OptimizeReferences>true</OptimizeReferences>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <SetChecksum>true</SetChecksum>
+ <ImportLibrary>$(OutDir)D3D8.lib</ImportLibrary>
+ <TargetMachine>MachineX86</TargetMachine>
+ <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
+ </Link>
+ <PostBuildEvent>
+ <Command>mkdir "$(SolutionDir)lib\$(Configuration)_$(Platform)\"
+copy "$(OutDir)d3d8.dll" "$(SolutionDir)lib\$(Configuration)_$(Platform)\"</Command>
+ </PostBuildEvent>
+ <ProjectReference>
+ <LinkLibraryDependencies>false</LinkLibraryDependencies>
+ </ProjectReference>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">
+ <ClCompile>
+ <Optimization>Full</Optimization>
+ <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
+ <IntrinsicFunctions>false</IntrinsicFunctions>
+ <FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
+ <OmitFramePointers>false</OmitFramePointers>
+ <WholeProgramOptimization>false</WholeProgramOptimization>
+ <AdditionalIncludeDirectories>..\;..\Main;..\Renderer;..\Shader;..\Common;..\SwiftAsm;..\libjpeg;..\SwiftShader;..\D3D9;..\Reactor;..\LLVM\include;..\LLVM\win32;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;D3D8DLL_EXPORTS;_CRT_SECURE_NO_DEPRECATE;_SECURE_SCL=0;_HAS_EXCEPTIONS=0;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <ExceptionHandling>false</ExceptionHandling>
+ <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+ <BufferSecurityCheck>false</BufferSecurityCheck>
+ <ForceConformanceInForLoopScope>true</ForceConformanceInForLoopScope>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <ExpandAttributedSource>false</ExpandAttributedSource>
+ <WarningLevel>Level3</WarningLevel>
+ <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+ <ForcedIncludeFiles>%(ForcedIncludeFiles)</ForcedIncludeFiles>
+ <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>
+ <StringPooling>true</StringPooling>
+ <FloatingPointExceptions>false</FloatingPointExceptions>
+ </ClCompile>
+ <Link>
+ <AdditionalDependencies>dxguid.lib;WS2_32.lib;comctl32.lib;user32.lib;gdi32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <OutputFile>$(OutDir)d3d8.dll</OutputFile>
+ <IgnoreSpecificDefaultLibraries>libci.lib;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
+ <ModuleDefinitionFile>d3d8.def</ModuleDefinitionFile>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <SubSystem>Windows</SubSystem>
+ <OptimizeReferences>true</OptimizeReferences>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <SetChecksum>true</SetChecksum>
+ <ImportLibrary>$(OutDir)D3D8.lib</ImportLibrary>
+ <TargetMachine>MachineX86</TargetMachine>
+ <LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
+ </Link>
+ <PostBuildEvent>
+ <Command>mkdir "$(SolutionDir)lib\$(Configuration)_$(Platform)\"
+copy "$(OutDir)d3d8.dll" "$(SolutionDir)lib\$(Configuration)_$(Platform)\"</Command>
+ </PostBuildEvent>
+ <ProjectReference>
+ <LinkLibraryDependencies>false</LinkLibraryDependencies>
+ </ProjectReference>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ClCompile Include="Capabilities.cpp" />
+ <ClCompile Include="D3D8.cpp">
+ <AssemblerOutput Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AssemblyAndSourceCode</AssemblerOutput>
+ <AssemblerOutput Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AssemblyAndMachineCode</AssemblerOutput>
+ <AssemblerOutput Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">AssemblyAndMachineCode</AssemblerOutput>
+ <ShowIncludes Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</ShowIncludes>
+ <ShowIncludes Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">false</ShowIncludes>
+ </ClCompile>
+ <ClCompile Include="Direct3D8.cpp" />
+ <ClCompile Include="Direct3DBaseTexture8.cpp" />
+ <ClCompile Include="Direct3DCubeTexture8.cpp" />
+ <ClCompile Include="Direct3DDevice8.cpp" />
+ <ClCompile Include="Direct3DIndexBuffer8.cpp" />
+ <ClCompile Include="Direct3DPixelShader8.cpp" />
+ <ClCompile Include="Direct3DResource8.cpp" />
+ <ClCompile Include="Direct3DStateBlock8.cpp" />
+ <ClCompile Include="Direct3DSurface8.cpp" />
+ <ClCompile Include="Direct3DSwapChain8.cpp" />
+ <ClCompile Include="Direct3DTexture8.cpp" />
+ <ClCompile Include="Direct3DVertexBuffer8.cpp" />
+ <ClCompile Include="Direct3DVertexDeclaration8.cpp" />
+ <ClCompile Include="Direct3DVertexShader8.cpp" />
+ <ClCompile Include="Direct3DVolume8.cpp" />
+ <ClCompile Include="Direct3DVolumeTexture8.cpp" />
+ <ClCompile Include="Unknown.cpp" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="Capabilities.hpp" />
+ <ClInclude Include="Debug.hpp" />
+ <ClInclude Include="Direct3D8.hpp" />
+ <ClInclude Include="Direct3DBaseTexture8.hpp" />
+ <ClInclude Include="Direct3DCubeTexture8.hpp" />
+ <ClInclude Include="Direct3DDevice8.hpp" />
+ <ClInclude Include="Direct3DIndexBuffer8.hpp" />
+ <ClInclude Include="Direct3DPixelShader8.hpp" />
+ <ClInclude Include="Direct3DResource8.hpp" />
+ <ClInclude Include="Direct3DStateBlock8.hpp" />
+ <ClInclude Include="Direct3DSurface8.hpp" />
+ <ClInclude Include="Direct3DSwapChain8.hpp" />
+ <ClInclude Include="Direct3DTexture8.hpp" />
+ <ClInclude Include="Direct3DVertexBuffer8.hpp" />
+ <ClInclude Include="Direct3DVertexDeclaration8.hpp" />
+ <ClInclude Include="Direct3DVertexShader8.hpp" />
+ <ClInclude Include="Direct3DVolume8.hpp" />
+ <ClInclude Include="Direct3DVolumeTexture8.hpp" />
+ <ClInclude Include="resource.h" />
+ <ClInclude Include="resource1.h" />
+ <ClInclude Include="Unknown.hpp" />
+ </ItemGroup>
+ <ItemGroup>
+ <ResourceCompile Include="D3D8.rc" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="d3d8.def" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\SwiftShader\SwiftShader.vcxproj">
+ <Project>{7b02cb19-4cdf-4f79-bc9b-7f3f6164a003}</Project>
+ <Private>false</Private>
+ <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
+ <CopyLocalSatelliteAssemblies>false</CopyLocalSatelliteAssemblies>
+ <LinkLibraryDependencies>true</LinkLibraryDependencies>
+ <UseLibraryDependencyInputs>false</UseLibraryDependencyInputs>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project>
\ No newline at end of file
diff --git a/src/D3D8/D3D8.vcxproj.filters b/src/D3D8/D3D8.vcxproj.filters
new file mode 100644
index 0000000..5348b4d
--- /dev/null
+++ b/src/D3D8/D3D8.vcxproj.filters
@@ -0,0 +1,149 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup>
+ <Filter Include="Source Files">
+ <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
+ <Extensions>cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+ </Filter>
+ <Filter Include="Header Files">
+ <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
+ <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
+ </Filter>
+ <Filter Include="Resource Files">
+ <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
+ <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx</Extensions>
+ </Filter>
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="Capabilities.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="D3D8.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="Direct3D8.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="Direct3DBaseTexture8.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="Direct3DCubeTexture8.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="Direct3DDevice8.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="Direct3DIndexBuffer8.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="Direct3DPixelShader8.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="Direct3DResource8.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="Direct3DStateBlock8.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="Direct3DSurface8.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="Direct3DSwapChain8.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="Direct3DTexture8.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="Direct3DVertexBuffer8.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="Direct3DVertexDeclaration8.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="Direct3DVertexShader8.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="Direct3DVolume8.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="Direct3DVolumeTexture8.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="Unknown.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="Capabilities.hpp">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="Debug.hpp">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="Direct3D8.hpp">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="Direct3DBaseTexture8.hpp">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="Direct3DCubeTexture8.hpp">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="Direct3DDevice8.hpp">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="Direct3DIndexBuffer8.hpp">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="Direct3DPixelShader8.hpp">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="Direct3DResource8.hpp">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="Direct3DStateBlock8.hpp">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="Direct3DSurface8.hpp">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="Direct3DSwapChain8.hpp">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="Direct3DTexture8.hpp">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="Direct3DVertexBuffer8.hpp">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="Direct3DVertexDeclaration8.hpp">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="Direct3DVertexShader8.hpp">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="Direct3DVolume8.hpp">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="Direct3DVolumeTexture8.hpp">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="resource.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="resource1.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="Unknown.hpp">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ </ItemGroup>
+ <ItemGroup>
+ <ResourceCompile Include="D3D8.rc">
+ <Filter>Resource Files</Filter>
+ </ResourceCompile>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="d3d8.def" />
+ </ItemGroup>
+</Project>
\ No newline at end of file
diff --git a/src/D3D8/Debug.hpp b/src/D3D8/Debug.hpp
new file mode 100644
index 0000000..fa216b8
--- /dev/null
+++ b/src/D3D8/Debug.hpp
@@ -0,0 +1,126 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef Debug_hpp
+#define Debug_hpp
+
+#ifndef WIN32_LEAN_AND_MEAN
+ #define WIN32_LEAN_AND_MEAN
+#endif
+#include <windows.h>
+#include <d3d8.h>
+#include <stdio.h>
+#include <guiddef.h>
+#include <assert.h>
+
+void trace(const char *format, ...);
+
+#ifndef NDEBUG
+ #define TRACE(format, ...) trace("[0x%0.8X]%s("format")\n", this, __FUNCTION__, ##__VA_ARGS__)
+#else
+ #define TRACE(...) ((void)0)
+#endif
+
+#ifndef NDEBUG
+ #define ASSERT(expression) {if(!(expression)) trace("\t! Assert failed in %s(%d): "#expression"\n", __FUNCTION__, __LINE__); assert(expression);}
+#else
+ #define ASSERT assert
+#endif
+
+#ifndef NDEBUG
+ #define UNIMPLEMENTED() {trace("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__); ASSERT(false);}
+#else
+ #define UNIMPLEMENTED() ((void)0)
+#endif
+
+#ifndef NDEBUG
+ #define NOINTERFACE(iid) _NOINTERFACE(__FUNCTION__, iid)
+
+ inline long _NOINTERFACE(const char *function, const IID &iid)
+ {
+ trace("\t! No interface {0x%0.8X, 0x%0.4X, 0x%0.4X, 0x%0.2X, 0x%0.2X, 0x%0.2X, 0x%0.2X, 0x%0.2X, 0x%0.2X, 0x%0.2X, 0x%0.2X} for %s\n", iid.Data1, iid.Data2, iid.Data3, iid.Data4[0], iid.Data4[1], iid.Data4[2], iid.Data4[3], iid.Data4[4], iid.Data4[5], iid.Data4[6], iid.Data4[7], function);
+
+ return E_NOINTERFACE;
+ }
+#else
+ #define NOINTERFACE(iid) E_NOINTERFACE
+#endif
+
+#ifndef NDEBUG
+ inline long INVALIDCALL()
+ {
+ trace("\t! D3DERR_INVALIDCALL\n");
+
+ return D3DERR_INVALIDCALL;
+ }
+#else
+ #define INVALIDCALL() D3DERR_INVALIDCALL
+#endif
+
+#ifndef NDEBUG
+ inline long OUTOFMEMORY()
+ {
+ trace("\t! E_OUTOFMEMORY\n");
+
+ return E_OUTOFMEMORY;
+ }
+#else
+ #define OUTOFMEMORY() E_OUTOFMEMORY
+#endif
+
+#ifndef NDEBUG
+ inline long OUTOFVIDEOMEMORY()
+ {
+ trace("\t! D3DERR_OUTOFVIDEOMEMORY\n");
+
+ return D3DERR_OUTOFVIDEOMEMORY;
+ }
+#else
+ #define OUTOFVIDEOMEMORY() D3DERR_OUTOFVIDEOMEMORY
+#endif
+
+#ifndef NDEBUG
+ inline long NOTAVAILABLE()
+ {
+ trace("\t! D3DERR_NOTAVAILABLE\n");
+
+ return D3DERR_NOTAVAILABLE;
+ }
+#else
+ #define NOTAVAILABLE() D3DERR_NOTAVAILABLE
+#endif
+
+#ifndef NDEBUG
+ inline long NOTFOUND()
+ {
+ trace("\t! D3DERR_NOTFOUND\n");
+
+ return D3DERR_NOTFOUND;
+ }
+#else
+ #define NOTFOUND() D3DERR_NOTFOUND
+#endif
+
+#ifndef NDEBUG
+ inline long MOREDATA()
+ {
+ trace("\t! D3DERR_MOREDATA\n");
+
+ return D3DERR_MOREDATA;
+ }
+#else
+ #define MOREDATA() D3DERR_MOREDATA
+#endif
+
+#endif // Debug_hpp
diff --git a/src/D3D8/Direct3D8.cpp b/src/D3D8/Direct3D8.cpp
new file mode 100644
index 0000000..f4ce020
--- /dev/null
+++ b/src/D3D8/Direct3D8.cpp
@@ -0,0 +1,1074 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "Direct3D8.hpp"
+
+#include "Direct3DDevice8.hpp"
+#include "Capabilities.hpp"
+#include "Configurator.hpp"
+#include "Debug.hpp"
+#include "CPUID.hpp"
+#include "Version.h"
+#include "Config.hpp"
+
+#define COMPILE_MULTIMON_STUBS
+#include <multimon.h>
+#include <assert.h>
+
+namespace D3D8
+{
+ Direct3D8::Direct3D8(int version, const HINSTANCE instance) : version(version), instance(instance)
+ {
+ displayMode = 0;
+ numDisplayModes = 0;
+
+ DEVMODE devmode;
+ devmode.dmSize = sizeof(DEVMODE);
+
+ // Count number of display modes
+ while(EnumDisplaySettings(0, numDisplayModes, &devmode))
+ {
+ numDisplayModes++;
+ }
+
+ displayMode = new DEVMODE[numDisplayModes];
+
+ // Store display modes information
+ for(int i = 0; i < numDisplayModes; i++)
+ {
+ displayMode[i].dmSize = sizeof(DEVMODE);
+ EnumDisplaySettings(0, i, &displayMode[i]);
+ }
+
+ d3d8Lib = 0;
+ d3d8 = 0;
+
+ sw::Configurator ini("SwiftShader.ini");
+
+ int ps = ini.getInteger("Capabilities", "PixelShaderVersion", 14);
+ int vs = ini.getInteger("Capabilities", "VertexShaderVersion", 11);
+
+ if(ps == 0) pixelShaderVersion = D3DPS_VERSION(0, 0);
+ else if(ps <= 11) pixelShaderVersion = D3DPS_VERSION(1, 1);
+ else if(ps <= 12) pixelShaderVersion = D3DPS_VERSION(1, 2);
+ else if(ps <= 13) pixelShaderVersion = D3DPS_VERSION(1, 3);
+ else pixelShaderVersion = D3DPS_VERSION(1, 4);
+
+ if(vs == 0) vertexShaderVersion = D3DVS_VERSION(0, 0);
+ else vertexShaderVersion = D3DVS_VERSION(1, 1);
+
+ textureMemory = 1024 * 1024 * ini.getInteger("Capabilities", "TextureMemory", 256);
+ }
+
+ Direct3D8::~Direct3D8()
+ {
+ delete[] displayMode;
+ displayMode = 0;
+
+ if(d3d8)
+ {
+ d3d8->Release();
+ d3d8 = 0;
+ }
+
+ if(d3d8Lib)
+ {
+ FreeLibrary(d3d8Lib);
+ d3d8Lib = 0;
+ }
+ }
+
+ long Direct3D8::QueryInterface(const IID &iid, void **object)
+ {
+ TRACE("");
+
+ if(iid == IID_IDirect3D8 ||
+ iid == IID_IUnknown)
+ {
+ AddRef();
+ *object = this;
+
+ return S_OK;
+ }
+
+ *object = 0;
+
+ return NOINTERFACE(iid);
+ }
+
+ unsigned long Direct3D8::AddRef()
+ {
+ TRACE("");
+
+ return Unknown::AddRef();
+ }
+
+ unsigned long Direct3D8::Release()
+ {
+ TRACE("");
+
+ return Unknown::Release();
+ }
+
+ long Direct3D8::CheckDepthStencilMatch(unsigned int adapter, D3DDEVTYPE deviceType, D3DFORMAT adapterFormat, D3DFORMAT renderTargetFormat, D3DFORMAT depthStencilFormat)
+ {
+ TRACE("");
+
+ if(deviceType != D3DDEVTYPE_HAL)
+ {
+ loadSystemD3D8();
+
+ if(d3d8)
+ {
+ return d3d8->CheckDepthStencilMatch(adapter, deviceType, adapterFormat, renderTargetFormat, depthStencilFormat);
+ }
+ else
+ {
+ return CheckDepthStencilMatch(adapter, D3DDEVTYPE_HAL, adapterFormat, renderTargetFormat, depthStencilFormat);
+ }
+ }
+
+ return D3D_OK; // Any format combination is ok
+ }
+
+ long Direct3D8::CheckDeviceFormat(unsigned int adapter, D3DDEVTYPE deviceType, D3DFORMAT adapterFormat, unsigned long usage, D3DRESOURCETYPE resourceType, D3DFORMAT checkFormat)
+ {
+ TRACE("unsigned int adapter = %d, D3DDEVTYPE deviceType = %d, D3DFORMAT adapterFormat = %d, unsigned long usage = %d, D3DRESOURCETYPE resourceType = %d, D3DFORMAT checkFormat = %d", adapter, deviceType, adapterFormat, usage, resourceType, checkFormat);
+
+ if(deviceType != D3DDEVTYPE_HAL)
+ {
+ loadSystemD3D8();
+
+ if(d3d8)
+ {
+ return d3d8->CheckDeviceFormat(adapter, deviceType, adapterFormat, usage, resourceType, checkFormat);
+ }
+ else
+ {
+ return CheckDeviceFormat(adapter, D3DDEVTYPE_HAL, adapterFormat, usage, resourceType, checkFormat);
+ }
+ }
+
+ switch(resourceType)
+ {
+ case D3DRTYPE_SURFACE:
+ if(usage & D3DUSAGE_RENDERTARGET)
+ {
+ switch(checkFormat)
+ {
+ case D3DFMT_R8G8B8: if(!Capabilities::Surface::RenderTarget::R8G8B8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_R5G6B5: if(!Capabilities::Surface::RenderTarget::R5G6B5) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_X1R5G5B5: if(!Capabilities::Surface::RenderTarget::X1R5G5B5) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A1R5G5B5: if(!Capabilities::Surface::RenderTarget::A1R5G5B5) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A4R4G4B4: if(!Capabilities::Surface::RenderTarget::A4R4G4B4) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_R3G3B2: if(!Capabilities::Surface::RenderTarget::R3G3B2) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A8R3G3B2: if(!Capabilities::Surface::RenderTarget::A8R3G3B2) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_X4R4G4B4: if(!Capabilities::Surface::RenderTarget::X4R4G4B4) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A8R8G8B8: if(!Capabilities::Surface::RenderTarget::A8R8G8B8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_X8R8G8B8: if(!Capabilities::Surface::RenderTarget::X8R8G8B8) return NOTAVAILABLE(); else return D3D_OK;
+ // Integer HDR formats
+ case D3DFMT_G16R16: if(!Capabilities::Surface::RenderTarget::G16R16) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A2B10G10R10: if(!Capabilities::Surface::RenderTarget::A2B10G10R10) return NOTAVAILABLE(); else return D3D_OK;
+ default:
+ return NOTAVAILABLE();
+ }
+ }
+ else if(usage & D3DUSAGE_DEPTHSTENCIL)
+ {
+ switch(checkFormat)
+ {
+ case D3DFMT_D32: if(!Capabilities::Surface::DepthStencil::D32) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_D24S8: if(!Capabilities::Surface::DepthStencil::D24S8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_D24X8: if(!Capabilities::Surface::DepthStencil::D24X8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_D16: if(!Capabilities::Surface::DepthStencil::D16) return NOTAVAILABLE(); else return D3D_OK;
+ default:
+ return NOTAVAILABLE();
+ }
+ }
+ else
+ {
+ switch(checkFormat)
+ {
+ case D3DFMT_A8: if(!Capabilities::Surface::A8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_R5G6B5: if(!Capabilities::Surface::R5G6B5) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_X1R5G5B5: if(!Capabilities::Surface::X1R5G5B5) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A1R5G5B5: if(!Capabilities::Surface::A1R5G5B5) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A4R4G4B4: if(!Capabilities::Surface::A4R4G4B4) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_R3G3B2: if(!Capabilities::Surface::R3G3B2) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A8R3G3B2: if(!Capabilities::Surface::A8R3G3B2) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_X4R4G4B4: if(!Capabilities::Surface::X4R4G4B4) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_R8G8B8: if(!Capabilities::Surface::R8G8B8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_X8R8G8B8: if(!Capabilities::Surface::X8R8G8B8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A8R8G8B8: if(!Capabilities::Surface::A8R8G8B8) return NOTAVAILABLE(); else return D3D_OK;
+ // Paletted formats
+ case D3DFMT_P8: if(!Capabilities::Surface::P8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A8P8: if(!Capabilities::Surface::A8P8) return NOTAVAILABLE(); else return D3D_OK;
+ // Integer HDR formats
+ case D3DFMT_G16R16: if(!Capabilities::Surface::G16R16) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A2B10G10R10: if(!Capabilities::Surface::A2B10G10R10) return NOTAVAILABLE(); else return D3D_OK;
+ // Compressed formats
+ case D3DFMT_DXT1: if(!Capabilities::Surface::DXT1) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_DXT2: if(!Capabilities::Surface::DXT2) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_DXT3: if(!Capabilities::Surface::DXT3) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_DXT4: if(!Capabilities::Surface::DXT4) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_DXT5: if(!Capabilities::Surface::DXT5) return NOTAVAILABLE(); else return D3D_OK;
+ // Bump map formats
+ case D3DFMT_V8U8: if(!Capabilities::Surface::V8U8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_L6V5U5: if(!Capabilities::Surface::L6V5U5) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_X8L8V8U8: if(!Capabilities::Surface::X8L8V8U8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_Q8W8V8U8: if(!Capabilities::Surface::Q8W8V8U8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_V16U16: if(!Capabilities::Surface::V16U16) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A2W10V10U10: if(!Capabilities::Surface::A2W10V10U10) return NOTAVAILABLE(); else return D3D_OK;
+ // Luminance formats
+ case D3DFMT_L8: if(!Capabilities::Surface::L8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A4L4: if(!Capabilities::Surface::A4L4) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A8L8: if(!Capabilities::Surface::A8L8) return NOTAVAILABLE(); else return D3D_OK;
+ default:
+ return NOTAVAILABLE();
+ }
+ }
+ case D3DRTYPE_VOLUME:
+ switch(checkFormat)
+ {
+ case D3DFMT_A8: if(!Capabilities::Volume::A8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_R5G6B5: if(!Capabilities::Volume::R5G6B5) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_X1R5G5B5: if(!Capabilities::Volume::X1R5G5B5) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A1R5G5B5: if(!Capabilities::Volume::A1R5G5B5) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A4R4G4B4: if(!Capabilities::Volume::A4R4G4B4) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_R3G3B2: if(!Capabilities::Volume::R3G3B2) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A8R3G3B2: if(!Capabilities::Volume::A8R3G3B2) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_X4R4G4B4: if(!Capabilities::Volume::X4R4G4B4) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_R8G8B8: if(!Capabilities::Volume::R8G8B8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_X8R8G8B8: if(!Capabilities::Volume::X8R8G8B8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A8R8G8B8: if(!Capabilities::Volume::A8R8G8B8) return NOTAVAILABLE(); else return D3D_OK;
+ // Paletted formats
+ case D3DFMT_P8: if(!Capabilities::Volume::P8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A8P8: if(!Capabilities::Volume::A8P8) return NOTAVAILABLE(); else return D3D_OK;
+ // Integer HDR formats
+ case D3DFMT_G16R16: if(!Capabilities::Volume::G16R16) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A2B10G10R10: if(!Capabilities::Volume::A2B10G10R10) return NOTAVAILABLE(); else return D3D_OK;
+ // Compressed formats
+ case D3DFMT_DXT1: if(!Capabilities::Volume::DXT1) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_DXT2: if(!Capabilities::Volume::DXT2) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_DXT3: if(!Capabilities::Volume::DXT3) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_DXT4: if(!Capabilities::Volume::DXT4) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_DXT5: if(!Capabilities::Volume::DXT5) return NOTAVAILABLE(); else return D3D_OK;
+ // Bump map formats
+ case D3DFMT_V8U8: if(!Capabilities::Volume::V8U8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_L6V5U5: if(!Capabilities::Volume::L6V5U5) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_X8L8V8U8: if(!Capabilities::Volume::X8L8V8U8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_Q8W8V8U8: if(!Capabilities::Volume::Q8W8V8U8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_V16U16: if(!Capabilities::Volume::V16U16) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A2W10V10U10: if(!Capabilities::Volume::A2W10V10U10) return NOTAVAILABLE(); else return D3D_OK;
+ // Luminance formats
+ case D3DFMT_L8: if(!Capabilities::Volume::L8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A4L4: if(!Capabilities::Volume::A4L4) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A8L8: if(!Capabilities::Volume::A8L8) return NOTAVAILABLE(); else return D3D_OK;
+ default:
+ return NOTAVAILABLE();
+ }
+ case D3DRTYPE_CUBETEXTURE:
+ if(usage & D3DUSAGE_RENDERTARGET)
+ {
+ switch(checkFormat)
+ {
+ case D3DFMT_R8G8B8: if(!Capabilities::CubeMap::RenderTarget::R8G8B8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_R5G6B5: if(!Capabilities::CubeMap::RenderTarget::R5G6B5) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_X1R5G5B5: if(!Capabilities::CubeMap::RenderTarget::X1R5G5B5) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A1R5G5B5: if(!Capabilities::CubeMap::RenderTarget::A1R5G5B5) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A4R4G4B4: if(!Capabilities::CubeMap::RenderTarget::A4R4G4B4) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_R3G3B2: if(!Capabilities::CubeMap::RenderTarget::R3G3B2) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A8R3G3B2: if(!Capabilities::CubeMap::RenderTarget::A8R3G3B2) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_X4R4G4B4: if(!Capabilities::CubeMap::RenderTarget::X4R4G4B4) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A8R8G8B8: if(!Capabilities::CubeMap::RenderTarget::A8R8G8B8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_X8R8G8B8: if(!Capabilities::CubeMap::RenderTarget::X8R8G8B8) return NOTAVAILABLE(); else return D3D_OK;
+ // Integer HDR formats
+ case D3DFMT_G16R16: if(!Capabilities::CubeMap::RenderTarget::G16R16) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A2B10G10R10: if(!Capabilities::CubeMap::RenderTarget::A2B10G10R10) return NOTAVAILABLE(); else return D3D_OK;
+ default:
+ return NOTAVAILABLE();
+ }
+ }
+ else if(usage & D3DUSAGE_DEPTHSTENCIL)
+ {
+ switch(checkFormat)
+ {
+ case D3DFMT_D32: if(!Capabilities::CubeMap::DepthStencil::D32) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_D24S8: if(!Capabilities::CubeMap::DepthStencil::D24S8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_D24X8: if(!Capabilities::CubeMap::DepthStencil::D24X8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_D16: if(!Capabilities::CubeMap::DepthStencil::D16) return NOTAVAILABLE(); else return D3D_OK;
+ default:
+ return NOTAVAILABLE();
+ }
+ }
+ else
+ {
+ switch(checkFormat)
+ {
+ case D3DFMT_A8: if(!Capabilities::CubeMap::A8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_R5G6B5: if(!Capabilities::CubeMap::R5G6B5) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_X1R5G5B5: if(!Capabilities::CubeMap::X1R5G5B5) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A1R5G5B5: if(!Capabilities::CubeMap::A1R5G5B5) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A4R4G4B4: if(!Capabilities::CubeMap::A4R4G4B4) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_R3G3B2: if(!Capabilities::CubeMap::R3G3B2) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A8R3G3B2: if(!Capabilities::CubeMap::A8R3G3B2) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_X4R4G4B4: if(!Capabilities::CubeMap::X4R4G4B4) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_R8G8B8: if(!Capabilities::CubeMap::R8G8B8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_X8R8G8B8: if(!Capabilities::CubeMap::X8R8G8B8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A8R8G8B8: if(!Capabilities::CubeMap::A8R8G8B8) return NOTAVAILABLE(); else return D3D_OK;
+ // Paletted formats
+ case D3DFMT_P8: if(!Capabilities::CubeMap::P8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A8P8: if(!Capabilities::CubeMap::A8P8) return NOTAVAILABLE(); else return D3D_OK;
+ // Integer HDR formats
+ case D3DFMT_G16R16: if(!Capabilities::CubeMap::G16R16) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A2B10G10R10: if(!Capabilities::CubeMap::A2B10G10R10) return NOTAVAILABLE(); else return D3D_OK;
+ // Compressed formats
+ case D3DFMT_DXT1: if(!Capabilities::CubeMap::DXT1) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_DXT2: if(!Capabilities::CubeMap::DXT2) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_DXT3: if(!Capabilities::CubeMap::DXT3) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_DXT4: if(!Capabilities::CubeMap::DXT4) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_DXT5: if(!Capabilities::CubeMap::DXT5) return NOTAVAILABLE(); else return D3D_OK;
+ // Bump map formats
+ case D3DFMT_V8U8: if(!Capabilities::CubeMap::V8U8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_L6V5U5: if(!Capabilities::CubeMap::L6V5U5) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_X8L8V8U8: if(!Capabilities::CubeMap::X8L8V8U8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_Q8W8V8U8: if(!Capabilities::CubeMap::Q8W8V8U8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_V16U16: if(!Capabilities::CubeMap::V16U16) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A2W10V10U10: if(!Capabilities::CubeMap::A2W10V10U10) return NOTAVAILABLE(); else return D3D_OK;
+ // Luminance formats
+ case D3DFMT_L8: if(!Capabilities::CubeMap::L8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A4L4: if(!Capabilities::CubeMap::A4L4) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A8L8: if(!Capabilities::CubeMap::A8L8) return NOTAVAILABLE(); else return D3D_OK;
+ default:
+ return NOTAVAILABLE();
+ }
+ }
+ case D3DRTYPE_VOLUMETEXTURE:
+ switch(checkFormat)
+ {
+ case D3DFMT_A8: if(!Capabilities::VolumeTexture::A8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_R5G6B5: if(!Capabilities::VolumeTexture::R5G6B5) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_X1R5G5B5: if(!Capabilities::VolumeTexture::X1R5G5B5) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A1R5G5B5: if(!Capabilities::VolumeTexture::A1R5G5B5) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A4R4G4B4: if(!Capabilities::VolumeTexture::A4R4G4B4) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_R3G3B2: if(!Capabilities::VolumeTexture::R3G3B2) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A8R3G3B2: if(!Capabilities::VolumeTexture::A8R3G3B2) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_X4R4G4B4: if(!Capabilities::VolumeTexture::X4R4G4B4) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_R8G8B8: if(!Capabilities::VolumeTexture::R8G8B8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_X8R8G8B8: if(!Capabilities::VolumeTexture::X8R8G8B8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A8R8G8B8: if(!Capabilities::VolumeTexture::A8R8G8B8) return NOTAVAILABLE(); else return D3D_OK;
+ // Paletted formats
+ case D3DFMT_P8: if(!Capabilities::VolumeTexture::P8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A8P8: if(!Capabilities::VolumeTexture::A8P8) return NOTAVAILABLE(); else return D3D_OK;
+ // Integer HDR formats
+ case D3DFMT_G16R16: if(!Capabilities::VolumeTexture::G16R16) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A2B10G10R10: if(!Capabilities::VolumeTexture::A2B10G10R10) return NOTAVAILABLE(); else return D3D_OK;
+ // Compressed formats
+ case D3DFMT_DXT1: if(!Capabilities::VolumeTexture::DXT1) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_DXT2: if(!Capabilities::VolumeTexture::DXT2) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_DXT3: if(!Capabilities::VolumeTexture::DXT3) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_DXT4: if(!Capabilities::VolumeTexture::DXT4) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_DXT5: if(!Capabilities::VolumeTexture::DXT5) return NOTAVAILABLE(); else return D3D_OK;
+ // Bump map formats
+ case D3DFMT_V8U8: if(!Capabilities::VolumeTexture::V8U8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_L6V5U5: if(!Capabilities::VolumeTexture::L6V5U5) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_X8L8V8U8: if(!Capabilities::VolumeTexture::X8L8V8U8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_Q8W8V8U8: if(!Capabilities::VolumeTexture::Q8W8V8U8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_V16U16: if(!Capabilities::VolumeTexture::V16U16) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A2W10V10U10: if(!Capabilities::VolumeTexture::A2W10V10U10) return NOTAVAILABLE(); else return D3D_OK;
+ // Luminance formats
+ case D3DFMT_L8: if(!Capabilities::VolumeTexture::L8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A4L4: if(!Capabilities::VolumeTexture::A4L4) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A8L8: if(!Capabilities::VolumeTexture::A8L8) return NOTAVAILABLE(); else return D3D_OK;
+ default:
+ return NOTAVAILABLE();
+ }
+ case D3DRTYPE_TEXTURE:
+ if(usage & D3DUSAGE_RENDERTARGET)
+ {
+ switch(checkFormat)
+ {
+ case D3DFMT_R8G8B8: if(!Capabilities::Texture::RenderTarget::R8G8B8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_R5G6B5: if(!Capabilities::Texture::RenderTarget::R5G6B5) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_X1R5G5B5: if(!Capabilities::Texture::RenderTarget::X1R5G5B5) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A1R5G5B5: if(!Capabilities::Texture::RenderTarget::A1R5G5B5) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A4R4G4B4: if(!Capabilities::Texture::RenderTarget::A4R4G4B4) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_R3G3B2: if(!Capabilities::Texture::RenderTarget::R3G3B2) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A8R3G3B2: if(!Capabilities::Texture::RenderTarget::A8R3G3B2) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_X4R4G4B4: if(!Capabilities::Texture::RenderTarget::X4R4G4B4) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A8R8G8B8: if(!Capabilities::Texture::RenderTarget::A8R8G8B8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_X8R8G8B8: if(!Capabilities::Texture::RenderTarget::X8R8G8B8) return NOTAVAILABLE(); else return D3D_OK;
+ // Integer HDR formats
+ case D3DFMT_G16R16: if(!Capabilities::Texture::RenderTarget::G16R16) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A2B10G10R10: if(!Capabilities::Texture::RenderTarget::A2B10G10R10) return NOTAVAILABLE(); else return D3D_OK;
+ default:
+ return NOTAVAILABLE();
+ }
+ }
+ else if(usage & D3DUSAGE_DEPTHSTENCIL)
+ {
+ switch(checkFormat)
+ {
+ case D3DFMT_D32: if(!Capabilities::Texture::DepthStencil::D32) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_D24S8: if(!Capabilities::Texture::DepthStencil::D24S8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_D24X8: if(!Capabilities::Texture::DepthStencil::D24X8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_D16: if(!Capabilities::Texture::DepthStencil::D16) return NOTAVAILABLE(); else return D3D_OK;
+ default:
+ return NOTAVAILABLE();
+ }
+ }
+ else
+ {
+ switch(checkFormat)
+ {
+ case D3DFMT_A8: if(!Capabilities::Texture::A8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_R5G6B5: if(!Capabilities::Texture::R5G6B5) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_X1R5G5B5: if(!Capabilities::Texture::X1R5G5B5) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A1R5G5B5: if(!Capabilities::Texture::A1R5G5B5) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A4R4G4B4: if(!Capabilities::Texture::A4R4G4B4) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_R3G3B2: if(!Capabilities::Texture::R3G3B2) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A8R3G3B2: if(!Capabilities::Texture::A8R3G3B2) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_X4R4G4B4: if(!Capabilities::Texture::X4R4G4B4) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_R8G8B8: if(!Capabilities::Texture::R8G8B8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_X8R8G8B8: if(!Capabilities::Texture::X8R8G8B8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A8R8G8B8: if(!Capabilities::Texture::A8R8G8B8) return NOTAVAILABLE(); else return D3D_OK;
+ // Paletted formats
+ case D3DFMT_P8: if(!Capabilities::Texture::P8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A8P8: if(!Capabilities::Texture::A8P8) return NOTAVAILABLE(); else return D3D_OK;
+ // Integer HDR formats
+ case D3DFMT_G16R16: if(!Capabilities::Texture::G16R16) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A2B10G10R10: if(!Capabilities::Texture::A2B10G10R10) return NOTAVAILABLE(); else return D3D_OK;
+ // Compressed formats
+ case D3DFMT_DXT1: if(!Capabilities::Texture::DXT1) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_DXT2: if(!Capabilities::Texture::DXT2) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_DXT3: if(!Capabilities::Texture::DXT3) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_DXT4: if(!Capabilities::Texture::DXT4) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_DXT5: if(!Capabilities::Texture::DXT5) return NOTAVAILABLE(); else return D3D_OK;
+ // Bump map formats
+ case D3DFMT_V8U8: if(!Capabilities::Texture::V8U8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_L6V5U5: if(!Capabilities::Texture::L6V5U5) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_X8L8V8U8: if(!Capabilities::Texture::X8L8V8U8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_Q8W8V8U8: if(!Capabilities::Texture::Q8W8V8U8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_V16U16: if(!Capabilities::Texture::V16U16) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A2W10V10U10: if(!Capabilities::Texture::A2W10V10U10) return NOTAVAILABLE(); else return D3D_OK;
+ // Luminance formats
+ case D3DFMT_L8: if(!Capabilities::Texture::L8) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A4L4: if(!Capabilities::Texture::A4L4) return NOTAVAILABLE(); else return D3D_OK;
+ case D3DFMT_A8L8: if(!Capabilities::Texture::A8L8) return NOTAVAILABLE(); else return D3D_OK;
+ default:
+ return NOTAVAILABLE();
+ }
+ }
+ case D3DRTYPE_VERTEXBUFFER:
+ if(checkFormat == D3DFMT_VERTEXDATA)
+ {
+ return D3D_OK;
+ }
+ else
+ {
+ return NOTAVAILABLE();
+ }
+ case D3DRTYPE_INDEXBUFFER:
+ switch(checkFormat)
+ {
+ case D3DFMT_INDEX16:
+ case D3DFMT_INDEX32:
+ return D3D_OK;
+ default:
+ return NOTAVAILABLE();
+ };
+ default:
+ return NOTAVAILABLE();
+ }
+ }
+
+ long Direct3D8::CheckDeviceMultiSampleType(unsigned int adapter, D3DDEVTYPE deviceType, D3DFORMAT surfaceFormat, int windowed, D3DMULTISAMPLE_TYPE multiSampleType)
+ {
+ TRACE("");
+
+ if(deviceType != D3DDEVTYPE_HAL)
+ {
+ loadSystemD3D8();
+
+ if(d3d8)
+ {
+ return d3d8->CheckDeviceMultiSampleType(adapter, deviceType, surfaceFormat, windowed, multiSampleType);
+ }
+ else
+ {
+ return CheckDeviceMultiSampleType(adapter, D3DDEVTYPE_HAL, surfaceFormat, windowed, multiSampleType);
+ }
+ }
+
+ if(adapter >= GetAdapterCount())
+ {
+ return INVALIDCALL();
+ }
+
+ if(multiSampleType == D3DMULTISAMPLE_NONE ||
+ multiSampleType == D3DMULTISAMPLE_2_SAMPLES ||
+ multiSampleType == D3DMULTISAMPLE_4_SAMPLES ||
+ multiSampleType == D3DMULTISAMPLE_8_SAMPLES ||
+ multiSampleType == D3DMULTISAMPLE_16_SAMPLES)
+ {
+ if(surfaceFormat != D3DFMT_UNKNOWN)
+ {
+ return D3D_OK;
+ }
+ }
+
+ return NOTAVAILABLE();
+ }
+
+ long Direct3D8::CheckDeviceType(unsigned int adapter, D3DDEVTYPE checkType, D3DFORMAT displayFormat, D3DFORMAT backBufferFormat, int windowed)
+ {
+ TRACE("");
+
+ if(checkType != D3DDEVTYPE_HAL)
+ {
+ loadSystemD3D8();
+
+ if(d3d8)
+ {
+ return d3d8->CheckDeviceType(adapter, checkType, displayFormat, backBufferFormat, windowed);
+ }
+ else
+ {
+ return CheckDeviceType(adapter, D3DDEVTYPE_HAL, displayFormat, backBufferFormat, windowed);
+ }
+ }
+
+ return D3D_OK; // TODO
+ }
+
+ long Direct3D8::CreateDevice(unsigned int adapter, D3DDEVTYPE deviceType, HWND focusWindow, unsigned long behaviorFlags, D3DPRESENT_PARAMETERS *presentParameters, IDirect3DDevice8 **returnedDeviceInterface)
+ {
+ TRACE("");
+
+ if(deviceType != D3DDEVTYPE_HAL)
+ {
+ loadSystemD3D8();
+
+ if(d3d8)
+ {
+ return d3d8->CreateDevice(adapter, deviceType, focusWindow, behaviorFlags, presentParameters, returnedDeviceInterface);
+ }
+ else
+ {
+ return CreateDevice(adapter, D3DDEVTYPE_HAL, focusWindow, behaviorFlags, presentParameters, returnedDeviceInterface);
+ }
+ }
+
+ if(!focusWindow || !presentParameters || !returnedDeviceInterface)
+ {
+ *returnedDeviceInterface = NULL;
+ return INVALIDCALL();
+ }
+
+ if(!sw::CPUID::supportsSSE())
+ {
+ return NOTAVAILABLE();
+ }
+
+ *returnedDeviceInterface = new Direct3DDevice8(instance, this, adapter, deviceType, focusWindow, behaviorFlags, presentParameters);
+
+ if(*returnedDeviceInterface)
+ {
+ (*returnedDeviceInterface)->AddRef();
+ }
+
+ return D3D_OK;
+ }
+
+ long Direct3D8::EnumAdapterModes(unsigned int adapter, unsigned int index, D3DDISPLAYMODE *mode)
+ {
+ TRACE("");
+
+ if(adapter != D3DADAPTER_DEFAULT || !mode)
+ {
+ return INVALIDCALL();
+ }
+
+ for(int i = 0; i < numDisplayModes; i++)
+ {
+ if(index-- == 0)
+ {
+ mode->Width = displayMode[i].dmPelsWidth;
+ mode->Height = displayMode[i].dmPelsHeight;
+ mode->RefreshRate = displayMode[i].dmDisplayFrequency;
+
+ displayMode[i].dmBitsPerPel = 32; // FIXME
+
+ switch(displayMode[i].dmBitsPerPel)
+ {
+ case 4:
+ mode->Format = D3DFMT_A4L4;
+ break;
+ case 8:
+ mode->Format = D3DFMT_P8;
+ break;
+ case 16:
+ mode->Format = D3DFMT_R5G6B5;
+ break;
+ case 24:
+ mode->Format = D3DFMT_R8G8B8;
+ break;
+ case 32:
+ mode->Format = D3DFMT_X8R8G8B8;
+ break;
+ default:
+ ASSERT(false);
+ }
+
+ return D3D_OK;
+ }
+ }
+
+ return INVALIDCALL();
+ }
+
+ unsigned int Direct3D8::GetAdapterCount()
+ {
+ TRACE("");
+
+ return 1; // SwiftShader does not support multiple display adapters
+ }
+
+ long Direct3D8::GetAdapterDisplayMode(unsigned int adapter, D3DDISPLAYMODE *mode)
+ {
+ TRACE("");
+
+ if(adapter != D3DADAPTER_DEFAULT || !mode)
+ {
+ return INVALIDCALL();
+ }
+
+ HDC deviceContext = GetDC(0);
+
+ mode->Width = ::GetDeviceCaps(deviceContext, HORZRES);
+ mode->Height = ::GetDeviceCaps(deviceContext, VERTRES);
+ mode->RefreshRate = ::GetDeviceCaps(deviceContext, VREFRESH);
+ unsigned int bpp = ::GetDeviceCaps(deviceContext, BITSPIXEL);
+
+ ReleaseDC(0, deviceContext);
+
+ bpp = 32; // FIXME
+
+ switch(bpp)
+ {
+ case 32: mode->Format = D3DFMT_X8R8G8B8; break;
+ case 24: mode->Format = D3DFMT_R8G8B8; break;
+ case 16: mode->Format = D3DFMT_R5G6B5; break;
+ default:
+ ASSERT(false); // Unexpected display mode color depth
+ }
+
+ return D3D_OK;
+ }
+
+ long Direct3D8::GetAdapterIdentifier(unsigned int adapter, unsigned long flags, D3DADAPTER_IDENTIFIER8 *identifier)
+ {
+ TRACE("");
+
+ if(!identifier)
+ {
+ return INVALIDCALL();
+ }
+
+ unsigned short product = 'sw';
+ unsigned short version = 3;
+ unsigned short subVersion = 0;
+ unsigned short revision = BUILD_REVISION;
+ GUID guid = {0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
+
+ identifier->DriverVersion.HighPart = product << 16 | version;
+ identifier->DriverVersion.LowPart = subVersion << 16 | revision;
+ strcpy(identifier->Driver, "SwiftShader");
+ strcpy(identifier->Description, "Google SwiftShader 3D Renderer");
+ identifier->VendorId = 0;
+ identifier->DeviceId = 0;
+ identifier->SubSysId = 0;
+ identifier->Revision = 0;
+ identifier->DeviceIdentifier = guid;
+ identifier->WHQLLevel = 0;
+
+ return D3D_OK;
+ }
+
+ unsigned int Direct3D8::GetAdapterModeCount(unsigned int adapter)
+ {
+ TRACE("");
+
+ if(adapter != D3DADAPTER_DEFAULT)
+ {
+ return 0;
+ }
+
+ return numDisplayModes;
+ }
+
+ HMONITOR Direct3D8::GetAdapterMonitor(unsigned int adapter)
+ {
+ TRACE("");
+
+ POINT point = {0, 0};
+
+ return MonitorFromPoint(point, MONITOR_DEFAULTTOPRIMARY); // FIXME: Ignores adapter parameter
+ }
+
+ long Direct3D8::GetDeviceCaps(unsigned int adapter, D3DDEVTYPE deviceType, D3DCAPS8 *capabilities)
+ {
+ TRACE("");
+
+ if(deviceType != D3DDEVTYPE_HAL)
+ {
+ loadSystemD3D8();
+
+ if(d3d8)
+ {
+ return d3d8->GetDeviceCaps(adapter, deviceType, capabilities);
+ }
+ else
+ {
+ return GetDeviceCaps(adapter, D3DDEVTYPE_HAL, capabilities);
+ }
+ }
+
+ if(!capabilities)
+ {
+ return INVALIDCALL();
+ }
+
+ D3DCAPS8 caps;
+ ZeroMemory(&caps, sizeof(D3DCAPS8));
+
+ // Device info
+ caps.DeviceType = D3DDEVTYPE_HAL;
+ caps.AdapterOrdinal = D3DADAPTER_DEFAULT;
+
+ // Caps from DX7
+ caps.Caps = 0; // D3DCAPS_READ_SCANLINE
+
+ caps.Caps2 = // D3DCAPS2_CANCALIBRATEGAMMA | // The system has a calibrator installed that can automatically adjust the gamma ramp so that the result is identical on all systems that have a calibrator. To invoke the calibrator when setting new gamma levels, use the D3DSGR_CALIBRATE flag when calling IDirect3DDevice8::SetGammaRamp. Calibrating gamma ramps incurs some processing overhead and should not be used frequently.
+ D3DCAPS2_CANRENDERWINDOWED | // The driver is capable of rendering in windowed mode.
+ D3DCAPS2_CANMANAGERESOURCE | // The driver is capable of managing resources. On such drivers, D3DPOOL_MANAGED resources will be managed by the driver. To have Microsoft® Direct3D® override the driver so that Direct3D manages resources, use the D3DCREATE_DISABLE_DRIVER_MANAGEMENT flag when calling IDirect3D8::CreateDevice.
+ D3DCAPS2_DYNAMICTEXTURES | // The driver supports dynamic textures.
+ D3DCAPS2_FULLSCREENGAMMA; // The driver supports dynamic gamma ramp adjustment in full-screen mode.
+ // D3DCAPS2_NO2DDURING3DSCENE; // When the D3DCAPS2_NO2DDURING3DSCENE capability is set by the driver, it means that 2-D operations cannot be performed between calls to IDirect3DDevice8::BeginScene and IDirect3DDevice8::EndScene.
+
+ caps.Caps3 = D3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD; //The device will work as expected with the D3DRS_ALPHABLENDENABLE render state when a full-screen application uses D3DSWAPEFFECT_FLIP or D3DRS_SWAPEFFECT_DISCARD. D3DRS_ALPHABLENDENABLE works as expected when using D3DSWAPEFFECT_COPY and D3DSWAPEFFECT_COPYSYNC
+
+ caps.PresentationIntervals = D3DPRESENT_INTERVAL_IMMEDIATE |
+ D3DPRESENT_INTERVAL_ONE;
+ // D3DPRESENT_INTERVAL_TWO;
+ // D3DPRESENT_INTERVAL_THREE;
+ // D3DPRESENT_INTERVAL_FOUR;
+
+ // Cursor caps
+ caps.CursorCaps = D3DCURSORCAPS_COLOR | // A full-color cursor is supported in hardware. Specifically, this flag indicates that the driver supports at least a hardware color cursor in high-resolution modes (with scan lines greater than or equal to 400).
+ D3DCURSORCAPS_LOWRES; // A full-color cursor is supported in hardware. Specifically, this flag indicates that the driver supports a hardware color cursor in both high-resolution and low-resolution modes (with scan lines less than 400).
+
+ // 3D Device caps
+ caps.DevCaps = D3DDEVCAPS_CANBLTSYSTONONLOCAL | // Device supports blits from system-memory textures to nonlocal video-memory textures.
+ D3DDEVCAPS_CANRENDERAFTERFLIP | // Device can queue rendering commands after a page flip. Applications do not change their behavior if this flag is set; this capability means that the device is relatively fast.
+ D3DDEVCAPS_DRAWPRIMITIVES2 | // Device can support DrawPrimitives2.
+ D3DDEVCAPS_DRAWPRIMITIVES2EX | // Device can support extended DrawPrimitives2; that is, this is a DirectX 7.0-compliant driver.
+ D3DDEVCAPS_DRAWPRIMTLVERTEX | // Device exports an IDirect3DDevice8::DrawPrimitive-aware hardware abstraction layer (HAL).
+ // D3DDEVCAPS_EXECUTESYSTEMMEMORY | // Device can use execute buffers from system memory.
+ // D3DDEVCAPS_EXECUTEVIDEOMEMORY | // Device can use execute buffers from video memory.
+ D3DDEVCAPS_HWRASTERIZATION | // Device has hardware acceleration for scene rasterization.
+ D3DDEVCAPS_HWTRANSFORMANDLIGHT | // Device can support transformation and lighting in hardware.
+ // D3DDEVCAPS_NPATCHES | // Device supports N patches.
+ D3DDEVCAPS_PUREDEVICE | // Device can support rasterization, transform, lighting, and shading in hardware.
+ // D3DDEVCAPS_QUINTICRTPATCHES | // Device supports quintic Bézier curves and B-splines.
+ // D3DDEVCAPS_RTPATCHES | // Device supports rectangular and triangular patches.
+ D3DDEVCAPS_RTPATCHHANDLEZERO | // When this device capability is set, the hardware architecture does not require caching of any information and uncached patches (handle zero) will be drawn as efficiently as cached ones. Note that setting D3DDEVCAPS_RTPATCHHANDLEZERO does not mean that a patch with handle zero can be drawn. A handle-zero patch can always be drawn whether this cap is set or not.
+ // D3DDEVCAPS_SEPARATETEXTUREMEMORIES | // Device is texturing from separate memory pools.
+ D3DDEVCAPS_TEXTURENONLOCALVIDMEM | // Device can retrieve textures from non-local video memory.
+ D3DDEVCAPS_TEXTURESYSTEMMEMORY | // Device can retrieve textures from system memory.
+ D3DDEVCAPS_TEXTUREVIDEOMEMORY | // Device can retrieve textures from device memory.
+ D3DDEVCAPS_TLVERTEXSYSTEMMEMORY | // Device can use buffers from system memory for transformed and lit vertices.
+ D3DDEVCAPS_TLVERTEXVIDEOMEMORY; // Device can use buffers from video memory for transformed and lit vertices.
+
+ caps.PrimitiveMiscCaps = D3DPMISCCAPS_BLENDOP | // Device supports the alpha-blending operations defined in the D3DBLENDOP enumerated type.
+ D3DPMISCCAPS_CLIPPLANESCALEDPOINTS | // Device correctly clips scaled points of size greater than 1.0 to user-defined clipping planes.
+ D3DPMISCCAPS_CLIPTLVERTS | // Device clips post-transformed vertex primitives.
+ D3DPMISCCAPS_COLORWRITEENABLE | // Device supports per-channel writes for the render target color buffer through the D3DRS_COLORWRITEENABLE state.
+ D3DPMISCCAPS_CULLCCW | // The driver supports counterclockwise culling through the D3DRS_CULLMODE state. (This applies only to triangle primitives.) This flag corresponds to the D3DCULL_CCW member of the D3DCULL enumerated type.
+ D3DPMISCCAPS_CULLCW | // The driver supports clockwise triangle culling through the D3DRS_CULLMODE state. (This applies only to triangle primitives.) This flag corresponds to the D3DCULL_CW member of the D3DCULL enumerated type.
+ D3DPMISCCAPS_CULLNONE | // The driver does not perform triangle culling. This corresponds to the D3DCULL_NONE member of the D3DCULL enumerated type.
+ // D3DPMISCCAPS_LINEPATTERNREP | // The driver can handle values other than 1 in the wRepeatFactor member of the D3DLINEPATTERN structure. (This applies only to line-drawing primitives.)
+ D3DPMISCCAPS_MASKZ | // Device can enable and disable modification of the depth buffer on pixel operations.
+ D3DPMISCCAPS_TSSARGTEMP; // Device supports D3DTA_TEMP for temporary register.
+
+ caps.RasterCaps = D3DPRASTERCAPS_ANISOTROPY | // Device supports anisotropic filtering.
+ // D3DPRASTERCAPS_ANTIALIASEDGES | // Device can antialias lines forming the convex outline of objects. For more information, see D3DRS_EDGEANTIALIAS.
+ D3DPRASTERCAPS_COLORPERSPECTIVE | // Device iterates colors perspective correctly.
+ // D3DPRASTERCAPS_DITHER | // Device can dither to improve color resolution.
+ D3DPRASTERCAPS_ZBIAS | // Device supports legacy depth bias. For true depth bias, see D3DPRASTERCAPS_SLOPESCALEDEPTHBIAS.
+ D3DPRASTERCAPS_FOGRANGE | // Device supports range-based fog. In range-based fog, the distance of an object from the viewer is used to compute fog effects, not the depth of the object (that is, the z-coordinate) in the scene.
+ D3DPRASTERCAPS_FOGTABLE | // Device calculates the fog value by referring to a lookup table containing fog values that are indexed to the depth of a given pixel.
+ D3DPRASTERCAPS_FOGVERTEX | // Device calculates the fog value during the lighting operation and interpolates the fog value during rasterization.
+ D3DPRASTERCAPS_MIPMAPLODBIAS | // Device supports level of detail (LOD) bias adjustments. These bias adjustments enable an application to make a mipmap appear crisper or less sharp than it normally would. For more information about LOD bias in mipmaps, see D3DSAMP_MIPMAPLODBIAS.
+ // D3DPRASTERCAPS_PAT | // The driver can perform patterned drawing lines or fills with D3DRS_LINEPATTERN for the primitive being queried.
+ // D3DPRASTERCAPS_STRETCHBLTMULTISAMPLE | // Device provides limited multisample support through a stretch-blt implementation. When this capability is set, D3DRS_MULTISAMPLEANTIALIAS cannot be turned on and off in the middle of a scene. Multisample masking cannot be performed if this flag is set.
+ // D3DPRASTERCAPS_WBUFFER | // Device supports depth buffering using w.
+ D3DPRASTERCAPS_WFOG | // Device supports w-based fog. W-based fog is used when a perspective projection matrix is specified, but affine projections still use z-based fog. The system considers a projection matrix that contains a nonzero value in the [3][4] element to be a perspective projection matrix.
+ D3DPRASTERCAPS_ZBIAS | // Device supports z-bias values. These are integer values assigned to polygons that allow physically coplanar polygons to appear separate. For more information, see D3DRS_ZBIAS.
+ // D3DPRASTERCAPS_ZBUFFERLESSHSR | // Device can perform hidden-surface removal (HSR) without requiring the application to sort polygons and without requiring the allocation of a depth-buffer. This leaves more video memory for textures. The method used to perform HSR is hardware-dependent and is transparent to the application. Z-bufferless HSR is performed if no depth-buffer surface is associated with the rendering-target surface and the depth-buffer comparison test is enabled (that is, when the state value associated with the D3DRS_ZENABLE enumeration constant is set to TRUE).
+ D3DPRASTERCAPS_ZFOG; // Device supports z-based fog.
+ // D3DPRASTERCAPS_ZTEST; // Device can perform z-test operations. This effectively renders a primitive and indicates whether any z pixels have been rendered.
+
+ caps.ZCmpCaps = D3DPCMPCAPS_ALWAYS | // Always pass the z-test.
+ D3DPCMPCAPS_EQUAL | // Pass the z-test if the new z equals the current z.
+ D3DPCMPCAPS_GREATER | // Pass the z-test if the new z is greater than the current z.
+ D3DPCMPCAPS_GREATEREQUAL | // Pass the z-test if the new z is greater than or equal to the current z.
+ D3DPCMPCAPS_LESS | // Pass the z-test if the new z is less than the current z.
+ D3DPCMPCAPS_LESSEQUAL | // Pass the z-test if the new z is less than or equal to the current z.
+ D3DPCMPCAPS_NEVER | // Always fail the z-test.
+ D3DPCMPCAPS_NOTEQUAL; // Pass the z-test if the new z does not equal the current z.
+
+ caps.SrcBlendCaps = D3DPBLENDCAPS_BOTHINVSRCALPHA | // Source blend factor is (1-As,1-As,1-As,1-As) and destination blend factor is (As,As,As,As); the destination blend selection is overridden.
+ D3DPBLENDCAPS_BOTHSRCALPHA | // The driver supports the D3DBLEND_BOTHSRCALPHA blend mode. (This blend mode is obsolete. For more information, see D3DBLEND.)
+ D3DPBLENDCAPS_DESTALPHA | // Blend factor is (Ad, Ad, Ad, Ad).
+ D3DPBLENDCAPS_DESTCOLOR | // Blend factor is (Rd, Gd, Bd, Ad).
+ D3DPBLENDCAPS_INVDESTALPHA | // Blend factor is (1-Ad, 1-Ad, 1-Ad, 1-Ad).
+ D3DPBLENDCAPS_INVDESTCOLOR | // Blend factor is (1-Rd, 1-Gd, 1-Bd, 1-Ad).
+ D3DPBLENDCAPS_INVSRCALPHA | // Blend factor is (1-As, 1-As, 1-As, 1-As).
+ D3DPBLENDCAPS_INVSRCCOLOR | // Blend factor is (1-Rs, 1-Gs, 1-Bs, 1-As).
+ D3DPBLENDCAPS_ONE | // Blend factor is (1, 1, 1, 1).
+ D3DPBLENDCAPS_SRCALPHA | // Blend factor is (As, As, As, As).
+ D3DPBLENDCAPS_SRCALPHASAT | // Blend factor is (f, f, f, 1); f = min(As, 1-Ad).
+ D3DPBLENDCAPS_SRCCOLOR | // Blend factor is (Rs, Gs, Bs, As).
+ D3DPBLENDCAPS_ZERO; // Blend factor is (0, 0, 0, 0).
+
+ caps.DestBlendCaps = D3DPBLENDCAPS_BOTHINVSRCALPHA | // Source blend factor is (1-As,1-As,1-As,1-As) and destination blend factor is (As,As,As,As); the destination blend selection is overridden.
+ D3DPBLENDCAPS_BOTHSRCALPHA | // The driver supports the D3DBLEND_BOTHSRCALPHA blend mode. (This blend mode is obsolete. For more information, see D3DBLEND.)
+ D3DPBLENDCAPS_DESTALPHA | // Blend factor is (Ad, Ad, Ad, Ad).
+ D3DPBLENDCAPS_DESTCOLOR | // Blend factor is (Rd, Gd, Bd, Ad).
+ D3DPBLENDCAPS_INVDESTALPHA | // Blend factor is (1-Ad, 1-Ad, 1-Ad, 1-Ad).
+ D3DPBLENDCAPS_INVDESTCOLOR | // Blend factor is (1-Rd, 1-Gd, 1-Bd, 1-Ad).
+ D3DPBLENDCAPS_INVSRCALPHA | // Blend factor is (1-As, 1-As, 1-As, 1-As).
+ D3DPBLENDCAPS_INVSRCCOLOR | // Blend factor is (1-Rs, 1-Gs, 1-Bs, 1-As).
+ D3DPBLENDCAPS_ONE | // Blend factor is (1, 1, 1, 1).
+ D3DPBLENDCAPS_SRCALPHA | // Blend factor is (As, As, As, As).
+ D3DPBLENDCAPS_SRCALPHASAT | // Blend factor is (f, f, f, 1); f = min(As, 1-Ad).
+ D3DPBLENDCAPS_SRCCOLOR | // Blend factor is (Rs, Gs, Bs, As).
+ D3DPBLENDCAPS_ZERO; // Blend factor is (0, 0, 0, 0).
+
+ caps.AlphaCmpCaps = D3DPCMPCAPS_ALWAYS | // Always pass the apha-test.
+ D3DPCMPCAPS_EQUAL | // Pass the apha-test if the new apha equals the current apha.
+ D3DPCMPCAPS_GREATER | // Pass the apha-test if the new apha is greater than the current apha.
+ D3DPCMPCAPS_GREATEREQUAL | // Pass the apha-test if the new apha is greater than or equal to the current apha.
+ D3DPCMPCAPS_LESS | // Pass the apha-test if the new apha is less than the current apha.
+ D3DPCMPCAPS_LESSEQUAL | // Pass the apha-test if the new apha is less than or equal to the current apha.
+ D3DPCMPCAPS_NEVER | // Always fail the apha-test.
+ D3DPCMPCAPS_NOTEQUAL; // Pass the apha-test if the new apha does not equal the current apha.
+
+ caps.ShadeCaps = D3DPSHADECAPS_ALPHAGOURAUDBLEND | // Device can support an alpha component for Gouraud-blended transparency (the D3DSHADE_GOURAUD state for the D3DSHADEMODE enumerated type). In this mode, the alpha color component of a primitive is provided at vertices and interpolated across a face along with the other color components.
+ D3DPSHADECAPS_COLORGOURAUDRGB | // Device can support colored Gouraud shading in the RGB color model. In this mode, the color component for a primitive is provided at vertices and interpolated across a face along with the other color components. In the RGB lighting model, the red, green, and blue components are interpolated.
+ D3DPSHADECAPS_FOGGOURAUD | // Device can support fog in the Gouraud shading mode.
+ D3DPSHADECAPS_SPECULARGOURAUDRGB; // Device supports Gouraud shading of specular highlights.
+
+ caps.TextureCaps = D3DPTEXTURECAPS_ALPHA | // Alpha in texture pixels is supported.
+ D3DPTEXTURECAPS_ALPHAPALETTE | // Device can draw alpha from texture palettes.
+ D3DPTEXTURECAPS_CUBEMAP | // Supports cube textures.
+ // D3DPTEXTURECAPS_CUBEMAP_POW2 | // Device requires that cube texture maps have dimensions specified as powers of two.
+ D3DPTEXTURECAPS_MIPCUBEMAP | // Device supports mipmapped cube textures.
+ D3DPTEXTURECAPS_MIPMAP | // Device supports mipmapped textures.
+ D3DPTEXTURECAPS_MIPVOLUMEMAP | // Device supports mipmapped volume textures.
+ // D3DPTEXTURECAPS_NONPOW2CONDITIONAL | // Conditionally supports the use of 2-D textures with dimensions that are not powers of two. A device that exposes this capability can use such a texture if all of the following requirements are met...
+ D3DPTEXTURECAPS_PERSPECTIVE | // Perspective correction texturing is supported.
+ // D3DPTEXTURECAPS_POW2 | // All textures must have widths and heights specified as powers of two. This requirement does not apply to either cube textures or volume textures.
+ D3DPTEXTURECAPS_PROJECTED | // Supports the D3DTTFF_PROJECTED texture transformation flag. When applied, the device divides transformed texture coordinates by the last texture coordinate. If this capability is present, then the projective divide occurs per pixel. If this capability is not present, but the projective divide needs to occur anyway, then it is performed on a per-vertex basis by the Direct3D runtime.
+ // D3DPTEXTURECAPS_SQUAREONLY | // All textures must be square.
+ D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE | // Texture indices are not scaled by the texture size prior to interpolation.
+ D3DPTEXTURECAPS_VOLUMEMAP; // Device supports volume textures.
+ // D3DPTEXTURECAPS_VOLUMEMAP_POW2; // Device requires that volume texture maps have dimensions specified as powers of two.
+
+ caps.TextureFilterCaps = // D3DPTFILTERCAPS_MAGFAFLATCUBIC | // Device supports per-stage flat cubic filtering for magnifying textures. The flat cubic magnification filter is represented by the D3DTEXF_FLATCUBIC member of the D3DTEXTUREFILTERTYPE enumerated type.
+ // D3DPTFILTERCAPS_MAGFANISOTROPIC | // Device supports per-stage anisotropic filtering for magnifying textures. The anisotropic magnification filter is represented by the D3DTEXF_ANISOTROPIC member of the D3DTEXTUREFILTERTYPE enumerated type.
+ // D3DPTFILTERCAPS_MAGFGAUSSIANCUBIC | // Device supports the per-stage Gaussian cubic filtering for magnifying textures. The Gaussian cubic magnification filter is represented by the D3DTEXF_GAUSSIANCUBIC member of the D3DTEXTUREFILTERTYPE enumerated type.
+ D3DPTFILTERCAPS_MAGFLINEAR | // Device supports per-stage bilinear interpolation filtering for magnifying mipmaps. The bilinear interpolation mipmapping filter is represented by the D3DTEXF_LINEAR member of the D3DTEXTUREFILTERTYPE enumerated type.
+ D3DPTFILTERCAPS_MAGFPOINT | // Device supports per-stage point-sample filtering for magnifying textures. The point-sample magnification filter is represented by the D3DTEXF_POINT member of the D3DTEXTUREFILTERTYPE enumerated type.
+ D3DPTFILTERCAPS_MINFANISOTROPIC | // Device supports per-stage anisotropic filtering for minifying textures. The anisotropic minification filter is represented by the D3DTEXF_ANISOTROPIC member of the D3DTEXTUREFILTERTYPE enumerated type.
+ D3DPTFILTERCAPS_MINFLINEAR | // Device supports per-stage linear filtering for minifying textures. The linear minification filter is represented by the D3DTEXF_LINEAR member of the D3DTEXTUREFILTERTYPE enumerated type.
+ D3DPTFILTERCAPS_MINFPOINT | // Device supports per-stage point-sample filtering for minifying textures. The point-sample minification filter is represented by the D3DTEXF_POINT member of the D3DTEXTUREFILTERTYPE enumerated type.
+ D3DPTFILTERCAPS_MIPFLINEAR | // Device supports per-stage bilinear interpolation filtering for mipmaps. The bilinear interpolation mipmapping filter is represented by the D3DTEXF_LINEAR member of the D3DTEXTUREFILTERTYPE enumerated type.
+ D3DPTFILTERCAPS_MIPFPOINT; // Device supports per-stage point-sample filtering for mipmaps. The point-sample mipmapping filter is represented by the D3DTEXF_POINT member of the D3DTEXTUREFILTERTYPE enumerated type.
+
+ caps.CubeTextureFilterCaps = // D3DPTFILTERCAPS_MAGFAFLATCUBIC | // Device supports per-stage flat cubic filtering for magnifying textures. The flat cubic magnification filter is represented by the D3DTEXF_FLATCUBIC member of the D3DTEXTUREFILTERTYPE enumerated type.
+ // D3DPTFILTERCAPS_MAGFANISOTROPIC | // Device supports per-stage anisotropic filtering for magnifying textures. The anisotropic magnification filter is represented by the D3DTEXF_ANISOTROPIC member of the D3DTEXTUREFILTERTYPE enumerated type.
+ // D3DPTFILTERCAPS_MAGFGAUSSIANCUBIC | // Device supports the per-stage Gaussian cubic filtering for magnifying textures. The Gaussian cubic magnification filter is represented by the D3DTEXF_GAUSSIANCUBIC member of the D3DTEXTUREFILTERTYPE enumerated type.
+ D3DPTFILTERCAPS_MAGFLINEAR | // Device supports per-stage bilinear interpolation filtering for magnifying mipmaps. The bilinear interpolation mipmapping filter is represented by the D3DTEXF_LINEAR member of the D3DTEXTUREFILTERTYPE enumerated type.
+ D3DPTFILTERCAPS_MAGFPOINT | // Device supports per-stage point-sample filtering for magnifying textures. The point-sample magnification filter is represented by the D3DTEXF_POINT member of the D3DTEXTUREFILTERTYPE enumerated type.
+ // D3DPTFILTERCAPS_MINFANISOTROPIC | // Device supports per-stage anisotropic filtering for minifying textures. The anisotropic minification filter is represented by the D3DTEXF_ANISOTROPIC member of the D3DTEXTUREFILTERTYPE enumerated type.
+ D3DPTFILTERCAPS_MINFLINEAR | // Device supports per-stage linear filtering for minifying textures. The linear minification filter is represented by the D3DTEXF_LINEAR member of the D3DTEXTUREFILTERTYPE enumerated type.
+ D3DPTFILTERCAPS_MINFPOINT | // Device supports per-stage point-sample filtering for minifying textures. The point-sample minification filter is represented by the D3DTEXF_POINT member of the D3DTEXTUREFILTERTYPE enumerated type.
+ D3DPTFILTERCAPS_MIPFLINEAR | // Device supports per-stage bilinear interpolation filtering for mipmaps. The bilinear interpolation mipmapping filter is represented by the D3DTEXF_LINEAR member of the D3DTEXTUREFILTERTYPE enumerated type.
+ D3DPTFILTERCAPS_MIPFPOINT; // Device supports per-stage point-sample filtering for mipmaps. The point-sample mipmapping filter is represented by the D3DTEXF_POINT member of the D3DTEXTUREFILTERTYPE enumerated type.
+
+ caps.VolumeTextureFilterCaps = // D3DPTFILTERCAPS_MAGFAFLATCUBIC | // Device supports per-stage flat cubic filtering for magnifying textures. The flat cubic magnification filter is represented by the D3DTEXF_FLATCUBIC member of the D3DTEXTUREFILTERTYPE enumerated type.
+ // D3DPTFILTERCAPS_MAGFANISOTROPIC | // Device supports per-stage anisotropic filtering for magnifying textures. The anisotropic magnification filter is represented by the D3DTEXF_ANISOTROPIC member of the D3DTEXTUREFILTERTYPE enumerated type.
+ // D3DPTFILTERCAPS_MAGFGAUSSIANCUBIC | // Device supports the per-stage Gaussian cubic filtering for magnifying textures. The Gaussian cubic magnification filter is represented by the D3DTEXF_GAUSSIANCUBIC member of the D3DTEXTUREFILTERTYPE enumerated type.
+ D3DPTFILTERCAPS_MAGFLINEAR | // Device supports per-stage bilinear interpolation filtering for magnifying mipmaps. The bilinear interpolation mipmapping filter is represented by the D3DTEXF_LINEAR member of the D3DTEXTUREFILTERTYPE enumerated type.
+ D3DPTFILTERCAPS_MAGFPOINT | // Device supports per-stage point-sample filtering for magnifying textures. The point-sample magnification filter is represented by the D3DTEXF_POINT member of the D3DTEXTUREFILTERTYPE enumerated type.
+ // D3DPTFILTERCAPS_MINFANISOTROPIC | // Device supports per-stage anisotropic filtering for minifying textures. The anisotropic minification filter is represented by the D3DTEXF_ANISOTROPIC member of the D3DTEXTUREFILTERTYPE enumerated type.
+ D3DPTFILTERCAPS_MINFLINEAR | // Device supports per-stage linear filtering for minifying textures. The linear minification filter is represented by the D3DTEXF_LINEAR member of the D3DTEXTUREFILTERTYPE enumerated type.
+ D3DPTFILTERCAPS_MINFPOINT | // Device supports per-stage point-sample filtering for minifying textures. The point-sample minification filter is represented by the D3DTEXF_POINT member of the D3DTEXTUREFILTERTYPE enumerated type.
+ D3DPTFILTERCAPS_MIPFLINEAR | // Device supports per-stage bilinear interpolation filtering for mipmaps. The bilinear interpolation mipmapping filter is represented by the D3DTEXF_LINEAR member of the D3DTEXTUREFILTERTYPE enumerated type.
+ D3DPTFILTERCAPS_MIPFPOINT; // Device supports per-stage point-sample filtering for mipmaps. The point-sample mipmapping filter is represented by the D3DTEXF_POINT member of the D3DTEXTUREFILTERTYPE enumerated type.
+
+ caps.TextureAddressCaps = D3DPTADDRESSCAPS_BORDER | // Device supports setting coordinates outside the range [0.0, 1.0] to the border color, as specified by the D3DSAMP_BORDERCOLOR texture-stage state.
+ D3DPTADDRESSCAPS_CLAMP | // Device can clamp textures to addresses.
+ D3DPTADDRESSCAPS_INDEPENDENTUV | // Device can separate the texture-addressing modes of the u and v coordinates of the texture. This ability corresponds to the D3DSAMP_ADDRESSU and D3DSAMP_ADDRESSV render-state values.
+ D3DPTADDRESSCAPS_MIRROR | // Device can mirror textures to addresses.
+ D3DPTADDRESSCAPS_MIRRORONCE | // Device can take the absolute value of the texture coordinate (thus, mirroring around 0) and then clamp to the maximum value.
+ D3DPTADDRESSCAPS_WRAP; // Device can wrap textures to addresses.
+
+ caps.VolumeTextureAddressCaps = D3DPTADDRESSCAPS_BORDER | // Device supports setting coordinates outside the range [0.0, 1.0] to the border color, as specified by the D3DSAMP_BORDERCOLOR texture-stage state.
+ D3DPTADDRESSCAPS_CLAMP | // Device can clamp textures to addresses.
+ D3DPTADDRESSCAPS_INDEPENDENTUV | // Device can separate the texture-addressing modes of the u and v coordinates of the texture. This ability corresponds to the D3DSAMP_ADDRESSU and D3DSAMP_ADDRESSV render-state values.
+ D3DPTADDRESSCAPS_MIRROR | // Device can mirror textures to addresses.
+ D3DPTADDRESSCAPS_MIRRORONCE | // Device can take the absolute value of the texture coordinate (thus, mirroring around 0) and then clamp to the maximum value.
+ D3DPTADDRESSCAPS_WRAP; // Device can wrap textures to addresses.
+
+ caps.LineCaps = D3DLINECAPS_ALPHACMP | // Supports alpha-test comparisons.
+ D3DLINECAPS_BLEND | // Supports source-blending.
+ D3DLINECAPS_FOG | // Supports fog.
+ D3DLINECAPS_TEXTURE | // Supports texture-mapping.
+ D3DLINECAPS_ZTEST; // Supports z-buffer comparisons.
+
+ caps.MaxTextureWidth = 1 << (sw::MIPMAP_LEVELS - 1);
+ caps.MaxTextureHeight = 1 << (sw::MIPMAP_LEVELS - 1);
+ caps.MaxVolumeExtent = 1 << (sw::MIPMAP_LEVELS - 1);
+ caps.MaxTextureRepeat = 8192;
+ caps.MaxTextureAspectRatio = 1 << (sw::MIPMAP_LEVELS - 1);
+ caps.MaxAnisotropy = maxAnisotropy;
+ caps.MaxVertexW = 1e+010;
+
+ caps.GuardBandLeft = -1e+008;
+ caps.GuardBandTop = -1e+008;
+ caps.GuardBandRight = 1e+008;
+ caps.GuardBandBottom = 1e+008;
+
+ caps.ExtentsAdjust = 0;
+
+ caps.StencilCaps = D3DSTENCILCAPS_KEEP | // Do not update the entry in the stencil buffer. This is the default value.
+ D3DSTENCILCAPS_ZERO | // Set the stencil-buffer entry to 0.
+ D3DSTENCILCAPS_REPLACE | // Replace the stencil-buffer entry with reference value.
+ D3DSTENCILCAPS_INCRSAT | // Increment the stencil-buffer entry, clamping to the maximum value.
+ D3DSTENCILCAPS_DECRSAT | // Decrement the stencil-buffer entry, clamping to zero.
+ D3DSTENCILCAPS_INVERT | // Invert the bits in the stencil-buffer entry.
+ D3DSTENCILCAPS_INCR | // Increment the stencil-buffer entry, wrapping to zero if the new value exceeds the maximum value.
+ D3DSTENCILCAPS_DECR; // Decrement the stencil-buffer entry, wrapping to the maximum value if the new value is less than zero.
+
+ caps.FVFCaps = D3DFVFCAPS_DONOTSTRIPELEMENTS | // It is preferable that vertex elements not be stripped. That is, if the vertex format contains elements that are not used with the current render states, there is no need to regenerate the vertices. If this capability flag is not present, stripping extraneous elements from the vertex format provides better performance.
+ D3DFVFCAPS_PSIZE | // Point size is determined by either the render state or the vertex data.
+ // D3DFVFCAPS_TEXCOORDCOUNTMASK | // Masks the low WORD of FVFCaps. These bits, cast to the WORD data type, describe the total number of texture coordinate sets that the device can simultaneously use for multiple texture blending. (You can use up to eight texture coordinate sets for any vertex, but the device can blend using only the specified number of texture coordinate sets.)
+ 8;
+
+ caps.TextureOpCaps = D3DTEXOPCAPS_ADD | // The D3DTOP_ADD texture-blending operation is supported.
+ D3DTEXOPCAPS_ADDSIGNED | // The D3DTOP_ADDSIGNED texture-blending operation is supported.
+ D3DTEXOPCAPS_ADDSIGNED2X | // The D3DTOP_ADDSIGNED2X texture-blending operation is supported.
+ D3DTEXOPCAPS_ADDSMOOTH | // The D3DTOP_ADDSMOOTH texture-blending operation is supported.
+ D3DTEXOPCAPS_BLENDCURRENTALPHA | // The D3DTOP_BLENDCURRENTALPHA texture-blending operation is supported.
+ D3DTEXOPCAPS_BLENDDIFFUSEALPHA | // The D3DTOP_BLENDDIFFUSEALPHA texture-blending operation is supported.
+ D3DTEXOPCAPS_BLENDFACTORALPHA | // The D3DTOP_BLENDFACTORALPHA texture-blending operation is supported.
+ D3DTEXOPCAPS_BLENDTEXTUREALPHA | // The D3DTOP_BLENDTEXTUREALPHA texture-blending operation is supported.
+ D3DTEXOPCAPS_BLENDTEXTUREALPHAPM | // The D3DTOP_BLENDTEXTUREALPHAPM texture-blending operation is supported.
+ D3DTEXOPCAPS_BUMPENVMAP | // The D3DTOP_BUMPENVMAP texture-blending operation is supported.
+ D3DTEXOPCAPS_BUMPENVMAPLUMINANCE | // The D3DTOP_BUMPENVMAPLUMINANCE texture-blending operation is supported.
+ D3DTEXOPCAPS_DISABLE | // The D3DTOP_DISABLE texture-blending operation is supported.
+ D3DTEXOPCAPS_DOTPRODUCT3 | // The D3DTOP_DOTPRODUCT3 texture-blending operation is supported.
+ D3DTEXOPCAPS_LERP | // The D3DTOP_LERP texture-blending operation is supported.
+ D3DTEXOPCAPS_MODULATE | // The D3DTOP_MODULATE texture-blending operation is supported.
+ D3DTEXOPCAPS_MODULATE2X | // The D3DTOP_MODULATE2X texture-blending operation is supported.
+ D3DTEXOPCAPS_MODULATE4X | // The D3DTOP_MODULATE4X texture-blending operation is supported.
+ D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR | // The D3DTOP_MODULATEALPHA_ADDCOLOR texture-blending operation is supported.
+ D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA | // The D3DTOP_MODULATECOLOR_ADDALPHA texture-blending operation is supported.
+ D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR | // The D3DTOP_MODULATEINVALPHA_ADDCOLOR texture-blending operation is supported.
+ D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA | // The D3DTOP_MODULATEINVCOLOR_ADDALPHA texture-blending operation is supported.
+ D3DTEXOPCAPS_MULTIPLYADD | // The D3DTOP_MULTIPLYADD texture-blending operation is supported.
+ D3DTEXOPCAPS_PREMODULATE | // The D3DTOP_PREMODULATE texture-blending operation is supported.
+ D3DTEXOPCAPS_SELECTARG1 | // The D3DTOP_SELECTARG1 texture-blending operation is supported.
+ D3DTEXOPCAPS_SELECTARG2 | // The D3DTOP_SELECTARG2 texture-blending operation is supported.
+ D3DTEXOPCAPS_SUBTRACT; // The D3DTOP_SUBTRACT texture-blending operation is supported.
+
+ caps.MaxTextureBlendStages = 8;
+ caps.MaxSimultaneousTextures = 8;
+
+ caps.VertexProcessingCaps = D3DVTXPCAPS_DIRECTIONALLIGHTS | // Device can do directional lights.
+ D3DVTXPCAPS_LOCALVIEWER | // Device can do local viewer.
+ D3DVTXPCAPS_MATERIALSOURCE7 | // Device can do Microsoft® DirectX® 7.0 colormaterialsource operations.
+ D3DVTXPCAPS_POSITIONALLIGHTS | // Device can do positional lights (includes point and spot).
+ D3DVTXPCAPS_TEXGEN | // Device can do texgen.
+ D3DVTXPCAPS_TWEENING; // Device can do vertex tweening.
+ // D3DVTXPCAPS_NO_VSDT_UBYTE4; // Device does not support the D3DVSDT_UBYTE4 vertex declaration type.
+
+ caps.MaxActiveLights = 8; // Maximum number of lights that can be active simultaneously. For a given physical device, this capability might vary across Direct3DDevice objects depending on the parameters supplied to IDirect3D8::CreateDevice.
+ caps.MaxUserClipPlanes = 6; // Maximum number of user-defined clipping planes supported. This member can range from 0 through D3DMAXUSERCLIPPLANES. For a given physical device, this capability may vary across Direct3DDevice objects depending on the parameters supplied to IDirect3D8::CreateDevice.
+ caps.MaxVertexBlendMatrices = 4; // Maximum number of matrices that this device can apply when performing multimatrix vertex blending. For a given physical device, this capability may vary across Direct3DDevice objects depending on the parameters supplied to IDirect3D8::CreateDevice.
+ caps.MaxVertexBlendMatrixIndex = 11; // DWORD value that specifies the maximum matrix index that can be indexed into using the per-vertex indices. The number of matrices is MaxVertexBlendMatrixIndex + 1, which is the size of the matrix palette. If normals are present in the vertex data that needs to be blended for lighting, then the number of matrices is half the number specified by this capability flag. If MaxVertexBlendMatrixIndex is set to zero, the driver does not support indexed vertex blending. If this value is not zero then the valid range of indices is zero through MaxVertexBlendMatrixIndex.
+ caps.MaxPointSize = 8192.0f; // Maximum size of a point primitive. If set to 1.0f then device does not support point size control. The range is greater than or equal to 1.0f.
+ caps.MaxPrimitiveCount = 1 << 21; // Maximum number of primitives for each IDirect3DDevice8::DrawPrimitive call. Note that when Direct3D is working with a DirectX 6.0 or DirectX 7.0 driver, this field is set to 0xFFFF. This means that not only the number of primitives but also the number of vertices is limited by this value.
+ caps.MaxVertexIndex = 1 << 24; // Maximum size of indices supported for hardware vertex processing. It is possible to create 32-bit index buffers by specifying D3DFMT_INDEX32; however, you will not be able to render with the index buffer unless this value is greater than 0x0000FFFF.
+ caps.MaxStreams = 16; // Maximum number of concurrent data streams for IDirect3DDevice8::SetStreamSource. The valid range is 1 to 16. Note that if this value is 0, then the driver is not a DirectX 9.0 driver.
+ caps.MaxStreamStride = 65536; // Maximum stride for IDirect3DDevice8::SetStreamSource.
+ caps.VertexShaderVersion = vertexShaderVersion; // Two numbers that represent the vertex shader main and sub versions. For more information about the instructions supported for each vertex shader version, see Version 1_x, Version 2_0, Version 2_0 Extended, or Version 3_0.
+ caps.MaxVertexShaderConst = 256; // The number of vertex shader Registers that are reserved for constants.
+ caps.PixelShaderVersion = pixelShaderVersion; // Two numbers that represent the pixel shader main and sub versions. For more information about the instructions supported for each pixel shader version, see Version 1_x, Version 2_0, Version 2_0 Extended, or Version 3_0.
+ caps.MaxPixelShaderValue = 8.0;
+
+ *capabilities = caps;
+
+ return D3D_OK;
+ }
+
+ long Direct3D8::RegisterSoftwareDevice(void *initializeFunction)
+ {
+ TRACE("");
+
+ loadSystemD3D8();
+
+ if(d3d8)
+ {
+ return d3d8->RegisterSoftwareDevice(initializeFunction);
+ }
+ else
+ {
+ return INVALIDCALL();
+ }
+ }
+
+ void Direct3D8::loadSystemD3D8()
+ {
+ if(d3d8)
+ {
+ return;
+ }
+
+ char d3d8Path[MAX_PATH + 16];
+ GetSystemDirectory(d3d8Path, MAX_PATH);
+ strcat(d3d8Path, "\\d3d8.dll");
+ d3d8Lib = LoadLibrary(d3d8Path);
+
+ if(d3d8Lib)
+ {
+ typedef IDirect3D8* (__stdcall *DIRECT3DCREATE8)(unsigned int);
+ DIRECT3DCREATE8 direct3DCreate8 = (DIRECT3DCREATE8)GetProcAddress(d3d8Lib, "Direct3DCreate8");
+ d3d8 = direct3DCreate8(D3D_SDK_VERSION);
+ }
+ }
+}
diff --git a/src/D3D8/Direct3D8.hpp b/src/D3D8/Direct3D8.hpp
new file mode 100644
index 0000000..1017846
--- /dev/null
+++ b/src/D3D8/Direct3D8.hpp
@@ -0,0 +1,71 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef D3D8_Direct3D8_hpp
+#define D3D8_Direct3D8_hpp
+
+#include "Unknown.hpp"
+
+#include <stdio.h>
+#include <initguid.h>
+#include <d3d8.h>
+
+namespace D3D8
+{
+ class Direct3DDevice8;
+
+ class Direct3D8 : public IDirect3D8, protected Unknown
+ {
+ public:
+ Direct3D8(int version, const HINSTANCE instance);
+
+ virtual ~Direct3D8();
+
+ // IUnknown methods
+ long __stdcall QueryInterface(const IID &iid, void **object);
+ unsigned long __stdcall AddRef();
+ unsigned long __stdcall Release();
+
+ // IDirect3D8 methods
+ long __stdcall CheckDepthStencilMatch(unsigned int adapter, D3DDEVTYPE deviceType, D3DFORMAT adapterFormat, D3DFORMAT renderTargetFormat, D3DFORMAT depthStencilFormat);
+ long __stdcall CheckDeviceFormat(unsigned int adapter, D3DDEVTYPE deviceType, D3DFORMAT adapaterFormat, unsigned long usage, D3DRESOURCETYPE type, D3DFORMAT checkFormat);
+ long __stdcall CheckDeviceMultiSampleType(unsigned int adapter, D3DDEVTYPE deviceType, D3DFORMAT surfaceFormat, int windowed, D3DMULTISAMPLE_TYPE multiSampleType);
+ long __stdcall CheckDeviceType(unsigned int adapter, D3DDEVTYPE checkType, D3DFORMAT displayFormat, D3DFORMAT backBufferFormat, int windowed);
+ long __stdcall CreateDevice(unsigned int adapter, D3DDEVTYPE deviceType, HWND focusWindow, unsigned long behaviorFlags, D3DPRESENT_PARAMETERS *presentParameters, IDirect3DDevice8 **returnedDeviceInterface);
+ long __stdcall EnumAdapterModes(unsigned int adapter, unsigned int index, D3DDISPLAYMODE *mode);
+ unsigned int __stdcall GetAdapterCount();
+ long __stdcall GetAdapterDisplayMode(unsigned int adapter, D3DDISPLAYMODE *mode);
+ long __stdcall GetAdapterIdentifier(unsigned int adapter, unsigned long flags, D3DADAPTER_IDENTIFIER8 *identifier);
+ unsigned int __stdcall GetAdapterModeCount(unsigned int adapter);
+ HMONITOR __stdcall GetAdapterMonitor(unsigned int adapter);
+ long __stdcall GetDeviceCaps(unsigned int adapter, D3DDEVTYPE deviceType, D3DCAPS8 *caps);
+ long __stdcall RegisterSoftwareDevice(void *initializeFunction);
+
+ private:
+ void loadSystemD3D8();
+
+ // Creation parameters
+ const int version;
+ const HINSTANCE instance;
+
+ DEVMODE *displayMode;
+ int numDisplayModes;
+
+ // Real D3D8 library and IDirect3D8 object
+ HMODULE d3d8Lib;
+ IDirect3D8 *d3d8;
+ };
+}
+
+#endif // D3D8_Direct3D8_hpp
diff --git a/src/D3D8/Direct3DBaseTexture8.cpp b/src/D3D8/Direct3DBaseTexture8.cpp
new file mode 100644
index 0000000..3a3f208
--- /dev/null
+++ b/src/D3D8/Direct3DBaseTexture8.cpp
@@ -0,0 +1,156 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "Direct3DBaseTexture8.hpp"
+
+#include "Resource.hpp"
+#include "Debug.hpp"
+
+namespace D3D8
+{
+ Direct3DBaseTexture8::Direct3DBaseTexture8(Direct3DDevice8 *device, D3DRESOURCETYPE type, unsigned long levels, unsigned long usage) : Direct3DResource8(device, type, 0), levels(levels), usage(usage)
+ {
+ filterType = D3DTEXF_LINEAR;
+ LOD = 0;
+
+ resource = new sw::Resource(0);
+ }
+
+ Direct3DBaseTexture8::~Direct3DBaseTexture8()
+ {
+ resource->destruct();
+ }
+
+ long Direct3DBaseTexture8::QueryInterface(const IID &iid, void **object)
+ {
+ TRACE("");
+
+ if(iid == IID_IDirect3DBaseTexture8 ||
+ iid == IID_IDirect3DResource8 ||
+ iid == IID_IUnknown)
+ {
+ AddRef();
+ *object = this;
+
+ return S_OK;
+ }
+
+ *object = 0;
+
+ return NOINTERFACE(iid);
+ }
+
+ unsigned long Direct3DBaseTexture8::AddRef()
+ {
+ TRACE("");
+
+ return Direct3DResource8::AddRef();
+ }
+
+ unsigned long Direct3DBaseTexture8::Release()
+ {
+ TRACE("");
+
+ return Direct3DResource8::Release();
+ }
+
+ long Direct3DBaseTexture8::FreePrivateData(const GUID &guid)
+ {
+ TRACE("");
+
+ return Direct3DResource8::FreePrivateData(guid);
+ }
+
+ long Direct3DBaseTexture8::GetPrivateData(const GUID &guid, void *data, unsigned long *size)
+ {
+ TRACE("");
+
+ return Direct3DResource8::GetPrivateData(guid, data, size);
+ }
+
+ void Direct3DBaseTexture8::PreLoad()
+ {
+ TRACE("");
+
+ Direct3DResource8::PreLoad();
+ }
+
+ long Direct3DBaseTexture8::SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags)
+ {
+ TRACE("");
+
+ return Direct3DResource8::SetPrivateData(guid, data, size, flags);
+ }
+
+ long Direct3DBaseTexture8::GetDevice(IDirect3DDevice8 **device)
+ {
+ TRACE("");
+
+ return Direct3DResource8::GetDevice(device);
+ }
+
+ unsigned long Direct3DBaseTexture8::SetPriority(unsigned long newPriority)
+ {
+ TRACE("");
+
+ return Direct3DResource8::SetPriority(newPriority);
+ }
+
+ unsigned long Direct3DBaseTexture8::GetPriority()
+ {
+ TRACE("");
+
+ return Direct3DResource8::GetPriority();
+ }
+
+ D3DRESOURCETYPE Direct3DBaseTexture8::GetType()
+ {
+ TRACE("");
+
+ return Direct3DResource8::GetType();
+ }
+
+ unsigned long Direct3DBaseTexture8::GetLevelCount()
+ {
+ TRACE("");
+
+ return levels;
+ }
+
+ unsigned long Direct3DBaseTexture8::GetLOD()
+ {
+ TRACE("");
+
+ return LOD;
+ }
+
+ long Direct3DBaseTexture8::SetLOD(long newLOD)
+ {
+ TRACE("");
+
+ LOD = newLOD;
+
+ return 0; // TODO
+ }
+
+ sw::Resource *Direct3DBaseTexture8::getResource() const
+ {
+ return resource;
+ }
+
+ unsigned long Direct3DBaseTexture8::getInternalLevelCount()
+ {
+ return levels;
+ }
+}
diff --git a/src/D3D8/Direct3DBaseTexture8.hpp b/src/D3D8/Direct3DBaseTexture8.hpp
new file mode 100644
index 0000000..ab69aba
--- /dev/null
+++ b/src/D3D8/Direct3DBaseTexture8.hpp
@@ -0,0 +1,73 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef D3D8_Direct3DBaseTexture8_hpp
+#define D3D8_Direct3DBaseTexture8_hpp
+
+#include "Direct3DResource8.hpp"
+
+#include <d3d8.h>
+
+namespace sw
+{
+ class Resource;
+}
+
+namespace D3D8
+{
+ class Direct3DBaseTexture8 : public IDirect3DBaseTexture8, public Direct3DResource8
+ {
+ public:
+ Direct3DBaseTexture8(Direct3DDevice8 *device, D3DRESOURCETYPE type, unsigned long levels, unsigned long usage);
+
+ virtual ~Direct3DBaseTexture8();
+
+ // IUnknown methods
+ long __stdcall QueryInterface(const IID &iid, void **object);
+ unsigned long __stdcall AddRef();
+ unsigned long __stdcall Release();
+
+ // IDirect3DResource8 methods
+ long __stdcall FreePrivateData(const GUID &guid);
+ long __stdcall GetPrivateData(const GUID &guid, void *data, unsigned long *size);
+ void __stdcall PreLoad();
+ long __stdcall SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags);
+ long __stdcall GetDevice(IDirect3DDevice8 **device);
+ unsigned long __stdcall SetPriority(unsigned long newPriority);
+ unsigned long __stdcall GetPriority();
+ D3DRESOURCETYPE __stdcall GetType();
+
+ // IDirect3DBaseTexture8 methods
+ unsigned long __stdcall GetLevelCount();
+ unsigned long __stdcall GetLOD();
+ long __stdcall SetLOD(long newLOD);
+
+ // Intenal methods
+ sw::Resource *getResource() const;
+ unsigned long getInternalLevelCount();
+
+ protected:
+ // Creation paramters
+ unsigned long levels; // Recalculated when 0
+ const unsigned long usage;
+
+ sw::Resource *resource;
+
+ private:
+ D3DTEXTUREFILTERTYPE filterType;
+ unsigned long LOD;
+ };
+}
+
+#endif // D3D8_Direct3DBaseTexture8_hpp
diff --git a/src/D3D8/Direct3DCubeTexture8.cpp b/src/D3D8/Direct3DCubeTexture8.cpp
new file mode 100644
index 0000000..d8b4a3c
--- /dev/null
+++ b/src/D3D8/Direct3DCubeTexture8.cpp
@@ -0,0 +1,255 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "Direct3DCubeTexture8.hpp"
+
+#include "Direct3DSurface8.hpp"
+#include "Resource.hpp"
+#include "Debug.hpp"
+
+#include <assert.h>
+
+namespace D3D8
+{
+ Direct3DCubeTexture8::Direct3DCubeTexture8(Direct3DDevice8 *device, unsigned int edgeLength, unsigned int levels, unsigned long usage, D3DFORMAT format, D3DPOOL pool) : Direct3DBaseTexture8(device, D3DRTYPE_CUBETEXTURE, levels, usage), edgeLength(edgeLength), format(format), pool(pool)
+ {
+ if(levels == 0)
+ {
+ this->levels = sw::log2(sw::max((int)edgeLength, 1)) + 1;
+ }
+
+ for(unsigned int face = 0; face < 6; face++)
+ {
+ int width = edgeLength;
+ int height = edgeLength;
+
+ for(unsigned int level = 0; level < sw::MIPMAP_LEVELS; level++)
+ {
+ if(level < this->levels)
+ {
+ surfaceLevel[face][level] = new Direct3DSurface8(device, this, width, height, format, pool, D3DMULTISAMPLE_NONE, true, usage);
+ surfaceLevel[face][level]->bind();
+ }
+ else
+ {
+ surfaceLevel[face][level] = 0;
+ }
+
+ width = sw::max(1, width / 2);
+ height = sw::max(1, height / 2);
+ }
+ }
+ }
+
+ Direct3DCubeTexture8::~Direct3DCubeTexture8()
+ {
+ resource->lock(sw::DESTRUCT);
+
+ for(unsigned int face = 0; face < 6; face++)
+ {
+ for(int level = 0; level < sw::MIPMAP_LEVELS; level++)
+ {
+ if(surfaceLevel[face][level])
+ {
+ surfaceLevel[face][level]->unbind();
+ surfaceLevel[face][level] = 0;
+ }
+ }
+ }
+
+ resource->unlock();
+ }
+
+ long Direct3DCubeTexture8::QueryInterface(const IID &iid, void **object)
+ {
+ TRACE("");
+
+ if(iid == IID_IDirect3DCubeTexture8 ||
+ iid == IID_IDirect3DBaseTexture8 ||
+ iid == IID_IDirect3DResource8 ||
+ iid == IID_IUnknown)
+ {
+ AddRef();
+ *object = this;
+
+ return S_OK;
+ }
+
+ *object = 0;
+
+ return NOINTERFACE(iid);
+ }
+
+ unsigned long Direct3DCubeTexture8::AddRef()
+ {
+ TRACE("");
+
+ return Direct3DBaseTexture8::AddRef();
+ }
+
+ unsigned long Direct3DCubeTexture8::Release()
+ {
+ TRACE("");
+
+ return Direct3DBaseTexture8::Release();
+ }
+
+ long Direct3DCubeTexture8::FreePrivateData(const GUID &guid)
+ {
+ TRACE("");
+
+ return Direct3DBaseTexture8::FreePrivateData(guid);
+ }
+
+ long Direct3DCubeTexture8::GetPrivateData(const GUID &guid, void *data, unsigned long *size)
+ {
+ TRACE("");
+
+ return Direct3DBaseTexture8::GetPrivateData(guid, data, size);
+ }
+
+ void Direct3DCubeTexture8::PreLoad()
+ {
+ TRACE("");
+
+ Direct3DBaseTexture8::PreLoad();
+ }
+
+ long Direct3DCubeTexture8::SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags)
+ {
+ TRACE("");
+
+ return Direct3DBaseTexture8::SetPrivateData(guid, data, size, flags);
+ }
+
+ long Direct3DCubeTexture8::GetDevice(IDirect3DDevice8 **device)
+ {
+ TRACE("");
+
+ return Direct3DBaseTexture8::GetDevice(device);
+ }
+
+ unsigned long Direct3DCubeTexture8::SetPriority(unsigned long newPriority)
+ {
+ TRACE("");
+
+ return Direct3DBaseTexture8::SetPriority(newPriority);
+ }
+
+ unsigned long Direct3DCubeTexture8::GetPriority()
+ {
+ TRACE("");
+
+ return Direct3DBaseTexture8::GetPriority();
+ }
+
+ D3DRESOURCETYPE Direct3DCubeTexture8::GetType()
+ {
+ TRACE("");
+
+ return Direct3DBaseTexture8::GetType();
+ }
+
+ unsigned long Direct3DCubeTexture8::GetLevelCount()
+ {
+ TRACE("");
+
+ return Direct3DBaseTexture8::GetLevelCount();
+ }
+
+ unsigned long Direct3DCubeTexture8::GetLOD()
+ {
+ TRACE("");
+
+ return Direct3DBaseTexture8::GetLOD();
+ }
+
+ unsigned long Direct3DCubeTexture8::SetLOD(unsigned long newLOD)
+ {
+ TRACE("");
+
+ return Direct3DBaseTexture8::SetLOD(newLOD);
+ }
+
+ long Direct3DCubeTexture8::AddDirtyRect(D3DCUBEMAP_FACES face, const RECT *dirtyRect)
+ {
+ TRACE("");
+
+ // UNIMPLEMENTED();
+
+ return D3D_OK;
+ }
+
+ long Direct3DCubeTexture8::GetCubeMapSurface(D3DCUBEMAP_FACES face, unsigned int level , IDirect3DSurface8 **cubeMapSurface)
+ {
+ TRACE("");
+
+ *cubeMapSurface = 0; // FIXME: Verify
+
+ if(face >= 6 || level >= GetLevelCount() || !surfaceLevel[face][level])
+ {
+ return INVALIDCALL();
+ }
+
+ surfaceLevel[face][level]->AddRef();
+ *cubeMapSurface = surfaceLevel[face][level];
+
+ return D3D_OK;
+ }
+
+ long Direct3DCubeTexture8::GetLevelDesc(unsigned int level, D3DSURFACE_DESC *description)
+ {
+ TRACE("");
+
+ if(!description || level >= GetLevelCount() || !surfaceLevel[0][level])
+ {
+ return INVALIDCALL();
+ }
+
+ surfaceLevel[0][level]->GetDesc(description);
+
+ return D3D_OK;
+ }
+
+ long Direct3DCubeTexture8::LockRect(D3DCUBEMAP_FACES face, unsigned int level, D3DLOCKED_RECT *lockedRect, const RECT *rect, unsigned long flags)
+ {
+ TRACE("");
+
+ if(!lockedRect || face >= 6 || level >= GetLevelCount() || !surfaceLevel[face][level])
+ {
+ return INVALIDCALL();
+ }
+
+ surfaceLevel[face][level]->LockRect(lockedRect, rect, flags);
+
+ return D3D_OK;
+ }
+
+ long Direct3DCubeTexture8::UnlockRect(D3DCUBEMAP_FACES face, unsigned int level)
+ {
+ TRACE("");
+
+ if(face >= 6 || level >= GetLevelCount() || !surfaceLevel[face][level])
+ {
+ return INVALIDCALL();
+ }
+
+ return surfaceLevel[face][level]->UnlockRect();
+ }
+
+ Direct3DSurface8 *Direct3DCubeTexture8::getInternalCubeMapSurface(D3DCUBEMAP_FACES face, unsigned int level)
+ {
+ return surfaceLevel[face][level];
+ }
+}
diff --git a/src/D3D8/Direct3DCubeTexture8.hpp b/src/D3D8/Direct3DCubeTexture8.hpp
new file mode 100644
index 0000000..9107152
--- /dev/null
+++ b/src/D3D8/Direct3DCubeTexture8.hpp
@@ -0,0 +1,75 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef D3D8_Direct3DCubeTexture8_hpp
+#define D3D8_Direct3DCubeTexture8_hpp
+
+#include "Direct3DBaseTexture8.hpp"
+
+#include "Config.hpp"
+
+#include <d3d8.h>
+
+namespace D3D8
+{
+ class Direct3DSurface8;
+
+ class Direct3DCubeTexture8 : public IDirect3DCubeTexture8, public Direct3DBaseTexture8
+ {
+ public:
+ Direct3DCubeTexture8(Direct3DDevice8 *device, unsigned int edgeLength, unsigned int levels, unsigned long usage, D3DFORMAT format, D3DPOOL pool);
+
+ virtual ~Direct3DCubeTexture8();
+
+ // IUnknown methods
+ long __stdcall QueryInterface(const IID &iid, void **object);
+ unsigned long __stdcall AddRef();
+ unsigned long __stdcall Release();
+
+ // IDirect3DResource8 methods
+ long __stdcall FreePrivateData(const GUID &guid);
+ long __stdcall GetPrivateData(const GUID &guid, void *data, unsigned long *size);
+ void __stdcall PreLoad();
+ long __stdcall SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags);
+ long __stdcall GetDevice(IDirect3DDevice8 **device);
+ unsigned long __stdcall SetPriority(unsigned long newPriority);
+ unsigned long __stdcall GetPriority();
+ D3DRESOURCETYPE __stdcall GetType();
+
+ // IDirect3DBaseTexture methods
+ unsigned long __stdcall GetLevelCount();
+ unsigned long __stdcall GetLOD();
+ unsigned long __stdcall SetLOD(unsigned long newLOD);
+
+ // IDirect3DCubeTexture8 methods
+ long __stdcall AddDirtyRect(D3DCUBEMAP_FACES face, const RECT *dirtyRect);
+ long __stdcall GetCubeMapSurface(D3DCUBEMAP_FACES face, unsigned int level , IDirect3DSurface8 **cubeMapSurface);
+ long __stdcall GetLevelDesc(unsigned int level, D3DSURFACE_DESC *description);
+ long __stdcall LockRect(D3DCUBEMAP_FACES face, unsigned int level, D3DLOCKED_RECT *lockedRect, const RECT *rect, unsigned long flags);
+ long __stdcall UnlockRect(D3DCUBEMAP_FACES face, unsigned int level);
+
+ // Internal methods
+ Direct3DSurface8 *getInternalCubeMapSurface(D3DCUBEMAP_FACES face, unsigned int level);
+
+ private:
+ // Creation parameters
+ const unsigned int edgeLength;
+ const D3DFORMAT format;
+ const D3DPOOL pool;
+
+ Direct3DSurface8 *surfaceLevel[6][sw::MIPMAP_LEVELS];
+ };
+}
+
+#endif // D3D8_Direct3D8_hpp
diff --git a/src/D3D8/Direct3DDevice8.cpp b/src/D3D8/Direct3DDevice8.cpp
new file mode 100644
index 0000000..ff85a7a
--- /dev/null
+++ b/src/D3D8/Direct3DDevice8.cpp
@@ -0,0 +1,4926 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "Direct3DDevice8.hpp"
+
+#include "Direct3D8.hpp"
+#include "Direct3DSurface8.hpp"
+#include "Direct3DIndexBuffer8.hpp"
+#include "Direct3DVertexBuffer8.hpp"
+#include "Direct3DTexture8.hpp"
+#include "Direct3DVolumeTexture8.hpp"
+#include "Direct3DCubeTexture8.hpp"
+#include "Direct3DSwapChain8.hpp"
+#include "Direct3DPixelShader8.hpp"
+#include "Direct3DVertexShader8.hpp"
+#include "Direct3DVolume8.hpp"
+
+#include "Debug.hpp"
+#include "Capabilities.hpp"
+#include "Renderer.hpp"
+#include "Config.hpp"
+#include "FrameBuffer.hpp"
+#include "Clipper.hpp"
+#include "Configurator.hpp"
+#include "Timer.hpp"
+#include "Resource.hpp"
+
+#include <assert.h>
+
+bool localShaderConstants = false;
+
+namespace D3D8
+{
+ inline unsigned long FtoDW(float f) // FIXME: Deprecate
+ {
+ return (unsigned long&)f;
+ }
+
+ Direct3DDevice8::Direct3DDevice8(const HINSTANCE instance, Direct3D8 *d3d8, unsigned int adapter, D3DDEVTYPE deviceType, HWND focusWindow, unsigned long behaviourFlags, D3DPRESENT_PARAMETERS *presentParameters) : instance(instance), d3d8(d3d8), adapter(adapter), deviceType(deviceType), focusWindow(focusWindow), behaviourFlags(behaviourFlags), presentParameters(*presentParameters)
+ {
+ init = true;
+ recordState = false;
+
+ d3d8->AddRef();
+
+ context = new sw::Context();
+ renderer = new sw::Renderer(context, sw::Direct3D, false);
+
+ swapChain.push_back(0);
+ depthStencil = 0;
+ renderTarget = 0;
+
+ for(int i = 0; i < 8; i++)
+ {
+ texture[i] = 0;
+ }
+
+ cursor = 0;
+ unsigned char one[32 * 32 / sizeof(unsigned char)];
+ memset(one, 0xFFFFFFFF, sizeof(one));
+ unsigned char zero[32 * 32 / sizeof(unsigned char)] = {0};
+ nullCursor = CreateCursor(instance, 0, 0, 32, 32, one, zero);
+ win32Cursor = GetCursor();
+
+ Reset(presentParameters);
+
+ pixelShader.push_back(0); // pixelShader[0] = 0
+ vertexShader.push_back(0); // vertexShader[0] = 0
+ vertexShaderHandle = 0;
+ pixelShaderHandle = 0;
+
+ lightsDirty = true;
+
+ for(int i = 0; i < 16; i++)
+ {
+ dataStream[i] = 0;
+ streamStride[i] = 0;
+ }
+
+ indexData = 0;
+ baseVertexIndex = 0;
+ declaration = 0;
+ FVF = 0;
+
+ D3DMATERIAL8 material;
+
+ material.Diffuse.r = 1.0f;
+ material.Diffuse.g = 1.0f;
+ material.Diffuse.b = 1.0f;
+ material.Diffuse.a = 0.0f;
+ material.Ambient.r = 0.0f;
+ material.Ambient.g = 0.0f;
+ material.Ambient.b = 0.0f;
+ material.Ambient.a = 0.0f;
+ material.Emissive.r = 0.0f;
+ material.Emissive.g = 0.0f;
+ material.Emissive.b = 0.0f;
+ material.Emissive.a = 0.0f;
+ material.Specular.r = 0.0f;
+ material.Specular.g = 0.0f;
+ material.Specular.b = 0.0f;
+ material.Specular.a = 0.0f;
+ material.Power = 0.0f;
+
+ SetMaterial(&material);
+
+ D3DMATRIX identity = {1, 0, 0, 0,
+ 0, 1, 0, 0,
+ 0, 0, 1, 0,
+ 0, 0, 0, 1};
+
+ SetTransform(D3DTS_VIEW, &identity);
+ SetTransform(D3DTS_PROJECTION, &identity);
+ SetTransform(D3DTS_TEXTURE0, &identity);
+ SetTransform(D3DTS_TEXTURE1, &identity);
+ SetTransform(D3DTS_TEXTURE2, &identity);
+ SetTransform(D3DTS_TEXTURE3, &identity);
+ SetTransform(D3DTS_TEXTURE4, &identity);
+ SetTransform(D3DTS_TEXTURE5, &identity);
+ SetTransform(D3DTS_TEXTURE6, &identity);
+ SetTransform(D3DTS_TEXTURE7, &identity);
+
+ for(int i = 0; i < 12; i++)
+ {
+ SetTransform(D3DTS_WORLDMATRIX(i), &identity);
+ }
+
+ for(int i = 0; i < 8; i++)
+ {
+ float zero[4] = {0, 0, 0, 0};
+
+ SetPixelShaderConstant(i, zero, 1);
+ }
+
+ for(int i = 0; i < 256; i++)
+ {
+ float zero[4] = {0, 0, 0, 0};
+
+ SetVertexShaderConstant(i, zero, 1);
+ }
+
+ init = false;
+
+ if(!(behaviourFlags & D3DCREATE_FPU_PRESERVE))
+ {
+ configureFPU();
+ }
+ }
+
+ Direct3DDevice8::~Direct3DDevice8()
+ {
+ delete renderer;
+ renderer = 0;
+ delete context;
+ context = 0;
+
+ d3d8->Release();
+ d3d8 = 0;
+
+ for(unsigned int i = 0; i < swapChain.size(); i++)
+ {
+ if(swapChain[i])
+ {
+ swapChain[i]->unbind();
+ swapChain[i] = 0;
+ }
+ }
+
+ if(depthStencil)
+ {
+ depthStencil->unbind();
+ depthStencil = 0;
+ }
+
+ if(renderTarget)
+ {
+ renderTarget->unbind();
+ renderTarget = 0;
+ }
+
+ for(int i = 0; i < 8; i++)
+ {
+ if(texture[i])
+ {
+ texture[i]->unbind();
+ texture[i] = 0;
+ }
+ }
+
+ for(int i = 0; i < 16; i++)
+ {
+ if(dataStream[i])
+ {
+ dataStream[i]->unbind();
+ dataStream[i] = 0;
+ }
+ }
+
+ if(indexData)
+ {
+ indexData->unbind();
+ indexData = 0;
+ }
+
+ for(unsigned int i = 0; i < pixelShader.size(); i++)
+ {
+ if(pixelShader[i])
+ {
+ pixelShader[i]->unbind();
+ pixelShader[i] = 0;
+ }
+ }
+
+ for(unsigned int i = 0; i < vertexShader.size(); i++)
+ {
+ if(vertexShader[i])
+ {
+ vertexShader[i]->unbind();
+ vertexShader[i] = 0;
+ }
+ }
+
+ for(unsigned int i = 0; i < stateRecorder.size(); i++)
+ {
+ if(stateRecorder[i])
+ {
+ stateRecorder[i]->unbind();
+ stateRecorder[i] = 0;
+ }
+ }
+
+ palette.clear();
+
+ delete cursor;
+ DestroyCursor(nullCursor);
+ }
+
+ long Direct3DDevice8::QueryInterface(const IID &iid, void **object)
+ {
+ TRACE("");
+
+ if(iid == IID_IDirect3DDevice8 ||
+ iid == IID_IUnknown)
+ {
+ AddRef();
+ *object = this;
+
+ return S_OK;
+ }
+
+ *object = 0;
+
+ return NOINTERFACE(iid);
+ }
+
+ unsigned long Direct3DDevice8::AddRef()
+ {
+ TRACE("");
+
+ return Unknown::AddRef();
+ }
+
+ unsigned long Direct3DDevice8::Release()
+ {
+ TRACE("");
+
+ return Unknown::Release();
+ }
+
+ long Direct3DDevice8::ApplyStateBlock(unsigned long token)
+ {
+ TRACE("");
+
+ stateRecorder[token]->Apply();
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::BeginScene()
+ {
+ TRACE("");
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::BeginStateBlock()
+ {
+ TRACE("");
+
+ recordState = true;
+ Direct3DStateBlock8 *stateBlock = new Direct3DStateBlock8(this, (D3DSTATEBLOCKTYPE)0);
+ stateBlock->bind();
+ stateRecorder.push_back(stateBlock);
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::CaptureStateBlock(unsigned long token)
+ {
+ TRACE("");
+
+ stateRecorder[token]->Capture();
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::Clear(unsigned long count, const D3DRECT *rects, unsigned long flags, unsigned long color, float z, unsigned long stencil)
+ {
+ TRACE("unsigned long count = %d, const D3DRECT *rects = 0x%0.8p, unsigned long flags = 0x%0.8X, unsigned long color = 0x%0.8X, float z = %f, unsigned long stencil = %d", count, rects, flags, color, z, stencil);
+
+ if(!rects && count != 0)
+ {
+ return INVALIDCALL();
+ }
+
+ if(flags & (D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL) && !depthStencil)
+ {
+ return INVALIDCALL();
+ }
+
+ if(flags & D3DCLEAR_STENCIL) // Check for stencil component
+ {
+ D3DSURFACE_DESC description;
+ depthStencil->GetDesc(&description);
+
+ switch(description.Format)
+ {
+ case D3DFMT_D15S1:
+ case D3DFMT_D24S8:
+ case D3DFMT_D24X8:
+ case D3DFMT_D24X4S4:
+ break;
+ case D3DFMT_D16_LOCKABLE:
+ case D3DFMT_D32:
+ case D3DFMT_D16:
+ return INVALIDCALL();
+ default:
+ ASSERT(false);
+ }
+ }
+
+ if(!rects)
+ {
+ count = 1;
+
+ D3DRECT rect;
+ rect.x1 = viewport.X;
+ rect.x2 = viewport.X + viewport.Width;
+ rect.y1 = viewport.Y;
+ rect.y2 = viewport.Y + viewport.Height;
+
+ rects = ▭
+ }
+
+ for(unsigned int i = 0; i < count; i++)
+ {
+ sw::SliceRect clearRect(rects[i].x1, rects[i].y1, rects[i].x2, rects[i].y2, 0);
+
+ clearRect.clip(viewport.X, viewport.Y, viewport.X + viewport.Width, viewport.Y + viewport.Height);
+
+ if(flags & D3DCLEAR_TARGET)
+ {
+ if(renderTarget)
+ {
+ D3DSURFACE_DESC description;
+ renderTarget->GetDesc(&description);
+
+ float rgba[4];
+ rgba[0] = (float)(color & 0x00FF0000) / 0x00FF0000;
+ rgba[1] = (float)(color & 0x0000FF00) / 0x0000FF00;
+ rgba[2] = (float)(color & 0x000000FF) / 0x000000FF;
+ rgba[3] = (float)(color & 0xFF000000) / 0xFF000000;
+
+ renderer->clear(rgba, sw::FORMAT_A32B32G32R32F, renderTarget, clearRect, 0xF);
+ }
+ }
+
+ if(flags & D3DCLEAR_ZBUFFER)
+ {
+ z = sw::clamp01(z);
+ depthStencil->clearDepth(z, clearRect.x0, clearRect.y0, clearRect.width(), clearRect.height());
+ }
+
+ if(flags & D3DCLEAR_STENCIL)
+ {
+ depthStencil->clearStencil(stencil, 0xFF, clearRect.x0, clearRect.y0, clearRect.width(), clearRect.height());
+ }
+ }
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::CopyRects(IDirect3DSurface8 *sourceSurface, const RECT *sourceRectsArray, unsigned int rects, IDirect3DSurface8 *destinationSurface, const POINT *destPointsArray)
+ {
+ TRACE("");
+
+ if(!sourceSurface || !destinationSurface)
+ {
+ return INVALIDCALL();
+ }
+
+ if(sourceRectsArray && rects == 0 || !sourceRectsArray && rects > 0)
+ {
+ return INVALIDCALL(); // FIXME: Verify REF behaviour
+ }
+
+ D3DSURFACE_DESC sourceDescription;
+ D3DSURFACE_DESC destDescription;
+
+ sourceSurface->GetDesc(&sourceDescription);
+ destinationSurface->GetDesc(&destDescription);
+
+ if(sourceDescription.Format != destDescription.Format)
+ {
+ return INVALIDCALL();
+ }
+
+ int sWidth = sourceDescription.Width;
+ int sHeight = sourceDescription.Height;
+ int dWidth = destDescription.Width;
+ int dHeight = destDescription.Height;
+
+ RECT sRect = {0, 0, sWidth, sHeight};
+ POINT dPoint = {0, 0};
+
+ if(!sourceRectsArray || !destPointsArray)
+ {
+ sourceRectsArray = &sRect;
+ destPointsArray = &dPoint;
+
+ rects = 1;
+ }
+
+ int bpp = 8 * Direct3DSurface8::bytes(sourceDescription.Format);
+
+ for(unsigned int i = 0; i < rects; i++)
+ {
+ const RECT &sRect = sourceRectsArray[i];
+ const POINT &dPoint = destPointsArray[i];
+
+ int rWidth = sRect.right - sRect.left;
+ int rHeight = sRect.bottom - sRect.top;
+
+ RECT dRect;
+
+ dRect.top = dPoint.y;
+ dRect.left = dPoint.x;
+ dRect.bottom = dPoint.y + rHeight;
+ dRect.right = dPoint.x + rWidth;
+
+ D3DLOCKED_RECT sourceLock;
+ D3DLOCKED_RECT destLock;
+
+ sourceSurface->LockRect(&sourceLock, &sRect, D3DLOCK_READONLY);
+ destinationSurface->LockRect(&destLock, &dRect, D3DLOCK_DISCARD);
+
+ for(int y = 0; y < rHeight; y++)
+ {
+ switch(sourceDescription.Format)
+ {
+ case D3DFMT_DXT1:
+ case D3DFMT_DXT2:
+ case D3DFMT_DXT3:
+ case D3DFMT_DXT4:
+ case D3DFMT_DXT5:
+ memcpy(destLock.pBits, sourceLock.pBits, rWidth * bpp / 8);
+ y += 3; // Advance four lines at once
+ break;
+ default:
+ memcpy(destLock.pBits, sourceLock.pBits, rWidth * bpp / 8);
+ }
+
+ (char*&)sourceLock.pBits += sourceLock.Pitch;
+ (char*&)destLock.pBits += destLock.Pitch;
+ }
+
+ sourceSurface->UnlockRect();
+ destinationSurface->UnlockRect();
+ }
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::CreateAdditionalSwapChain(D3DPRESENT_PARAMETERS *presentParameters, IDirect3DSwapChain8 **swapChain)
+ {
+ TRACE("");
+
+ *swapChain = 0;
+
+ if(!presentParameters || !swapChain)
+ {
+ return INVALIDCALL();
+ }
+
+ if(presentParameters->BackBufferCount > 3)
+ {
+ return INVALIDCALL(); // Maximum of three back buffers
+ }
+
+ if(presentParameters->BackBufferCount == 0)
+ {
+ presentParameters->BackBufferCount = 1;
+ }
+
+ D3DPRESENT_PARAMETERS present = *presentParameters;
+
+ *swapChain = new Direct3DSwapChain8(this, &present);
+
+ if(!*swapChain)
+ {
+ return OUTOFMEMORY();
+ }
+
+ if(GetAvailableTextureMem() == 0)
+ {
+ delete *swapChain;
+
+ return OUTOFVIDEOMEMORY();
+ }
+
+ this->swapChain.push_back(static_cast<Direct3DSwapChain8*>(*swapChain));
+
+ (*swapChain)->AddRef();
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::CreateCubeTexture(unsigned int edgeLength, unsigned int levels, unsigned long usage, D3DFORMAT format, D3DPOOL pool, IDirect3DCubeTexture8 **cubeTexture)
+ {
+ TRACE("");
+
+ *cubeTexture = 0;
+
+ if(edgeLength == 0 || d3d8->CheckDeviceFormat(adapter, deviceType, D3DFMT_X8R8G8B8, usage, D3DRTYPE_CUBETEXTURE, format) != D3D_OK)
+ {
+ return INVALIDCALL();
+ }
+
+ *cubeTexture = new Direct3DCubeTexture8(this, edgeLength, levels, usage, format, pool);
+
+ if(!*cubeTexture)
+ {
+ return OUTOFMEMORY();
+ }
+
+ if(GetAvailableTextureMem() == 0)
+ {
+ delete *cubeTexture;
+
+ return OUTOFVIDEOMEMORY();
+ }
+
+ (*cubeTexture)->AddRef();
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::CreateDepthStencilSurface(unsigned int width, unsigned int height, D3DFORMAT format, D3DMULTISAMPLE_TYPE multiSample, IDirect3DSurface8 **surface)
+ {
+ TRACE("");
+
+ *surface = 0;
+
+ if(width == 0 || height == 0 || d3d8->CheckDeviceFormat(adapter, deviceType, D3DFMT_X8R8G8B8, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, format) != D3D_OK || height > sw::OUTLINE_RESOLUTION)
+ {
+ return INVALIDCALL();
+ }
+
+ *surface = new Direct3DSurface8(this, this, width, height, format, D3DPOOL_DEFAULT, multiSample, format == D3DFMT_D16_LOCKABLE, D3DUSAGE_DEPTHSTENCIL);
+
+ if(!*surface)
+ {
+ return OUTOFMEMORY();
+ }
+
+ if(GetAvailableTextureMem() == 0)
+ {
+ delete *surface;
+
+ return OUTOFVIDEOMEMORY();
+ }
+
+ (*surface)->AddRef();
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::CreateImageSurface(unsigned int width, unsigned int height, D3DFORMAT format, IDirect3DSurface8 **surface)
+ {
+ TRACE("");
+
+ *surface = 0;
+
+ if(width == 0 || height == 0 || d3d8->CheckDeviceFormat(adapter, deviceType, D3DFMT_X8R8G8B8, 0, D3DRTYPE_SURFACE, format) != D3D_OK)
+ {
+ return INVALIDCALL();
+ }
+
+ *surface = new Direct3DSurface8(this, this, width, height, format, D3DPOOL_SYSTEMMEM, D3DMULTISAMPLE_NONE, true, 0);
+
+ if(!*surface)
+ {
+ return OUTOFMEMORY();
+ }
+
+ if(GetAvailableTextureMem() == 0)
+ {
+ delete *surface;
+
+ return OUTOFVIDEOMEMORY();
+ }
+
+ (*surface)->AddRef();
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::CreateIndexBuffer(unsigned int length, unsigned long usage, D3DFORMAT format, D3DPOOL pool, IDirect3DIndexBuffer8 **indexBuffer)
+ {
+ TRACE("");
+
+ *indexBuffer = new Direct3DIndexBuffer8(this, length, usage, format, pool);
+
+ if(!*indexBuffer)
+ {
+ return OUTOFMEMORY();
+ }
+
+ if(GetAvailableTextureMem() == 0)
+ {
+ delete *indexBuffer;
+
+ return OUTOFVIDEOMEMORY();
+ }
+
+ (*indexBuffer)->AddRef();
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::CreatePixelShader(const unsigned long *function, unsigned long *handle)
+ {
+ TRACE("");
+
+ if(!function || !handle || function[0] > pixelShaderVersion)
+ {
+ return INVALIDCALL();
+ }
+
+ unsigned int index;
+
+ for(index = 1; index < pixelShader.size(); index++) // Skip NULL handle
+ {
+ if(pixelShader[index] == 0)
+ {
+ pixelShader[index] = new Direct3DPixelShader8(this, function); // FIXME: Check for null
+
+ break;
+ }
+ }
+
+ if(index == pixelShader.size())
+ {
+ pixelShader.push_back(new Direct3DPixelShader8(this, function));
+ }
+
+ pixelShader[index]->AddRef();
+
+ *handle = index;
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::CreateRenderTarget(unsigned int width, unsigned int height, D3DFORMAT format, D3DMULTISAMPLE_TYPE multiSample, int lockable, IDirect3DSurface8 **surface)
+ {
+ TRACE("");
+
+ *surface = 0;
+
+ if(width == 0 || height == 0 || d3d8->CheckDeviceFormat(adapter, deviceType, D3DFMT_X8R8G8B8, D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, format) != D3D_OK || height > sw::OUTLINE_RESOLUTION)
+ {
+ return INVALIDCALL();
+ }
+
+ *surface = new Direct3DSurface8(this, this, width, height, format, D3DPOOL_DEFAULT, multiSample, lockable != FALSE, D3DUSAGE_RENDERTARGET);
+
+ if(!*surface)
+ {
+ return OUTOFMEMORY();
+ }
+
+ if(GetAvailableTextureMem() == 0)
+ {
+ delete *surface;
+
+ return OUTOFVIDEOMEMORY();
+ }
+
+ (*surface)->AddRef();
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::CreateStateBlock(D3DSTATEBLOCKTYPE type, unsigned long *token)
+ {
+ TRACE("");
+
+ if(!token)
+ {
+ return INVALIDCALL();
+ }
+
+ Direct3DStateBlock8 *stateBlock = new Direct3DStateBlock8(this, type);
+ stateBlock->bind();
+ stateRecorder.push_back(stateBlock);
+ *token = (unsigned long)(stateRecorder.size() - 1);
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::CreateTexture(unsigned int width, unsigned int height, unsigned int levels, unsigned long usage, D3DFORMAT format, D3DPOOL pool, IDirect3DTexture8 **texture)
+ {
+ TRACE("");
+
+ *texture = 0;
+
+ if(width == 0 || height == 0 || d3d8->CheckDeviceFormat(adapter, deviceType, D3DFMT_X8R8G8B8, usage, D3DRTYPE_TEXTURE, format) != D3D_OK)
+ {
+ return INVALIDCALL();
+ }
+
+ *texture = new Direct3DTexture8(this, width, height, levels, usage, format, pool);
+
+ if(!*texture)
+ {
+ return OUTOFMEMORY();
+ }
+
+ if(GetAvailableTextureMem() == 0)
+ {
+ delete *texture;
+
+ return OUTOFVIDEOMEMORY();
+ }
+
+ (*texture)->AddRef();
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::CreateVertexBuffer(unsigned int length, unsigned long usage, unsigned long FVF, D3DPOOL pool, IDirect3DVertexBuffer8 **vertexBuffer)
+ {
+ TRACE("");
+
+ *vertexBuffer = new Direct3DVertexBuffer8(this, length, usage, FVF, pool);
+
+ if(!*vertexBuffer)
+ {
+ return OUTOFMEMORY();
+ }
+
+ if(GetAvailableTextureMem() == 0)
+ {
+ delete *vertexBuffer;
+
+ return OUTOFVIDEOMEMORY();
+ }
+
+ (*vertexBuffer)->AddRef();
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::CreateVertexShader(const unsigned long *declaration, const unsigned long *function, unsigned long *handle, unsigned long usage)
+ {
+ TRACE("const unsigned long *declaration = 0x%0.8p, const unsigned long *function = 0x%0.8p, unsigned long *handle = 0x%0.8p, unsigned long usage = %d", declaration, function, handle, usage);
+
+ if(!declaration || !handle || (function && function[0] > vertexShaderVersion))
+ {
+ return INVALIDCALL();
+ }
+
+ unsigned int index;
+
+ for(index = 1; index < vertexShader.size(); index++) // NOTE: skip NULL handle
+ {
+ if(vertexShader[index] == 0)
+ {
+ vertexShader[index] = new Direct3DVertexShader8(this, declaration, function); // FIXME: Check for null
+
+ break;
+ }
+ }
+
+ if(index == vertexShader.size())
+ {
+ vertexShader.push_back(new Direct3DVertexShader8(this, declaration, function));
+ }
+
+ vertexShader[index]->AddRef();
+
+ *handle = (index << 16) + 1;
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::CreateVolumeTexture(unsigned int width, unsigned int height, unsigned int depth, unsigned int levels, unsigned long usage, D3DFORMAT format, D3DPOOL pool, IDirect3DVolumeTexture8 **volumeTexture)
+ {
+ TRACE("");
+
+ *volumeTexture = 0;
+
+ if(width == 0 || height == 0 || depth == 0 || d3d8->CheckDeviceFormat(adapter, deviceType, D3DFMT_X8R8G8B8, usage, D3DRTYPE_VOLUMETEXTURE, format) != D3D_OK)
+ {
+ return INVALIDCALL();
+ }
+
+ *volumeTexture = new Direct3DVolumeTexture8(this, width, height, depth, levels, usage, format, pool);
+
+ if(!*volumeTexture)
+ {
+ return OUTOFMEMORY();
+ }
+
+ if(GetAvailableTextureMem() == 0)
+ {
+ delete *volumeTexture;
+
+ return OUTOFVIDEOMEMORY();
+ }
+
+ (*volumeTexture)->AddRef();
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::DeletePatch(unsigned int handle)
+ {
+ TRACE("");
+
+ UNIMPLEMENTED();
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::DeleteStateBlock(unsigned long token)
+ {
+ TRACE("");
+
+ if(token >= stateRecorder.size() || !stateRecorder[token])
+ {
+ return INVALIDCALL();
+ }
+
+ stateRecorder[token]->unbind();
+ stateRecorder[token] = 0;
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::DeleteVertexShader(unsigned long handle)
+ {
+ TRACE("");
+
+ unsigned int index = handle >> 16;
+
+ if(index >= vertexShader.size() || !vertexShader[index])
+ {
+ return INVALIDCALL();
+ }
+
+ vertexShader[index]->Release();
+ vertexShader[index] = 0;
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::DrawIndexedPrimitive(D3DPRIMITIVETYPE type, unsigned int minIndex, unsigned int numVertices, unsigned int startIndex, unsigned int primitiveCount)
+ {
+ TRACE("");
+
+ if(!indexData)
+ {
+ return INVALIDCALL();
+ }
+
+ if(!bindData(indexData, baseVertexIndex) || !primitiveCount)
+ {
+ return D3D_OK;
+ }
+
+ unsigned int indexOffset = startIndex * (indexData->is32Bit() ? 4 : 2); // FIXME: Doesn't take stream frequencies into account
+
+ sw::DrawType drawType;
+
+ if(indexData->is32Bit())
+ {
+ switch(type)
+ {
+ case D3DPT_POINTLIST: drawType = sw::DRAW_INDEXEDPOINTLIST32; break;
+ case D3DPT_LINELIST: drawType = sw::DRAW_INDEXEDLINELIST32; break;
+ case D3DPT_LINESTRIP: drawType = sw::DRAW_INDEXEDLINESTRIP32; break;
+ case D3DPT_TRIANGLELIST: drawType = sw::DRAW_INDEXEDTRIANGLELIST32; break;
+ case D3DPT_TRIANGLESTRIP: drawType = sw::DRAW_INDEXEDTRIANGLESTRIP32; break;
+ case D3DPT_TRIANGLEFAN: drawType = sw::DRAW_INDEXEDTRIANGLEFAN32; break;
+ default:
+ ASSERT(false);
+ }
+ }
+ else
+ {
+ switch(type)
+ {
+ case D3DPT_POINTLIST: drawType = sw::DRAW_INDEXEDPOINTLIST16; break;
+ case D3DPT_LINELIST: drawType = sw::DRAW_INDEXEDLINELIST16; break;
+ case D3DPT_LINESTRIP: drawType = sw::DRAW_INDEXEDLINESTRIP16; break;
+ case D3DPT_TRIANGLELIST: drawType = sw::DRAW_INDEXEDTRIANGLELIST16; break;
+ case D3DPT_TRIANGLESTRIP: drawType = sw::DRAW_INDEXEDTRIANGLESTRIP16; break;
+ case D3DPT_TRIANGLEFAN: drawType = sw::DRAW_INDEXEDTRIANGLEFAN16; break;
+ default:
+ ASSERT(false);
+ }
+ }
+
+ bindData(indexData, baseVertexIndex);
+
+ renderer->draw(drawType, indexOffset, primitiveCount);
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::DeletePixelShader(unsigned long handle)
+ {
+ TRACE("");
+
+ if(handle >= pixelShader.size() || !pixelShader[handle])
+ {
+ return INVALIDCALL();
+ }
+
+ pixelShader[handle]->Release();
+ pixelShader[handle] = 0;
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::DrawIndexedPrimitiveUP(D3DPRIMITIVETYPE type, unsigned int minIndex, unsigned int numVertices, unsigned int primitiveCount, const void *indexData, D3DFORMAT indexDataFormat, const void *vertexStreamZeroData, unsigned int vertexStreamZeroStride)
+ {
+ TRACE("");
+
+ if(!vertexStreamZeroData || !indexData)
+ {
+ return INVALIDCALL();
+ }
+
+ int length = (minIndex + numVertices) * vertexStreamZeroStride;
+
+ Direct3DVertexBuffer8 *vertexBuffer = new Direct3DVertexBuffer8(this, length, 0, 0, D3DPOOL_DEFAULT);
+
+ unsigned char *data;
+ vertexBuffer->Lock(0, 0, &data, 0);
+ memcpy(data, vertexStreamZeroData, length);
+ vertexBuffer->Unlock();
+
+ SetStreamSource(0, vertexBuffer, vertexStreamZeroStride);
+
+ switch(type)
+ {
+ case D3DPT_POINTLIST: length = primitiveCount; break;
+ case D3DPT_LINELIST: length = primitiveCount * 2; break;
+ case D3DPT_LINESTRIP: length = primitiveCount + 1; break;
+ case D3DPT_TRIANGLELIST: length = primitiveCount * 3; break;
+ case D3DPT_TRIANGLESTRIP: length = primitiveCount + 2; break;
+ case D3DPT_TRIANGLEFAN: length = primitiveCount + 2; break;
+ default:
+ ASSERT(false);
+ }
+
+ length *= indexDataFormat == D3DFMT_INDEX32 ? 4 : 2;
+
+ Direct3DIndexBuffer8 *indexBuffer = new Direct3DIndexBuffer8(this, length, 0, indexDataFormat, D3DPOOL_DEFAULT);
+
+ indexBuffer->Lock(0, 0, &data, 0);
+ memcpy(data, indexData, length);
+ indexBuffer->Unlock();
+
+ SetIndices(indexBuffer, 0);
+
+ if(!bindData(indexBuffer, 0) || !primitiveCount)
+ {
+ vertexBuffer->Release();
+
+ return D3D_OK;
+ }
+
+ sw::DrawType drawType;
+
+ if(indexDataFormat == D3DFMT_INDEX32)
+ {
+ switch(type)
+ {
+ case D3DPT_POINTLIST: drawType = sw::DRAW_INDEXEDPOINTLIST32; break;
+ case D3DPT_LINELIST: drawType = sw::DRAW_INDEXEDLINELIST32; break;
+ case D3DPT_LINESTRIP: drawType = sw::DRAW_INDEXEDLINESTRIP32; break;
+ case D3DPT_TRIANGLELIST: drawType = sw::DRAW_INDEXEDTRIANGLELIST32; break;
+ case D3DPT_TRIANGLESTRIP: drawType = sw::DRAW_INDEXEDTRIANGLESTRIP32; break;
+ case D3DPT_TRIANGLEFAN: drawType = sw::DRAW_INDEXEDTRIANGLEFAN32; break;
+ default:
+ ASSERT(false);
+ }
+ }
+ else
+ {
+ switch(type)
+ {
+ case D3DPT_POINTLIST: drawType = sw::DRAW_INDEXEDPOINTLIST16; break;
+ case D3DPT_LINELIST: drawType = sw::DRAW_INDEXEDLINELIST16; break;
+ case D3DPT_LINESTRIP: drawType = sw::DRAW_INDEXEDLINESTRIP16; break;
+ case D3DPT_TRIANGLELIST: drawType = sw::DRAW_INDEXEDTRIANGLELIST16; break;
+ case D3DPT_TRIANGLESTRIP: drawType = sw::DRAW_INDEXEDTRIANGLESTRIP16; break;
+ case D3DPT_TRIANGLEFAN: drawType = sw::DRAW_INDEXEDTRIANGLEFAN16; break;
+ default:
+ ASSERT(false);
+ }
+ }
+
+ renderer->draw(drawType, 0, primitiveCount);
+
+ SetStreamSource(0, 0, 0);
+ SetIndices(0, 0);
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::DrawPrimitive(D3DPRIMITIVETYPE primitiveType, unsigned int startVertex, unsigned int primitiveCount)
+ {
+ TRACE("");
+
+ if(!bindData(0, startVertex) || !primitiveCount)
+ {
+ return D3D_OK;
+ }
+
+ sw::DrawType drawType;
+
+ switch(primitiveType)
+ {
+ case D3DPT_POINTLIST: drawType = sw::DRAW_POINTLIST; break;
+ case D3DPT_LINELIST: drawType = sw::DRAW_LINELIST; break;
+ case D3DPT_LINESTRIP: drawType = sw::DRAW_LINESTRIP; break;
+ case D3DPT_TRIANGLELIST: drawType = sw::DRAW_TRIANGLELIST; break;
+ case D3DPT_TRIANGLESTRIP: drawType = sw::DRAW_TRIANGLESTRIP; break;
+ case D3DPT_TRIANGLEFAN: drawType = sw::DRAW_TRIANGLEFAN; break;
+ default:
+ ASSERT(false);
+ }
+
+ renderer->draw(drawType, 0, primitiveCount);
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::DrawPrimitiveUP(D3DPRIMITIVETYPE primitiveType, unsigned int primitiveCount, const void *vertexStreamZeroData, unsigned int vertexStreamZeroStride)
+ {
+ TRACE("");
+
+ if(!vertexStreamZeroData)
+ {
+ return INVALIDCALL();
+ }
+
+ IDirect3DVertexBuffer8 *vertexBuffer = 0;
+ int length = 0;
+
+ switch(primitiveType)
+ {
+ case D3DPT_POINTLIST: length = primitiveCount; break;
+ case D3DPT_LINELIST: length = primitiveCount * 2; break;
+ case D3DPT_LINESTRIP: length = primitiveCount + 1; break;
+ case D3DPT_TRIANGLELIST: length = primitiveCount * 3; break;
+ case D3DPT_TRIANGLESTRIP: length = primitiveCount + 2; break;
+ case D3DPT_TRIANGLEFAN: length = primitiveCount + 2; break;
+ default:
+ ASSERT(false);
+ }
+
+ length *= vertexStreamZeroStride;
+
+ CreateVertexBuffer(length, 0, 0, D3DPOOL_DEFAULT, &vertexBuffer);
+
+ unsigned char *data;
+ vertexBuffer->Lock(0, 0, &data, 0);
+ memcpy(data, vertexStreamZeroData, length);
+ vertexBuffer->Unlock();
+
+ SetStreamSource(0, vertexBuffer, vertexStreamZeroStride);
+
+ if(!bindData(0, 0) || !primitiveCount)
+ {
+ vertexBuffer->Release();
+
+ return D3D_OK;
+ }
+
+ sw::DrawType drawType;
+
+ switch(primitiveType)
+ {
+ case D3DPT_POINTLIST: drawType = sw::DRAW_POINTLIST; break;
+ case D3DPT_LINELIST: drawType = sw::DRAW_LINELIST; break;
+ case D3DPT_LINESTRIP: drawType = sw::DRAW_LINESTRIP; break;
+ case D3DPT_TRIANGLELIST: drawType = sw::DRAW_TRIANGLELIST; break;
+ case D3DPT_TRIANGLESTRIP: drawType = sw::DRAW_TRIANGLESTRIP; break;
+ case D3DPT_TRIANGLEFAN: drawType = sw::DRAW_TRIANGLEFAN; break;
+ default:
+ ASSERT(false);
+ }
+
+ renderer->draw(drawType, 0, primitiveCount);
+
+ SetStreamSource(0, 0, 0);
+ vertexBuffer->Release();
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::DrawRectPatch(unsigned int handle, const float *numSegs, const D3DRECTPATCH_INFO *rectPatchInfo)
+ {
+ TRACE("");
+
+ if(!numSegs || !rectPatchInfo)
+ {
+ return INVALIDCALL();
+ }
+
+ UNIMPLEMENTED();
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::DrawTriPatch(unsigned int handle, const float *numSegs, const D3DTRIPATCH_INFO *triPatchInfo)
+ {
+ TRACE("");
+
+ if(!numSegs || !triPatchInfo)
+ {
+ return INVALIDCALL();
+ }
+
+ UNIMPLEMENTED();
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::EndScene()
+ {
+ TRACE("");
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::EndStateBlock(unsigned long *token)
+ {
+ TRACE("");
+
+ if(!token)
+ {
+ return INVALIDCALL();
+ }
+
+ recordState = false;
+ *token = (unsigned long)(stateRecorder.size() - 1);
+
+ return D3D_OK;
+ }
+
+ unsigned int Direct3DDevice8::GetAvailableTextureMem()
+ {
+ TRACE("");
+
+ int availableMemory = textureMemory - Direct3DResource8::getMemoryUsage();
+ if(availableMemory < 0) availableMemory = 0;
+
+ // Round to nearest MB
+ return (availableMemory + 0x80000) & 0xFFF00000;
+ }
+
+ long Direct3DDevice8::GetBackBuffer(unsigned int index, D3DBACKBUFFER_TYPE type, IDirect3DSurface8 **backBuffer)
+ {
+ TRACE("");
+
+ if(!backBuffer/* || type != D3DBACKBUFFER_TYPE_MONO*/)
+ {
+ return INVALIDCALL();
+ }
+
+ swapChain[index]->GetBackBuffer(index, type, backBuffer);
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::GetClipPlane(unsigned long index, float *plane)
+ {
+ TRACE("");
+
+ if(!plane || index >= 6)
+ {
+ return INVALIDCALL();
+ }
+
+ plane[0] = this->plane[index][0];
+ plane[1] = this->plane[index][1];
+ plane[2] = this->plane[index][2];
+ plane[3] = this->plane[index][3];
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::GetClipStatus(D3DCLIPSTATUS8 *clipStatus)
+ {
+ TRACE("");
+
+ if(!clipStatus)
+ {
+ return INVALIDCALL();
+ }
+
+ *clipStatus = this->clipStatus;
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::GetCreationParameters(D3DDEVICE_CREATION_PARAMETERS *parameters)
+ {
+ TRACE("");
+
+ if(!parameters)
+ {
+ return INVALIDCALL();
+ }
+
+ parameters->AdapterOrdinal = adapter;
+ parameters->BehaviorFlags = behaviourFlags;
+ parameters->DeviceType = deviceType;
+ parameters->hFocusWindow = focusWindow;
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::GetCurrentTexturePalette(unsigned int *paletteNumber)
+ {
+ TRACE("");
+
+ if(!paletteNumber)
+ {
+ return INVALIDCALL();
+ }
+
+ *paletteNumber = currentPalette;
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::GetDepthStencilSurface(IDirect3DSurface8 **depthStencilSurface)
+ {
+ TRACE("");
+
+ if(!depthStencilSurface)
+ {
+ return INVALIDCALL();
+ }
+
+ *depthStencilSurface = depthStencil;
+
+ if(depthStencil)
+ {
+ depthStencil->AddRef();
+ }
+
+ return D3D_OK; // FIXME: Return NOTFOUND() when no depthStencil?
+ }
+
+ long Direct3DDevice8::GetDeviceCaps(D3DCAPS8 *caps)
+ {
+ TRACE("");
+
+ return d3d8->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, caps);
+ }
+
+ long Direct3DDevice8::GetDirect3D(IDirect3D8 **d3d8)
+ {
+ TRACE("");
+
+ if(!d3d8)
+ {
+ return INVALIDCALL();
+ }
+
+ ASSERT(this->d3d8);
+
+ *d3d8 = this->d3d8;
+ this->d3d8->AddRef();
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::GetDisplayMode(D3DDISPLAYMODE *mode)
+ {
+ TRACE("");
+
+ if(!mode)
+ {
+ return INVALIDCALL();
+ }
+
+ d3d8->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, mode);
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::GetFrontBuffer(IDirect3DSurface8 *destSurface)
+ {
+ TRACE("");
+
+ if(!destSurface)
+ {
+ return INVALIDCALL();
+ }
+
+ D3DLOCKED_RECT description;
+ destSurface->LockRect(&description, 0, 0);
+
+ swapChain[0]->screenshot(description.pBits);
+
+ destSurface->UnlockRect();
+
+ return D3D_OK;
+ }
+
+ void Direct3DDevice8::GetGammaRamp(D3DGAMMARAMP *ramp)
+ {
+ TRACE("");
+
+ if(!ramp)
+ {
+ return;
+ }
+
+ swapChain[0]->getGammaRamp((sw::GammaRamp*)ramp);
+ }
+
+ long Direct3DDevice8::GetIndices(IDirect3DIndexBuffer8 **indexData, unsigned int *baseVertexIndex)
+ {
+ TRACE("");
+
+ if(!indexData || !baseVertexIndex)
+ {
+ return INVALIDCALL();
+ }
+
+ *indexData = this->indexData;
+
+ if(this->indexData)
+ {
+ this->indexData->AddRef();
+ }
+
+ *baseVertexIndex = this->baseVertexIndex;
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::GetInfo(unsigned long devInfoID, void *devInfoStruct, unsigned long devInfoStructSize)
+ {
+ TRACE("");
+
+ if(!devInfoStruct || devInfoStructSize == 0)
+ {
+ return INVALIDCALL();
+ }
+
+ switch(devInfoID)
+ {
+ case 0: return E_FAIL;
+ case 1: return E_FAIL;
+ case 2: return E_FAIL;
+ case 3: return E_FAIL;
+ case 4: return S_FALSE;
+ case 5: UNIMPLEMENTED(); // FIXME: D3DDEVINFOID_RESOURCEMANAGER
+ case 6: UNIMPLEMENTED(); // FIXME: D3DDEVINFOID_D3DVERTEXSTATS
+ case 7: return E_FAIL;
+ }
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::GetLight(unsigned long index, D3DLIGHT8 *light)
+ {
+ TRACE("");
+
+ if(!light)
+ {
+ return INVALIDCALL();
+ }
+
+ if(!this->light.exists(index))
+ {
+ return INVALIDCALL();
+ }
+
+ *light = this->light[index];
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::GetLightEnable(unsigned long index , int *enable)
+ {
+ TRACE("");
+
+ if(!enable)
+ {
+ return INVALIDCALL();
+ }
+
+ if(!light.exists(index))
+ {
+ return INVALIDCALL();
+ }
+
+ *enable = light[index].enable;
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::GetMaterial(D3DMATERIAL8 *material)
+ {
+ TRACE("");
+
+ if(!material)
+ {
+ return INVALIDCALL();
+ }
+
+ *material = this->material;
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::GetPaletteEntries(unsigned int paletteNumber, PALETTEENTRY *entries)
+ {
+ TRACE("");
+
+ if(paletteNumber > 0xFFFF || !entries)
+ {
+ return INVALIDCALL();
+ }
+
+ for(int i = 0; i < 256; i++)
+ {
+ entries[i] = palette[paletteNumber].entry[i];
+ }
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::GetPixelShader(unsigned long *handle)
+ {
+ TRACE("");
+
+ if(!handle)
+ {
+ return INVALIDCALL();
+ }
+
+ *handle = pixelShaderHandle;
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::GetPixelShaderFunction(unsigned long handle, void *data, unsigned long *size)
+ {
+ TRACE("");
+
+ if(!data)
+ {
+ return INVALIDCALL();
+ }
+
+ UNIMPLEMENTED();
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::GetPixelShaderConstant(unsigned long startRegister, void *constantData, unsigned long count)
+ {
+ TRACE("");
+
+ if(!constantData)
+ {
+ return INVALIDCALL();
+ }
+
+ for(unsigned int i = 0; i < count; i++)
+ {
+ ((float*)constantData)[i * 4 + 0] = pixelShaderConstant[startRegister + i][0];
+ ((float*)constantData)[i * 4 + 1] = pixelShaderConstant[startRegister + i][1];
+ ((float*)constantData)[i * 4 + 2] = pixelShaderConstant[startRegister + i][2];
+ ((float*)constantData)[i * 4 + 3] = pixelShaderConstant[startRegister + i][3];
+ }
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::GetRasterStatus(D3DRASTER_STATUS *rasterStatus)
+ {
+ TRACE("");
+
+ if(!rasterStatus)
+ {
+ return INVALIDCALL();
+ }
+
+ UNIMPLEMENTED();
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::GetRenderState(D3DRENDERSTATETYPE state, unsigned long *value)
+ {
+ TRACE("");
+
+ if(!value)
+ {
+ return INVALIDCALL();
+ }
+
+ *value = renderState[state];
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::GetRenderTarget(IDirect3DSurface8 **renderTarget)
+ {
+ TRACE("");
+
+ if(!renderTarget)
+ {
+ return INVALIDCALL();
+ }
+
+ *renderTarget = this->renderTarget;
+ this->renderTarget->AddRef();
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::GetStreamSource(unsigned int streamNumber, IDirect3DVertexBuffer8 **streamData, unsigned int *stride)
+ {
+ TRACE("");
+
+ if(streamNumber >= 16 || !streamData || !stride)
+ {
+ return INVALIDCALL();
+ }
+
+ *streamData = dataStream[streamNumber];
+
+ if(dataStream[streamNumber])
+ {
+ dataStream[streamNumber]->AddRef();
+ }
+
+ *stride = 0; // NOTE: Unimplemented
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::GetTexture(unsigned long stage, IDirect3DBaseTexture8 **texture)
+ {
+ TRACE("");
+
+ if(!texture || stage >= 8)
+ {
+ return INVALIDCALL();
+ }
+
+ *texture = this->texture[stage];
+
+ if(this->texture[stage])
+ {
+ this->texture[stage]->AddRef();
+ }
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::GetTextureStageState(unsigned long stage, D3DTEXTURESTAGESTATETYPE state, unsigned long *value)
+ {
+ TRACE("");
+
+ if(!value || stage < 0 || stage >= 8 || state < 0 || state > D3DTSS_RESULTARG) // FIXME: Set *value to 0?
+ {
+ return INVALIDCALL();
+ }
+
+ *value = textureStageState[stage][state];
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::GetTransform(D3DTRANSFORMSTATETYPE state, D3DMATRIX *matrix)
+ {
+ TRACE("");
+
+ if(!matrix || state < 0 || state > 511)
+ {
+ return INVALIDCALL();
+ }
+
+ *matrix = this->matrix[state];
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::GetVertexShader(unsigned long *handle)
+ {
+ TRACE("");
+
+ if(!handle)
+ {
+ return INVALIDCALL();
+ }
+
+ *handle = vertexShaderHandle;
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::GetVertexShaderConstant(unsigned long startRegister, void *constantData, unsigned long count)
+ {
+ TRACE("");
+
+ if(!constantData)
+ {
+ return INVALIDCALL();
+ }
+
+ for(unsigned int i = 0; i < count; i++)
+ {
+ ((float*)constantData)[i * 4 + 0] = vertexShaderConstant[startRegister + i][0];
+ ((float*)constantData)[i * 4 + 1] = vertexShaderConstant[startRegister + i][1];
+ ((float*)constantData)[i * 4 + 2] = vertexShaderConstant[startRegister + i][2];
+ ((float*)constantData)[i * 4 + 3] = vertexShaderConstant[startRegister + i][3];
+ }
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::GetVertexShaderDeclaration(unsigned long handle, void *data, unsigned long *size)
+ {
+ TRACE("");
+
+ if(!data || !size)
+ {
+ return INVALIDCALL();
+ }
+
+ UNIMPLEMENTED();
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::GetVertexShaderFunction(unsigned long handle, void *data, unsigned long *size)
+ {
+ TRACE("");
+
+ if(!data || !size)
+ {
+ return INVALIDCALL();
+ }
+
+ UNIMPLEMENTED();
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::GetViewport(D3DVIEWPORT8 *viewport)
+ {
+ TRACE("");
+
+ if(!viewport)
+ {
+ return INVALIDCALL();
+ }
+
+ *viewport = this->viewport;
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::LightEnable(unsigned long index, int enable)
+ {
+ TRACE("");
+
+ if(!recordState)
+ {
+ if(!light.exists(index)) // Insert default light
+ {
+ D3DLIGHT8 light;
+
+ light.Type = D3DLIGHT_DIRECTIONAL;
+ light.Diffuse.r = 1;
+ light.Diffuse.g = 1;
+ light.Diffuse.b = 1;
+ light.Diffuse.a = 0;
+ light.Specular.r = 0;
+ light.Specular.g = 0;
+ light.Specular.b = 0;
+ light.Specular.a = 0;
+ light.Ambient.r = 0;
+ light.Ambient.g = 0;
+ light.Ambient.b = 0;
+ light.Ambient.a = 0;
+ light.Position.x = 0;
+ light.Position.y = 0;
+ light.Position.z = 0;
+ light.Direction.x = 0;
+ light.Direction.y = 0;
+ light.Direction.z = 1;
+ light.Range = 0;
+ light.Falloff = 0;
+ light.Attenuation0 = 0;
+ light.Attenuation1 = 0;
+ light.Attenuation2 = 0;
+ light.Theta = 0;
+ light.Phi = 0;
+
+ SetLight(index, &light);
+ }
+
+ light[index].enable = (enable != FALSE);
+
+ lightsDirty = true;
+ }
+ else
+ {
+ stateRecorder.back()->lightEnable(index, enable);
+ }
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::MultiplyTransform(D3DTRANSFORMSTATETYPE state, const D3DMATRIX *matrix)
+ {
+ TRACE("");
+
+ if(!matrix)
+ {
+ return INVALIDCALL();
+ }
+
+ D3DMATRIX *current = &this->matrix[state];
+
+ sw::Matrix C(current->_11, current->_21, current->_31, current->_41,
+ current->_12, current->_22, current->_32, current->_42,
+ current->_13, current->_23, current->_33, current->_43,
+ current->_14, current->_24, current->_34, current->_44);
+
+ sw::Matrix M(matrix->_11, matrix->_21, matrix->_31, matrix->_41,
+ matrix->_12, matrix->_22, matrix->_32, matrix->_42,
+ matrix->_13, matrix->_23, matrix->_33, matrix->_43,
+ matrix->_14, matrix->_24, matrix->_34, matrix->_44);
+
+ switch(state)
+ {
+ case D3DTS_WORLD:
+ renderer->setModelMatrix(C * M);
+ break;
+ case D3DTS_VIEW:
+ renderer->setViewMatrix(C * M);
+ break;
+ case D3DTS_PROJECTION:
+ renderer->setProjectionMatrix(C * M);
+ break;
+ case D3DTS_TEXTURE0:
+ renderer->setTextureMatrix(0, C * M);
+ break;
+ case D3DTS_TEXTURE1:
+ renderer->setTextureMatrix(1, C * M);
+ break;
+ case D3DTS_TEXTURE2:
+ renderer->setTextureMatrix(2, C * M);
+ break;
+ case D3DTS_TEXTURE3:
+ renderer->setTextureMatrix(3, C * M);
+ break;
+ case D3DTS_TEXTURE4:
+ renderer->setTextureMatrix(4, C * M);
+ break;
+ case D3DTS_TEXTURE5:
+ renderer->setTextureMatrix(5, C * M);
+ break;
+ case D3DTS_TEXTURE6:
+ renderer->setTextureMatrix(6, C * M);
+ break;
+ case D3DTS_TEXTURE7:
+ renderer->setTextureMatrix(7, C * M);
+ break;
+ default:
+ if(state > 256 && state < 512)
+ {
+ renderer->setModelMatrix(C * M, state - 256);
+ }
+ else ASSERT(false);
+ }
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::Present(const RECT *sourceRect, const RECT *destRect, HWND destWindowOverride, const RGNDATA *dirtyRegion)
+ {
+ TRACE("");
+
+ // NOTE: sourceRect and destRect can be null, dirtyRegion has to be null
+
+ HWND windowHandle = presentParameters.hDeviceWindow ? presentParameters.hDeviceWindow : focusWindow;
+
+ if(destWindowOverride && destWindowOverride != windowHandle)
+ {
+ UNIMPLEMENTED();
+ }
+
+ if(dirtyRegion)
+ {
+ return INVALIDCALL();
+ }
+
+ swapChain[0]->Present(sourceRect, destRect, destWindowOverride, dirtyRegion);
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::ProcessVertices(unsigned int srcStartIndex, unsigned int destIndex, unsigned int vertexCount, IDirect3DVertexBuffer8 *destBuffer, unsigned long flags)
+ {
+ TRACE("");
+
+ if(!destBuffer)
+ {
+ return INVALIDCALL();
+ }
+
+ UNIMPLEMENTED();
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::Reset(D3DPRESENT_PARAMETERS *presentParameters)
+ {
+ TRACE("");
+
+ if(!presentParameters)
+ {
+ return INVALIDCALL();
+ }
+
+ if(swapChain[0])
+ {
+ swapChain[0]->unbind();
+ swapChain[0] = 0;
+ }
+
+ if(depthStencil)
+ {
+ depthStencil->unbind();
+ depthStencil = 0;
+ }
+
+ if(renderTarget)
+ {
+ renderTarget->unbind();
+ renderTarget = 0;
+ }
+
+ D3DPRESENT_PARAMETERS present = *presentParameters;
+
+ if(!swapChain[0])
+ {
+ swapChain[0] = new Direct3DSwapChain8(this, &present);
+ swapChain[0]->bind();
+ }
+ else
+ {
+ swapChain[0]->reset(&present);
+ }
+
+ HWND windowHandle = presentParameters->hDeviceWindow ? presentParameters->hDeviceWindow : focusWindow;
+
+ int width = 0;
+ int height = 0;
+
+ if(presentParameters->Windowed && (presentParameters->BackBufferHeight == 0 || presentParameters->BackBufferWidth == 0))
+ {
+ RECT rectangle;
+ GetClientRect(windowHandle, &rectangle);
+
+ width = rectangle.right - rectangle.left;
+ height = rectangle.bottom - rectangle.top;
+ }
+ else
+ {
+ width = presentParameters->BackBufferWidth;
+ height = presentParameters->BackBufferHeight;
+ }
+
+ if(presentParameters->EnableAutoDepthStencil != FALSE)
+ {
+ depthStencil = new Direct3DSurface8(this, this, width, height, presentParameters->AutoDepthStencilFormat, D3DPOOL_DEFAULT, presentParameters->MultiSampleType, presentParameters->AutoDepthStencilFormat == D3DFMT_D16_LOCKABLE, D3DUSAGE_DEPTHSTENCIL);
+ depthStencil->bind();
+ }
+
+ IDirect3DSurface8 *renderTarget;
+ swapChain[0]->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &renderTarget);
+ SetRenderTarget(renderTarget, depthStencil);
+ renderTarget->Release();
+
+ SetRenderState(D3DRS_ZENABLE, presentParameters->EnableAutoDepthStencil != FALSE ? D3DZB_TRUE : D3DZB_FALSE);
+ SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
+ SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD);
+ SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
+ SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
+ SetRenderState(D3DRS_LASTPIXEL, TRUE);
+ SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
+ SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ZERO);
+ SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
+ SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
+ SetRenderState(D3DRS_ALPHAREF, 0);
+ SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_ALWAYS);
+ SetRenderState(D3DRS_DITHERENABLE, FALSE);
+ SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
+ SetRenderState(D3DRS_FOGENABLE, FALSE);
+ SetRenderState(D3DRS_SPECULARENABLE, FALSE);
+ // SetRenderState(D3DRS_ZVISIBLE, 0);
+ SetRenderState(D3DRS_FOGCOLOR, 0);
+ SetRenderState(D3DRS_FOGTABLEMODE, D3DFOG_NONE);
+ SetRenderState(D3DRS_FOGSTART, FtoDW(0.0f));
+ SetRenderState(D3DRS_FOGEND, FtoDW(1.0f));
+ SetRenderState(D3DRS_FOGDENSITY, FtoDW(1.0f));
+ SetRenderState(D3DRS_EDGEANTIALIAS, FALSE);
+ SetRenderState(D3DRS_RANGEFOGENABLE, FALSE);
+ SetRenderState(D3DRS_ZBIAS, 0);
+ SetRenderState(D3DRS_STENCILENABLE, FALSE);
+ SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP);
+ SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP);
+ SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP);
+ SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS);
+ SetRenderState(D3DRS_STENCILREF, 0);
+ SetRenderState(D3DRS_STENCILMASK, 0xFFFFFFFF);
+ SetRenderState(D3DRS_STENCILWRITEMASK, 0xFFFFFFFF);
+ SetRenderState(D3DRS_TEXTUREFACTOR, 0xFFFFFFFF);
+ SetRenderState(D3DRS_WRAP0, 0);
+ SetRenderState(D3DRS_WRAP1, 0);
+ SetRenderState(D3DRS_WRAP2, 0);
+ SetRenderState(D3DRS_WRAP3, 0);
+ SetRenderState(D3DRS_WRAP4, 0);
+ SetRenderState(D3DRS_WRAP5, 0);
+ SetRenderState(D3DRS_WRAP6, 0);
+ SetRenderState(D3DRS_WRAP7, 0);
+ SetRenderState(D3DRS_CLIPPING, TRUE);
+ SetRenderState(D3DRS_LIGHTING, TRUE);
+ SetRenderState(D3DRS_AMBIENT, 0);
+ SetRenderState(D3DRS_FOGVERTEXMODE, D3DFOG_NONE);
+ SetRenderState(D3DRS_COLORVERTEX, TRUE);
+ SetRenderState(D3DRS_LOCALVIEWER, TRUE);
+ SetRenderState(D3DRS_NORMALIZENORMALS, FALSE);
+ SetRenderState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_COLOR1);
+ SetRenderState(D3DRS_SPECULARMATERIALSOURCE, D3DMCS_COLOR2);
+ SetRenderState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL);
+ SetRenderState(D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_MATERIAL);
+ SetRenderState(D3DRS_VERTEXBLEND, D3DVBF_DISABLE);
+ SetRenderState(D3DRS_CLIPPLANEENABLE, 0);
+ SetRenderState(D3DRS_SOFTWAREVERTEXPROCESSING, FALSE);
+ SetRenderState(D3DRS_POINTSIZE, FtoDW(1.0f));
+ SetRenderState(D3DRS_POINTSIZE_MIN, FtoDW(0.0f));
+ SetRenderState(D3DRS_POINTSPRITEENABLE, FALSE);
+ SetRenderState(D3DRS_POINTSCALEENABLE, FALSE);
+ SetRenderState(D3DRS_POINTSCALE_A, FtoDW(1.0f));
+ SetRenderState(D3DRS_POINTSCALE_B, FtoDW(0.0f));
+ SetRenderState(D3DRS_POINTSCALE_C, FtoDW(0.0f));
+ SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, TRUE);
+ SetRenderState(D3DRS_MULTISAMPLEMASK, 0xFFFFFFFF);
+ SetRenderState(D3DRS_PATCHEDGESTYLE, D3DPATCHEDGE_DISCRETE);
+ SetRenderState(D3DRS_DEBUGMONITORTOKEN, D3DDMT_ENABLE);
+ SetRenderState(D3DRS_POINTSIZE_MAX, FtoDW(64.0f));
+ SetRenderState(D3DRS_INDEXEDVERTEXBLENDENABLE, FALSE);
+ SetRenderState(D3DRS_COLORWRITEENABLE, 0x0000000F);
+ SetRenderState(D3DRS_TWEENFACTOR, FtoDW(0.0f));
+ SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);
+ SetRenderState(D3DRS_POSITIONORDER, D3DORDER_CUBIC);
+ SetRenderState(D3DRS_NORMALORDER, D3DORDER_LINEAR);
+
+ for(int i = 0; i < 8; i++)
+ {
+ SetTexture(i, 0);
+
+ SetTextureStageState(i, D3DTSS_COLOROP, i == 0 ? D3DTOP_MODULATE : D3DTOP_DISABLE);
+ SetTextureStageState(i, D3DTSS_COLORARG1, D3DTA_TEXTURE); // TODO: D3DTA_DIFFUSE when no texture assigned
+ SetTextureStageState(i, D3DTSS_COLORARG2, D3DTA_CURRENT);
+ SetTextureStageState(i, D3DTSS_ALPHAOP, i == 0 ? D3DTOP_SELECTARG1 : D3DTOP_DISABLE);
+ SetTextureStageState(i, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); // TODO: D3DTA_DIFFUSE when no texture assigned
+ SetTextureStageState(i, D3DTSS_ALPHAARG2, D3DTA_CURRENT);
+ SetTextureStageState(i, D3DTSS_BUMPENVMAT00, FtoDW(0.0f));
+ SetTextureStageState(i, D3DTSS_BUMPENVMAT01, FtoDW(0.0f));
+ SetTextureStageState(i, D3DTSS_BUMPENVMAT10, FtoDW(0.0f));
+ SetTextureStageState(i, D3DTSS_BUMPENVMAT11, FtoDW(0.0f));
+ SetTextureStageState(i, D3DTSS_TEXCOORDINDEX, i);
+ SetTextureStageState(i, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);
+ SetTextureStageState(i, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);
+ SetTextureStageState(i, D3DTSS_ADDRESSW, D3DTADDRESS_WRAP);
+ SetTextureStageState(i, D3DTSS_BORDERCOLOR, 0x00000000);
+ SetTextureStageState(i, D3DTSS_MAGFILTER, D3DTEXF_POINT);
+ SetTextureStageState(i, D3DTSS_MINFILTER, D3DTEXF_POINT);
+ SetTextureStageState(i, D3DTSS_MIPFILTER, D3DTEXF_NONE);
+ SetTextureStageState(i, D3DTSS_MIPMAPLODBIAS, 0);
+ SetTextureStageState(i, D3DTSS_MAXMIPLEVEL, 0);
+ SetTextureStageState(i, D3DTSS_MAXANISOTROPY, 1);
+ SetTextureStageState(i, D3DTSS_BUMPENVLSCALE, FtoDW(0.0f));
+ SetTextureStageState(i, D3DTSS_BUMPENVLOFFSET, FtoDW(0.0f));
+ SetTextureStageState(i, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);
+ SetTextureStageState(i, D3DTSS_COLORARG0, D3DTA_CURRENT);
+ SetTextureStageState(i, D3DTSS_ALPHAARG0, D3DTA_CURRENT);
+ SetTextureStageState(i, D3DTSS_RESULTARG, D3DTA_CURRENT);
+ }
+
+ currentPalette = 0xFFFF;
+
+ delete cursor;
+ showCursor = false;
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::ResourceManagerDiscardBytes(unsigned long bytes)
+ {
+ TRACE("");
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::SetClipPlane(unsigned long index, const float *plane)
+ {
+ TRACE("");
+
+ if(!plane || index > 6)
+ {
+ return INVALIDCALL();
+ }
+
+ if(!recordState)
+ {
+ this->plane[index][0] = plane[0];
+ this->plane[index][1] = plane[1];
+ this->plane[index][2] = plane[2];
+ this->plane[index][3] = plane[3];
+
+ renderer->setClipPlane(index, plane);
+ }
+ else
+ {
+ stateRecorder.back()->setClipPlane(index, plane);
+ }
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::SetClipStatus(const D3DCLIPSTATUS8 *clipStatus)
+ {
+ TRACE("");
+
+ if(!clipStatus)
+ {
+ return INVALIDCALL();
+ }
+
+ this->clipStatus = *clipStatus;
+
+ UNIMPLEMENTED();
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::SetCurrentTexturePalette(unsigned int paletteNumber)
+ {
+ TRACE("");
+
+ if(paletteNumber > 0xFFFF || palette.find(paletteNumber) == palette.end())
+ {
+ return INVALIDCALL();
+ }
+
+ if(!recordState)
+ {
+ currentPalette = paletteNumber;
+
+ sw::Surface::setTexturePalette((unsigned int*)&palette[currentPalette]);
+ }
+ else
+ {
+ stateRecorder.back()->setCurrentTexturePalette(paletteNumber);
+ }
+
+ return D3D_OK;
+ }
+
+ void Direct3DDevice8::SetCursorPosition(int x, int y, unsigned long flags)
+ {
+ TRACE("");
+
+ POINT point = {x, y};
+ HWND window = focusWindow ? focusWindow : presentParameters.hDeviceWindow;
+ ScreenToClient(window, &point);
+
+ sw::FrameBuffer::setCursorPosition(point.x, point.y);
+ }
+
+ void Direct3DDevice8::SetCursorPosition(unsigned int x, unsigned int y, unsigned long flags)
+ {
+ SetCursorPosition((int)x, (int)y, flags);
+ }
+
+ long Direct3DDevice8::SetCursorProperties(unsigned int x0, unsigned int y0, IDirect3DSurface8 *cursorBitmap)
+ {
+ TRACE("");
+
+ if(!cursorBitmap)
+ {
+ return INVALIDCALL();
+ }
+
+ D3DSURFACE_DESC desc;
+ D3DLOCKED_RECT lock;
+
+ cursorBitmap->GetDesc(&desc);
+ cursorBitmap->LockRect(&lock, 0, 0);
+
+ delete cursor;
+ cursor = new sw::Surface(0, desc.Width, desc.Height, 1, sw::FORMAT_A8R8G8B8, false, false);
+
+ void *buffer = cursor->lockExternal(0, 0, 0, sw::LOCK_DISCARD, sw::PUBLIC);
+ memcpy(buffer, lock.pBits, desc.Width * desc.Height * sizeof(unsigned int));
+ cursor->unlockExternal();
+
+ cursorBitmap->UnlockRect();
+
+ sw::FrameBuffer::setCursorOrigin(x0, y0);
+
+ bindCursor();
+
+ return D3D_OK;
+ }
+
+ void Direct3DDevice8::SetGammaRamp(unsigned long flags, const D3DGAMMARAMP *ramp)
+ {
+ TRACE("");
+
+ if(!ramp)
+ {
+ return;
+ }
+
+ swapChain[0]->setGammaRamp((sw::GammaRamp*)ramp, flags & D3DSGR_CALIBRATE);
+
+ return;
+ }
+
+ long Direct3DDevice8::SetLight(unsigned long index, const D3DLIGHT8 *light)
+ {
+ TRACE("");
+
+ if(!light)
+ {
+ return INVALIDCALL();
+ }
+
+ if(!recordState)
+ {
+ this->light[index] = *light;
+
+ lightsDirty = true;
+ }
+ else
+ {
+ stateRecorder.back()->setLight(index, light);
+ }
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::SetMaterial(const D3DMATERIAL8 *material)
+ {
+ TRACE("");
+
+ if(!material)
+ {
+ return INVALIDCALL(); // FIXME: Correct behaviour?
+ }
+
+ if(!recordState)
+ {
+ this->material = *material;
+
+ renderer->setMaterialAmbient(sw::Color<float>(material->Ambient.r, material->Ambient.g, material->Ambient.b, material->Ambient.a));
+ renderer->setMaterialDiffuse(sw::Color<float>(material->Diffuse.r, material->Diffuse.g, material->Diffuse.b, material->Diffuse.a));
+ renderer->setMaterialEmission(sw::Color<float>(material->Emissive.r, material->Emissive.g, material->Emissive.b, material->Emissive.a));
+ renderer->setMaterialShininess(material->Power);
+ renderer->setMaterialSpecular(sw::Color<float>(material->Specular.r, material->Specular.g, material->Specular.b, material->Specular.a));
+ }
+ else
+ {
+ stateRecorder.back()->setMaterial(material);
+ }
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::SetPaletteEntries(unsigned int paletteNumber, const PALETTEENTRY *entries)
+ {
+ TRACE("");
+
+ if(paletteNumber > 0xFFFF || !entries)
+ {
+ return INVALIDCALL();
+ }
+
+ for(int i = 0; i < 256; i++)
+ {
+ palette[paletteNumber].entry[i] = entries[i];
+ }
+
+ if(paletteNumber == currentPalette)
+ {
+ sw::Surface::setTexturePalette((unsigned int*)&palette[currentPalette]);
+ }
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::SetPixelShader(unsigned long handle)
+ {
+ TRACE("");
+
+ if(!recordState)
+ {
+ if(pixelShader[handle])
+ {
+ pixelShader[handle]->bind();
+ }
+
+ if(pixelShader[pixelShaderHandle])
+ {
+ pixelShader[pixelShaderHandle]->unbind();
+ }
+
+ pixelShaderHandle = handle;
+
+ if(handle != 0)
+ {
+ renderer->setPixelShader(pixelShader[handle]->getPixelShader());
+ }
+ else
+ {
+ renderer->setPixelShader(0);
+ }
+ }
+ else
+ {
+ stateRecorder.back()->setPixelShader(handle);
+ }
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::SetPixelShaderConstant(unsigned long startRegister, const void *constantData, unsigned long count)
+ {
+ TRACE("");
+
+ if(!recordState)
+ {
+ for(unsigned int i = 0; i < count; i++)
+ {
+ pixelShaderConstant[startRegister + i][0] = ((float*)constantData)[i * 4 + 0];
+ pixelShaderConstant[startRegister + i][1] = ((float*)constantData)[i * 4 + 1];
+ pixelShaderConstant[startRegister + i][2] = ((float*)constantData)[i * 4 + 2];
+ pixelShaderConstant[startRegister + i][3] = ((float*)constantData)[i * 4 + 3];
+ }
+
+ renderer->setPixelShaderConstantF(startRegister, (const float*)constantData, count);
+ }
+ else
+ {
+ stateRecorder.back()->setPixelShaderConstant(startRegister, constantData, count);
+ }
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::SetRenderState(D3DRENDERSTATETYPE state, unsigned long value)
+ {
+ TRACE("D3DRENDERSTATETYPE state = %d, unsigned long value = %d", state, value);
+
+ if(state < D3DRS_ZENABLE || state > D3DRS_NORMALORDER)
+ {
+ return D3D_OK; // FIXME: Warning
+ }
+
+ if(!recordState)
+ {
+ if(!init && renderState[state] == value)
+ {
+ return D3D_OK;
+ }
+
+ renderState[state] = value;
+
+ switch(state)
+ {
+ case D3DRS_ZENABLE:
+ switch(value)
+ {
+ case D3DZB_TRUE:
+ case D3DZB_USEW:
+ renderer->setDepthBufferEnable(true);
+ break;
+ case D3DZB_FALSE:
+ renderer->setDepthBufferEnable(false);
+ break;
+ default:
+ ASSERT(false);
+ }
+ break;
+ case D3DRS_FILLMODE:
+ switch(value)
+ {
+ case D3DFILL_POINT:
+ renderer->setFillMode(sw::FILL_VERTEX);
+ break;
+ case D3DFILL_WIREFRAME:
+ renderer->setFillMode(sw::FILL_WIREFRAME);
+ break;
+ case D3DFILL_SOLID:
+ renderer->setFillMode(sw::FILL_SOLID);
+ break;
+ default:
+ ASSERT(false);
+ }
+ break;
+ case D3DRS_SHADEMODE:
+ switch(value)
+ {
+ case D3DSHADE_FLAT:
+ renderer->setShadingMode(sw::SHADING_FLAT);
+ break;
+ case D3DSHADE_GOURAUD:
+ renderer->setShadingMode(sw::SHADING_GOURAUD);
+ break;
+ case D3DSHADE_PHONG:
+ // FIXME: Unimplemented (should set gouraud)?
+ break;
+ default:
+ ASSERT(false);
+ }
+ break;
+ case D3DRS_LINEPATTERN:
+ if(!init) UNIMPLEMENTED();
+ break;
+ case D3DRS_ZWRITEENABLE:
+ renderer->setDepthWriteEnable(value != FALSE);
+ break;
+ case D3DRS_ALPHATESTENABLE:
+ renderer->setAlphaTestEnable(value != FALSE);
+ break;
+ case D3DRS_LASTPIXEL:
+ if(!init) UNIMPLEMENTED();
+ break;
+ case D3DRS_SRCBLEND:
+ switch(value)
+ {
+ case D3DBLEND_ZERO:
+ renderer->setSourceBlendFactor(sw::BLEND_ZERO);
+ break;
+ case D3DBLEND_ONE:
+ renderer->setSourceBlendFactor(sw::BLEND_ONE);
+ break;
+ case D3DBLEND_SRCCOLOR:
+ renderer->setSourceBlendFactor(sw::BLEND_SOURCE);
+ break;
+ case D3DBLEND_INVSRCCOLOR:
+ renderer->setSourceBlendFactor(sw::BLEND_INVSOURCE);
+ break;
+ case D3DBLEND_SRCALPHA:
+ renderer->setSourceBlendFactor(sw::BLEND_SOURCEALPHA);
+ break;
+ case D3DBLEND_INVSRCALPHA:
+ renderer->setSourceBlendFactor(sw::BLEND_INVSOURCEALPHA);
+ break;
+ case D3DBLEND_DESTALPHA:
+ renderer->setSourceBlendFactor(sw::BLEND_DESTALPHA);
+ break;
+ case D3DBLEND_INVDESTALPHA:
+ renderer->setSourceBlendFactor(sw::BLEND_INVDESTALPHA);
+ break;
+ case D3DBLEND_DESTCOLOR:
+ renderer->setSourceBlendFactor(sw::BLEND_DEST);
+ break;
+ case D3DBLEND_INVDESTCOLOR:
+ renderer->setSourceBlendFactor(sw::BLEND_INVDEST);
+ break;
+ case D3DBLEND_SRCALPHASAT:
+ renderer->setSourceBlendFactor(sw::BLEND_SRCALPHASAT);
+ break;
+ case D3DBLEND_BOTHSRCALPHA:
+ renderer->setSourceBlendFactor(sw::BLEND_SOURCEALPHA);
+ renderer->setDestBlendFactor(sw::BLEND_INVSOURCEALPHA);
+ break;
+ case D3DBLEND_BOTHINVSRCALPHA:
+ renderer->setSourceBlendFactor(sw::BLEND_INVSOURCEALPHA);
+ renderer->setDestBlendFactor(sw::BLEND_SOURCEALPHA);
+ break;
+ default:
+ ASSERT(false);
+ }
+ break;
+ case D3DRS_DESTBLEND:
+ switch(value)
+ {
+ case D3DBLEND_ZERO:
+ renderer->setDestBlendFactor(sw::BLEND_ZERO);
+ break;
+ case D3DBLEND_ONE:
+ renderer->setDestBlendFactor(sw::BLEND_ONE);
+ break;
+ case D3DBLEND_SRCCOLOR:
+ renderer->setDestBlendFactor(sw::BLEND_SOURCE);
+ break;
+ case D3DBLEND_INVSRCCOLOR:
+ renderer->setDestBlendFactor(sw::BLEND_INVSOURCE);
+ break;
+ case D3DBLEND_SRCALPHA:
+ renderer->setDestBlendFactor(sw::BLEND_SOURCEALPHA);
+ break;
+ case D3DBLEND_INVSRCALPHA:
+ renderer->setDestBlendFactor(sw::BLEND_INVSOURCEALPHA);
+ break;
+ case D3DBLEND_DESTALPHA:
+ renderer->setDestBlendFactor(sw::BLEND_DESTALPHA);
+ break;
+ case D3DBLEND_INVDESTALPHA:
+ renderer->setDestBlendFactor(sw::BLEND_INVDESTALPHA);
+ break;
+ case D3DBLEND_DESTCOLOR:
+ renderer->setDestBlendFactor(sw::BLEND_DEST);
+ break;
+ case D3DBLEND_INVDESTCOLOR:
+ renderer->setDestBlendFactor(sw::BLEND_INVDEST);
+ break;
+ case D3DBLEND_SRCALPHASAT:
+ renderer->setDestBlendFactor(sw::BLEND_SRCALPHASAT);
+ break;
+ case D3DBLEND_BOTHSRCALPHA:
+ renderer->setSourceBlendFactor(sw::BLEND_SOURCEALPHA);
+ renderer->setDestBlendFactor(sw::BLEND_INVSOURCEALPHA);
+ break;
+ case D3DBLEND_BOTHINVSRCALPHA:
+ renderer->setSourceBlendFactor(sw::BLEND_INVSOURCEALPHA);
+ renderer->setDestBlendFactor(sw::BLEND_SOURCEALPHA);
+ break;
+ default:
+ ASSERT(false);
+ }
+ break;
+ case D3DRS_CULLMODE:
+ switch(value)
+ {
+ case D3DCULL_NONE:
+ renderer->setCullMode(sw::CULL_NONE);
+ break;
+ case D3DCULL_CCW:
+ renderer->setCullMode(sw::CULL_COUNTERCLOCKWISE);
+ break;
+ case D3DCULL_CW:
+ renderer->setCullMode(sw::CULL_CLOCKWISE);
+ break;
+ default:
+ ASSERT(false);
+ }
+ break;
+ case D3DRS_ZFUNC:
+ switch(value)
+ {
+ case D3DCMP_NEVER:
+ renderer->setDepthCompare(sw::DEPTH_NEVER);
+ break;
+ case D3DCMP_LESS:
+ renderer->setDepthCompare(sw::DEPTH_LESS);
+ break;
+ case D3DCMP_EQUAL:
+ renderer->setDepthCompare(sw::DEPTH_EQUAL);
+ break;
+ case D3DCMP_LESSEQUAL:
+ renderer->setDepthCompare(sw::DEPTH_LESSEQUAL);
+ break;
+ case D3DCMP_GREATER:
+ renderer->setDepthCompare(sw::DEPTH_GREATER);
+ break;
+ case D3DCMP_NOTEQUAL:
+ renderer->setDepthCompare(sw::DEPTH_NOTEQUAL);
+ break;
+ case D3DCMP_GREATEREQUAL:
+ renderer->setDepthCompare(sw::DEPTH_GREATEREQUAL);
+ break;
+ case D3DCMP_ALWAYS:
+ renderer->setDepthCompare(sw::DEPTH_ALWAYS);
+ break;
+ default:
+ ASSERT(false);
+ }
+ break;
+ case D3DRS_ALPHAREF:
+ renderer->setAlphaReference(value & 0x000000FF);
+ break;
+ case D3DRS_ALPHAFUNC:
+ switch(value)
+ {
+ case D3DCMP_NEVER:
+ renderer->setAlphaCompare(sw::ALPHA_NEVER);
+ break;
+ case D3DCMP_LESS:
+ renderer->setAlphaCompare(sw::ALPHA_LESS);
+ break;
+ case D3DCMP_EQUAL:
+ renderer->setAlphaCompare(sw::ALPHA_EQUAL);
+ break;
+ case D3DCMP_LESSEQUAL:
+ renderer->setAlphaCompare(sw::ALPHA_LESSEQUAL);
+ break;
+ case D3DCMP_GREATER:
+ renderer->setAlphaCompare(sw::ALPHA_GREATER);
+ break;
+ case D3DCMP_NOTEQUAL:
+ renderer->setAlphaCompare(sw::ALPHA_NOTEQUAL);
+ break;
+ case D3DCMP_GREATEREQUAL:
+ renderer->setAlphaCompare(sw::ALPHA_GREATEREQUAL);
+ break;
+ case D3DCMP_ALWAYS:
+ renderer->setAlphaCompare(sw::ALPHA_ALWAYS);
+ break;
+ default:
+ ASSERT(false);
+ }
+ break;
+ case D3DRS_DITHERENABLE:
+ // if(!init && value == 1) UNIMPLEMENTED(); // FIXME: Unimplemented
+ break;
+ case D3DRS_ALPHABLENDENABLE:
+ renderer->setAlphaBlendEnable(value != FALSE);
+ break;
+ case D3DRS_FOGENABLE:
+ renderer->setFogEnable(value != FALSE);
+ break;
+ case D3DRS_ZVISIBLE:
+ break; // Not supported
+ case D3DRS_FOGCOLOR:
+ renderer->setFogColor(value);
+ break;
+ case D3DRS_FOGTABLEMODE:
+ switch(value)
+ {
+ case D3DFOG_NONE:
+ renderer->setPixelFogMode(sw::FOG_NONE);
+ break;
+ case D3DFOG_LINEAR:
+ renderer->setPixelFogMode(sw::FOG_LINEAR);
+ break;
+ case D3DFOG_EXP:
+ renderer->setPixelFogMode(sw::FOG_EXP);
+ break;
+ case D3DFOG_EXP2:
+ renderer->setPixelFogMode(sw::FOG_EXP2);
+ break;
+ default:
+ ASSERT(false);
+ }
+ break;
+ case D3DRS_FOGSTART:
+ renderer->setFogStart((float&)value);
+ break;
+ case D3DRS_FOGEND:
+ renderer->setFogEnd((float&)value);
+ break;
+ case D3DRS_FOGDENSITY:
+ renderer->setFogDensity((float&)value);
+ break;
+ case D3DRS_EDGEANTIALIAS:
+ if(!init) if(value != FALSE) UNIMPLEMENTED();
+ break;
+ case D3DRS_ZBIAS:
+ renderer->setDepthBias(-2.0e-6f * value);
+ renderer->setSlopeDepthBias(0.0f);
+ break;
+ case D3DRS_RANGEFOGENABLE:
+ renderer->setRangeFogEnable(value != FALSE);
+ break;
+ case D3DRS_SPECULARENABLE:
+ renderer->setSpecularEnable(value != FALSE);
+ break;
+ case D3DRS_STENCILENABLE:
+ renderer->setStencilEnable(value != FALSE);
+ break;
+ case D3DRS_STENCILFAIL:
+ switch(value)
+ {
+ case D3DSTENCILOP_KEEP:
+ renderer->setStencilFailOperation(sw::OPERATION_KEEP);
+ break;
+ case D3DSTENCILOP_ZERO:
+ renderer->setStencilFailOperation(sw::OPERATION_ZERO);
+ break;
+ case D3DSTENCILOP_REPLACE:
+ renderer->setStencilFailOperation(sw::OPERATION_REPLACE);
+ break;
+ case D3DSTENCILOP_INCRSAT:
+ renderer->setStencilFailOperation(sw::OPERATION_INCRSAT);
+ break;
+ case D3DSTENCILOP_DECRSAT:
+ renderer->setStencilFailOperation(sw::OPERATION_DECRSAT);
+ break;
+ case D3DSTENCILOP_INVERT:
+ renderer->setStencilFailOperation(sw::OPERATION_INVERT);
+ break;
+ case D3DSTENCILOP_INCR:
+ renderer->setStencilFailOperation(sw::OPERATION_INCR);
+ break;
+ case D3DSTENCILOP_DECR:
+ renderer->setStencilFailOperation(sw::OPERATION_DECR);
+ break;
+ default:
+ ASSERT(false);
+ }
+ break;
+ case D3DRS_STENCILZFAIL:
+ switch(value)
+ {
+ case D3DSTENCILOP_KEEP:
+ renderer->setStencilZFailOperation(sw::OPERATION_KEEP);
+ break;
+ case D3DSTENCILOP_ZERO:
+ renderer->setStencilZFailOperation(sw::OPERATION_ZERO);
+ break;
+ case D3DSTENCILOP_REPLACE:
+ renderer->setStencilZFailOperation(sw::OPERATION_REPLACE);
+ break;
+ case D3DSTENCILOP_INCRSAT:
+ renderer->setStencilZFailOperation(sw::OPERATION_INCRSAT);
+ break;
+ case D3DSTENCILOP_DECRSAT:
+ renderer->setStencilZFailOperation(sw::OPERATION_DECRSAT);
+ break;
+ case D3DSTENCILOP_INVERT:
+ renderer->setStencilZFailOperation(sw::OPERATION_INVERT);
+ break;
+ case D3DSTENCILOP_INCR:
+ renderer->setStencilZFailOperation(sw::OPERATION_INCR);
+ break;
+ case D3DSTENCILOP_DECR:
+ renderer->setStencilZFailOperation(sw::OPERATION_DECR);
+ break;
+ default:
+ ASSERT(false);
+ }
+ break;
+ case D3DRS_STENCILPASS:
+ switch(value)
+ {
+ case D3DSTENCILOP_KEEP:
+ renderer->setStencilPassOperation(sw::OPERATION_KEEP);
+ break;
+ case D3DSTENCILOP_ZERO:
+ renderer->setStencilPassOperation(sw::OPERATION_ZERO);
+ break;
+ case D3DSTENCILOP_REPLACE:
+ renderer->setStencilPassOperation(sw::OPERATION_REPLACE);
+ break;
+ case D3DSTENCILOP_INCRSAT:
+ renderer->setStencilPassOperation(sw::OPERATION_INCRSAT);
+ break;
+ case D3DSTENCILOP_DECRSAT:
+ renderer->setStencilPassOperation(sw::OPERATION_DECRSAT);
+ break;
+ case D3DSTENCILOP_INVERT:
+ renderer->setStencilPassOperation(sw::OPERATION_INVERT);
+ break;
+ case D3DSTENCILOP_INCR:
+ renderer->setStencilPassOperation(sw::OPERATION_INCR);
+ break;
+ case D3DSTENCILOP_DECR:
+ renderer->setStencilPassOperation(sw::OPERATION_DECR);
+ break;
+ default:
+ ASSERT(false);
+ }
+ break;
+ case D3DRS_STENCILFUNC:
+ switch(value)
+ {
+ case D3DCMP_NEVER:
+ renderer->setStencilCompare(sw::STENCIL_NEVER);
+ break;
+ case D3DCMP_LESS:
+ renderer->setStencilCompare(sw::STENCIL_LESS);
+ break;
+ case D3DCMP_EQUAL:
+ renderer->setStencilCompare(sw::STENCIL_EQUAL);
+ break;
+ case D3DCMP_LESSEQUAL:
+ renderer->setStencilCompare(sw::STENCIL_LESSEQUAL);
+ break;
+ case D3DCMP_GREATER:
+ renderer->setStencilCompare(sw::STENCIL_GREATER);
+ break;
+ case D3DCMP_NOTEQUAL:
+ renderer->setStencilCompare(sw::STENCIL_NOTEQUAL);
+ break;
+ case D3DCMP_GREATEREQUAL:
+ renderer->setStencilCompare(sw::STENCIL_GREATEREQUAL);
+ break;
+ case D3DCMP_ALWAYS:
+ renderer->setStencilCompare(sw::STENCIL_ALWAYS);
+ break;
+ default:
+ ASSERT(false);
+ }
+ break;
+ case D3DRS_STENCILREF:
+ renderer->setStencilReference(value);
+ renderer->setStencilReferenceCCW(value);
+ break;
+ case D3DRS_STENCILMASK:
+ renderer->setStencilMask(value);
+ renderer->setStencilMaskCCW(value);
+ break;
+ case D3DRS_STENCILWRITEMASK:
+ renderer->setStencilWriteMask(value);
+ renderer->setStencilWriteMaskCCW(value);
+ break;
+ case D3DRS_TEXTUREFACTOR:
+ renderer->setTextureFactor(value);
+ break;
+ case D3DRS_WRAP0:
+ renderer->setTextureWrap(0, value);
+ break;
+ case D3DRS_WRAP1:
+ renderer->setTextureWrap(1, value);
+ break;
+ case D3DRS_WRAP2:
+ renderer->setTextureWrap(2, value);
+ break;
+ case D3DRS_WRAP3:
+ renderer->setTextureWrap(3, value);
+ break;
+ case D3DRS_WRAP4:
+ renderer->setTextureWrap(4, value);
+ break;
+ case D3DRS_WRAP5:
+ renderer->setTextureWrap(5, value);
+ break;
+ case D3DRS_WRAP6:
+ renderer->setTextureWrap(6, value);
+ break;
+ case D3DRS_WRAP7:
+ renderer->setTextureWrap(7, value);
+ break;
+ case D3DRS_CLIPPING:
+ // Ignored, clipping is always performed
+ break;
+ case D3DRS_LIGHTING:
+ renderer->setLightingEnable(value != FALSE);
+ break;
+ case D3DRS_AMBIENT:
+ renderer->setGlobalAmbient(value);
+ break;
+ case D3DRS_FOGVERTEXMODE:
+ switch(value)
+ {
+ case D3DFOG_NONE:
+ renderer->setVertexFogMode(sw::FOG_NONE);
+ break;
+ case D3DFOG_LINEAR:
+ renderer->setVertexFogMode(sw::FOG_LINEAR);
+ break;
+ case D3DFOG_EXP:
+ renderer->setVertexFogMode(sw::FOG_EXP);
+ break;
+ case D3DFOG_EXP2:
+ renderer->setVertexFogMode(sw::FOG_EXP2);
+ break;
+ default:
+ ASSERT(false);
+ }
+ break;
+ case D3DRS_COLORVERTEX:
+ renderer->setColorVertexEnable(value != FALSE);
+ break;
+ case D3DRS_LOCALVIEWER:
+ renderer->setLocalViewer(value != FALSE);
+ break;
+ case D3DRS_NORMALIZENORMALS:
+ renderer->setNormalizeNormals(value != FALSE);
+ break;
+ case D3DRS_DIFFUSEMATERIALSOURCE:
+ switch(value)
+ {
+ case D3DMCS_MATERIAL:
+ renderer->setDiffuseMaterialSource(sw::MATERIAL_MATERIAL);
+ break;
+ case D3DMCS_COLOR1:
+ renderer->setDiffuseMaterialSource(sw::MATERIAL_COLOR1);
+ break;
+ case D3DMCS_COLOR2:
+ renderer->setDiffuseMaterialSource(sw::MATERIAL_COLOR2);
+ break;
+ default:
+ ASSERT(false);
+ }
+ break;
+ case D3DRS_SPECULARMATERIALSOURCE:
+ switch(value)
+ {
+ case D3DMCS_MATERIAL:
+ renderer->setSpecularMaterialSource(sw::MATERIAL_MATERIAL);
+ break;
+ case D3DMCS_COLOR1:
+ renderer->setSpecularMaterialSource(sw::MATERIAL_COLOR1);
+ break;
+ case D3DMCS_COLOR2:
+ renderer->setSpecularMaterialSource(sw::MATERIAL_COLOR2);
+ break;
+ default:
+ ASSERT(false);
+ }
+ break;
+ case D3DRS_AMBIENTMATERIALSOURCE:
+ switch(value)
+ {
+ case D3DMCS_MATERIAL:
+ renderer->setAmbientMaterialSource(sw::MATERIAL_MATERIAL);
+ break;
+ case D3DMCS_COLOR1:
+ renderer->setAmbientMaterialSource(sw::MATERIAL_COLOR1);
+ break;
+ case D3DMCS_COLOR2:
+ renderer->setAmbientMaterialSource(sw::MATERIAL_COLOR2);
+ break;
+ default:
+ ASSERT(false);
+ }
+ break;
+ case D3DRS_EMISSIVEMATERIALSOURCE:
+ switch(value)
+ {
+ case D3DMCS_MATERIAL:
+ renderer->setEmissiveMaterialSource(sw::MATERIAL_MATERIAL);
+ break;
+ case D3DMCS_COLOR1:
+ renderer->setEmissiveMaterialSource(sw::MATERIAL_COLOR1);
+ break;
+ case D3DMCS_COLOR2:
+ renderer->setEmissiveMaterialSource(sw::MATERIAL_COLOR2);
+ break;
+ default:
+ ASSERT(false);
+ }
+ break;
+ case D3DRS_VERTEXBLEND:
+ switch(value)
+ {
+ case D3DVBF_DISABLE:
+ renderer->setVertexBlendMatrixCount(0);
+ break;
+ case D3DVBF_1WEIGHTS:
+ renderer->setVertexBlendMatrixCount(2);
+ break;
+ case D3DVBF_2WEIGHTS:
+ renderer->setVertexBlendMatrixCount(3);
+ break;
+ case D3DVBF_3WEIGHTS:
+ renderer->setVertexBlendMatrixCount(4);
+ break;
+ case D3DVBF_TWEENING:
+ UNIMPLEMENTED();
+ break;
+ case D3DVBF_0WEIGHTS:
+ renderer->setVertexBlendMatrixCount(1);
+ break;
+ default:
+ ASSERT(false);
+ }
+ break;
+ case D3DRS_CLIPPLANEENABLE:
+ renderer->setClipFlags(value);
+ break;
+ case D3DRS_SOFTWAREVERTEXPROCESSING:
+ break;
+ case D3DRS_POINTSIZE:
+ renderer->setPointSize((float&)value);
+ break;
+ case D3DRS_POINTSIZE_MIN:
+ renderer->setPointSizeMin((float&)value);
+ break;
+ case D3DRS_POINTSPRITEENABLE:
+ renderer->setPointSpriteEnable(value != FALSE);
+ break;
+ case D3DRS_POINTSCALEENABLE:
+ renderer->setPointScaleEnable(value != FALSE);
+ break;
+ case D3DRS_POINTSCALE_A:
+ renderer->setPointScaleA((float&)value);
+ break;
+ case D3DRS_POINTSCALE_B:
+ renderer->setPointScaleB((float&)value);
+ break;
+ case D3DRS_POINTSCALE_C:
+ renderer->setPointScaleC((float&)value);
+ break;
+ case D3DRS_MULTISAMPLEANTIALIAS:
+ // if(!init) UNIMPLEMENTED();
+ break;
+ case D3DRS_MULTISAMPLEMASK:
+ SetRenderTarget(renderTarget, depthStencil); // Sets the multi-sample mask, if maskable
+ break;
+ case D3DRS_PATCHEDGESTYLE:
+ // if(!init) UNIMPLEMENTED();
+ break;
+ case D3DRS_PATCHSEGMENTS:
+ // UNIMPLEMENTED(); // FIXME
+ break;
+ case D3DRS_DEBUGMONITORTOKEN:
+ if(!init) UNIMPLEMENTED();
+ break;
+ case D3DRS_POINTSIZE_MAX:
+ renderer->setPointSizeMax((float&)value);
+ break;
+ case D3DRS_INDEXEDVERTEXBLENDENABLE:
+ renderer->setIndexedVertexBlendEnable(value != FALSE);
+ break;
+ case D3DRS_COLORWRITEENABLE:
+ renderer->setColorWriteMask(0, value);
+ break;
+ case D3DRS_TWEENFACTOR:
+ if(!init) UNIMPLEMENTED();
+ break;
+ case D3DRS_BLENDOP:
+ switch(value)
+ {
+ case D3DBLENDOP_ADD:
+ renderer->setBlendOperation(sw::BLENDOP_ADD);
+ break;
+ case D3DBLENDOP_SUBTRACT:
+ renderer->setBlendOperation(sw::BLENDOP_SUB);
+ break;
+ case D3DBLENDOP_REVSUBTRACT:
+ renderer->setBlendOperation(sw::BLENDOP_INVSUB);
+ break;
+ case D3DBLENDOP_MIN:
+ renderer->setBlendOperation(sw::BLENDOP_MIN);
+ break;
+ case D3DBLENDOP_MAX:
+ renderer->setBlendOperation(sw::BLENDOP_MAX);
+ break;
+ default:
+ ASSERT(false);
+ }
+ break;
+ case D3DRS_POSITIONORDER:
+ if(!init) UNIMPLEMENTED();
+ break;
+ case D3DRS_NORMALORDER:
+ if(!init) UNIMPLEMENTED();
+ break;
+ default:
+ ASSERT(false);
+ }
+ }
+ else // stateRecorder
+ {
+ stateRecorder.back()->setRenderState(state, value);
+ }
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::SetRenderTarget(IDirect3DSurface8 *newRenderTarget, IDirect3DSurface8 *newDepthStencil)
+ {
+ TRACE("");
+
+ Direct3DSurface8 *renderTarget = static_cast<Direct3DSurface8*>(newRenderTarget);
+
+ if(renderTarget) // FIXME: Check for D3DUSAGE_RENDERTARGET
+ {
+ renderTarget->bind();
+ }
+
+ if(this->renderTarget)
+ {
+ this->renderTarget->unbind();
+ }
+
+ this->renderTarget = renderTarget;
+
+ Direct3DSurface8 *depthStencil = static_cast<Direct3DSurface8*>(newDepthStencil);
+
+ if(depthStencil) // FIXME: Check for D3DUSAGE_DEPTHSTENCIL and D3DPOOL_DEFAULT
+ {
+ depthStencil->bind();
+ }
+
+ if(this->depthStencil)
+ {
+ this->depthStencil->unbind();
+ }
+
+ this->depthStencil = depthStencil;
+
+ // Reset viewport to size of current render target
+ D3DSURFACE_DESC renderTargetDesc;
+ renderTarget->GetDesc(&renderTargetDesc);
+
+ D3DVIEWPORT8 viewport;
+ viewport.X = 0;
+ viewport.Y = 0;
+ viewport.Width = renderTargetDesc.Width;
+ viewport.Height = renderTargetDesc.Height;
+ viewport.MinZ = 0;
+ viewport.MaxZ = 1;
+
+ SetViewport(&viewport);
+
+ // Set the multi-sample mask, if maskable
+ if(renderTargetDesc.MultiSampleType != D3DMULTISAMPLE_NONE)
+ {
+ renderer->setMultiSampleMask(renderState[D3DRS_MULTISAMPLEMASK]);
+ }
+ else
+ {
+ renderer->setMultiSampleMask(0xFFFFFFFF);
+ }
+
+ renderer->setRenderTarget(0, renderTarget);
+ renderer->setDepthBuffer(depthStencil);
+ renderer->setStencilBuffer(depthStencil);
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::SetStreamSource(unsigned int stream, IDirect3DVertexBuffer8 *iVertexBuffer, unsigned int stride)
+ {
+ TRACE("");
+
+ Direct3DVertexBuffer8 *vertexBuffer = static_cast<Direct3DVertexBuffer8*>(iVertexBuffer);
+
+ if(!recordState)
+ {
+ if(vertexBuffer)
+ {
+ vertexBuffer->bind();
+ }
+
+ if(dataStream[stream])
+ {
+ dataStream[stream]->unbind();
+ streamStride[stream] = 0;
+ }
+
+ dataStream[stream] = vertexBuffer;
+ streamStride[stream] = stride;
+ }
+ else
+ {
+ stateRecorder.back()->setStreamSource(stream, vertexBuffer, stride);
+ }
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::SetTexture(unsigned long stage, IDirect3DBaseTexture8 *iBaseTexture)
+ {
+ TRACE("");
+
+ if(stage >= 8)
+ {
+ return INVALIDCALL();
+ }
+
+ Direct3DBaseTexture8 *baseTexture = dynamic_cast<Direct3DBaseTexture8*>(iBaseTexture);
+
+ if(!recordState)
+ {
+ if(texture[stage] == baseTexture)
+ {
+ return D3D_OK;
+ }
+
+ if(baseTexture)
+ {
+ baseTexture->bind();
+ }
+
+ if(texture[stage])
+ {
+ texture[stage]->unbind();
+ }
+
+ texture[stage] = baseTexture;
+ }
+ else
+ {
+ stateRecorder.back()->setTexture(stage, baseTexture);
+ }
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::SetTextureStageState(unsigned long stage, D3DTEXTURESTAGESTATETYPE type, unsigned long value)
+ {
+ TRACE("unsigned long stage = %d, D3DTEXTURESTAGESTATETYPE type = %d, unsigned long value = %d", stage, type, value);
+
+ if(stage >= 8 || type < 0 || type > D3DTSS_RESULTARG)
+ {
+ return INVALIDCALL();
+ }
+
+ if(!recordState)
+ {
+ if(!init && textureStageState[stage][type] == value)
+ {
+ return D3D_OK;
+ }
+
+ textureStageState[stage][type] = value;
+
+ switch(type)
+ {
+ case D3DTSS_COLOROP:
+ switch(value)
+ {
+ case D3DTOP_DISABLE:
+ renderer->setStageOperation(stage, sw::TextureStage::STAGE_DISABLE);
+ break;
+ case D3DTOP_SELECTARG1:
+ renderer->setStageOperation(stage, sw::TextureStage::STAGE_SELECTARG1);
+ break;
+ case D3DTOP_SELECTARG2:
+ renderer->setStageOperation(stage, sw::TextureStage::STAGE_SELECTARG2);
+ break;
+ case D3DTOP_MODULATE:
+ renderer->setStageOperation(stage, sw::TextureStage::STAGE_MODULATE);
+ break;
+ case D3DTOP_MODULATE2X:
+ renderer->setStageOperation(stage, sw::TextureStage::STAGE_MODULATE2X);
+ break;
+ case D3DTOP_MODULATE4X:
+ renderer->setStageOperation(stage, sw::TextureStage::STAGE_MODULATE4X);
+ break;
+ case D3DTOP_ADD:
+ renderer->setStageOperation(stage, sw::TextureStage::STAGE_ADD);
+ break;
+ case D3DTOP_ADDSIGNED:
+ renderer->setStageOperation(stage, sw::TextureStage::STAGE_ADDSIGNED);
+ break;
+ case D3DTOP_ADDSIGNED2X:
+ renderer->setStageOperation(stage, sw::TextureStage::STAGE_ADDSIGNED2X);
+ break;
+ case D3DTOP_SUBTRACT:
+ renderer->setStageOperation(stage, sw::TextureStage::STAGE_SUBTRACT);
+ break;
+ case D3DTOP_ADDSMOOTH:
+ renderer->setStageOperation(stage, sw::TextureStage::STAGE_ADDSMOOTH);
+ break;
+ case D3DTOP_BLENDDIFFUSEALPHA:
+ renderer->setStageOperation(stage, sw::TextureStage::STAGE_BLENDDIFFUSEALPHA);
+ break;
+ case D3DTOP_BLENDTEXTUREALPHA:
+ renderer->setStageOperation(stage, sw::TextureStage::STAGE_BLENDTEXTUREALPHA);
+ break;
+ case D3DTOP_BLENDFACTORALPHA:
+ renderer->setStageOperation(stage, sw::TextureStage::STAGE_BLENDFACTORALPHA);
+ break;
+ case D3DTOP_BLENDTEXTUREALPHAPM:
+ renderer->setStageOperation(stage, sw::TextureStage::STAGE_BLENDTEXTUREALPHAPM);
+ break;
+ case D3DTOP_BLENDCURRENTALPHA:
+ renderer->setStageOperation(stage, sw::TextureStage::STAGE_BLENDCURRENTALPHA);
+ break;
+ case D3DTOP_PREMODULATE:
+ renderer->setStageOperation(stage, sw::TextureStage::STAGE_PREMODULATE);
+ break;
+ case D3DTOP_MODULATEALPHA_ADDCOLOR:
+ renderer->setStageOperation(stage, sw::TextureStage::STAGE_MODULATEALPHA_ADDCOLOR);
+ break;
+ case D3DTOP_MODULATECOLOR_ADDALPHA:
+ renderer->setStageOperation(stage, sw::TextureStage::STAGE_MODULATECOLOR_ADDALPHA);
+ break;
+ case D3DTOP_MODULATEINVALPHA_ADDCOLOR:
+ renderer->setStageOperation(stage, sw::TextureStage::STAGE_MODULATEINVALPHA_ADDCOLOR);
+ break;
+ case D3DTOP_MODULATEINVCOLOR_ADDALPHA:
+ renderer->setStageOperation(stage, sw::TextureStage::STAGE_MODULATEINVCOLOR_ADDALPHA);
+ break;
+ case D3DTOP_BUMPENVMAP:
+ renderer->setStageOperation(stage, sw::TextureStage::STAGE_BUMPENVMAP);
+ break;
+ case D3DTOP_BUMPENVMAPLUMINANCE:
+ renderer->setStageOperation(stage, sw::TextureStage::STAGE_BUMPENVMAPLUMINANCE);
+ break;
+ case D3DTOP_DOTPRODUCT3:
+ renderer->setStageOperation(stage, sw::TextureStage::STAGE_DOT3);
+ break;
+ case D3DTOP_MULTIPLYADD:
+ renderer->setStageOperation(stage, sw::TextureStage::STAGE_MULTIPLYADD);
+ break;
+ case D3DTOP_LERP:
+ renderer->setStageOperation(stage, sw::TextureStage::STAGE_LERP);
+ break;
+ default:
+ ASSERT(false);
+ }
+ break;
+ case D3DTSS_COLORARG1:
+ switch(value & D3DTA_SELECTMASK)
+ {
+ case D3DTA_DIFFUSE:
+ renderer->setFirstArgument(stage, sw::TextureStage::SOURCE_DIFFUSE);
+ break;
+ case D3DTA_CURRENT:
+ renderer->setFirstArgument(stage, sw::TextureStage::SOURCE_CURRENT);
+ break;
+ case D3DTA_TEXTURE:
+ renderer->setFirstArgument(stage, sw::TextureStage::SOURCE_TEXTURE);
+ break;
+ case D3DTA_TFACTOR:
+ renderer->setFirstArgument(stage, sw::TextureStage::SOURCE_TFACTOR);
+ break;
+ case D3DTA_SPECULAR:
+ renderer->setFirstArgument(stage, sw::TextureStage::SOURCE_SPECULAR);
+ break;
+ case D3DTA_TEMP:
+ renderer->setFirstArgument(stage, sw::TextureStage::SOURCE_TEMP);
+ break;
+ default:
+ ASSERT(false);
+ }
+
+ switch(value & ~D3DTA_SELECTMASK)
+ {
+ case 0:
+ renderer->setFirstModifier(stage, sw::TextureStage::MODIFIER_COLOR);
+ break;
+ case D3DTA_COMPLEMENT:
+ renderer->setFirstModifier(stage, sw::TextureStage::MODIFIER_INVCOLOR);
+ break;
+ case D3DTA_ALPHAREPLICATE:
+ renderer->setFirstModifier(stage, sw::TextureStage::MODIFIER_ALPHA);
+ break;
+ case D3DTA_COMPLEMENT | D3DTA_ALPHAREPLICATE:
+ renderer->setFirstModifier(stage, sw::TextureStage::MODIFIER_INVALPHA);
+ break;
+ default:
+ ASSERT(false);
+ }
+ break;
+ case D3DTSS_COLORARG2:
+ switch(value & D3DTA_SELECTMASK)
+ {
+ case D3DTA_DIFFUSE:
+ renderer->setSecondArgument(stage, sw::TextureStage::SOURCE_DIFFUSE);
+ break;
+ case D3DTA_CURRENT:
+ renderer->setSecondArgument(stage, sw::TextureStage::SOURCE_CURRENT);
+ break;
+ case D3DTA_TEXTURE:
+ renderer->setSecondArgument(stage, sw::TextureStage::SOURCE_TEXTURE);
+ break;
+ case D3DTA_TFACTOR:
+ renderer->setSecondArgument(stage, sw::TextureStage::SOURCE_TFACTOR);
+ break;
+ case D3DTA_SPECULAR:
+ renderer->setSecondArgument(stage, sw::TextureStage::SOURCE_SPECULAR);
+ break;
+ case D3DTA_TEMP:
+ renderer->setSecondArgument(stage, sw::TextureStage::SOURCE_TEMP);
+ break;
+ default:
+ ASSERT(false);
+ }
+
+ switch(value & ~D3DTA_SELECTMASK)
+ {
+ case 0:
+ renderer->setSecondModifier(stage, sw::TextureStage::MODIFIER_COLOR);
+ break;
+ case D3DTA_COMPLEMENT:
+ renderer->setSecondModifier(stage, sw::TextureStage::MODIFIER_INVCOLOR);
+ break;
+ case D3DTA_ALPHAREPLICATE:
+ renderer->setSecondModifier(stage, sw::TextureStage::MODIFIER_ALPHA);
+ break;
+ case D3DTA_COMPLEMENT | D3DTA_ALPHAREPLICATE:
+ renderer->setSecondModifier(stage, sw::TextureStage::MODIFIER_INVALPHA);
+ break;
+ default:
+ ASSERT(false);
+ }
+ break;
+ case D3DTSS_ALPHAOP:
+ switch(value)
+ {
+ case D3DTOP_DISABLE:
+ renderer->setStageOperationAlpha(stage, sw::TextureStage::STAGE_DISABLE);
+ break;
+ case D3DTOP_SELECTARG1:
+ renderer->setStageOperationAlpha(stage, sw::TextureStage::STAGE_SELECTARG1);
+ break;
+ case D3DTOP_SELECTARG2:
+ renderer->setStageOperationAlpha(stage, sw::TextureStage::STAGE_SELECTARG2);
+ break;
+ case D3DTOP_MODULATE:
+ renderer->setStageOperationAlpha(stage, sw::TextureStage::STAGE_MODULATE);
+ break;
+ case D3DTOP_MODULATE2X:
+ renderer->setStageOperationAlpha(stage, sw::TextureStage::STAGE_MODULATE2X);
+ break;
+ case D3DTOP_MODULATE4X:
+ renderer->setStageOperationAlpha(stage, sw::TextureStage::STAGE_MODULATE4X);
+ break;
+ case D3DTOP_ADD:
+ renderer->setStageOperationAlpha(stage, sw::TextureStage::STAGE_ADD);
+ break;
+ case D3DTOP_ADDSIGNED:
+ renderer->setStageOperationAlpha(stage, sw::TextureStage::STAGE_ADDSIGNED);
+ break;
+ case D3DTOP_ADDSIGNED2X:
+ renderer->setStageOperationAlpha(stage, sw::TextureStage::STAGE_ADDSIGNED2X);
+ break;
+ case D3DTOP_SUBTRACT:
+ renderer->setStageOperationAlpha(stage, sw::TextureStage::STAGE_SUBTRACT);
+ break;
+ case D3DTOP_ADDSMOOTH:
+ renderer->setStageOperationAlpha(stage, sw::TextureStage::STAGE_ADDSMOOTH);
+ break;
+ case D3DTOP_BLENDDIFFUSEALPHA:
+ renderer->setStageOperationAlpha(stage, sw::TextureStage::STAGE_BLENDDIFFUSEALPHA);
+ break;
+ case D3DTOP_BLENDTEXTUREALPHA:
+ renderer->setStageOperationAlpha(stage, sw::TextureStage::STAGE_BLENDTEXTUREALPHA);
+ break;
+ case D3DTOP_BLENDFACTORALPHA:
+ renderer->setStageOperationAlpha(stage, sw::TextureStage::STAGE_BLENDFACTORALPHA);
+ break;
+ case D3DTOP_BLENDTEXTUREALPHAPM:
+ renderer->setStageOperationAlpha(stage, sw::TextureStage::STAGE_BLENDTEXTUREALPHAPM);
+ break;
+ case D3DTOP_BLENDCURRENTALPHA:
+ renderer->setStageOperationAlpha(stage, sw::TextureStage::STAGE_BLENDCURRENTALPHA);
+ break;
+ case D3DTOP_PREMODULATE:
+ renderer->setStageOperationAlpha(stage, sw::TextureStage::STAGE_PREMODULATE);
+ break;
+ case D3DTOP_MODULATEALPHA_ADDCOLOR:
+ renderer->setStageOperationAlpha(stage, sw::TextureStage::STAGE_MODULATEALPHA_ADDCOLOR);
+ break;
+ case D3DTOP_MODULATECOLOR_ADDALPHA:
+ renderer->setStageOperationAlpha(stage, sw::TextureStage::STAGE_MODULATECOLOR_ADDALPHA);
+ break;
+ case D3DTOP_MODULATEINVALPHA_ADDCOLOR:
+ renderer->setStageOperationAlpha(stage, sw::TextureStage::STAGE_MODULATEINVALPHA_ADDCOLOR);
+ break;
+ case D3DTOP_MODULATEINVCOLOR_ADDALPHA:
+ renderer->setStageOperationAlpha(stage, sw::TextureStage::STAGE_MODULATEINVCOLOR_ADDALPHA);
+ break;
+ case D3DTOP_BUMPENVMAP:
+ renderer->setStageOperationAlpha(stage, sw::TextureStage::STAGE_BUMPENVMAP);
+ break;
+ case D3DTOP_BUMPENVMAPLUMINANCE:
+ renderer->setStageOperationAlpha(stage, sw::TextureStage::STAGE_BUMPENVMAPLUMINANCE);
+ break;
+ case D3DTOP_DOTPRODUCT3:
+ renderer->setStageOperationAlpha(stage, sw::TextureStage::STAGE_DOT3);
+ break;
+ case D3DTOP_MULTIPLYADD:
+ renderer->setStageOperationAlpha(stage, sw::TextureStage::STAGE_MULTIPLYADD);
+ break;
+ case D3DTOP_LERP:
+ renderer->setStageOperationAlpha(stage, sw::TextureStage::STAGE_LERP);
+ break;
+ default:
+ ASSERT(false);
+ }
+ break;
+ case D3DTSS_ALPHAARG1:
+ switch(value & D3DTA_SELECTMASK)
+ {
+ case D3DTA_DIFFUSE:
+ renderer->setFirstArgumentAlpha(stage, sw::TextureStage::SOURCE_DIFFUSE);
+ break;
+ case D3DTA_CURRENT:
+ renderer->setFirstArgumentAlpha(stage, sw::TextureStage::SOURCE_CURRENT);
+ break;
+ case D3DTA_TEXTURE:
+ renderer->setFirstArgumentAlpha(stage, sw::TextureStage::SOURCE_TEXTURE);
+ break;
+ case D3DTA_TFACTOR:
+ renderer->setFirstArgumentAlpha(stage, sw::TextureStage::SOURCE_TFACTOR);
+ break;
+ case D3DTA_SPECULAR:
+ renderer->setFirstArgumentAlpha(stage, sw::TextureStage::SOURCE_SPECULAR);
+ break;
+ case D3DTA_TEMP:
+ renderer->setFirstArgumentAlpha(stage, sw::TextureStage::SOURCE_TEMP);
+ break;
+ default:
+ ASSERT(false);
+ }
+
+ switch(value & ~D3DTA_SELECTMASK)
+ {
+ case 0:
+ renderer->setFirstModifierAlpha(stage, sw::TextureStage::MODIFIER_COLOR);
+ break;
+ case D3DTA_COMPLEMENT:
+ renderer->setFirstModifierAlpha(stage, sw::TextureStage::MODIFIER_INVCOLOR);
+ break;
+ case D3DTA_ALPHAREPLICATE:
+ renderer->setFirstModifierAlpha(stage, sw::TextureStage::MODIFIER_ALPHA);
+ break;
+ case D3DTA_COMPLEMENT | D3DTA_ALPHAREPLICATE:
+ renderer->setSecondModifier(stage, sw::TextureStage::MODIFIER_INVALPHA);
+ break;
+ default:
+ ASSERT(false);
+ }
+ break;
+ case D3DTSS_ALPHAARG2:
+ switch(value & D3DTA_SELECTMASK)
+ {
+ case D3DTA_DIFFUSE:
+ renderer->setSecondArgumentAlpha(stage, sw::TextureStage::SOURCE_DIFFUSE);
+ break;
+ case D3DTA_CURRENT:
+ renderer->setSecondArgumentAlpha(stage, sw::TextureStage::SOURCE_CURRENT);
+ break;
+ case D3DTA_TEXTURE:
+ renderer->setSecondArgumentAlpha(stage, sw::TextureStage::SOURCE_TEXTURE);
+ break;
+ case D3DTA_TFACTOR:
+ renderer->setSecondArgumentAlpha(stage, sw::TextureStage::SOURCE_TFACTOR);
+ break;
+ case D3DTA_SPECULAR:
+ renderer->setSecondArgumentAlpha(stage, sw::TextureStage::SOURCE_SPECULAR);
+ break;
+ case D3DTA_TEMP:
+ renderer->setSecondArgumentAlpha(stage, sw::TextureStage::SOURCE_TEMP);
+ break;
+ default:
+ ASSERT(false);
+ }
+
+ switch(value & ~D3DTA_SELECTMASK)
+ {
+ case 0:
+ renderer->setSecondModifierAlpha(stage, sw::TextureStage::MODIFIER_COLOR);
+ break;
+ case D3DTA_COMPLEMENT:
+ renderer->setSecondModifierAlpha(stage, sw::TextureStage::MODIFIER_INVCOLOR);
+ break;
+ case D3DTA_ALPHAREPLICATE:
+ renderer->setSecondModifierAlpha(stage, sw::TextureStage::MODIFIER_ALPHA);
+ break;
+ case D3DTA_COMPLEMENT | D3DTA_ALPHAREPLICATE:
+ renderer->setSecondModifierAlpha(stage, sw::TextureStage::MODIFIER_INVALPHA);
+ break;
+ default:
+ ASSERT(false);
+ }
+ break;
+ case D3DTSS_BUMPENVMAT00:
+ renderer->setBumpmapMatrix(stage, 0, (float&)value);
+ break;
+ case D3DTSS_BUMPENVMAT01:
+ renderer->setBumpmapMatrix(stage, 1, (float&)value);
+ break;
+ case D3DTSS_BUMPENVMAT10:
+ renderer->setBumpmapMatrix(stage, 2, (float&)value);
+ break;
+ case D3DTSS_BUMPENVMAT11:
+ renderer->setBumpmapMatrix(stage, 3, (float&)value);
+ break;
+ case D3DTSS_TEXCOORDINDEX:
+ renderer->setTexCoordIndex(stage, value & 0xFFFF);
+
+ switch(value & 0xFFFF0000)
+ {
+ case D3DTSS_TCI_PASSTHRU:
+ renderer->setTexGen(stage, sw::TEXGEN_PASSTHRU);
+ break;
+ case D3DTSS_TCI_CAMERASPACENORMAL:
+ renderer->setTexCoordIndex(stage, stage);
+ renderer->setTexGen(stage, sw::TEXGEN_NORMAL);
+ break;
+ case D3DTSS_TCI_CAMERASPACEPOSITION:
+ renderer->setTexCoordIndex(stage, stage);
+ renderer->setTexGen(stage, sw::TEXGEN_POSITION);
+ break;
+ case D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR:
+ renderer->setTexCoordIndex(stage, stage);
+ renderer->setTexGen(stage, sw::TEXGEN_REFLECTION);
+ break;
+ default:
+ ASSERT(false);
+ }
+ break;
+ case D3DTSS_ADDRESSU:
+ switch(value)
+ {
+ case D3DTADDRESS_WRAP:
+ renderer->setAddressingModeU(sw::SAMPLER_PIXEL, stage, sw::ADDRESSING_WRAP);
+ break;
+ case D3DTADDRESS_MIRROR:
+ renderer->setAddressingModeU(sw::SAMPLER_PIXEL, stage, sw::ADDRESSING_MIRROR);
+ break;
+ case D3DTADDRESS_CLAMP:
+ renderer->setAddressingModeU(sw::SAMPLER_PIXEL, stage, sw::ADDRESSING_CLAMP);
+ break;
+ case D3DTADDRESS_BORDER:
+ renderer->setAddressingModeU(sw::SAMPLER_PIXEL, stage, sw::ADDRESSING_BORDER);
+ break;
+ case D3DTADDRESS_MIRRORONCE:
+ renderer->setAddressingModeU(sw::SAMPLER_PIXEL, stage, sw::ADDRESSING_MIRRORONCE);
+ break;
+ default:
+ ASSERT(false);
+ }
+ break;
+ case D3DTSS_ADDRESSV:
+ switch(value)
+ {
+ case D3DTADDRESS_WRAP:
+ renderer->setAddressingModeV(sw::SAMPLER_PIXEL, stage, sw::ADDRESSING_WRAP);
+ break;
+ case D3DTADDRESS_MIRROR:
+ renderer->setAddressingModeV(sw::SAMPLER_PIXEL, stage, sw::ADDRESSING_MIRROR);
+ break;
+ case D3DTADDRESS_CLAMP:
+ renderer->setAddressingModeV(sw::SAMPLER_PIXEL, stage, sw::ADDRESSING_CLAMP);
+ break;
+ case D3DTADDRESS_BORDER:
+ renderer->setAddressingModeV(sw::SAMPLER_PIXEL, stage, sw::ADDRESSING_BORDER);
+ break;
+ case D3DTADDRESS_MIRRORONCE:
+ renderer->setAddressingModeV(sw::SAMPLER_PIXEL, stage, sw::ADDRESSING_MIRRORONCE);
+ break;
+ default:
+ ASSERT(false);
+ }
+ break;
+ case D3DTSS_BORDERCOLOR:
+ renderer->setBorderColor(sw::SAMPLER_PIXEL, stage, value);
+ break;
+ case D3DTSS_MAGFILTER:
+ // NOTE: SwiftShader does not differentiate between minification and magnification filter
+ switch(value)
+ {
+ case D3DTEXF_NONE:
+ renderer->setTextureFilter(sw::SAMPLER_PIXEL, stage, sw::FILTER_POINT);
+ break;
+ case D3DTEXF_POINT:
+ renderer->setTextureFilter(sw::SAMPLER_PIXEL, stage, sw::FILTER_POINT);
+ break;
+ case D3DTEXF_LINEAR:
+ renderer->setTextureFilter(sw::SAMPLER_PIXEL, stage, sw::FILTER_LINEAR);
+ break;
+ case D3DTEXF_ANISOTROPIC:
+ renderer->setTextureFilter(sw::SAMPLER_PIXEL, stage, sw::FILTER_ANISOTROPIC);
+ break;
+ case D3DTEXF_FLATCUBIC:
+ renderer->setTextureFilter(sw::SAMPLER_PIXEL, stage, sw::FILTER_LINEAR); // NOTE: Unimplemented, fail silently
+ break;
+ case D3DTEXF_GAUSSIANCUBIC:
+ renderer->setTextureFilter(sw::SAMPLER_PIXEL, stage, sw::FILTER_LINEAR); // NOTE: Unimplemented, fail silently
+ break;
+ default:
+ return INVALIDCALL();
+ };
+ break;
+ case D3DTSS_MINFILTER:
+ // NOTE: SwiftShader does not differentiate between minification and magnification filter
+ switch(value)
+ {
+ case D3DTEXF_NONE:
+ renderer->setTextureFilter(sw::SAMPLER_PIXEL, stage, sw::FILTER_POINT);
+ break;
+ case D3DTEXF_POINT:
+ renderer->setTextureFilter(sw::SAMPLER_PIXEL, stage, sw::FILTER_POINT);
+ break;
+ case D3DTEXF_LINEAR:
+ renderer->setTextureFilter(sw::SAMPLER_PIXEL, stage, sw::FILTER_LINEAR);
+ break;
+ case D3DTEXF_ANISOTROPIC:
+ renderer->setTextureFilter(sw::SAMPLER_PIXEL, stage, sw::FILTER_ANISOTROPIC);
+ break;
+ case D3DTEXF_FLATCUBIC:
+ renderer->setTextureFilter(sw::SAMPLER_PIXEL, stage, sw::FILTER_LINEAR); // NOTE: Unimplemented, fail silently
+ break;
+ case D3DTEXF_GAUSSIANCUBIC:
+ renderer->setTextureFilter(sw::SAMPLER_PIXEL, stage, sw::FILTER_LINEAR); // NOTE: Unimplemented, fail silently
+ break;
+ default:
+ return INVALIDCALL();
+ };
+ break;
+ case D3DTSS_MIPFILTER:
+ switch(value)
+ {
+ case D3DTEXF_NONE:
+ renderer->setMipmapFilter(sw::SAMPLER_PIXEL, stage, sw::MIPMAP_NONE);
+ break;
+ case D3DTEXF_POINT:
+ renderer->setMipmapFilter(sw::SAMPLER_PIXEL, stage, sw::MIPMAP_POINT);
+ break;
+ case D3DTEXF_LINEAR:
+ renderer->setMipmapFilter(sw::SAMPLER_PIXEL, stage, sw::MIPMAP_LINEAR);
+ break;
+ case D3DTEXF_ANISOTROPIC:
+ renderer->setMipmapFilter(sw::SAMPLER_PIXEL, stage, sw::MIPMAP_LINEAR); // NOTE: Unimplemented, fail silently
+ break;
+ case D3DTEXF_FLATCUBIC:
+ renderer->setMipmapFilter(sw::SAMPLER_PIXEL, stage, sw::MIPMAP_LINEAR); // NOTE: Unimplemented, fail silently
+ break;
+ case D3DTEXF_GAUSSIANCUBIC:
+ renderer->setMipmapFilter(sw::SAMPLER_PIXEL, stage, sw::MIPMAP_LINEAR); // NOTE: Unimplemented, fail silently
+ break;
+ default:
+ return INVALIDCALL();
+ };
+ break;
+ case D3DTSS_MIPMAPLODBIAS:
+ {
+ float LOD = (float&)value - sw::log2((float)context->renderTarget[0]->getSuperSampleCount()); // FIXME: Update when render target changes
+ renderer->setMipmapLOD(sw::SAMPLER_PIXEL, stage, LOD);
+ }
+ break;
+ case D3DTSS_MAXMIPLEVEL:
+ break;
+ case D3DTSS_MAXANISOTROPY:
+ renderer->setMaxAnisotropy(sw::SAMPLER_PIXEL, stage, sw::clamp((unsigned int)value, (unsigned int)1, maxAnisotropy));
+ break;
+ case D3DTSS_BUMPENVLSCALE:
+ renderer->setLuminanceScale(stage, (float&)value);
+ break;
+ case D3DTSS_BUMPENVLOFFSET:
+ renderer->setLuminanceOffset(stage, (float&)value);
+ break;
+ case D3DTSS_TEXTURETRANSFORMFLAGS:
+ switch(value & ~D3DTTFF_PROJECTED)
+ {
+ case D3DTTFF_DISABLE:
+ renderer->setTextureTransform(stage, 0, (value & D3DTTFF_PROJECTED) == D3DTTFF_PROJECTED);
+ break;
+ case D3DTTFF_COUNT1:
+ renderer->setTextureTransform(stage, 1, (value & D3DTTFF_PROJECTED) == D3DTTFF_PROJECTED);
+ break;
+ case D3DTTFF_COUNT2:
+ renderer->setTextureTransform(stage, 2, (value & D3DTTFF_PROJECTED) == D3DTTFF_PROJECTED);
+ break;
+ case D3DTTFF_COUNT3:
+ renderer->setTextureTransform(stage, 3, (value & D3DTTFF_PROJECTED) == D3DTTFF_PROJECTED);
+ break;
+ case D3DTTFF_COUNT4:
+ renderer->setTextureTransform(stage, 4, (value & D3DTTFF_PROJECTED) == D3DTTFF_PROJECTED);
+ break;
+ default:
+ ASSERT(false);
+ }
+ break;
+ case D3DTSS_ADDRESSW:
+ switch(value)
+ {
+ case D3DTADDRESS_WRAP:
+ renderer->setAddressingModeW(sw::SAMPLER_PIXEL, stage, sw::ADDRESSING_WRAP);
+ break;
+ case D3DTADDRESS_MIRROR:
+ renderer->setAddressingModeW(sw::SAMPLER_PIXEL, stage, sw::ADDRESSING_MIRROR);
+ break;
+ case D3DTADDRESS_CLAMP:
+ renderer->setAddressingModeW(sw::SAMPLER_PIXEL, stage, sw::ADDRESSING_CLAMP);
+ break;
+ case D3DTADDRESS_BORDER:
+ renderer->setAddressingModeW(sw::SAMPLER_PIXEL, stage, sw::ADDRESSING_BORDER);
+ break;
+ case D3DTADDRESS_MIRRORONCE:
+ renderer->setAddressingModeW(sw::SAMPLER_PIXEL, stage, sw::ADDRESSING_MIRRORONCE);
+ break;
+ default:
+ ASSERT(false);
+ }
+ break;
+ case D3DTSS_COLORARG0:
+ switch(value & D3DTA_SELECTMASK)
+ {
+ case D3DTA_CURRENT:
+ renderer->setThirdArgument(stage, sw::TextureStage::SOURCE_CURRENT);
+ break;
+ case D3DTA_DIFFUSE:
+ renderer->setThirdArgument(stage, sw::TextureStage::SOURCE_DIFFUSE);
+ break;
+ case D3DTA_SPECULAR:
+ renderer->setThirdArgument(stage, sw::TextureStage::SOURCE_SPECULAR);
+ break;
+ case D3DTA_TEMP:
+ renderer->setThirdArgument(stage, sw::TextureStage::SOURCE_TEMP);
+ break;
+ case D3DTA_TEXTURE:
+ renderer->setThirdArgument(stage, sw::TextureStage::SOURCE_TEXTURE);
+ break;
+ case D3DTA_TFACTOR:
+ renderer->setThirdArgument(stage, sw::TextureStage::SOURCE_TFACTOR);
+ break;
+ default:
+ ASSERT(false);
+ }
+
+ switch(value & ~D3DTA_SELECTMASK)
+ {
+ case 0:
+ renderer->setThirdModifier(stage, sw::TextureStage::MODIFIER_COLOR);
+ break;
+ case D3DTA_COMPLEMENT:
+ renderer->setThirdModifier(stage, sw::TextureStage::MODIFIER_INVCOLOR);
+ break;
+ case D3DTA_ALPHAREPLICATE:
+ renderer->setThirdModifier(stage, sw::TextureStage::MODIFIER_ALPHA);
+ break;
+ case D3DTA_COMPLEMENT | D3DTA_ALPHAREPLICATE:
+ renderer->setThirdModifier(stage, sw::TextureStage::MODIFIER_INVALPHA);
+ break;
+ default:
+ ASSERT(false);
+ }
+ break;
+ case D3DTSS_ALPHAARG0:
+ switch(value & D3DTA_SELECTMASK)
+ {
+ case D3DTA_DIFFUSE:
+ renderer->setThirdArgumentAlpha(stage, sw::TextureStage::SOURCE_DIFFUSE);
+ break;
+ case D3DTA_CURRENT:
+ renderer->setThirdArgumentAlpha(stage, sw::TextureStage::SOURCE_CURRENT);
+ break;
+ case D3DTA_TEXTURE:
+ renderer->setThirdArgumentAlpha(stage, sw::TextureStage::SOURCE_TEXTURE);
+ break;
+ case D3DTA_TFACTOR:
+ renderer->setThirdArgumentAlpha(stage, sw::TextureStage::SOURCE_TFACTOR);
+ break;
+ case D3DTA_SPECULAR:
+ renderer->setThirdArgumentAlpha(stage, sw::TextureStage::SOURCE_SPECULAR);
+ break;
+ case D3DTA_TEMP:
+ renderer->setThirdArgumentAlpha(stage, sw::TextureStage::SOURCE_TEMP);
+ break;
+ default:
+ ASSERT(false);
+ }
+
+ switch(value & ~D3DTA_SELECTMASK)
+ {
+ case 0:
+ renderer->setThirdModifierAlpha(stage, sw::TextureStage::MODIFIER_COLOR);
+ break;
+ case D3DTA_COMPLEMENT:
+ renderer->setThirdModifierAlpha(stage, sw::TextureStage::MODIFIER_INVCOLOR);
+ break;
+ case D3DTA_ALPHAREPLICATE:
+ renderer->setThirdModifierAlpha(stage, sw::TextureStage::MODIFIER_ALPHA);
+ break;
+ case D3DTA_COMPLEMENT | D3DTA_ALPHAREPLICATE:
+ renderer->setThirdModifierAlpha(stage, sw::TextureStage::MODIFIER_INVALPHA);
+ break;
+ default:
+ ASSERT(false);
+ }
+ break;
+ case D3DTSS_RESULTARG:
+ switch(value & D3DTA_SELECTMASK)
+ {
+ case D3DTA_CURRENT:
+ renderer->setDestinationArgument(stage, sw::TextureStage::DESTINATION_CURRENT);
+ break;
+ case D3DTA_TEMP:
+ renderer->setDestinationArgument(stage, sw::TextureStage::DESTINATION_TEMP);
+ break;
+ default:
+ ASSERT(false);
+ }
+ break;
+ default:
+ ASSERT(false);
+ }
+ }
+ else // stateRecorder
+ {
+ stateRecorder.back()->setTextureStageState(stage, type, value);
+ }
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::SetTransform(D3DTRANSFORMSTATETYPE state, const D3DMATRIX *matrix)
+ {
+ TRACE("");
+
+ if(!matrix || state < 0 || state > 511)
+ {
+ return INVALIDCALL();
+ }
+
+ if(!recordState)
+ {
+ this->matrix[state] = *matrix;
+
+ sw::Matrix M(matrix->_11, matrix->_21, matrix->_31, matrix->_41,
+ matrix->_12, matrix->_22, matrix->_32, matrix->_42,
+ matrix->_13, matrix->_23, matrix->_33, matrix->_43,
+ matrix->_14, matrix->_24, matrix->_34, matrix->_44);
+
+ switch(state)
+ {
+ case D3DTS_WORLD:
+ renderer->setModelMatrix(M);
+ break;
+ case D3DTS_VIEW:
+ renderer->setViewMatrix(M);
+ break;
+ case D3DTS_PROJECTION:
+ renderer->setProjectionMatrix(M);
+ break;
+ case D3DTS_TEXTURE0:
+ renderer->setTextureMatrix(0, M);
+ break;
+ case D3DTS_TEXTURE1:
+ renderer->setTextureMatrix(1, M);
+ break;
+ case D3DTS_TEXTURE2:
+ renderer->setTextureMatrix(2, M);
+ break;
+ case D3DTS_TEXTURE3:
+ renderer->setTextureMatrix(3, M);
+ break;
+ case D3DTS_TEXTURE4:
+ renderer->setTextureMatrix(4, M);
+ break;
+ case D3DTS_TEXTURE5:
+ renderer->setTextureMatrix(5, M);
+ break;
+ case D3DTS_TEXTURE6:
+ renderer->setTextureMatrix(6, M);
+ break;
+ case D3DTS_TEXTURE7:
+ renderer->setTextureMatrix(7, M);
+ break;
+ default:
+ if(state > 256 && state < 512)
+ {
+ renderer->setModelMatrix(M, state - 256);
+ }
+ else ASSERT(false);
+ }
+ }
+ else // stateRecorder
+ {
+ stateRecorder.back()->setTransform(state, matrix);
+ }
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::SetVertexShader(unsigned long handle)
+ {
+ TRACE("");
+
+ if(!recordState)
+ {
+ if(handle & 0x00000001)
+ {
+ unsigned int index = handle >> 16;
+
+ if(vertexShader[index])
+ {
+ vertexShader[index]->bind();
+ }
+
+ if(vertexShader[vertexShaderHandle >> 16])
+ {
+ vertexShader[vertexShaderHandle >> 16]->unbind();
+ }
+
+ vertexShaderHandle = handle;
+
+ Direct3DVertexShader8 *shader = vertexShader[index];
+ renderer->setVertexShader(shader->getVertexShader());
+ declaration = shader->getDeclaration();
+
+ FVF = 0;
+ }
+ else
+ {
+ renderer->setVertexShader(0);
+ declaration = 0;
+
+ FVF = handle;
+ }
+ }
+ else
+ {
+ stateRecorder.back()->setVertexShader(handle);
+ }
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::SetVertexShaderConstant(unsigned long startRegister, const void *constantData, unsigned long count)
+ {
+ TRACE("");
+
+ if(!constantData)
+ {
+ return INVALIDCALL();
+ }
+
+ if(!recordState)
+ {
+ for(unsigned int i = 0; i < count; i++)
+ {
+ vertexShaderConstant[startRegister + i][0] = ((float*)constantData)[i * 4 + 0];
+ vertexShaderConstant[startRegister + i][1] = ((float*)constantData)[i * 4 + 1];
+ vertexShaderConstant[startRegister + i][2] = ((float*)constantData)[i * 4 + 2];
+ vertexShaderConstant[startRegister + i][3] = ((float*)constantData)[i * 4 + 3];
+ }
+
+ renderer->setVertexShaderConstantF(startRegister, (const float*)constantData, count);
+ }
+ else
+ {
+ stateRecorder.back()->setVertexShaderConstant(startRegister, constantData, count);
+ }
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::SetViewport(const D3DVIEWPORT8 *viewport)
+ {
+ TRACE("");
+
+ if(!viewport)
+ {
+ return INVALIDCALL();
+ }
+
+ if(!recordState)
+ {
+ this->viewport = *viewport;
+ }
+ else
+ {
+ stateRecorder.back()->setViewport(viewport);
+ }
+
+ return D3D_OK;
+ }
+
+ int Direct3DDevice8::ShowCursor(int show)
+ {
+ TRACE("");
+
+ int oldValue = showCursor ? TRUE : FALSE;
+
+ showCursor = show != FALSE && cursor;
+
+ bindCursor();
+
+ return oldValue;
+ }
+
+ long Direct3DDevice8::TestCooperativeLevel()
+ {
+ TRACE("");
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::UpdateTexture(IDirect3DBaseTexture8 *sourceTexture, IDirect3DBaseTexture8 *destinationTexture)
+ {
+ TRACE("");
+
+ if(!sourceTexture || !destinationTexture)
+ {
+ return INVALIDCALL();
+ }
+
+ D3DRESOURCETYPE type = sourceTexture->GetType();
+
+ if(type != destinationTexture->GetType())
+ {
+ return INVALIDCALL();
+ }
+
+ switch(type)
+ {
+ case D3DRTYPE_TEXTURE:
+ {
+ IDirect3DTexture8 *source;
+ IDirect3DTexture8 *dest;
+
+ sourceTexture->QueryInterface(IID_IDirect3DTexture8, (void**)&source);
+ destinationTexture->QueryInterface(IID_IDirect3DTexture8, (void**)&dest);
+
+ ASSERT(source && dest);
+
+ for(unsigned int level = 0; level < source->GetLevelCount() && level < dest->GetLevelCount(); level++)
+ {
+ IDirect3DSurface8 *sourceSurface;
+ IDirect3DSurface8 *destinationSurface;
+
+ source->GetSurfaceLevel(level, &sourceSurface);
+ dest->GetSurfaceLevel(level, &destinationSurface);
+
+ updateSurface(sourceSurface, 0, destinationSurface, 0);
+
+ sourceSurface->Release();
+ destinationSurface->Release();
+ }
+
+ source->Release();
+ dest->Release();
+ }
+ break;
+ case D3DRTYPE_VOLUMETEXTURE:
+ {
+ IDirect3DVolumeTexture8 *source;
+ IDirect3DVolumeTexture8 *dest;
+
+ sourceTexture->QueryInterface(IID_IDirect3DVolumeTexture8, (void**)&source);
+ destinationTexture->QueryInterface(IID_IDirect3DVolumeTexture8, (void**)&dest);
+
+ ASSERT(source && dest);
+
+ for(unsigned int level = 0; level < source->GetLevelCount() && level < dest->GetLevelCount(); level++) // FIXME: Fail when source texture has fewer levels than the destination
+ {
+ IDirect3DVolume8 *sourceVolume;
+ IDirect3DVolume8 *destinationVolume;
+
+ source->GetVolumeLevel(level, &sourceVolume);
+ dest->GetVolumeLevel(level, &destinationVolume);
+
+ updateVolume(sourceVolume, destinationVolume);
+
+ sourceVolume->Release();
+ destinationVolume->Release();
+ }
+
+ source->Release();
+ dest->Release();
+ }
+ break;
+ case D3DRTYPE_CUBETEXTURE:
+ {
+ IDirect3DCubeTexture8 *source;
+ IDirect3DCubeTexture8 *dest;
+
+ sourceTexture->QueryInterface(IID_IDirect3DCubeTexture8, (void**)&source);
+ destinationTexture->QueryInterface(IID_IDirect3DCubeTexture8, (void**)&dest);
+
+ ASSERT(source && dest);
+
+ for(int face = 0; face < 6; face++)
+ {
+ for(unsigned int level = 0; level < source->GetLevelCount() && level < dest->GetLevelCount(); level++)
+ {
+ IDirect3DSurface8 *sourceSurface;
+ IDirect3DSurface8 *destinationSurface;
+
+ source->GetCubeMapSurface((D3DCUBEMAP_FACES)face, level, &sourceSurface);
+ dest->GetCubeMapSurface((D3DCUBEMAP_FACES)face, level, &destinationSurface);
+
+ updateSurface(sourceSurface, 0, destinationSurface, 0);
+
+ sourceSurface->Release();
+ destinationSurface->Release();
+ }
+ }
+
+ source->Release();
+ dest->Release();
+ }
+ break;
+ default:
+ ASSERT(false);
+ }
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::ValidateDevice(unsigned long *numPasses)
+ {
+ TRACE("");
+
+ if(!numPasses)
+ {
+ return INVALIDCALL();
+ }
+
+ *numPasses = 1;
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::updateSurface(IDirect3DSurface8 *sourceSurface, const RECT *sourceRect, IDirect3DSurface8 *destinationSurface, const POINT *destPoint)
+ {
+ TRACE("IDirect3DSurface8 *sourceSurface = 0x%0.8p, const RECT *sourceRect = 0x%0.8p, IDirect3DSurface8 *destinationSurface = 0x%0.8p, const POINT *destPoint = 0x%0.8p", sourceSurface, sourceRect, destinationSurface, destPoint);
+
+ if(!sourceSurface || !destinationSurface)
+ {
+ return INVALIDCALL();
+ }
+
+ D3DSURFACE_DESC sourceDescription;
+ D3DSURFACE_DESC destinationDescription;
+
+ sourceSurface->GetDesc(&sourceDescription);
+ destinationSurface->GetDesc(&destinationDescription);
+
+ RECT sRect;
+ RECT dRect;
+
+ if(sourceRect && destPoint)
+ {
+ sRect.left = sourceRect->left;
+ sRect.top = sourceRect->top;
+ sRect.right = sourceRect->right;
+ sRect.bottom = sourceRect->bottom;
+
+ dRect.left = destPoint->x;
+ dRect.top = destPoint->y;
+ dRect.right = destPoint->x + sourceRect->right - sourceRect->left;
+ dRect.bottom = destPoint->y + sourceRect->bottom - sourceRect->top;
+ }
+ else
+ {
+ sRect.left = 0;
+ sRect.top = 0;
+ sRect.right = sourceDescription.Width;
+ sRect.bottom = sourceDescription.Height;
+
+ dRect.left = 0;
+ dRect.top = 0;
+ dRect.right = destinationDescription.Width;
+ dRect.bottom = destinationDescription.Height;
+ }
+
+ int sWidth = sRect.right - sRect.left;
+ int sHeight = sRect.bottom - sRect.top;
+
+ int dWidth = dRect.right - dRect.left;
+ int dHeight = dRect.bottom - dRect.top;
+
+ if(sourceDescription.MultiSampleType != D3DMULTISAMPLE_NONE ||
+ destinationDescription.MultiSampleType != D3DMULTISAMPLE_NONE ||
+ // sourceDescription.Pool != D3DPOOL_SYSTEMMEM || // FIXME: Check back buffer and depth buffer memory pool flags
+ // destinationDescription.Pool != D3DPOOL_DEFAULT ||
+ sourceDescription.Format != destinationDescription.Format ||
+ sWidth != dWidth ||
+ sHeight != dHeight)
+ {
+ return INVALIDCALL();
+ }
+
+ D3DLOCKED_RECT sourceLock;
+ D3DLOCKED_RECT destinationLock;
+
+ sourceSurface->LockRect(&sourceLock, &sRect, D3DLOCK_READONLY);
+ destinationSurface->LockRect(&destinationLock, &dRect, 0);
+
+ unsigned int width;
+ unsigned int height;
+ unsigned int bytes;
+
+ switch(sourceDescription.Format)
+ {
+ case D3DFMT_DXT1:
+ width = (dWidth + 3) / 4;
+ height = (dHeight + 3) / 4;
+ bytes = width * 8; // 64 bit per 4x4 block
+ break;
+ case D3DFMT_DXT2:
+ case D3DFMT_DXT3:
+ case D3DFMT_DXT4:
+ case D3DFMT_DXT5:
+ width = (dWidth + 3) / 4;
+ height = (dHeight + 3) / 4;
+ bytes = width * 16; // 128 bit per 4x4 block
+ break;
+ default:
+ width = dWidth;
+ height = dHeight;
+ bytes = width * Direct3DSurface8::bytes(sourceDescription.Format);
+ }
+
+ for(unsigned int y = 0; y < height; y++)
+ {
+ memcpy(destinationLock.pBits, sourceLock.pBits, bytes);
+
+ (byte*&)sourceLock.pBits += sourceLock.Pitch;
+ (byte*&)destinationLock.pBits += destinationLock.Pitch;
+ }
+
+ sourceSurface->UnlockRect();
+ destinationSurface->UnlockRect();
+
+ return D3D_OK;
+ }
+
+ long Direct3DDevice8::SetIndices(IDirect3DIndexBuffer8 *iIndexBuffer, unsigned int baseVertexIndex)
+ {
+ TRACE("");
+
+ Direct3DIndexBuffer8 *indexBuffer = static_cast<Direct3DIndexBuffer8*>(iIndexBuffer);
+
+ if(!recordState)
+ {
+ if(indexBuffer)
+ {
+ indexBuffer->bind();
+ }
+
+ if(this->indexData)
+ {
+ this->indexData->unbind();
+ }
+
+ this->indexData = indexBuffer;
+ this->baseVertexIndex = baseVertexIndex;
+ }
+ else
+ {
+ stateRecorder.back()->setIndices(indexBuffer, baseVertexIndex);
+ }
+
+ return D3D_OK;
+ }
+
+ int Direct3DDevice8::FVFStride(unsigned long FVF)
+ {
+ int stride = 0;
+
+ switch(FVF & D3DFVF_POSITION_MASK)
+ {
+ case D3DFVF_XYZ: stride += 12; break;
+ case D3DFVF_XYZRHW: stride += 16; break;
+ case D3DFVF_XYZB1: stride += 16; break;
+ case D3DFVF_XYZB2: stride += 20; break;
+ case D3DFVF_XYZB3: stride += 24; break;
+ case D3DFVF_XYZB4: stride += 28; break;
+ case D3DFVF_XYZB5: stride += 32; break;
+ }
+
+ if(FVF & D3DFVF_NORMAL) stride += 12;
+ if(FVF & D3DFVF_PSIZE) stride += 4;
+ if(FVF & D3DFVF_DIFFUSE) stride += 4;
+ if(FVF & D3DFVF_SPECULAR) stride += 4;
+
+ switch((FVF & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT)
+ {
+ case 8: stride += 4 + 4 * ((1 + (FVF >> 30)) % 4);
+ case 7: stride += 4 + 4 * ((1 + (FVF >> 28)) % 4);
+ case 6: stride += 4 + 4 * ((1 + (FVF >> 26)) % 4);
+ case 5: stride += 4 + 4 * ((1 + (FVF >> 24)) % 4);
+ case 4: stride += 4 + 4 * ((1 + (FVF >> 22)) % 4);
+ case 3: stride += 4 + 4 * ((1 + (FVF >> 20)) % 4);
+ case 2: stride += 4 + 4 * ((1 + (FVF >> 18)) % 4);
+ case 1: stride += 4 + 4 * ((1 + (FVF >> 16)) % 4);
+ case 0: break;
+ default:
+ ASSERT(false);
+ }
+
+ return stride;
+ }
+
+ int Direct3DDevice8::typeStride(unsigned char type)
+ {
+ static const int LUT[] =
+ {
+ 4, // D3DDECLTYPE_FLOAT1 = 0, // 1D float expanded to (value, 0., 0., 1.)
+ 8, // D3DDECLTYPE_FLOAT2 = 1, // 2D float expanded to (value, value, 0., 1.)
+ 12, // D3DDECLTYPE_FLOAT3 = 2, // 3D float expanded to (value, value, value, 1.)
+ 16, // D3DDECLTYPE_FLOAT4 = 3, // 4D float
+ 4, // D3DDECLTYPE_D3DCOLOR = 4, // 4D packed unsigned bytes mapped to 0. to 1. range. Input is in D3DCOLOR format (ARGB) expanded to (R, G, B, A)
+ 4, // D3DDECLTYPE_UBYTE4 = 5, // 4D unsigned byte
+ 4, // D3DDECLTYPE_SHORT2 = 6, // 2D signed short expanded to (value, value, 0., 1.)
+ 8 // D3DDECLTYPE_SHORT4 = 7, // 4D signed short
+ };
+
+ if(type <= 7)
+ {
+ return LUT[type];
+ }
+ else ASSERT(false);
+
+ return 0;
+ }
+
+ bool Direct3DDevice8::bindData(Direct3DIndexBuffer8 *indexBuffer, int base)
+ {
+ if(!bindViewport())
+ {
+ return false; // Zero-area target region
+ }
+
+ bindTextures();
+ bindStreams(base);
+ bindIndexBuffer(indexBuffer);
+ bindLights();
+
+ return true;
+ }
+
+ void Direct3DDevice8::bindStreams(int base)
+ {
+ renderer->resetInputStreams((FVF & D3DFVF_POSITION_MASK) == D3DFVF_XYZRHW);
+
+ int stride;
+
+ if(!declaration) // Fixed-function vertex pipeline
+ {
+ const void *buffer = 0;
+
+ ASSERT(dataStream[0]);
+
+ Direct3DVertexBuffer8 *stream = dataStream[0];
+ sw::Resource *resource = stream->getResource();
+ buffer = (char*)resource->data();
+ stride = FVFStride(FVF);
+
+ ASSERT(stride == streamStride[0]); // FIXME
+ ASSERT(buffer && stride);
+
+ (char*&)buffer += stride * base;
+
+ sw::Stream attribute(resource, buffer, stride);
+
+ switch(FVF & D3DFVF_POSITION_MASK)
+ {
+ case D3DFVF_XYZ:
+ renderer->setInputStream(sw::Position, attribute.define(buffer, sw::STREAMTYPE_FLOAT, 3));
+ (char*&)buffer += 12;
+ break;
+ case D3DFVF_XYZRHW:
+ renderer->setInputStream(sw::PositionT, attribute.define(buffer, sw::STREAMTYPE_FLOAT, 4));
+ (char*&)buffer += 16;
+ break;
+ case D3DFVF_XYZB1:
+ renderer->setInputStream(sw::Position, attribute.define(buffer, sw::STREAMTYPE_FLOAT, 3));
+ (char*&)buffer += 12;
+
+ renderer->setInputStream(sw::BlendWeight, attribute.define(buffer, sw::STREAMTYPE_FLOAT, 1)); // FIXME: Stream type depends on indexed blending active?
+ (char*&)buffer += 4;
+ break;
+ case D3DFVF_XYZB2:
+ renderer->setInputStream(sw::Position, attribute.define(buffer, sw::STREAMTYPE_FLOAT, 3));
+ (char*&)buffer += 12;
+
+ renderer->setInputStream(sw::BlendWeight, attribute.define(buffer, sw::STREAMTYPE_FLOAT, 1)); // FIXME: Stream type depends on indexed blending active?
+ (char*&)buffer += 8;
+ break;
+ case D3DFVF_XYZB3:
+ renderer->setInputStream(sw::Position, attribute.define(buffer, sw::STREAMTYPE_FLOAT, 3));
+ (char*&)buffer += 12;
+
+ renderer->setInputStream(sw::BlendWeight, attribute.define(buffer, sw::STREAMTYPE_FLOAT, 2)); // FIXME: Stream type depends on indexed blending active?
+ (char*&)buffer += 12;
+ break;
+ case D3DFVF_XYZB4:
+ renderer->setInputStream(sw::Position, attribute.define(buffer, sw::STREAMTYPE_FLOAT, 3));
+ (char*&)buffer += 12;
+
+ renderer->setInputStream(sw::BlendWeight, attribute.define(buffer, sw::STREAMTYPE_FLOAT, 3)); // FIXME: Stream type depends on indexed blending active?
+ (char*&)buffer += 16;
+ break;
+ case D3DFVF_XYZB5:
+ renderer->setInputStream(sw::Position, attribute.define(buffer, sw::STREAMTYPE_FLOAT, 3));
+ (char*&)buffer += 12;
+
+ renderer->setInputStream(sw::BlendWeight, attribute.define(buffer, sw::STREAMTYPE_FLOAT, 4)); // FIXME: Stream type depends on indexed blending active?
+ (char*&)buffer += 20;
+ break;
+ }
+
+ if(FVF & D3DFVF_LASTBETA_UBYTE4)
+ {
+ renderer->setInputStream(sw::BlendIndices, attribute.define((char*&)buffer - 4, sw::STREAMTYPE_INDICES, 1));
+ }
+
+ if(FVF & D3DFVF_NORMAL)
+ {
+ renderer->setInputStream(sw::Normal, attribute.define(buffer, sw::STREAMTYPE_FLOAT, 3));
+ (char*&)buffer += 12;
+ }
+
+ if(FVF & D3DFVF_PSIZE)
+ {
+ renderer->setInputStream(sw::PointSize, attribute.define(buffer, sw::STREAMTYPE_FLOAT, 1));
+ (char*&)buffer += 4;
+ }
+
+ if(FVF & D3DFVF_DIFFUSE)
+ {
+ renderer->setInputStream(sw::Color0, attribute.define(buffer, sw::STREAMTYPE_COLOR, 4));
+ (char*&)buffer += 4;
+ }
+
+ if(FVF & D3DFVF_SPECULAR)
+ {
+ renderer->setInputStream(sw::Color1, attribute.define(buffer, sw::STREAMTYPE_COLOR, 4));
+ (char*&)buffer += 4;
+ }
+
+ for(unsigned int i = 0; i < 8; i++)
+ {
+ if((FVF & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT >= i + 1)
+ {
+ renderer->setInputStream(sw::TexCoord0 + i, attribute.define(buffer, sw::STREAMTYPE_FLOAT, 1 + (1 + (FVF >> (16 + i * 2))) % 4));
+ (char*&)buffer += 4 + 4 * ((1 + (FVF >> (16 + i * 2))) % 4);
+ }
+ }
+ }
+ else
+ {
+ const unsigned long *element = declaration;
+ int stream = 0;
+ sw::Resource *resource;
+ const void *buffer = 0;
+
+ while(*element != 0xFFFFFFFF)
+ {
+ switch((*element & 0xE0000000) >> 29)
+ {
+ case 0: // NOP
+ if(*element != 0x00000000)
+ {
+ ASSERT(false);
+ }
+ break;
+ case 1: // Stream selector
+ stream = *element & 0x0000000F;
+ {
+ ASSERT(dataStream[stream]); // Expected a stream
+
+ Direct3DVertexBuffer8 *streamBuffer = (Direct3DVertexBuffer8*)dataStream[stream];
+ resource = streamBuffer->getResource();
+ buffer = (char*)resource->data();
+
+ const unsigned long *streamElement = element + 1;
+ stride = 0;
+
+ while((*streamElement & 0xE0000000) >> 29 == 2) // Data definition
+ {
+ if(*streamElement & 0x10000000) // Data skip
+ {
+ int skip = (*streamElement & 0x000F0000) >> 16;
+
+ stride += 4 * skip;
+ }
+ else
+ {
+ stride += typeStride((unsigned char)((*streamElement & 0x000F0000) >> 16));
+ }
+
+ streamElement++;
+ }
+
+ // ASSERT(stride == streamStride[stream]); // FIXME: Probably just ignore
+
+ (char*&)buffer += stride * base;
+ }
+ break;
+ case 2: // Data definition
+ if(*element & 0x10000000) // Data skip
+ {
+ int skip = (*element & 0x000F0000) >> 16;
+
+ (char*&)buffer += 4 * skip;
+ }
+ else
+ {
+ int type = (*element & 0x000F0000) >> 16;
+ int index = (*element & 0x0000000F) >> 0;
+
+ sw::Stream attribute(resource, buffer, stride);
+
+ switch(type)
+ {
+ case D3DVSDT_FLOAT1: attribute.define(sw::STREAMTYPE_FLOAT, 1); break;
+ case D3DVSDT_FLOAT2: attribute.define(sw::STREAMTYPE_FLOAT, 2); break;
+ case D3DVSDT_FLOAT3: attribute.define(sw::STREAMTYPE_FLOAT, 3); break;
+ case D3DVSDT_FLOAT4: attribute.define(sw::STREAMTYPE_FLOAT, 4); break;
+ case D3DVSDT_D3DCOLOR: attribute.define(sw::STREAMTYPE_COLOR, 4); break;
+ case D3DVSDT_UBYTE4: attribute.define(sw::STREAMTYPE_BYTE, 4); break;
+ case D3DVSDT_SHORT2: attribute.define(sw::STREAMTYPE_SHORT, 2); break;
+ case D3DVSDT_SHORT4: attribute.define(sw::STREAMTYPE_SHORT, 4); break;
+ default: attribute.define(sw::STREAMTYPE_FLOAT, 0); ASSERT(false);
+ }
+
+ switch(index)
+ {
+ case D3DVSDE_POSITION: renderer->setInputStream(sw::Position, attribute); break;
+ case D3DVSDE_BLENDWEIGHT: renderer->setInputStream(sw::BlendWeight, attribute); break;
+ case D3DVSDE_BLENDINDICES: renderer->setInputStream(sw::BlendIndices, attribute); break;
+ case D3DVSDE_NORMAL: renderer->setInputStream(sw::Normal, attribute); break;
+ case D3DVSDE_PSIZE: renderer->setInputStream(sw::PointSize, attribute); break;
+ case D3DVSDE_DIFFUSE: renderer->setInputStream(sw::Color0, attribute); break;
+ case D3DVSDE_SPECULAR: renderer->setInputStream(sw::Color1, attribute); break;
+ case D3DVSDE_TEXCOORD0: renderer->setInputStream(sw::TexCoord0, attribute); break;
+ case D3DVSDE_TEXCOORD1: renderer->setInputStream(sw::TexCoord1, attribute); break;
+ case D3DVSDE_TEXCOORD2: renderer->setInputStream(sw::TexCoord2, attribute); break;
+ case D3DVSDE_TEXCOORD3: renderer->setInputStream(sw::TexCoord3, attribute); break;
+ case D3DVSDE_TEXCOORD4: renderer->setInputStream(sw::TexCoord4, attribute); break;
+ case D3DVSDE_TEXCOORD5: renderer->setInputStream(sw::TexCoord5, attribute); break;
+ case D3DVSDE_TEXCOORD6: renderer->setInputStream(sw::TexCoord6, attribute); break;
+ case D3DVSDE_TEXCOORD7: renderer->setInputStream(sw::TexCoord7, attribute); break;
+ // case D3DVSDE_POSITION2: renderer->setInputStream(sw::Position1, attribute); break;
+ // case D3DVSDE_NORMAL2: renderer->setInputStream(sw::Normal1, attribute); break;
+ default:
+ ASSERT(false);
+ }
+
+ (char*&)buffer += typeStride(type);
+ }
+ break;
+ case 3: // Tesselator data
+ UNIMPLEMENTED();
+ break;
+ case 4: // Constant data
+ {
+ int count = (*element & 0x1E000000) >> 25;
+ int index = (*element & 0x0000007F) >> 0;
+
+ SetVertexShaderConstant(index, element + 1, count);
+
+ element += 4 * count;
+ }
+ break;
+ case 5: // Extension
+ UNIMPLEMENTED();
+ break;
+ default:
+ ASSERT(false);
+ }
+
+ element++;
+ }
+ }
+ }
+
+ void Direct3DDevice8::bindIndexBuffer(Direct3DIndexBuffer8 *indexBuffer)
+ {
+ sw::Resource *resource = 0;
+
+ if(indexBuffer)
+ {
+ resource = indexBuffer->getResource();
+ }
+
+ renderer->setIndexBuffer(resource);
+ }
+
+ void Direct3DDevice8::bindLights()
+ {
+ if(!lightsDirty) return;
+
+ Lights::iterator i = light.begin();
+ int active = 0;
+
+ // Set and enable renderer lights
+ while(active < 8)
+ {
+ while(i != light.end() && !i->second.enable)
+ {
+ i++;
+ }
+
+ if(i == light.end())
+ {
+ break;
+ }
+
+ const Light &l = i->second;
+
+ sw::Point position(l.Position.x, l.Position.y, l.Position.z);
+ sw::Color<float> diffuse(l.Diffuse.r, l.Diffuse.g, l.Diffuse.b, l.Diffuse.a);
+ sw::Color<float> specular(l.Specular.r, l.Specular.g, l.Specular.b, l.Specular.a);
+ sw::Color<float> ambient(l.Ambient.r, l.Ambient.g, l.Ambient.b, l.Ambient.a);
+ sw::Vector direction(l.Direction.x, l.Direction.y, l.Direction.z);
+
+ renderer->setLightDiffuse(active, diffuse);
+ renderer->setLightSpecular(active, specular);
+ renderer->setLightAmbient(active, ambient);
+
+ if(l.Type == D3DLIGHT_DIRECTIONAL)
+ {
+ // goto next; // FIXME
+
+ // FIXME: Unsupported, make it a positional light far away without falloff
+ renderer->setLightPosition(active, -1000 * direction);
+ renderer->setLightRange(active, l.Range);
+ renderer->setLightAttenuation(active, 1, 0, 0);
+ }
+ else if(l.Type == D3DLIGHT_SPOT)
+ {
+ // goto next; // FIXME
+
+ // FIXME: Unsupported, make it a positional light
+ renderer->setLightPosition(active, position);
+ renderer->setLightRange(active, l.Range);
+ renderer->setLightAttenuation(active, l.Attenuation0, l.Attenuation1, l.Attenuation2);
+ }
+ else
+ {
+ renderer->setLightPosition(active, position);
+ renderer->setLightRange(active, l.Range);
+ renderer->setLightAttenuation(active, l.Attenuation0, l.Attenuation1, l.Attenuation2);
+ }
+
+ renderer->setLightEnable(active, true);
+
+ active++;
+
+ // next: // FIXME
+ i++;
+ }
+
+ // Remaining lights are disabled
+ while(active < 8)
+ {
+ renderer->setLightEnable(active, false);
+
+ active++;
+ }
+
+ lightsDirty= false;
+ }
+
+ bool Direct3DDevice8::bindViewport()
+ {
+ if(viewport.Width == 0 || viewport.Height == 0)
+ {
+ return false;
+ }
+
+ sw::Viewport view;
+ view.x0 = (float)viewport.X;
+ view.y0 = (float)viewport.Y + viewport.Height;
+ view.width = (float)viewport.Width;
+ view.height = -(float)viewport.Height;
+ view.minZ = viewport.MinZ;
+ view.maxZ = viewport.MaxZ;
+
+ renderer->setViewport(view);
+
+ sw::Rect scissor;
+ scissor.x0 = viewport.X;
+ scissor.x1 = viewport.X + viewport.Width;
+ scissor.y0 = viewport.Y;
+ scissor.y1 = viewport.Y + viewport.Height;
+
+ renderer->setScissor(scissor);
+
+ return true;
+ }
+
+ void Direct3DDevice8::bindTextures()
+ {
+ for(int stage = 0; stage < 8; stage++)
+ {
+ Direct3DBaseTexture8 *baseTexture = texture[stage];
+ sw::Resource *resource = 0;
+
+ bool textureUsed = false;
+
+ if(pixelShader[pixelShaderHandle])
+ {
+ textureUsed = pixelShader[pixelShaderHandle]->getPixelShader()->usesSampler(stage);
+ }
+ else
+ {
+ textureUsed = true; // FIXME: Check fixed-function use?
+ }
+
+ if(baseTexture && textureUsed)
+ {
+ resource = baseTexture->getResource();
+ }
+
+ renderer->setTextureResource(stage, resource);
+
+ if(baseTexture && textureUsed)
+ {
+ int levelCount = baseTexture->getInternalLevelCount();
+
+ int textureLOD = baseTexture->GetLOD();
+ int stageLOD = textureStageState[stage][D3DTSS_MAXMIPLEVEL];
+ int LOD = textureLOD > stageLOD ? textureLOD : stageLOD;
+
+ if(textureStageState[stage][D3DTSS_MIPFILTER] == D3DTEXF_NONE)
+ {
+ LOD = 0;
+ }
+
+ switch(baseTexture->GetType())
+ {
+ case D3DRTYPE_TEXTURE:
+ {
+ Direct3DTexture8 *texture = dynamic_cast<Direct3DTexture8*>(baseTexture);
+ Direct3DSurface8 *surface;
+
+ for(int mipmapLevel = 0; mipmapLevel < sw::MIPMAP_LEVELS; mipmapLevel++)
+ {
+ int surfaceLevel = mipmapLevel;
+
+ if(surfaceLevel < LOD)
+ {
+ surfaceLevel = LOD;
+ }
+
+ if(surfaceLevel < 0)
+ {
+ surfaceLevel = 0;
+ }
+ else if(surfaceLevel >= levelCount)
+ {
+ surfaceLevel = levelCount - 1;
+ }
+
+ surface = texture->getInternalSurfaceLevel(surfaceLevel);
+ renderer->setTextureLevel(stage, 0, mipmapLevel, surface, sw::TEXTURE_2D);
+ }
+ }
+ break;
+ case D3DRTYPE_CUBETEXTURE:
+ for(int face = 0; face < 6; face++)
+ {
+ Direct3DCubeTexture8 *cubeTexture = dynamic_cast<Direct3DCubeTexture8*>(baseTexture);
+ Direct3DSurface8 *surface;
+
+ for(int mipmapLevel = 0; mipmapLevel < sw::MIPMAP_LEVELS; mipmapLevel++)
+ {
+ int surfaceLevel = mipmapLevel;
+
+ if(surfaceLevel < LOD)
+ {
+ surfaceLevel = LOD;
+ }
+
+ if(surfaceLevel < 0)
+ {
+ surfaceLevel = 0;
+ }
+ else if(surfaceLevel >= levelCount)
+ {
+ surfaceLevel = levelCount - 1;
+ }
+
+ surface = cubeTexture->getInternalCubeMapSurface((D3DCUBEMAP_FACES)face, surfaceLevel);
+ renderer->setTextureLevel(stage, face, mipmapLevel, surface, sw::TEXTURE_CUBE);
+ }
+ }
+ break;
+ case D3DRTYPE_VOLUMETEXTURE:
+ {
+ Direct3DVolumeTexture8 *volumeTexture = dynamic_cast<Direct3DVolumeTexture8*>(baseTexture);
+ Direct3DVolume8 *volume;
+
+ for(int mipmapLevel = 0; mipmapLevel < sw::MIPMAP_LEVELS; mipmapLevel++)
+ {
+ int surfaceLevel = mipmapLevel;
+
+ if(surfaceLevel < LOD)
+ {
+ surfaceLevel = LOD;
+ }
+
+ if(surfaceLevel < 0)
+ {
+ surfaceLevel = 0;
+ }
+ else if(surfaceLevel >= levelCount)
+ {
+ surfaceLevel = levelCount - 1;
+ }
+
+ volume = volumeTexture->getInternalVolumeLevel(surfaceLevel);
+ renderer->setTextureLevel(stage, 0, mipmapLevel, volume, sw::TEXTURE_3D);
+ }
+ }
+ break;
+ default:
+ UNIMPLEMENTED();
+ }
+ }
+ else
+ {
+ renderer->setTextureLevel(stage, 0, 0, 0, sw::TEXTURE_NULL);
+ }
+ }
+ }
+
+ void Direct3DDevice8::bindCursor()
+ {
+ if(showCursor)
+ {
+ sw::FrameBuffer::setCursorImage(cursor);
+
+ HCURSOR oldCursor = SetCursor(nullCursor);
+
+ if(oldCursor != nullCursor)
+ {
+ win32Cursor = oldCursor;
+ }
+ }
+ else
+ {
+ sw::FrameBuffer::setCursorImage(0);
+
+ if(GetCursor() == nullCursor)
+ {
+ SetCursor(win32Cursor);
+ }
+ }
+ }
+
+ long Direct3DDevice8::updateVolume(IDirect3DVolume8 *sourceVolume, IDirect3DVolume8 *destinationVolume)
+ {
+ TRACE("IDirect3DVolume8 *sourceVolume = 0x%0.8p, IDirect3DVolume8 *destinationVolume = 0x%0.8p", sourceVolume, destinationVolume);
+
+ if(!sourceVolume || !destinationVolume)
+ {
+ return INVALIDCALL();
+ }
+
+ D3DVOLUME_DESC sourceDescription;
+ D3DVOLUME_DESC destinationDescription;
+
+ sourceVolume->GetDesc(&sourceDescription);
+ destinationVolume->GetDesc(&destinationDescription);
+
+ if(sourceDescription.Pool != D3DPOOL_SYSTEMMEM ||
+ destinationDescription.Pool != D3DPOOL_DEFAULT ||
+ sourceDescription.Format != destinationDescription.Format ||
+ sourceDescription.Width != destinationDescription.Width ||
+ sourceDescription.Height != destinationDescription.Height)
+ {
+ return INVALIDCALL();
+ }
+
+ D3DLOCKED_BOX sourceLock;
+ D3DLOCKED_BOX destinationLock;
+
+ sourceVolume->LockBox(&sourceLock, 0, 0);
+ destinationVolume->LockBox(&destinationLock, 0, 0);
+
+ if(sourceLock.RowPitch != destinationLock.RowPitch ||
+ sourceLock.SlicePitch != destinationLock.SlicePitch)
+ {
+ UNIMPLEMENTED();
+ }
+
+ memcpy(destinationLock.pBits, sourceLock.pBits, sourceLock.SlicePitch * sourceDescription.Depth);
+
+ sourceVolume->UnlockBox();
+ destinationVolume->UnlockBox();
+
+ return D3D_OK;
+ }
+
+ void Direct3DDevice8::configureFPU()
+ {
+ unsigned short cw;
+
+ __asm
+ {
+ fstcw cw
+ and cw, 0xFCFC // Single-precision
+ or cw, 0x003F // Mask all exceptions
+ and cw, 0xF3FF // Round to nearest
+ fldcw cw
+ }
+ }
+}
diff --git a/src/D3D8/Direct3DDevice8.hpp b/src/D3D8/Direct3DDevice8.hpp
new file mode 100644
index 0000000..203849d
--- /dev/null
+++ b/src/D3D8/Direct3DDevice8.hpp
@@ -0,0 +1,272 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef D3D8_Direct3DDevice8_hpp
+#define D3D8_Direct3DDevice8_hpp
+
+#include "Unknown.hpp"
+
+#include "Direct3D8.hpp"
+#include "Direct3DStateBlock8.hpp"
+#include "Direct3DVertexDeclaration8.hpp"
+#include "Direct3DSwapChain8.hpp"
+
+#include "Stream.hpp"
+
+#include <d3d8.h>
+#include <vector>
+#include <list>
+#include <map>
+
+namespace sw
+{
+ class Renderer;
+ class Context;
+}
+
+namespace D3D8
+{
+ class Direct3DPixelShader8;
+ class Direct3DVertexShader8;
+ class Direct3DSurface8;
+ class Direct3DVertexBuffer8;
+ class Direct3DIndexBuffer8;
+
+ class Direct3DDevice8 : public IDirect3DDevice8, protected Unknown
+ {
+ public:
+ Direct3DDevice8(const HINSTANCE instance, Direct3D8 *d3d8, unsigned int adapter, D3DDEVTYPE deviceType, HWND focusWindow, unsigned long behaviourFlags, D3DPRESENT_PARAMETERS *presentParameters);
+
+ virtual ~Direct3DDevice8();
+
+ // IUnknown methods
+ long __stdcall QueryInterface(const IID &iid, void **object);
+ unsigned long __stdcall AddRef();
+ unsigned long __stdcall Release();
+
+ // IDirect3DDevice8 methods
+ long __stdcall ApplyStateBlock(unsigned long token);
+ long __stdcall BeginScene();
+ long __stdcall BeginStateBlock();
+ long __stdcall CaptureStateBlock(unsigned long token);
+ long __stdcall Clear(unsigned long count, const D3DRECT *rects, unsigned long flags, unsigned long color, float z, unsigned long stencil);
+ long __stdcall CopyRects(IDirect3DSurface8 *sourceSurface, const RECT *sourceRectsArray, unsigned int rects, IDirect3DSurface8 *destinationSurface, const POINT *destPointsArray);
+ long __stdcall CreateAdditionalSwapChain(D3DPRESENT_PARAMETERS *presentParameters, IDirect3DSwapChain8 **swapChain);
+ long __stdcall CreateCubeTexture(unsigned int edgeLength, unsigned int levels, unsigned long usage, D3DFORMAT format, D3DPOOL pool, IDirect3DCubeTexture8 **cubeTexture);
+ long __stdcall CreateDepthStencilSurface(unsigned int width, unsigned int height, D3DFORMAT format, D3DMULTISAMPLE_TYPE multiSample, IDirect3DSurface8 **surface);
+ long __stdcall CreateImageSurface(unsigned int width, unsigned int height, D3DFORMAT format, IDirect3DSurface8 **surface);
+ long __stdcall CreateIndexBuffer(unsigned int length, unsigned long usage, D3DFORMAT format, D3DPOOL pool, IDirect3DIndexBuffer8 **indexBuffer);
+ long __stdcall CreatePixelShader(const unsigned long *function, unsigned long *handle);
+ long __stdcall CreateRenderTarget(unsigned int width, unsigned int height, D3DFORMAT format, D3DMULTISAMPLE_TYPE multiSample, int lockable, IDirect3DSurface8 **surface);
+ long __stdcall CreateStateBlock(D3DSTATEBLOCKTYPE type, unsigned long *token);
+ long __stdcall CreateTexture(unsigned int width, unsigned int height, unsigned int levels, unsigned long usage, D3DFORMAT format, D3DPOOL pool, IDirect3DTexture8 **texture);
+ long __stdcall CreateVertexBuffer(unsigned int length, unsigned long usage, unsigned long FVF, D3DPOOL, IDirect3DVertexBuffer8 **vertexBuffer);
+ long __stdcall CreateVertexShader(const unsigned long *declaration, const unsigned long *function, unsigned long *handle, unsigned long usage);
+ long __stdcall CreateVolumeTexture(unsigned int width, unsigned int height, unsigned int depth, unsigned int levels, unsigned long usage, D3DFORMAT format, D3DPOOL pool, IDirect3DVolumeTexture8 **volumeTexture);
+ long __stdcall DeletePatch(unsigned int handle);
+ long __stdcall DeletePixelShader(unsigned long handle);
+ long __stdcall DeleteStateBlock(unsigned long token);
+ long __stdcall DeleteVertexShader(unsigned long handle);
+ long __stdcall DrawIndexedPrimitive(D3DPRIMITIVETYPE type, unsigned int minIndex, unsigned int numVertices, unsigned int startIndex, unsigned int primitiveCount);
+ long __stdcall DrawIndexedPrimitiveUP(D3DPRIMITIVETYPE type, unsigned int minVertexIndex, unsigned int numVertexIndices, unsigned int PrimitiveCount, const void *indexData, D3DFORMAT indexDataFormat, const void *vertexStreamZeroData, unsigned int VertexStreamZeroStride);
+ long __stdcall DrawPrimitive(D3DPRIMITIVETYPE primitiveType, unsigned int startVertex, unsigned int primiveCount);
+ long __stdcall DrawPrimitiveUP(D3DPRIMITIVETYPE primitiveType, unsigned int primitiveCount, const void *vertexStreamZeroData, unsigned int vertexStreamZeroStride);
+ long __stdcall DrawRectPatch(unsigned int handle, const float *numSegs, const D3DRECTPATCH_INFO *rectPatchInfo);
+ long __stdcall DrawTriPatch(unsigned int handle, const float *numSegs, const D3DTRIPATCH_INFO *triPatchInfo);
+ long __stdcall EndScene();
+ long __stdcall EndStateBlock(unsigned long *token);
+ unsigned int __stdcall GetAvailableTextureMem();
+ long __stdcall GetBackBuffer(unsigned int index, D3DBACKBUFFER_TYPE type, IDirect3DSurface8 **backBuffer);
+ long __stdcall GetClipPlane(unsigned long index, float *plane);
+ long __stdcall GetClipStatus(D3DCLIPSTATUS8 *clipStatus);
+ long __stdcall GetCreationParameters(D3DDEVICE_CREATION_PARAMETERS *parameters);
+ long __stdcall GetCurrentTexturePalette(unsigned int *paletteNumber);
+ long __stdcall GetDepthStencilSurface(IDirect3DSurface8 **depthStencilSurface);
+ long __stdcall GetDeviceCaps(D3DCAPS8 *caps);
+ long __stdcall GetDirect3D(IDirect3D8 **D3D);
+ long __stdcall GetDisplayMode(D3DDISPLAYMODE *mode);
+ long __stdcall GetFrontBuffer(IDirect3DSurface8 *destSurface);
+ void __stdcall GetGammaRamp(D3DGAMMARAMP *ramp);
+ long __stdcall GetIndices(IDirect3DIndexBuffer8 **indexData, unsigned int *baseVertexIndex);
+ long __stdcall GetInfo(unsigned long devInfoID, void *devInfoStruct, unsigned long devInfoStructSize);
+ long __stdcall GetLight(unsigned long index, D3DLIGHT8 *p);
+ long __stdcall GetLightEnable(unsigned long index , int *enable);
+ long __stdcall GetMaterial(D3DMATERIAL8 *material);
+ long __stdcall GetPaletteEntries(unsigned int paletteNumber, PALETTEENTRY *entries);
+ long __stdcall GetPixelShader(unsigned long *handle);
+ long __stdcall GetPixelShaderFunction(unsigned long handle, void *data, unsigned long *sizeOfData);
+ long __stdcall GetPixelShaderConstant(unsigned long startRegister, void *constantData, unsigned long constantCount);
+ long __stdcall GetRasterStatus(D3DRASTER_STATUS *rasterStatus);
+ long __stdcall GetRenderState(D3DRENDERSTATETYPE State, unsigned long *value);
+ long __stdcall GetRenderTarget(IDirect3DSurface8 **renderTarget);
+ long __stdcall GetStreamSource(unsigned int streamNumber, IDirect3DVertexBuffer8 **streamData, unsigned int *stride);
+ long __stdcall GetTexture(unsigned long stage, IDirect3DBaseTexture8 **texture);
+ long __stdcall GetTextureStageState(unsigned long stage, D3DTEXTURESTAGESTATETYPE type, unsigned long *value);
+ long __stdcall GetTransform(D3DTRANSFORMSTATETYPE state, D3DMATRIX *matrix);
+ long __stdcall GetVertexShader(unsigned long *handle);
+ long __stdcall GetVertexShaderConstant(unsigned long startRegister, void *constantData, unsigned long constantCount);
+ long __stdcall GetVertexShaderDeclaration(unsigned long handle, void *data, unsigned long *size);
+ long __stdcall GetVertexShaderFunction(unsigned long handle, void *data, unsigned long *size);
+ long __stdcall GetViewport(D3DVIEWPORT8 *viewport);
+ long __stdcall LightEnable(unsigned long index, int enable);
+ long __stdcall MultiplyTransform(D3DTRANSFORMSTATETYPE state, const D3DMATRIX *matrix);
+ long __stdcall Present(const RECT *sourceRect, const RECT *destRect, HWND destWindowOverride, const RGNDATA *dirtyRegion);
+ long __stdcall ProcessVertices(unsigned int srcStartIndex, unsigned int destIndex, unsigned int vertexCount, IDirect3DVertexBuffer8 *destBuffer, unsigned long flags);
+ long __stdcall Reset(D3DPRESENT_PARAMETERS *presentParameters);
+ long __stdcall ResourceManagerDiscardBytes(unsigned long bytes);
+ long __stdcall SetClipPlane(unsigned long index, const float *plane);
+ long __stdcall SetClipStatus(const D3DCLIPSTATUS8 *clipStatus);
+ long __stdcall SetCurrentTexturePalette(unsigned int paletteNumber);
+ void __stdcall SetCursorPosition(int x, int y, unsigned long flags);
+ void __stdcall SetCursorPosition(unsigned int x, unsigned int y, unsigned long flags);
+ long __stdcall SetCursorProperties(unsigned int x, unsigned int y, IDirect3DSurface8 *cursorBitmap);
+ void __stdcall SetGammaRamp(unsigned long flags, const D3DGAMMARAMP *ramp);
+ long __stdcall SetIndices(IDirect3DIndexBuffer8 *indexData, unsigned int baseVertexIndex);
+ long __stdcall SetLight(unsigned long index, const D3DLIGHT8 *light);
+ long __stdcall SetMaterial(const D3DMATERIAL8 *material);
+ long __stdcall SetPaletteEntries(unsigned int paletteNumber, const PALETTEENTRY *entries);
+ long __stdcall SetPixelShader(unsigned long shader);
+ long __stdcall SetPixelShaderConstant(unsigned long startRegister, const void *constantData, unsigned long constantCount);
+ long __stdcall SetRenderState(D3DRENDERSTATETYPE state, unsigned long value);
+ long __stdcall SetRenderTarget(IDirect3DSurface8 *renderTarget, IDirect3DSurface8 *newZStencil);
+ long __stdcall SetStreamSource(unsigned int streamNumber, IDirect3DVertexBuffer8 *streamData, unsigned int stride);
+ long __stdcall SetTexture(unsigned long stage, IDirect3DBaseTexture8 *texture);
+ long __stdcall SetTextureStageState(unsigned long stage, D3DTEXTURESTAGESTATETYPE type, unsigned long value);
+ long __stdcall SetTransform(D3DTRANSFORMSTATETYPE state, const D3DMATRIX *matrix);
+ long __stdcall SetVertexShader(unsigned long handle);
+ long __stdcall SetVertexShaderConstant(unsigned long startRegister, const void *constantData, unsigned long constantCount);
+ long __stdcall SetViewport(const D3DVIEWPORT8 *viewport);
+ int __stdcall ShowCursor(int show);
+ long __stdcall TestCooperativeLevel();
+ long __stdcall UpdateTexture(IDirect3DBaseTexture8 *sourceTexture, IDirect3DBaseTexture8 *destinationTexture);
+ long __stdcall ValidateDevice(unsigned long *numPasses);
+
+ // Internal methods
+ long __stdcall updateSurface(IDirect3DSurface8 *sourceSurface, const RECT *sourceRect, IDirect3DSurface8 *destinationSurface, const POINT *destPoint);
+
+ private:
+ static int FVFStride(unsigned long FVF);
+ static int typeStride(unsigned char streamType);
+ static sw::StreamType streamType(int type);
+ bool bindData(Direct3DIndexBuffer8 *indexBuffer, int base);
+ void bindStreams(int base);
+ void bindIndexBuffer(Direct3DIndexBuffer8 *indexBuffer);
+ void bindLights();
+ bool bindViewport();
+ void bindTextures();
+ void bindCursor();
+
+ long updateVolume(IDirect3DVolume8 *sourceVolume, IDirect3DVolume8 *destinationVolume);
+ void configureFPU();
+
+ // Creation parameters
+ const HINSTANCE instance;
+ Direct3D8 *d3d8;
+ const unsigned int adapter;
+ const D3DDEVTYPE deviceType;
+ const HWND focusWindow;
+ const unsigned long behaviourFlags;
+ const D3DPRESENT_PARAMETERS presentParameters;
+
+ HWND windowHandle;
+
+ D3DVIEWPORT8 viewport;
+ D3DMATRIX matrix[512];
+ Direct3DBaseTexture8 *texture[8];
+ D3DMATERIAL8 material;
+ float plane[6][4];
+ D3DCLIPSTATUS8 clipStatus;
+
+ struct Light : D3DLIGHT8
+ {
+ Light &operator=(const D3DLIGHT8 &light)
+ {
+ Type = light.Type;
+ Diffuse = light.Diffuse;
+ Specular = light.Specular;
+ Ambient = light.Ambient;
+ Position = light.Position;
+ Direction = light.Direction;
+ Range = light.Range;
+ Falloff = light.Falloff;
+ Attenuation0 = light.Attenuation0;
+ Attenuation1 = light.Attenuation1;
+ Attenuation2 = light.Attenuation2;
+ Theta = light.Theta;
+ Phi = light.Phi;
+
+ return *this;
+ }
+
+ bool enable;
+ };
+
+ struct Lights : std::map<int, Light>
+ {
+ bool exists(int index)
+ {
+ return find(index) != end();
+ }
+ };
+
+ Lights light;
+ bool lightsDirty;
+
+ Direct3DVertexBuffer8 *dataStream[16];
+ int streamStride[16];
+ Direct3DIndexBuffer8 *indexData;
+ unsigned int baseVertexIndex;
+
+ unsigned long FVF;
+
+ std::vector<Direct3DSwapChain8*> swapChain;
+
+ Direct3DSurface8 *renderTarget;
+ Direct3DSurface8 *depthStencil;
+
+ bool recordState;
+ std::vector<Direct3DStateBlock8*> stateRecorder;
+
+ unsigned long renderState[D3DRS_NORMALORDER + 1];
+ unsigned long textureStageState[8][D3DTSS_RESULTARG + 1];
+ bool init; // TODO: Deprecate when all state changes implemented
+
+ std::vector<Direct3DPixelShader8*> pixelShader;
+ std::vector<Direct3DVertexShader8*> vertexShader;
+ unsigned long pixelShaderHandle;
+ unsigned long vertexShaderHandle;
+ const unsigned long *declaration;
+
+ float pixelShaderConstant[8][4];
+ float vertexShaderConstant[256][4];
+
+ struct Palette
+ {
+ PALETTEENTRY entry[256];
+ };
+
+ unsigned int currentPalette;
+ std::map<int, Palette> palette;
+
+ sw::Context *context;
+ sw::Renderer *renderer;
+
+ sw::Surface *cursor;
+ bool showCursor;
+ HCURSOR nullCursor;
+ HCURSOR win32Cursor;
+ };
+}
+
+#endif // D3D8_Direct3DDevice8_hpp
diff --git a/src/D3D8/Direct3DIndexBuffer8.cpp b/src/D3D8/Direct3DIndexBuffer8.cpp
new file mode 100644
index 0000000..00e54d2
--- /dev/null
+++ b/src/D3D8/Direct3DIndexBuffer8.cpp
@@ -0,0 +1,191 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "Direct3DIndexBuffer8.hpp"
+
+#include "Direct3DDevice8.hpp"
+#include "Resource.hpp"
+#include "Debug.hpp"
+
+#include <assert.h>
+
+namespace D3D8
+{
+ Direct3DIndexBuffer8::Direct3DIndexBuffer8(Direct3DDevice8 *device, unsigned int length, unsigned long usage, D3DFORMAT format, D3DPOOL pool) : Direct3DResource8(device, D3DRTYPE_INDEXBUFFER, length), length(length), usage(usage), format(format), pool(pool)
+ {
+ indexBuffer = new sw::Resource(length + 16);
+ }
+
+ Direct3DIndexBuffer8::~Direct3DIndexBuffer8()
+ {
+ indexBuffer->destruct();
+ }
+
+ long Direct3DIndexBuffer8::QueryInterface(const IID &iid, void **object)
+ {
+ TRACE("");
+
+ if(iid == IID_IDirect3DIndexBuffer8 ||
+ iid == IID_IDirect3DResource8 ||
+ iid == IID_IUnknown)
+ {
+ AddRef();
+ *object = this;
+
+ return S_OK;
+ }
+
+ *object = 0;
+
+ return NOINTERFACE(iid);
+ }
+
+ unsigned long Direct3DIndexBuffer8::AddRef()
+ {
+ TRACE("");
+
+ return Direct3DResource8::AddRef();
+ }
+
+ unsigned long Direct3DIndexBuffer8::Release()
+ {
+ TRACE("");
+
+ return Direct3DResource8::Release();
+ }
+
+ long Direct3DIndexBuffer8::FreePrivateData(const GUID &guid)
+ {
+ TRACE("");
+
+ return Direct3DResource8::FreePrivateData(guid);
+ }
+
+ long Direct3DIndexBuffer8::GetPrivateData(const GUID &guid, void *data, unsigned long *size)
+ {
+ TRACE("");
+
+ return Direct3DResource8::GetPrivateData(guid, data, size);
+ }
+
+ void Direct3DIndexBuffer8::PreLoad()
+ {
+ TRACE("");
+
+ Direct3DResource8::PreLoad();
+ }
+
+ long Direct3DIndexBuffer8::SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags)
+ {
+ TRACE("");
+
+ return Direct3DResource8::SetPrivateData(guid, data, size, flags);
+ }
+
+ long Direct3DIndexBuffer8::GetDevice(IDirect3DDevice8 **device)
+ {
+ TRACE("");
+
+ return Direct3DResource8::GetDevice(device);
+ }
+
+ unsigned long Direct3DIndexBuffer8::SetPriority(unsigned long newPriority)
+ {
+ TRACE("");
+
+ return Direct3DResource8::SetPriority(newPriority);
+ }
+
+ unsigned long Direct3DIndexBuffer8::GetPriority()
+ {
+ TRACE("");
+
+ return Direct3DResource8::GetPriority();
+ }
+
+ D3DRESOURCETYPE Direct3DIndexBuffer8::GetType()
+ {
+ TRACE("");
+
+ return Direct3DResource8::GetType();
+ }
+
+ long Direct3DIndexBuffer8::GetDesc(D3DINDEXBUFFER_DESC *description)
+ {
+ TRACE("");
+
+ if(!description)
+ {
+ return INVALIDCALL();
+ }
+
+ description->Format = format;
+ description->Pool = pool;
+ description->Size = length;
+ description->Type = GetType();
+ description->Usage = usage;
+
+ return 0;
+ }
+
+ long Direct3DIndexBuffer8::Lock(unsigned int offset, unsigned int size, unsigned char **data, unsigned long flags)
+ {
+ TRACE("");
+
+ if(offset == 0 && size == 0) // Lock whole buffer
+ {
+ size = length;
+ }
+
+ if(!data || offset + size > length)
+ {
+ return INVALIDCALL();
+ }
+
+ lockOffset = offset;
+ lockSize = size;
+
+ *data = (unsigned char*)indexBuffer->lock(sw::PUBLIC) + offset;
+ indexBuffer->unlock();
+
+ return D3D_OK;
+ }
+
+ long Direct3DIndexBuffer8::Unlock()
+ {
+ TRACE("");
+
+ return D3D_OK;
+ }
+
+ sw::Resource *Direct3DIndexBuffer8::getResource() const
+ {
+ return indexBuffer;
+ }
+
+ bool Direct3DIndexBuffer8::is32Bit() const
+ {
+ switch(format)
+ {
+ case D3DFMT_INDEX16:
+ return false;
+ case D3DFMT_INDEX32:
+ return true;
+ default:
+ ASSERT(false);
+ }
+
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/src/D3D8/Direct3DIndexBuffer8.hpp b/src/D3D8/Direct3DIndexBuffer8.hpp
new file mode 100644
index 0000000..8b241ab
--- /dev/null
+++ b/src/D3D8/Direct3DIndexBuffer8.hpp
@@ -0,0 +1,76 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef D3D8_Direct3DIndexBuffer8_hpp
+#define D3D8_Direct3DIndexBuffer8_hpp
+
+#include "Direct3DResource8.hpp"
+
+#include <d3d8.h>
+
+namespace sw
+{
+ class Resource;
+}
+
+namespace D3D8
+{
+ class Direct3DIndexBuffer8 : public IDirect3DIndexBuffer8, public Direct3DResource8
+ {
+ public:
+ Direct3DIndexBuffer8(Direct3DDevice8 *device, unsigned int length, unsigned long usage, D3DFORMAT format, D3DPOOL pool);
+
+ virtual ~Direct3DIndexBuffer8();
+
+ // IUnknown methods
+ long __stdcall QueryInterface(const IID &iid, void **object);
+ unsigned long __stdcall AddRef();
+ unsigned long __stdcall Release();
+
+ // IDirect3DResource8 methods
+ long __stdcall FreePrivateData(const GUID &guid);
+ long __stdcall GetPrivateData(const GUID &guid, void *data, unsigned long *size);
+ void __stdcall PreLoad();
+ long __stdcall SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags);
+ long __stdcall GetDevice(IDirect3DDevice8 **device);
+ unsigned long __stdcall SetPriority(unsigned long newPriority);
+ unsigned long __stdcall GetPriority();
+ D3DRESOURCETYPE __stdcall GetType();
+
+ // IDirect3DIndexBuffer8 methods
+ long __stdcall GetDesc(D3DINDEXBUFFER_DESC *description);
+ long __stdcall Lock(unsigned int offset, unsigned int size, unsigned char **data, unsigned long flags);
+ long __stdcall Unlock();
+
+ // Internal methods
+ sw::Resource *getResource() const;
+ bool is32Bit() const;
+
+ private:
+ // Creation parameters
+ const unsigned int length;
+ const long usage;
+ const D3DFORMAT format;
+ const D3DPOOL pool;
+
+ bool locked;
+ unsigned int lockOffset;
+ unsigned int lockSize;
+ unsigned char *lockData;
+
+ sw::Resource *indexBuffer;
+ };
+}
+
+#endif // D3D8_Direct3DIndexBuffer8_hpp
diff --git a/src/D3D8/Direct3DPixelShader8.cpp b/src/D3D8/Direct3DPixelShader8.cpp
new file mode 100644
index 0000000..8757fbc
--- /dev/null
+++ b/src/D3D8/Direct3DPixelShader8.cpp
@@ -0,0 +1,83 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "Direct3DPixelShader8.hpp"
+
+#include "Debug.hpp"
+
+namespace D3D8
+{
+ Direct3DPixelShader8::Direct3DPixelShader8(Direct3DDevice8 *device, const unsigned long *shaderToken) : device(device), pixelShader(shaderToken)
+ {
+ const unsigned long *token = shaderToken;
+
+ size = 0;
+
+ while(shaderToken[size] != 0x0000FFFF)
+ {
+ size++;
+ }
+
+ size++;
+
+ this->shaderToken = new unsigned long[size];
+ memcpy(this->shaderToken, shaderToken, size * sizeof(unsigned long));
+ }
+
+ Direct3DPixelShader8::~Direct3DPixelShader8()
+ {
+ delete[] shaderToken;
+ shaderToken = 0;
+ }
+
+ long Direct3DPixelShader8::QueryInterface(const IID &iid, void **object)
+ {
+ TRACE("");
+
+ ASSERT(false); // Internal object
+
+ return NOINTERFACE(iid);
+ }
+
+ unsigned long Direct3DPixelShader8::AddRef()
+ {
+ TRACE("");
+
+ return Unknown::AddRef();
+ }
+
+ unsigned long Direct3DPixelShader8::Release()
+ {
+ TRACE("");
+
+ return Unknown::Release();
+ }
+
+ void Direct3DPixelShader8::GetFunction(void *data, unsigned int *size)
+ {
+ TRACE("");
+
+ if(data)
+ {
+ memcpy(data, shaderToken, this->size * 4);
+ }
+
+ *size = this->size * 4;
+ }
+
+ const sw::PixelShader *Direct3DPixelShader8::getPixelShader() const
+ {
+ return &pixelShader;
+ }
+}
\ No newline at end of file
diff --git a/src/D3D8/Direct3DPixelShader8.hpp b/src/D3D8/Direct3DPixelShader8.hpp
new file mode 100644
index 0000000..daf6a24
--- /dev/null
+++ b/src/D3D8/Direct3DPixelShader8.hpp
@@ -0,0 +1,54 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef D3D8_Direct3DPixelShader8_hpp
+#define D3D8_Direct3DPixelShader8_hpp
+
+#include "PixelShader.hpp"
+
+#include "Unknown.hpp"
+
+namespace D3D8
+{
+ class Direct3DDevice8;
+
+ class Direct3DPixelShader8 : public Unknown
+ {
+ public:
+ Direct3DPixelShader8(Direct3DDevice8 *device, const unsigned long *shaderToken);
+
+ virtual ~Direct3DPixelShader8();
+
+ // IUnknown methods
+ long __stdcall QueryInterface(const IID &iid, void **object);
+ unsigned long __stdcall AddRef();
+ unsigned long __stdcall Release();
+
+ // IDirect3DPixelShader8 methods
+ void __stdcall GetFunction(void *data, unsigned int *size);
+
+ // Internal methods
+ const sw::PixelShader *getPixelShader() const;
+
+ private:
+ // Creation parameters
+ Direct3DDevice8 *const device;
+ unsigned long *shaderToken;
+ unsigned int size;
+
+ sw::PixelShader pixelShader;
+ };
+}
+
+#endif // D3D8_Direct3DPixelShader8_hpp
\ No newline at end of file
diff --git a/src/D3D8/Direct3DResource8.cpp b/src/D3D8/Direct3DResource8.cpp
new file mode 100644
index 0000000..7674d80
--- /dev/null
+++ b/src/D3D8/Direct3DResource8.cpp
@@ -0,0 +1,215 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "Direct3DResource8.hpp"
+
+#include "Direct3DDevice8.hpp"
+#include "Debug.hpp"
+
+namespace D3D8
+{
+ unsigned int Direct3DResource8::memoryUsage = 0;
+
+ Direct3DResource8::PrivateData::PrivateData()
+ {
+ data = 0;
+ }
+
+ Direct3DResource8::PrivateData::PrivateData(const void *data, int size, bool managed)
+ {
+ this->size = size;
+ this->managed = managed;
+
+ this->data = (void*)new unsigned char[size];
+ memcpy(this->data, data, size);
+
+ if(managed)
+ {
+ ((IUnknown*)data)->AddRef();
+ }
+ }
+
+ Direct3DResource8::PrivateData &Direct3DResource8::PrivateData::operator=(const PrivateData &privateData)
+ {
+ size = privateData.size;
+ managed = privateData.managed;
+
+ if(data)
+ {
+ if(managed)
+ {
+ ((IUnknown*)data)->Release();
+ }
+
+ delete[] data;
+ }
+
+ data = (void*)new unsigned char[size];
+ memcpy(data, privateData.data, size);
+
+ return *this;
+ }
+
+ Direct3DResource8::PrivateData::~PrivateData()
+ {
+ if(data && managed)
+ {
+ ((IUnknown*)data)->Release();
+ }
+
+ delete[] data;
+ data = 0;
+ }
+
+ Direct3DResource8::Direct3DResource8(Direct3DDevice8 *device, D3DRESOURCETYPE type, unsigned int size) : device(device), type(type), size(size)
+ {
+ priority = 0;
+
+ memoryUsage += size;
+ }
+
+ Direct3DResource8::~Direct3DResource8()
+ {
+ memoryUsage -= size;
+ }
+
+ long Direct3DResource8::QueryInterface(const IID &iid, void **object)
+ {
+ TRACE("");
+
+ if(iid == IID_IDirect3DResource8 ||
+ iid == IID_IUnknown)
+ {
+ AddRef();
+ *object = this;
+
+ return S_OK;
+ }
+
+ *object = 0;
+
+ return NOINTERFACE(iid);
+ }
+
+ unsigned long Direct3DResource8::AddRef()
+ {
+ TRACE("");
+
+ return Unknown::AddRef();
+ }
+
+ unsigned long Direct3DResource8::Release()
+ {
+ TRACE("");
+
+ return Unknown::Release();
+ }
+
+ long Direct3DResource8::GetDevice(IDirect3DDevice8 **device)
+ {
+ TRACE("");
+
+ if(!device)
+ {
+ return INVALIDCALL();
+ }
+
+ this->device->AddRef();
+ *device = this->device;
+
+ return D3D_OK;
+ }
+
+ long Direct3DResource8::SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags)
+ {
+ TRACE("");
+
+ privateData[guid] = PrivateData(data, size, flags == D3DSPD_IUNKNOWN);
+
+ return D3D_OK;
+ }
+
+ long Direct3DResource8::GetPrivateData(const GUID &guid, void *data, unsigned long *size)
+ {
+ TRACE("");
+
+ Iterator result = privateData.find(guid);
+
+ if(result == privateData.end())
+ {
+ return NOTFOUND();
+ }
+
+ if(result->second.size > *size)
+ {
+ return MOREDATA();
+ }
+
+ memcpy(data, result->second.data, result->second.size);
+
+ return D3D_OK;
+ }
+
+ long Direct3DResource8::FreePrivateData(const GUID &guid)
+ {
+ TRACE("");
+
+ Iterator result = privateData.find(guid);
+
+ if(result == privateData.end())
+ {
+ return D3DERR_NOTFOUND;
+ }
+
+ privateData.erase(guid);
+
+ return D3D_OK;
+ }
+
+ unsigned long Direct3DResource8::SetPriority(unsigned long newPriority)
+ {
+ TRACE("");
+
+ unsigned long oldPriority = priority;
+ priority = newPriority;
+
+ return oldPriority;
+ }
+
+ unsigned long Direct3DResource8::GetPriority()
+ {
+ TRACE("");
+
+ return priority;
+ }
+
+ void Direct3DResource8::PreLoad()
+ {
+ TRACE("");
+
+ return; // FIXME: Anything to do?
+ }
+
+ D3DRESOURCETYPE Direct3DResource8::GetType()
+ {
+ TRACE("");
+
+ return type;
+ }
+
+ unsigned int Direct3DResource8::getMemoryUsage()
+ {
+ return memoryUsage;
+ }
+}
\ No newline at end of file
diff --git a/src/D3D8/Direct3DResource8.hpp b/src/D3D8/Direct3DResource8.hpp
new file mode 100644
index 0000000..b80296a
--- /dev/null
+++ b/src/D3D8/Direct3DResource8.hpp
@@ -0,0 +1,92 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef D3D8_Direct3DResource8_hpp
+#define D3D8_Direct3DResource8_hpp
+
+#include "Unknown.hpp"
+
+#include <d3d8.h>
+
+#include <map>
+
+namespace D3D8
+{
+ class Direct3DDevice8;
+
+ class Direct3DResource8 : public IDirect3DResource8, public Unknown
+ {
+ public:
+ Direct3DResource8(Direct3DDevice8 *device, D3DRESOURCETYPE type, unsigned int size);
+
+ virtual ~Direct3DResource8();
+
+ // IUnknown methods
+ long __stdcall QueryInterface(const IID &iid, void **object);
+ unsigned long __stdcall AddRef();
+ unsigned long __stdcall Release();
+
+ // IDirect3DResource8 methods
+ long __stdcall GetDevice(IDirect3DDevice8 **device);
+ long __stdcall SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags);
+ long __stdcall GetPrivateData(const GUID &guid, void *data, unsigned long *size);
+ long __stdcall FreePrivateData(const GUID &guid);
+ unsigned long __stdcall SetPriority(unsigned long newPriority);
+ unsigned long __stdcall GetPriority();
+ void __stdcall PreLoad();
+ D3DRESOURCETYPE __stdcall GetType();
+
+ // Internal methods
+ static unsigned int getMemoryUsage();
+
+ protected:
+ // Creation parameters
+ Direct3DDevice8 *const device;
+ const D3DRESOURCETYPE type;
+ const unsigned int size;
+
+ private:
+ unsigned long priority;
+
+ struct PrivateData
+ {
+ PrivateData();
+ PrivateData(const void *data, int size, bool managed);
+
+ ~PrivateData();
+
+ PrivateData &operator=(const PrivateData &privateData);
+
+ void *data;
+ unsigned long size;
+ bool managed; // IUnknown interface
+ };
+
+ struct CompareGUID
+ {
+ bool operator()(const GUID& left, const GUID& right) const
+ {
+ return memcmp(&left, &right, sizeof(GUID)) < 0;
+ }
+ };
+
+ typedef std::map<GUID, PrivateData, CompareGUID> PrivateDataMap;
+ typedef PrivateDataMap::iterator Iterator;
+ PrivateDataMap privateData;
+
+ static unsigned int memoryUsage;
+ };
+}
+
+#endif // D3D8_Direct3DResource8_hpp
diff --git a/src/D3D8/Direct3DStateBlock8.cpp b/src/D3D8/Direct3DStateBlock8.cpp
new file mode 100644
index 0000000..512c935
--- /dev/null
+++ b/src/D3D8/Direct3DStateBlock8.cpp
@@ -0,0 +1,743 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "Direct3DStateBlock8.hpp"
+
+#include "Direct3DDevice8.hpp"
+#include "Direct3DBaseTexture8.hpp"
+#include "Direct3DVertexBuffer8.hpp"
+#include "Direct3DIndexBuffer8.hpp"
+#include "Debug.hpp"
+
+#include <assert.h>
+
+namespace D3D8
+{
+ Direct3DStateBlock8::Direct3DStateBlock8(Direct3DDevice8 *device, D3DSTATEBLOCKTYPE type) : device(device), type(type)
+ {
+ vertexShaderHandle = 0;
+ pixelShaderHandle = 0;
+ indexBuffer = 0;
+
+ for(int stream = 0; stream < 16; stream++)
+ {
+ streamSource[stream].vertexBuffer = 0;
+ }
+
+ for(int stage = 0; stage < 8; stage++)
+ {
+ texture[stage] = 0;
+ }
+
+ clear();
+
+ if(type == D3DSBT_PIXELSTATE || type == D3DSBT_ALL)
+ {
+ capturePixelRenderStates();
+ capturePixelTextureStates();
+ capturePixelShaderStates();
+ }
+
+ if(type == D3DSBT_VERTEXSTATE || type == D3DSBT_ALL)
+ {
+ captureVertexRenderStates();
+ captureVertexTextureStates();
+ captureLightStates();
+ captureVertexShaderStates();
+ }
+
+ if(type == D3DSBT_ALL) // Capture remaining states
+ {
+ captureTextures();
+ captureVertexTextures();
+ captureDisplacementTextures();
+ captureTexturePalette();
+ captureVertexStreams();
+ captureIndexBuffer();
+ captureViewport();
+ captureTransforms();
+ captureTextureTransforms();
+ captureClippingPlanes();
+ captureMaterial();
+ }
+ }
+
+ Direct3DStateBlock8::~Direct3DStateBlock8()
+ {
+ clear();
+ }
+
+ long Direct3DStateBlock8::QueryInterface(const IID &iid, void **object)
+ {
+ TRACE("");
+
+ ASSERT(false); // Internal object
+
+ return NOINTERFACE(iid);
+ }
+
+ unsigned long Direct3DStateBlock8::AddRef()
+ {
+ TRACE("");
+
+ return Unknown::AddRef();
+ }
+
+ unsigned long Direct3DStateBlock8::Release()
+ {
+ TRACE("");
+
+ return Unknown::Release();
+ }
+
+ long Direct3DStateBlock8::Apply()
+ {
+ TRACE("");
+
+ if(vertexShaderCaptured)
+ {
+ device->SetVertexShader(vertexShaderHandle);
+ }
+
+ if(pixelShaderCaptured)
+ {
+ device->SetPixelShader(pixelShaderHandle);
+ }
+
+ if(indexBufferCaptured)
+ {
+ device->SetIndices(indexBuffer, baseVertexIndex);
+ }
+
+ for(int state = 0; state < D3DRS_NORMALORDER + 1; state++)
+ {
+ if(renderStateCaptured[state])
+ {
+ device->SetRenderState((D3DRENDERSTATETYPE)state, renderState[state]);
+ }
+ }
+
+ for(int stage = 0; stage < 8; stage++)
+ {
+ for(int state = 0; state < D3DTSS_RESULTARG + 1; state++)
+ {
+ if(textureStageStateCaptured[stage][state])
+ {
+ device->SetTextureStageState(stage, (D3DTEXTURESTAGESTATETYPE)state, textureStageState[stage][state]);
+ }
+ }
+ }
+
+ for(int stream = 0; stream < 16; stream++)
+ {
+ if(streamSourceCaptured[stream])
+ {
+ device->SetStreamSource(stream, streamSource[stream].vertexBuffer, streamSource[stream].stride);
+ }
+ }
+
+ for(int stage = 0; stage < 8; stage++)
+ {
+ if(textureCaptured[stage])
+ {
+ device->SetTexture(stage, texture[stage]);
+ }
+ }
+
+ for(int state = 0; state < 512; state++)
+ {
+ if(transformCaptured[state])
+ {
+ device->SetTransform((D3DTRANSFORMSTATETYPE)state, &transform[state]);
+ }
+ }
+
+ if(viewportCaptured)
+ {
+ device->SetViewport(&viewport);
+ }
+
+ for(int index = 0; index < 6; index++)
+ {
+ if(clipPlaneCaptured[index])
+ {
+ device->SetClipPlane(index, clipPlane[index]);
+ }
+ }
+
+ return D3D_OK;
+ }
+
+ long Direct3DStateBlock8::Capture()
+ {
+ TRACE("");
+
+ if(vertexShaderCaptured)
+ {
+ device->GetVertexShader(&vertexShaderHandle);
+ }
+
+ if(pixelShaderCaptured)
+ {
+ device->GetPixelShader(&pixelShaderHandle);
+ }
+
+ if(indexBufferCaptured)
+ {
+ if(indexBuffer)
+ {
+ indexBuffer->Release();
+ }
+
+ device->GetIndices(reinterpret_cast<IDirect3DIndexBuffer8**>(&indexBuffer), &baseVertexIndex);
+ }
+
+ for(int state = 0; state < D3DRS_NORMALORDER + 1; state++)
+ {
+ if(renderStateCaptured[state])
+ {
+ device->GetRenderState((D3DRENDERSTATETYPE)state, &renderState[state]);
+ }
+ }
+
+ for(int stage = 0; stage < 8; stage++)
+ {
+ for(int state = 0; state < D3DTSS_RESULTARG + 1; state++)
+ {
+ if(textureStageStateCaptured[stage][state])
+ {
+ device->GetTextureStageState(stage, (D3DTEXTURESTAGESTATETYPE)state, &textureStageState[stage][state]);
+ }
+ }
+ }
+
+ for(int stream = 0; stream < 16; stream++)
+ {
+ if(streamSourceCaptured[stream])
+ {
+ if(streamSource[stream].vertexBuffer)
+ {
+ streamSource[stream].vertexBuffer->Release();
+ }
+
+ device->GetStreamSource(stream, reinterpret_cast<IDirect3DVertexBuffer8**>(&streamSource[stream].vertexBuffer), &streamSource[stream].stride);
+ }
+ }
+
+ for(int stage = 0; stage < 8; stage++)
+ {
+ if(textureCaptured[stage])
+ {
+ if(texture[stage])
+ {
+ texture[stage]->Release();
+ }
+
+ device->GetTexture(stage, reinterpret_cast<IDirect3DBaseTexture8**>(&texture[stage]));
+ }
+ }
+
+ for(int state = 0; state < 512; state++)
+ {
+ if(transformCaptured[state])
+ {
+ device->GetTransform((D3DTRANSFORMSTATETYPE)state, &transform[state]);
+ }
+ }
+
+ if(viewportCaptured)
+ {
+ device->GetViewport(&viewport);
+ }
+
+ for(int index = 0; index < 6; index++)
+ {
+ if(clipPlaneCaptured[index])
+ {
+ device->GetClipPlane(index, clipPlane[index]);
+ }
+ }
+
+ return D3D_OK;
+ }
+
+ long Direct3DStateBlock8::GetDevice(IDirect3DDevice8 **device)
+ {
+ TRACE("");
+
+ if(!device)
+ {
+ return INVALIDCALL();
+ }
+
+ this->device->AddRef();
+ *device = this->device;
+
+ return D3D_OK;
+ }
+
+ void Direct3DStateBlock8::lightEnable(unsigned long index, int enable)
+ {
+ UNIMPLEMENTED();
+ }
+
+ void Direct3DStateBlock8::setClipPlane(unsigned long index, const float *plane)
+ {
+ clipPlaneCaptured[index] = true;
+ clipPlane[index][0] = plane[0];
+ clipPlane[index][1] = plane[1];
+ clipPlane[index][2] = plane[2];
+ clipPlane[index][3] = plane[3];
+ }
+
+ void Direct3DStateBlock8::setCurrentTexturePalette(unsigned int paletteNumber)
+ {
+ UNIMPLEMENTED();
+ }
+
+ void Direct3DStateBlock8::setFVF(unsigned long FVF)
+ {
+ UNIMPLEMENTED();
+ }
+
+ void Direct3DStateBlock8::setIndices(Direct3DIndexBuffer8 *indexData, unsigned int baseVertexIndex)
+ {
+ if(indexData) indexData->AddRef();
+
+ indexBufferCaptured = true;
+ indexBuffer = indexData;
+ this->baseVertexIndex = baseVertexIndex;
+ }
+
+ void Direct3DStateBlock8::setLight(unsigned long index, const D3DLIGHT8 *light)
+ {
+ UNIMPLEMENTED();
+ }
+
+ void Direct3DStateBlock8::setMaterial(const D3DMATERIAL8 *material)
+ {
+ UNIMPLEMENTED();
+ }
+
+ void Direct3DStateBlock8::setPixelShader(unsigned long shaderHandle)
+ {
+ pixelShaderCaptured = true;
+ pixelShaderHandle = shaderHandle;
+ }
+
+ void Direct3DStateBlock8::setPixelShaderConstant(unsigned int startRegister, const void *constantData, unsigned int count)
+ {
+ UNIMPLEMENTED();
+ }
+
+ void Direct3DStateBlock8::setRenderState(D3DRENDERSTATETYPE state, unsigned long value)
+ {
+ renderStateCaptured[state] = true;
+ renderState[state] = value;
+ }
+
+ void Direct3DStateBlock8::setScissorRect(const RECT *rect)
+ {
+ UNIMPLEMENTED();
+ }
+
+ void Direct3DStateBlock8::setStreamSource(unsigned int stream, Direct3DVertexBuffer8 *data, unsigned int stride)
+ {
+ if(data) data->AddRef();
+
+ streamSourceCaptured[stream] = true;
+ streamSource[stream].vertexBuffer = data;
+ streamSource[stream].stride = stride;
+ }
+
+ void Direct3DStateBlock8::setTexture(unsigned long stage, Direct3DBaseTexture8 *texture)
+ {
+ if(texture) texture->AddRef();
+
+ textureCaptured[stage] = true;
+ this->texture[stage] = texture;
+ }
+
+ void Direct3DStateBlock8::setTextureStageState(unsigned long stage, D3DTEXTURESTAGESTATETYPE type, unsigned long value)
+ {
+ textureStageStateCaptured[stage][type] = true;
+ textureStageState[stage][type] = value;
+ }
+
+ void Direct3DStateBlock8::setTransform(D3DTRANSFORMSTATETYPE state, const D3DMATRIX *matrix)
+ {
+ transformCaptured[state] = true;
+ transform[state] = *matrix;
+ }
+
+ void Direct3DStateBlock8::setViewport(const D3DVIEWPORT8 *viewport)
+ {
+ viewportCaptured = true;
+ this->viewport = *viewport;
+ }
+
+ void Direct3DStateBlock8::setVertexShader(unsigned long shaderHandle)
+ {
+ vertexShaderCaptured = true;
+ vertexShaderHandle = shaderHandle;
+ }
+
+ void Direct3DStateBlock8::setVertexShaderConstant(unsigned int startRegister, const void *constantData, unsigned int count)
+ {
+ UNIMPLEMENTED();
+ }
+
+ void Direct3DStateBlock8::clear()
+ {
+ // Erase capture flags
+ vertexShaderCaptured = false;
+ pixelShaderCaptured = false;
+ indexBufferCaptured = false;
+
+ for(int state = 0; state < D3DRS_NORMALORDER + 1; state++)
+ {
+ renderStateCaptured[state] = false;
+ }
+
+ for(int stage = 0; stage < 8; stage++)
+ {
+ for(int state = 0; state < D3DTSS_RESULTARG + 1; state++)
+ {
+ textureStageStateCaptured[stage][state] = false;
+ }
+ }
+
+ for(int stream = 0; stream < 16; stream++)
+ {
+ streamSourceCaptured[stream] = false;
+ }
+
+ for(int stage = 0; stage < 8; stage++)
+ {
+ textureCaptured[stage] = false;
+ }
+
+ for(int state = 0; state < 512; state++)
+ {
+ transformCaptured[state] = false;
+ }
+
+ viewportCaptured = false;
+
+ for(int index = 0; index < 6; index++)
+ {
+ clipPlaneCaptured[index] = false;
+ }
+
+ // Release resources
+ vertexShaderHandle = 0;
+ pixelShaderHandle = 0;
+
+ if(indexBuffer)
+ {
+ indexBuffer->Release();
+ indexBuffer = 0;
+ }
+
+ for(int stream = 0; stream < 16; stream++)
+ {
+ if(streamSource[stream].vertexBuffer)
+ {
+ streamSource[stream].vertexBuffer->Release();
+ streamSource[stream].vertexBuffer = 0;
+ }
+ }
+
+ for(int stage = 0; stage < 8; stage++)
+ {
+ if(texture[stage])
+ {
+ texture[stage]->Release();
+ texture[stage] = 0;
+ }
+ }
+ }
+
+ void Direct3DStateBlock8::captureRenderState(D3DRENDERSTATETYPE state)
+ {
+ device->GetRenderState(state, &renderState[state]);
+ renderStateCaptured[state] = true;
+ }
+
+ void Direct3DStateBlock8::captureTextureStageState(unsigned long stage, D3DTEXTURESTAGESTATETYPE type)
+ {
+ device->GetTextureStageState(stage, type, &textureStageState[stage][type]);
+ textureStageStateCaptured[stage][type] = true;
+ }
+
+ void Direct3DStateBlock8::captureTransform(D3DTRANSFORMSTATETYPE state)
+ {
+ device->GetTransform(state, &transform[state]);
+ transformCaptured[state] = true;
+ }
+
+ void Direct3DStateBlock8::capturePixelRenderStates()
+ {
+ captureRenderState(D3DRS_ZENABLE);
+ captureRenderState(D3DRS_FILLMODE);
+ captureRenderState(D3DRS_SHADEMODE);
+ captureRenderState(D3DRS_ZWRITEENABLE);
+ captureRenderState(D3DRS_ALPHATESTENABLE);
+ captureRenderState(D3DRS_LASTPIXEL);
+ captureRenderState(D3DRS_SRCBLEND);
+ captureRenderState(D3DRS_DESTBLEND);
+ captureRenderState(D3DRS_ZFUNC);
+ captureRenderState(D3DRS_ALPHAREF);
+ captureRenderState(D3DRS_ALPHAFUNC);
+ captureRenderState(D3DRS_DITHERENABLE);
+ captureRenderState(D3DRS_FOGSTART);
+ captureRenderState(D3DRS_FOGEND);
+ captureRenderState(D3DRS_FOGDENSITY);
+ captureRenderState(D3DRS_ALPHABLENDENABLE);
+ captureRenderState(D3DRS_ZBIAS);
+ captureRenderState(D3DRS_STENCILENABLE);
+ captureRenderState(D3DRS_STENCILFAIL);
+ captureRenderState(D3DRS_STENCILZFAIL);
+ captureRenderState(D3DRS_STENCILPASS);
+ captureRenderState(D3DRS_STENCILFUNC);
+ captureRenderState(D3DRS_STENCILREF);
+ captureRenderState(D3DRS_STENCILMASK);
+ captureRenderState(D3DRS_STENCILWRITEMASK);
+ captureRenderState(D3DRS_TEXTUREFACTOR);
+ captureRenderState(D3DRS_WRAP0);
+ captureRenderState(D3DRS_WRAP1);
+ captureRenderState(D3DRS_WRAP2);
+ captureRenderState(D3DRS_WRAP3);
+ captureRenderState(D3DRS_WRAP4);
+ captureRenderState(D3DRS_WRAP5);
+ captureRenderState(D3DRS_WRAP6);
+ captureRenderState(D3DRS_WRAP7);
+ captureRenderState(D3DRS_COLORWRITEENABLE);
+ captureRenderState(D3DRS_BLENDOP);
+ }
+
+ void Direct3DStateBlock8::capturePixelTextureStates()
+ {
+ for(int stage = 0; stage < 8; stage++)
+ {
+ captureTextureStageState(stage, D3DTSS_COLOROP);
+ captureTextureStageState(stage, D3DTSS_COLORARG1);
+ captureTextureStageState(stage, D3DTSS_COLORARG2);
+ captureTextureStageState(stage, D3DTSS_ALPHAOP);
+ captureTextureStageState(stage, D3DTSS_ALPHAARG1);
+ captureTextureStageState(stage, D3DTSS_ALPHAARG2);
+ captureTextureStageState(stage, D3DTSS_BUMPENVMAT00);
+ captureTextureStageState(stage, D3DTSS_BUMPENVMAT01);
+ captureTextureStageState(stage, D3DTSS_BUMPENVMAT10);
+ captureTextureStageState(stage, D3DTSS_BUMPENVMAT11);
+ captureTextureStageState(stage, D3DTSS_TEXCOORDINDEX);
+ captureTextureStageState(stage, D3DTSS_BUMPENVLSCALE);
+ captureTextureStageState(stage, D3DTSS_BUMPENVLOFFSET);
+ captureTextureStageState(stage, D3DTSS_TEXTURETRANSFORMFLAGS);
+ captureTextureStageState(stage, D3DTSS_COLORARG0);
+ captureTextureStageState(stage, D3DTSS_ALPHAARG0);
+ captureTextureStageState(stage, D3DTSS_RESULTARG);
+
+ captureTextureStageState(stage, D3DTSS_ADDRESSU);
+ captureTextureStageState(stage, D3DTSS_ADDRESSV);
+ captureTextureStageState(stage, D3DTSS_ADDRESSW);
+ captureTextureStageState(stage, D3DTSS_BORDERCOLOR);
+ captureTextureStageState(stage, D3DTSS_MAGFILTER);
+ captureTextureStageState(stage, D3DTSS_MINFILTER);
+ captureTextureStageState(stage, D3DTSS_MIPFILTER);
+ captureTextureStageState(stage, D3DTSS_MIPMAPLODBIAS);
+ captureTextureStageState(stage, D3DTSS_MAXMIPLEVEL);
+ captureTextureStageState(stage, D3DTSS_MAXANISOTROPY);
+ }
+ }
+
+ void Direct3DStateBlock8::capturePixelShaderStates()
+ {
+ pixelShaderCaptured = true;
+ device->GetPixelShader(&pixelShaderHandle);
+
+ device->GetPixelShaderConstant(0, pixelShaderConstant, 8);
+ }
+
+ void Direct3DStateBlock8::captureVertexRenderStates()
+ {
+ captureRenderState(D3DRS_CULLMODE);
+ captureRenderState(D3DRS_FOGENABLE);
+ captureRenderState(D3DRS_FOGCOLOR);
+ captureRenderState(D3DRS_FOGTABLEMODE);
+ captureRenderState(D3DRS_FOGSTART);
+ captureRenderState(D3DRS_FOGEND);
+ captureRenderState(D3DRS_FOGDENSITY);
+ captureRenderState(D3DRS_RANGEFOGENABLE);
+ captureRenderState(D3DRS_AMBIENT);
+ captureRenderState(D3DRS_COLORVERTEX);
+ captureRenderState(D3DRS_FOGVERTEXMODE);
+ captureRenderState(D3DRS_CLIPPING);
+ captureRenderState(D3DRS_LIGHTING);
+ captureRenderState(D3DRS_LOCALVIEWER);
+ captureRenderState(D3DRS_EMISSIVEMATERIALSOURCE);
+ captureRenderState(D3DRS_AMBIENTMATERIALSOURCE);
+ captureRenderState(D3DRS_DIFFUSEMATERIALSOURCE);
+ captureRenderState(D3DRS_SPECULARMATERIALSOURCE);
+ captureRenderState(D3DRS_VERTEXBLEND);
+ captureRenderState(D3DRS_CLIPPLANEENABLE);
+ captureRenderState(D3DRS_POINTSIZE);
+ captureRenderState(D3DRS_POINTSIZE_MIN);
+ captureRenderState(D3DRS_POINTSPRITEENABLE);
+ captureRenderState(D3DRS_POINTSCALEENABLE);
+ captureRenderState(D3DRS_POINTSCALE_A);
+ captureRenderState(D3DRS_POINTSCALE_B);
+ captureRenderState(D3DRS_POINTSCALE_C);
+ captureRenderState(D3DRS_MULTISAMPLEANTIALIAS);
+ captureRenderState(D3DRS_MULTISAMPLEMASK);
+ captureRenderState(D3DRS_PATCHEDGESTYLE);
+ captureRenderState(D3DRS_POINTSIZE_MAX);
+ captureRenderState(D3DRS_INDEXEDVERTEXBLENDENABLE);
+ captureRenderState(D3DRS_TWEENFACTOR);
+ captureRenderState(D3DRS_NORMALIZENORMALS);
+ captureRenderState(D3DRS_SPECULARENABLE);
+ captureRenderState(D3DRS_SHADEMODE);
+ }
+
+ void Direct3DStateBlock8::captureVertexTextureStates()
+ {
+ for(int stage = 0; stage < 8; stage++)
+ {
+ captureTextureStageState(stage, D3DTSS_TEXCOORDINDEX);
+ captureTextureStageState(stage, D3DTSS_TEXTURETRANSFORMFLAGS);
+ }
+ }
+
+ void Direct3DStateBlock8::captureLightStates()
+ {
+ for(int index = 0; index < 8; index++) // FIXME: Support unlimited index
+ {
+ device->GetLight(index, &light[index]);
+ lightCaptured[index] = true;
+ }
+
+ for(int index = 0; index < 8; index++) // FIXME: Support unlimited index
+ {
+ lightEnableState[index] = false;
+ device->GetLightEnable(index, &lightEnableState[index]);
+ lightEnableCaptured[index] = true;
+ }
+ }
+
+ void Direct3DStateBlock8::captureVertexShaderStates()
+ {
+ vertexShaderCaptured = true;
+ device->GetVertexShader(&vertexShaderHandle);
+
+ device->GetVertexShaderConstant(0, vertexShaderConstant[0], 256);
+ }
+
+ void Direct3DStateBlock8::captureTextures()
+ {
+ for(int sampler = 0; sampler < 8; sampler++)
+ {
+ textureCaptured[sampler] = true;
+ device->GetTexture(sampler, reinterpret_cast<IDirect3DBaseTexture8**>(&texture[sampler]));
+
+ if(texture[sampler])
+ {
+ texture[sampler]->bind();
+ texture[sampler]->Release();
+ }
+ }
+ }
+
+ void Direct3DStateBlock8::captureVertexTextures()
+ {
+ // FIXME
+ }
+
+ void Direct3DStateBlock8::captureDisplacementTextures()
+ {
+ // FIXME
+ }
+
+ void Direct3DStateBlock8::captureTexturePalette()
+ {
+ paletteNumberCaptured = true;
+ device->GetCurrentTexturePalette(&paletteNumber);
+ }
+
+ void Direct3DStateBlock8::captureVertexStreams()
+ {
+ for(int stream = 0; stream < 16; stream++)
+ {
+ streamSourceCaptured[stream] = true;
+ device->GetStreamSource(stream, reinterpret_cast<IDirect3DVertexBuffer8**>(&streamSource[stream].vertexBuffer), &streamSource[stream].stride);
+
+ if(streamSource[stream].vertexBuffer)
+ {
+ streamSource[stream].vertexBuffer->bind();
+ streamSource[stream].vertexBuffer->Release();
+ }
+ }
+ }
+
+ void Direct3DStateBlock8::captureIndexBuffer()
+ {
+ indexBufferCaptured = true;
+ device->GetIndices(reinterpret_cast<IDirect3DIndexBuffer8**>(&indexBuffer), &baseVertexIndex);
+
+ if(indexBuffer)
+ {
+ indexBuffer->bind();
+ indexBuffer->Release();
+ }
+ }
+
+ void Direct3DStateBlock8::captureViewport()
+ {
+ device->GetViewport(&viewport);
+ viewportCaptured = true;
+ }
+
+ void Direct3DStateBlock8::captureTransforms()
+ {
+ captureTransform(D3DTS_VIEW);
+ captureTransform(D3DTS_PROJECTION);
+ captureTransform(D3DTS_WORLD);
+ }
+
+ void Direct3DStateBlock8::captureTextureTransforms()
+ {
+ captureTransform(D3DTS_TEXTURE0);
+ captureTransform(D3DTS_TEXTURE1);
+ captureTransform(D3DTS_TEXTURE2);
+ captureTransform(D3DTS_TEXTURE3);
+ captureTransform(D3DTS_TEXTURE4);
+ captureTransform(D3DTS_TEXTURE5);
+ captureTransform(D3DTS_TEXTURE6);
+ captureTransform(D3DTS_TEXTURE7);
+ }
+
+ void Direct3DStateBlock8::captureClippingPlanes()
+ {
+ for(int index = 0; index < 6; index++)
+ {
+ device->GetClipPlane(index, (float*)&clipPlane[index]);
+ clipPlaneCaptured[index] = true;
+ }
+ }
+
+ void Direct3DStateBlock8::captureMaterial()
+ {
+ device->GetMaterial(&material);
+ materialCaptured = true;
+ }
+}
\ No newline at end of file
diff --git a/src/D3D8/Direct3DStateBlock8.hpp b/src/D3D8/Direct3DStateBlock8.hpp
new file mode 100644
index 0000000..744de2e
--- /dev/null
+++ b/src/D3D8/Direct3DStateBlock8.hpp
@@ -0,0 +1,161 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef D3D8_Direct3DStateBlock8_hpp
+#define D3D8_Direct3DStateBlock8_hpp
+
+#include "Unknown.hpp"
+
+#include <vector>
+
+#include <d3d8.h>
+
+namespace D3D8
+{
+ class Direct3DDevice8;
+ class Direct3DBaseTexture8;
+ class Direct3DVertexBuffer8;
+ class Direct3DIndexBuffer8;
+
+ class Direct3DStateBlock8 : public Unknown
+ {
+ public:
+ Direct3DStateBlock8(Direct3DDevice8 *device, D3DSTATEBLOCKTYPE type);
+
+ virtual ~Direct3DStateBlock8();
+
+ // IUnknown methods
+ long __stdcall QueryInterface(const IID &iid, void **object);
+ unsigned long __stdcall AddRef();
+ unsigned long __stdcall Release();
+
+ // IDirect3DStateBlock8 methods
+ long __stdcall Apply();
+ long __stdcall Capture();
+ long __stdcall GetDevice(IDirect3DDevice8 **device);
+
+ // Internal methods
+ void lightEnable(unsigned long index, int enable);
+ void setClipPlane(unsigned long index, const float *plane);
+ void setCurrentTexturePalette(unsigned int paletteNumber);
+ void setFVF(unsigned long FVF);
+ void setIndices(Direct3DIndexBuffer8 *indexData, unsigned int baseVertexIndex);
+ void setLight(unsigned long index, const D3DLIGHT8 *light);
+ void setMaterial(const D3DMATERIAL8 *material);
+ void setPixelShader(unsigned long shaderHandle);
+ void setPixelShaderConstant(unsigned int startRegister, const void *constantData, unsigned int count);
+ void setRenderState(D3DRENDERSTATETYPE state, unsigned long value);
+ void setScissorRect(const RECT *rect);
+ void setStreamSource(unsigned int stream, Direct3DVertexBuffer8 *data, unsigned int stride);
+ void setTexture(unsigned long stage, Direct3DBaseTexture8 *texture);
+ void setTextureStageState(unsigned long stage, D3DTEXTURESTAGESTATETYPE type, unsigned long value);
+ void setTransform(D3DTRANSFORMSTATETYPE state, const D3DMATRIX *matrix);
+ void setViewport(const D3DVIEWPORT8 *viewport);
+ void setVertexShader(unsigned long shaderHandle);
+ void setVertexShaderConstant(unsigned int startRegister, const void *constantData, unsigned int count);
+
+ private:
+ // Individual states
+ void captureRenderState(D3DRENDERSTATETYPE state);
+ void captureTextureStageState(unsigned long stage, D3DTEXTURESTAGESTATETYPE type);
+ void captureTransform(D3DTRANSFORMSTATETYPE state);
+
+ // Pixel states
+ void capturePixelRenderStates();
+ void capturePixelTextureStates();
+ void capturePixelShaderStates();
+
+ // Vertex states
+ void captureVertexRenderStates();
+ void captureVertexTextureStates();
+ void captureLightStates();
+ void captureVertexShaderStates();
+
+ // All (remaining) states
+ void captureTextures();
+ void captureVertexTextures();
+ void captureDisplacementTextures();
+ void captureTexturePalette();
+ void captureVertexStreams();
+ void captureIndexBuffer();
+ void captureViewport();
+ void captureTransforms();
+ void captureTextureTransforms();
+ void captureClippingPlanes();
+ void captureMaterial();
+
+ // Creation parameters
+ Direct3DDevice8 *const device;
+ const D3DSTATEBLOCKTYPE type;
+
+ // State data
+ bool vertexShaderCaptured;
+ unsigned long vertexShaderHandle;
+
+ bool pixelShaderCaptured;
+ unsigned long pixelShaderHandle;
+
+ bool indexBufferCaptured;
+ Direct3DIndexBuffer8 *indexBuffer;
+ unsigned int baseVertexIndex;
+
+ bool renderStateCaptured[D3DRS_NORMALORDER + 1];
+ unsigned long renderState[D3DRS_NORMALORDER + 1];
+
+ bool textureStageStateCaptured[8][D3DTSS_RESULTARG + 1];
+ unsigned long textureStageState[8][D3DTSS_RESULTARG + 1];
+
+ bool streamSourceCaptured[16];
+ struct StreamSource
+ {
+ Direct3DVertexBuffer8 *vertexBuffer;
+ unsigned int stride;
+ };
+ StreamSource streamSource[16];
+
+ bool textureCaptured[8];
+ Direct3DBaseTexture8 *texture[8];
+
+ bool transformCaptured[512];
+ D3DMATRIX transform[512];
+
+ bool viewportCaptured;
+ D3DVIEWPORT8 viewport;
+
+ bool clipPlaneCaptured[6];
+ float clipPlane[6][4];
+
+ bool materialCaptured;
+ D3DMATERIAL8 material;
+
+ bool lightCaptured[8]; // FIXME: Unlimited index
+ D3DLIGHT8 light[8];
+
+ bool lightEnableCaptured[8]; // FIXME: Unlimited index
+ int lightEnableState[8];
+
+ float pixelShaderConstant[8][4];
+ float vertexShaderConstant[256][4];
+
+ bool scissorRectCaptured;
+ RECT scissorRect;
+
+ bool paletteNumberCaptured;
+ unsigned int paletteNumber;
+
+ void clear();
+ };
+}
+
+#endif // D3D8_Direct3DStateBlock8_hpp
\ No newline at end of file
diff --git a/src/D3D8/Direct3DSurface8.cpp b/src/D3D8/Direct3DSurface8.cpp
new file mode 100644
index 0000000..2a4dea6
--- /dev/null
+++ b/src/D3D8/Direct3DSurface8.cpp
@@ -0,0 +1,280 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "Direct3DSurface8.hpp"
+
+#include "Direct3DBaseTexture8.hpp"
+#include "Debug.hpp"
+
+#include <malloc.h>
+#include <assert.h>
+
+extern bool quadLayoutEnabled;
+
+namespace D3D8
+{
+ static sw::Resource *getParentResource(Unknown *container)
+ {
+ Direct3DBaseTexture8 *baseTexture = dynamic_cast<Direct3DBaseTexture8*>(container);
+
+ if(baseTexture)
+ {
+ return baseTexture->getResource();
+ }
+
+ return 0;
+ }
+
+ int sampleCount(D3DMULTISAMPLE_TYPE multiSample)
+ {
+ if(multiSample == D3DMULTISAMPLE_2_SAMPLES)
+ {
+ return 2;
+ }
+ else if(multiSample == D3DMULTISAMPLE_4_SAMPLES)
+ {
+ return 4;
+ }
+ else if(multiSample == D3DMULTISAMPLE_8_SAMPLES)
+ {
+ return 8;
+ }
+ else if(multiSample == D3DMULTISAMPLE_16_SAMPLES)
+ {
+ return 16;
+ }
+
+ return 1;
+ }
+
+ Direct3DSurface8::Direct3DSurface8(Direct3DDevice8 *device, Unknown *container, int width, int height, D3DFORMAT format, D3DPOOL pool, D3DMULTISAMPLE_TYPE multiSample, bool lockable, unsigned long usage) : Surface(getParentResource(container), width, height, sampleCount(multiSample), translateFormat(format), lockable, (usage & D3DUSAGE_RENDERTARGET) == D3DUSAGE_RENDERTARGET || (usage & D3DUSAGE_DEPTHSTENCIL) == D3DUSAGE_DEPTHSTENCIL), device(device), container(container), width(width), height(height), format(format), pool(pool), multiSample(multiSample), lockable(lockable), usage(usage)
+ {
+ parentTexture = dynamic_cast<Direct3DBaseTexture8*>(container);
+
+ resource = new Direct3DResource8(device, D3DRTYPE_SURFACE, memoryUsage(width, height, format));
+ }
+
+ Direct3DSurface8::~Direct3DSurface8()
+ {
+ resource->Release();
+ }
+
+ long Direct3DSurface8::QueryInterface(const IID &iid, void **object)
+ {
+ TRACE("");
+
+ if(iid == IID_IDirect3DSurface8 ||
+ iid == IID_IUnknown)
+ {
+ AddRef();
+ *object = this;
+
+ return S_OK;
+ }
+
+ *object = 0;
+
+ return NOINTERFACE(iid);
+ }
+
+ unsigned long Direct3DSurface8::AddRef()
+ {
+ TRACE("");
+
+ if(parentTexture)
+ {
+ return parentTexture->AddRef();
+ }
+
+ return Unknown::AddRef();
+ }
+
+ unsigned long Direct3DSurface8::Release()
+ {
+ TRACE("");
+
+ if(parentTexture)
+ {
+ return parentTexture->Release();
+ }
+
+ return Unknown::Release();
+ }
+
+ long Direct3DSurface8::FreePrivateData(const GUID &guid)
+ {
+ TRACE("");
+
+ return resource->FreePrivateData(guid);
+ }
+
+ long Direct3DSurface8::GetPrivateData(const GUID &guid, void *data, unsigned long *size)
+ {
+ TRACE("");
+
+ return resource->GetPrivateData(guid, data, size);
+ }
+
+ long Direct3DSurface8::SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags)
+ {
+ TRACE("");
+
+ return resource->SetPrivateData(guid, data, size, flags);
+ }
+
+ long Direct3DSurface8::GetDevice(IDirect3DDevice8 **device)
+ {
+ TRACE("");
+
+ return resource->GetDevice(device);
+ }
+
+ long Direct3DSurface8::LockRect(D3DLOCKED_RECT *lockedRect, const RECT *rect, unsigned long flags)
+ {
+ TRACE("");
+
+ if(!lockedRect)
+ {
+ return INVALIDCALL();
+ }
+
+ lockedRect->Pitch = getExternalPitchB();
+
+ sw::Lock lock = sw::LOCK_READWRITE;
+
+ if(flags & D3DLOCK_DISCARD)
+ {
+ lock = sw::LOCK_DISCARD;
+ }
+
+ if(flags & D3DLOCK_READONLY)
+ {
+ lock = sw::LOCK_READONLY;
+ }
+
+ if(rect)
+ {
+ lockedRect->pBits = lockExternal(rect->left, rect->top, 0, lock, sw::PUBLIC);
+ }
+ else
+ {
+ lockedRect->pBits = lockExternal(0, 0, 0, lock, sw::PUBLIC);
+ }
+
+ unlockExternal();
+
+ return D3D_OK;
+ }
+
+ long Direct3DSurface8::UnlockRect()
+ {
+ TRACE("");
+
+ return D3D_OK;
+ }
+
+ long Direct3DSurface8::GetContainer(const IID &iid, void **container)
+ {
+ TRACE("");
+
+ if(!container)
+ {
+ return INVALIDCALL();
+ }
+
+ long result = this->container->QueryInterface(iid, container);
+
+ if(result == S_OK)
+ {
+ return D3D_OK;
+ }
+
+ return INVALIDCALL();
+ }
+
+ long Direct3DSurface8::GetDesc(D3DSURFACE_DESC *desc)
+ {
+ TRACE("");
+
+ if(!desc)
+ {
+ return INVALIDCALL();
+ }
+
+ desc->Format = format;
+ desc->Pool = pool;
+ desc->Type = D3DRTYPE_SURFACE;
+ desc->Height = height;
+ desc->Width = width;
+ desc->Size = size(getWidth(), getHeight(), getDepth(), getExternalFormat());
+ desc->MultiSampleType = multiSample;
+ desc->Usage = usage;
+
+ return D3D_OK;
+ }
+
+ sw::Format Direct3DSurface8::translateFormat(D3DFORMAT format)
+ {
+ switch(format)
+ {
+ case D3DFMT_DXT1: return sw::FORMAT_DXT1;
+ case D3DFMT_DXT2: return sw::FORMAT_DXT3;
+ case D3DFMT_DXT3: return sw::FORMAT_DXT3;
+ case D3DFMT_DXT4: return sw::FORMAT_DXT5;
+ case D3DFMT_DXT5: return sw::FORMAT_DXT5;
+ case D3DFMT_R3G3B2: return sw::FORMAT_R3G3B2;
+ case D3DFMT_A8R3G3B2: return sw::FORMAT_A8R3G3B2;
+ case D3DFMT_X4R4G4B4: return sw::FORMAT_X4R4G4B4;
+ case D3DFMT_A4R4G4B4: return sw::FORMAT_A4R4G4B4;
+ case D3DFMT_A8R8G8B8: return sw::FORMAT_A8R8G8B8;
+ case D3DFMT_G16R16: return sw::FORMAT_G16R16;
+ case D3DFMT_A2B10G10R10: return sw::FORMAT_A2B10G10R10;
+ case D3DFMT_P8: return sw::FORMAT_P8;
+ case D3DFMT_A8P8: return sw::FORMAT_A8P8;
+ case D3DFMT_A8: return sw::FORMAT_A8;
+ case D3DFMT_R5G6B5: return sw::FORMAT_R5G6B5;
+ case D3DFMT_X1R5G5B5: return sw::FORMAT_X1R5G5B5;
+ case D3DFMT_A1R5G5B5: return sw::FORMAT_A1R5G5B5;
+ case D3DFMT_R8G8B8: return sw::FORMAT_R8G8B8;
+ case D3DFMT_X8R8G8B8: return sw::FORMAT_X8R8G8B8;
+ case D3DFMT_V8U8: return sw::FORMAT_V8U8;
+ case D3DFMT_L6V5U5: return sw::FORMAT_L6V5U5;
+ case D3DFMT_Q8W8V8U8: return sw::FORMAT_Q8W8V8U8;
+ case D3DFMT_X8L8V8U8: return sw::FORMAT_X8L8V8U8;
+ case D3DFMT_A2W10V10U10: return sw::FORMAT_A2W10V10U10;
+ case D3DFMT_V16U16: return sw::FORMAT_V16U16;
+ case D3DFMT_L8: return sw::FORMAT_L8;
+ case D3DFMT_A4L4: return sw::FORMAT_A4L4;
+ case D3DFMT_A8L8: return sw::FORMAT_A8L8;
+ case D3DFMT_D16: return sw::FORMAT_D16;
+ case D3DFMT_D32: return sw::FORMAT_D32;
+ case D3DFMT_D24X8: return sw::FORMAT_D24X8;
+ case D3DFMT_D24S8: return sw::FORMAT_D24S8;
+ default:
+ ASSERT(false);
+ }
+
+ return sw::FORMAT_NULL;
+ }
+
+ int Direct3DSurface8::bytes(D3DFORMAT format)
+ {
+ return Surface::bytes(translateFormat(format));
+ }
+
+ unsigned int Direct3DSurface8::memoryUsage(int width, int height, D3DFORMAT format)
+ {
+ return Surface::size(width, height, 1, translateFormat(format));
+ }
+}
diff --git a/src/D3D8/Direct3DSurface8.hpp b/src/D3D8/Direct3DSurface8.hpp
new file mode 100644
index 0000000..2796480
--- /dev/null
+++ b/src/D3D8/Direct3DSurface8.hpp
@@ -0,0 +1,74 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef D3D8_Direct3DSurface8_hpp
+#define D3D8_Direct3DSurface8_hpp
+
+#include "Unknown.hpp"
+#include "Surface.hpp"
+
+#include <d3d8.h>
+
+namespace D3D8
+{
+ class Direct3DDevice8;
+ class Direct3DResource8;
+ class Direct3DBaseTexture8;
+
+ class Direct3DSurface8 : public IDirect3DSurface8, public Unknown, public sw::Surface
+ {
+ public:
+ Direct3DSurface8(Direct3DDevice8 *device, Unknown *container, int width, int height, D3DFORMAT format, D3DPOOL pool, D3DMULTISAMPLE_TYPE multiSample, bool lockable, unsigned long usage);
+
+ virtual ~Direct3DSurface8();
+
+ // IUnknown methods
+ long __stdcall QueryInterface(const IID &iid, void **object);
+ unsigned long __stdcall AddRef();
+ unsigned long __stdcall Release();
+
+ // IDirect3DSurface8 methods
+ long __stdcall GetDevice(IDirect3DDevice8 **device);
+ long __stdcall SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags);
+ long __stdcall GetPrivateData(const GUID &guid, void *data, unsigned long *size);
+ long __stdcall FreePrivateData(const GUID &guid);
+ long __stdcall GetContainer(const IID &iid, void **container);
+ long __stdcall GetDesc(D3DSURFACE_DESC *desc);
+ long __stdcall LockRect(D3DLOCKED_RECT *lockedRect, const RECT *rect, unsigned long Flags);
+ long __stdcall UnlockRect();
+
+ // Internal methods
+ static sw::Format translateFormat(D3DFORMAT format);
+ static int bytes(D3DFORMAT format);
+
+ private:
+ static unsigned int memoryUsage(int width, int height, D3DFORMAT format); // FIXME: Surface::size
+
+ // Creation parameters
+ Direct3DDevice8 *const device;
+ Unknown *const container;
+ const int width;
+ const int height;
+ const D3DFORMAT format;
+ const D3DMULTISAMPLE_TYPE multiSample;
+ const D3DPOOL pool;
+ const bool lockable;
+ const unsigned long usage;
+
+ Direct3DBaseTexture8 *parentTexture;
+ Direct3DResource8 *resource;
+ };
+}
+
+#endif // D3D8_Direct3DSurface8_hpp
diff --git a/src/D3D8/Direct3DSwapChain8.cpp b/src/D3D8/Direct3DSwapChain8.cpp
new file mode 100644
index 0000000..a49bf11
--- /dev/null
+++ b/src/D3D8/Direct3DSwapChain8.cpp
@@ -0,0 +1,230 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "Direct3DSwapChain8.hpp"
+
+#include "Direct3DDevice8.hpp"
+#include "Config.hpp"
+#include "Configurator.hpp"
+#include "Debug.hpp"
+
+#include "FrameBufferDD.hpp"
+#include "FrameBufferGDI.hpp"
+
+namespace D3D8
+{
+ Direct3DSwapChain8::Direct3DSwapChain8(Direct3DDevice8 *device, D3DPRESENT_PARAMETERS *presentParameters) : device(device), presentParameters(*presentParameters)
+ {
+ frameBuffer = 0;
+
+ for(int i = 0; i < 3; i++)
+ {
+ backBuffer[i] = 0;
+ }
+
+ reset(presentParameters);
+ }
+
+ Direct3DSwapChain8::~Direct3DSwapChain8()
+ {
+ release();
+ }
+
+ long Direct3DSwapChain8::QueryInterface(const IID &iid, void **object)
+ {
+ TRACE("");
+
+ if(iid == IID_IDirect3DSwapChain8 ||
+ iid == IID_IUnknown)
+ {
+ AddRef();
+ *object = this;
+
+ return S_OK;
+ }
+
+ *object = 0;
+
+ return NOINTERFACE(iid);
+ }
+
+ unsigned long Direct3DSwapChain8::AddRef()
+ {
+ TRACE("");
+
+ return Unknown::AddRef();
+ }
+
+ unsigned long Direct3DSwapChain8::Release()
+ {
+ TRACE("");
+
+ return Unknown::Release();
+ }
+
+ long Direct3DSwapChain8::Present(const RECT *sourceRect, const RECT *destRect, HWND destWindowOverride, const RGNDATA *dirtyRegion)
+ {
+ TRACE("");
+
+ #if PERF_PROFILE
+ profiler.nextFrame();
+ #endif
+
+ void *source = backBuffer[0]->lockInternal(0, 0, 0, sw::LOCK_READONLY, sw::PUBLIC); // FIXME: External
+ sw::Format format = backBuffer[0]->getInternalFormat();
+ int stride = backBuffer[0]->getInternalPitchB();
+
+ if(!sourceRect && !destRect) // FIXME: More cases?
+ {
+ frameBuffer->flip(destWindowOverride, source, format, stride);
+ }
+ else // TODO: Check for SWAPEFFECT_COPY
+ {
+ sw::Rect sRect(0, 0, 0, 0);
+ sw::Rect dRect(0, 0, 0, 0);
+
+ if(sourceRect)
+ {
+ sRect.x0 = sourceRect->left;
+ sRect.y0 = sourceRect->top;
+ sRect.x1 = sourceRect->right;
+ sRect.y1 = sourceRect->bottom;
+ }
+
+ if(destRect)
+ {
+ dRect.x0 = destRect->left;
+ dRect.y0 = destRect->top;
+ dRect.x1 = destRect->right;
+ dRect.y1 = destRect->bottom;
+ }
+
+ frameBuffer->blit(destWindowOverride, source, sourceRect ? &sRect : nullptr, destRect ? &dRect : nullptr, format, stride);
+ }
+
+ backBuffer[0]->unlockInternal(); // FIXME: External
+
+ return D3D_OK;
+ }
+
+ long Direct3DSwapChain8::GetBackBuffer(unsigned int index, D3DBACKBUFFER_TYPE type, IDirect3DSurface8 **backBuffer)
+ {
+ TRACE("");
+
+ if(!backBuffer/* || type != D3DBACKBUFFER_TYPE_MONO*/)
+ {
+ return INVALIDCALL();
+ }
+
+ if(index >= 3 || this->backBuffer[index] == 0)
+ {
+ return INVALIDCALL();
+ }
+
+ this->backBuffer[index]->AddRef();
+ *backBuffer = this->backBuffer[index];
+
+ return D3D_OK;
+ }
+
+ void Direct3DSwapChain8::reset(D3DPRESENT_PARAMETERS *presentParameters)
+ {
+ release();
+
+ this->presentParameters = *presentParameters;
+
+ ASSERT(presentParameters->BackBufferCount <= 3); // Maximum of three back buffers
+
+ if(presentParameters->BackBufferCount == 0)
+ {
+ presentParameters->BackBufferCount = 1;
+ }
+
+ D3DDEVICE_CREATION_PARAMETERS creationParameters;
+ device->GetCreationParameters(&creationParameters);
+
+ HWND windowHandle = presentParameters->hDeviceWindow ? presentParameters->hDeviceWindow : creationParameters.hFocusWindow;
+
+ int width = 0;
+ int height = 0;
+
+ if(presentParameters->Windowed && (presentParameters->BackBufferHeight == 0 || presentParameters->BackBufferWidth == 0))
+ {
+ RECT rectangle;
+ GetClientRect(windowHandle, &rectangle);
+
+ width = rectangle.right - rectangle.left;
+ height = rectangle.bottom - rectangle.top;
+ }
+ else
+ {
+ width = presentParameters->BackBufferWidth;
+ height = presentParameters->BackBufferHeight;
+ }
+
+ frameBuffer = createFrameBufferWin(windowHandle, presentParameters->BackBufferWidth, presentParameters->BackBufferHeight, presentParameters->Windowed == FALSE, true);
+
+ lockable = presentParameters->Flags & D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
+
+ backBuffer[0] = 0;
+ backBuffer[1] = 0;
+ backBuffer[2] = 0;
+
+ for(int i = 0; i < (int)presentParameters->BackBufferCount; i++)
+ {
+ backBuffer[i] = new Direct3DSurface8(device, this, width, height, presentParameters->BackBufferFormat, D3DPOOL_DEFAULT, presentParameters->MultiSampleType, lockable, D3DUSAGE_RENDERTARGET);
+ backBuffer[i]->bind();
+ }
+ }
+
+ void Direct3DSwapChain8::release()
+ {
+ delete frameBuffer;
+ frameBuffer = 0;
+
+ for(int i = 0; i < 3; i++)
+ {
+ if(backBuffer[i])
+ {
+ backBuffer[i]->unbind();
+ backBuffer[i] = 0;
+ }
+ }
+ }
+
+ void Direct3DSwapChain8::screenshot(void *destBuffer)
+ {
+ frameBuffer->screenshot(destBuffer);
+ }
+
+ void Direct3DSwapChain8::setGammaRamp(sw::GammaRamp *gammaRamp, bool calibrate)
+ {
+ frameBuffer->setGammaRamp(gammaRamp, calibrate);
+ }
+
+ void Direct3DSwapChain8::getGammaRamp(sw::GammaRamp *gammaRamp)
+ {
+ frameBuffer->getGammaRamp(gammaRamp);
+ }
+
+ void *Direct3DSwapChain8::lockBackBuffer(int index)
+ {
+ return backBuffer[index]->lockInternal(0, 0, 0, sw::LOCK_READWRITE, sw::PUBLIC); // FIXME: External
+ }
+
+ void Direct3DSwapChain8::unlockBackBuffer(int index)
+ {
+ backBuffer[index]->unlockInternal(); // FIXME: External
+ }
+}
diff --git a/src/D3D8/Direct3DSwapChain8.hpp b/src/D3D8/Direct3DSwapChain8.hpp
new file mode 100644
index 0000000..2a0c194
--- /dev/null
+++ b/src/D3D8/Direct3DSwapChain8.hpp
@@ -0,0 +1,70 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef D3D8_Direct3DSwapChain8_hpp
+#define D3D8_Direct3DSwapChain8_hpp
+
+#include "Unknown.hpp"
+
+#include "Direct3DSurface8.hpp"
+
+#include "FrameBufferWin.hpp"
+
+#include <d3d8.h>
+
+namespace D3D8
+{
+ class Direct3DSwapChain8 : public IDirect3DSwapChain8, public Unknown
+ {
+ public:
+ Direct3DSwapChain8(Direct3DDevice8 *device, D3DPRESENT_PARAMETERS *presentParameters);
+
+ virtual ~Direct3DSwapChain8();
+
+ // IUnknown methods
+ long __stdcall QueryInterface(const IID &iid, void **object);
+ unsigned long __stdcall AddRef();
+ unsigned long __stdcall Release();
+
+ // IDirect3DSwapChain8 methods
+ long __stdcall Present(const RECT *sourceRect, const RECT *destRect, HWND destWindowOverride, const RGNDATA *dirtyRegion);
+ long __stdcall GetBackBuffer(unsigned int index, D3DBACKBUFFER_TYPE type, IDirect3DSurface8 **backBuffer);
+
+ // Internal methods
+ void reset(D3DPRESENT_PARAMETERS *presentParameters);
+
+ void screenshot(void *destBuffer);
+ void setGammaRamp(sw::GammaRamp *gammaRamp, bool calibrate);
+ void getGammaRamp(sw::GammaRamp *gammaRamp);
+
+ void *lockBackBuffer(int index);
+ void unlockBackBuffer(int index);
+
+ private:
+ void release();
+
+ // Creation parameters
+ Direct3DDevice8 *const device;
+ D3DPRESENT_PARAMETERS presentParameters;
+
+ bool lockable;
+
+ sw::FrameBufferWin *frameBuffer;
+
+ public: // FIXME
+ Direct3DSurface8 *backBuffer[3]; // NOTE: Up to three
+ };
+}
+
+#endif // D3D8_Direct3DSwapChain8_hpp
diff --git a/src/D3D8/Direct3DTexture8.cpp b/src/D3D8/Direct3DTexture8.cpp
new file mode 100644
index 0000000..c7d8341
--- /dev/null
+++ b/src/D3D8/Direct3DTexture8.cpp
@@ -0,0 +1,242 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "Direct3DTexture8.hpp"
+
+#include "Direct3DSurface8.hpp"
+#include "Resource.hpp"
+#include "Debug.hpp"
+
+#include <assert.h>
+
+namespace D3D8
+{
+ Direct3DTexture8::Direct3DTexture8(Direct3DDevice8 *device, unsigned int width, unsigned int height, unsigned int levels, unsigned long usage, D3DFORMAT format, D3DPOOL pool) : Direct3DBaseTexture8(device, D3DRTYPE_TEXTURE, levels, usage), width(width), height(height), format(format), pool(pool)
+ {
+ if(levels == 0)
+ {
+ this->levels = sw::log2(sw::max((int)width, (int)height, 1)) + 1;
+ }
+
+ for(unsigned int level = 0; level < sw::MIPMAP_LEVELS; level++)
+ {
+ if(level < this->levels)
+ {
+ surfaceLevel[level] = new Direct3DSurface8(device, this, width, height, format, pool, D3DMULTISAMPLE_NONE, true, usage);
+ surfaceLevel[level]->bind();
+ }
+ else
+ {
+ surfaceLevel[level] = 0;
+ }
+
+ width = sw::max(1, (int)width / 2);
+ height = sw::max(1, (int)height / 2);
+ }
+ }
+
+ Direct3DTexture8::~Direct3DTexture8()
+ {
+ resource->lock(sw::DESTRUCT);
+
+ for(int level = 0; level < sw::MIPMAP_LEVELS; level++)
+ {
+ if(surfaceLevel[level])
+ {
+ surfaceLevel[level]->unbind();
+ surfaceLevel[level] = 0;
+ }
+ }
+
+ resource->unlock();
+ }
+
+ long Direct3DTexture8::QueryInterface(const IID &iid, void **object)
+ {
+ TRACE("");
+
+ if(iid == IID_IDirect3DTexture8 ||
+ iid == IID_IDirect3DBaseTexture8 ||
+ iid == IID_IDirect3DResource8 ||
+ iid == IID_IUnknown)
+ {
+ AddRef();
+ *object = this;
+
+ return S_OK;
+ }
+
+ *object = 0;
+
+ return NOINTERFACE(iid);
+ }
+
+ unsigned long Direct3DTexture8::AddRef()
+ {
+ TRACE("");
+
+ return Direct3DBaseTexture8::AddRef();
+ }
+
+ unsigned long Direct3DTexture8::Release()
+ {
+ TRACE("");
+
+ return Direct3DBaseTexture8::Release();
+ }
+
+ long Direct3DTexture8::FreePrivateData(const GUID &guid)
+ {
+ TRACE("");
+
+ return Direct3DBaseTexture8::FreePrivateData(guid);
+ }
+
+ long Direct3DTexture8::GetPrivateData(const GUID &guid, void *data, unsigned long *size)
+ {
+ TRACE("");
+
+ return Direct3DBaseTexture8::GetPrivateData(guid, data, size);
+ }
+
+ void Direct3DTexture8::PreLoad()
+ {
+ TRACE("");
+
+ Direct3DBaseTexture8::PreLoad();
+ }
+
+ long Direct3DTexture8::SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags)
+ {
+ TRACE("");
+
+ return Direct3DBaseTexture8::SetPrivateData(guid, data, size, flags);
+ }
+
+ long Direct3DTexture8::GetDevice(IDirect3DDevice8 **device)
+ {
+ TRACE("");
+
+ return Direct3DBaseTexture8::GetDevice(device);
+ }
+
+ unsigned long Direct3DTexture8::SetPriority(unsigned long newPriority)
+ {
+ TRACE("");
+
+ return Direct3DBaseTexture8::SetPriority(newPriority);
+ }
+
+ unsigned long Direct3DTexture8::GetPriority()
+ {
+ TRACE("");
+
+ return Direct3DBaseTexture8::GetPriority();
+ }
+
+ D3DRESOURCETYPE Direct3DTexture8::GetType()
+ {
+ TRACE("");
+
+ return Direct3DBaseTexture8::GetType();
+ }
+
+ unsigned long Direct3DTexture8::GetLevelCount()
+ {
+ TRACE("");
+
+ return Direct3DBaseTexture8::GetLevelCount();
+ }
+
+ unsigned long Direct3DTexture8::GetLOD()
+ {
+ TRACE("");
+
+ return Direct3DBaseTexture8::GetLOD();
+ }
+
+ unsigned long Direct3DTexture8::SetLOD(unsigned long newLOD)
+ {
+ TRACE("");
+
+ return Direct3DBaseTexture8::SetLOD(newLOD);
+ }
+
+ long Direct3DTexture8::GetLevelDesc(unsigned int level, D3DSURFACE_DESC *description)
+ {
+ TRACE("");
+
+ if(level >= GetLevelCount() || !surfaceLevel[level])
+ {
+ return INVALIDCALL();
+ }
+
+ return surfaceLevel[level]->GetDesc(description);
+ }
+
+ long Direct3DTexture8::LockRect(unsigned int level, D3DLOCKED_RECT *lockedRect, const RECT *rect, unsigned long flags)
+ {
+ TRACE("");
+
+ if(!lockedRect || level >= GetLevelCount() || !surfaceLevel[level])
+ {
+ return INVALIDCALL();
+ }
+
+ return surfaceLevel[level]->LockRect(lockedRect, rect, flags);
+ }
+
+ long Direct3DTexture8::GetSurfaceLevel(unsigned int level, IDirect3DSurface8 **surface)
+ {
+ TRACE("");
+
+ *surface = 0; // FIXME: Verify
+
+ if(level >= GetLevelCount() || !surfaceLevel[level])
+ {
+ return INVALIDCALL();
+ }
+
+ surfaceLevel[level]->AddRef();
+ *surface = surfaceLevel[level];
+
+ return D3D_OK;
+ }
+
+ long Direct3DTexture8::UnlockRect(unsigned int level)
+ {
+ TRACE("");
+
+ if(level >= GetLevelCount() || !surfaceLevel[level])
+ {
+ return INVALIDCALL();
+ }
+
+ return surfaceLevel[level]->UnlockRect();
+ }
+
+ long Direct3DTexture8::AddDirtyRect(const RECT *dirtyRect)
+ {
+ TRACE("");
+
+ // UNIMPLEMENTED();
+
+ return D3D_OK;
+ }
+
+ Direct3DSurface8 *Direct3DTexture8::getInternalSurfaceLevel(unsigned int level)
+ {
+ return surfaceLevel[level];
+ }
+}
diff --git a/src/D3D8/Direct3DTexture8.hpp b/src/D3D8/Direct3DTexture8.hpp
new file mode 100644
index 0000000..c031a27
--- /dev/null
+++ b/src/D3D8/Direct3DTexture8.hpp
@@ -0,0 +1,76 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef D3D8_Direct3DTexture8_hpp
+#define D3D8_Direct3DTexture8_hpp
+
+#include "Direct3DBaseTexture8.hpp"
+
+#include "Direct3DSurface8.hpp"
+
+#include "Config.hpp"
+
+#include <d3d8.h>
+
+namespace D3D8
+{
+ class Direct3DTexture8 : public IDirect3DTexture8, public Direct3DBaseTexture8
+ {
+ public:
+ Direct3DTexture8(Direct3DDevice8 *device, unsigned int width, unsigned int height, unsigned int levels, unsigned long usage, D3DFORMAT format, D3DPOOL pool);
+
+ virtual ~Direct3DTexture8();
+
+ // IUnknown methods
+ long __stdcall QueryInterface(const IID &iid, void **object);
+ unsigned long __stdcall AddRef();
+ unsigned long __stdcall Release();
+
+ // IDirect3DResource8 methods
+ long __stdcall FreePrivateData(const GUID &guid);
+ long __stdcall GetPrivateData(const GUID &guid, void *data, unsigned long *size);
+ void __stdcall PreLoad();
+ long __stdcall SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags);
+ long __stdcall GetDevice(IDirect3DDevice8 **device);
+ unsigned long __stdcall SetPriority(unsigned long newPriority);
+ unsigned long __stdcall GetPriority();
+ D3DRESOURCETYPE __stdcall GetType();
+
+ // IDirect3DBaseTexture methods
+ unsigned long __stdcall GetLevelCount();
+ unsigned long __stdcall GetLOD();
+ unsigned long __stdcall SetLOD(unsigned long newLOD);
+
+ // IDirect3DTexture8 methods
+ long __stdcall GetLevelDesc(unsigned int level, D3DSURFACE_DESC *description);
+ long __stdcall LockRect(unsigned int level, D3DLOCKED_RECT *lockedRect, const RECT *rect, unsigned long flags);
+ long __stdcall GetSurfaceLevel(unsigned int level, IDirect3DSurface8 **surface);
+ long __stdcall UnlockRect(unsigned int level);
+ long __stdcall AddDirtyRect(const RECT *dirtyRect);
+
+ // Internal methods
+ Direct3DSurface8 *getInternalSurfaceLevel(unsigned int level);
+
+ private:
+ // Creation parameters
+ const unsigned int width;
+ const unsigned int height;
+ const D3DFORMAT format;
+ const D3DPOOL pool;
+
+ Direct3DSurface8 *surfaceLevel[sw::MIPMAP_LEVELS];
+ };
+}
+
+#endif // D3D8_Direct3DTexture8_hpp
diff --git a/src/D3D8/Direct3DVertexBuffer8.cpp b/src/D3D8/Direct3DVertexBuffer8.cpp
new file mode 100644
index 0000000..bb748d1
--- /dev/null
+++ b/src/D3D8/Direct3DVertexBuffer8.cpp
@@ -0,0 +1,221 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "Direct3DVertexBuffer8.hpp"
+
+#include "Direct3DDevice8.hpp"
+#include "Resource.hpp"
+#include "Debug.hpp"
+
+#include <assert.h>
+
+namespace D3D8
+{
+ Direct3DVertexBuffer8::Direct3DVertexBuffer8(Direct3DDevice8 *device, unsigned int length, unsigned long usage, long FVF, D3DPOOL pool) : Direct3DResource8(device, D3DRTYPE_VERTEXBUFFER, length), length(length), usage(usage), FVF(FVF), pool(pool)
+ {
+ if(FVF)
+ {
+ unsigned int stride = 0;
+
+ switch(FVF & D3DFVF_POSITION_MASK)
+ {
+ case D3DFVF_XYZ: stride += 12; break;
+ case D3DFVF_XYZRHW: stride += 16; break;
+ case D3DFVF_XYZB1: stride += 16; break;
+ case D3DFVF_XYZB2: stride += 20; break;
+ case D3DFVF_XYZB3: stride += 24; break;
+ case D3DFVF_XYZB4: stride += 28; break;
+ case D3DFVF_XYZB5: stride += 32; break;
+ }
+
+ if(FVF & D3DFVF_NORMAL) stride += 12;
+ if(FVF & D3DFVF_PSIZE) stride += 4;
+ if(FVF & D3DFVF_DIFFUSE) stride += 4;
+ if(FVF & D3DFVF_SPECULAR) stride += 4;
+
+ switch((FVF & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT)
+ {
+ case 8: stride += 4 + 4 * ((1 + (FVF >> 30)) % 4);
+ case 7: stride += 4 + 4 * ((1 + (FVF >> 28)) % 4);
+ case 6: stride += 4 + 4 * ((1 + (FVF >> 26)) % 4);
+ case 5: stride += 4 + 4 * ((1 + (FVF >> 24)) % 4);
+ case 4: stride += 4 + 4 * ((1 + (FVF >> 22)) % 4);
+ case 3: stride += 4 + 4 * ((1 + (FVF >> 20)) % 4);
+ case 2: stride += 4 + 4 * ((1 + (FVF >> 18)) % 4);
+ case 1: stride += 4 + 4 * ((1 + (FVF >> 16)) % 4);
+ case 0: break;
+ default:
+ ASSERT(false);
+ }
+
+ ASSERT(length >= stride); // FIXME
+ ASSERT(length % stride == 0); // D3D vertex size calculated incorrectly // FIXME
+ }
+
+ vertexBuffer = new sw::Resource(length + 192 + 1024); // NOTE: Applications can 'overshoot' while writing vertices
+ }
+
+ Direct3DVertexBuffer8::~Direct3DVertexBuffer8()
+ {
+ vertexBuffer->destruct();
+ }
+
+ long Direct3DVertexBuffer8::QueryInterface(const IID &iid, void **object)
+ {
+ TRACE("");
+
+ if(iid == IID_IDirect3DVertexBuffer8 ||
+ iid == IID_IDirect3DResource8 ||
+ iid == IID_IUnknown)
+ {
+ AddRef();
+ *object = this;
+
+ return S_OK;
+ }
+
+ *object = 0;
+
+ return NOINTERFACE(iid);
+ }
+
+ unsigned long Direct3DVertexBuffer8::AddRef()
+ {
+ TRACE("");
+
+ return Direct3DResource8::AddRef();
+ }
+
+ unsigned long Direct3DVertexBuffer8::Release()
+ {
+ TRACE("");
+
+ return Direct3DResource8::Release();
+ }
+
+ long Direct3DVertexBuffer8::FreePrivateData(const GUID &guid)
+ {
+ TRACE("");
+
+ return Direct3DResource8::FreePrivateData(guid);
+ }
+
+ long Direct3DVertexBuffer8::GetPrivateData(const GUID &guid, void *data, unsigned long *size)
+ {
+ TRACE("");
+
+ return Direct3DResource8::GetPrivateData(guid, data, size);
+ }
+
+ void Direct3DVertexBuffer8::PreLoad()
+ {
+ TRACE("");
+
+ Direct3DResource8::PreLoad();
+ }
+
+ long Direct3DVertexBuffer8::SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags)
+ {
+ TRACE("");
+
+ return Direct3DResource8::SetPrivateData(guid, data, size, flags);
+ }
+
+ long Direct3DVertexBuffer8::GetDevice(IDirect3DDevice8 **device)
+ {
+ TRACE("");
+
+ return Direct3DResource8::GetDevice(device);
+ }
+
+ unsigned long Direct3DVertexBuffer8::SetPriority(unsigned long newPriority)
+ {
+ TRACE("");
+
+ return Direct3DResource8::SetPriority(newPriority);
+ }
+
+ unsigned long Direct3DVertexBuffer8::GetPriority()
+ {
+ TRACE("");
+
+ return Direct3DResource8::GetPriority();
+ }
+
+ D3DRESOURCETYPE Direct3DVertexBuffer8::GetType()
+ {
+ TRACE("");
+
+ return Direct3DResource8::GetType();
+ }
+
+ long Direct3DVertexBuffer8::Lock(unsigned int offset, unsigned int size, unsigned char **data, unsigned long flags)
+ {
+ TRACE("");
+
+ if(offset == 0 && size == 0) // Lock whole buffer
+ {
+ size = length;
+ }
+
+ if(!data || offset + size > length)
+ {
+ return INVALIDCALL();
+ }
+
+ lockOffset = offset;
+ lockSize = size;
+
+ *data = (unsigned char*)vertexBuffer->lock(sw::PUBLIC) + offset;
+ vertexBuffer->unlock();
+
+ return D3D_OK;
+ }
+
+ long Direct3DVertexBuffer8::Unlock()
+ {
+ TRACE("");
+
+ return D3D_OK;
+ }
+
+ long Direct3DVertexBuffer8::GetDesc(D3DVERTEXBUFFER_DESC *description)
+ {
+ TRACE("");
+
+ if(!description)
+ {
+ return INVALIDCALL();
+ }
+
+ description->FVF = FVF;
+ description->Format = D3DFMT_VERTEXDATA;
+ description->Pool = pool;
+ description->Size = length;
+ description->Type = D3DRTYPE_VERTEXBUFFER;
+ description->Usage = usage;
+
+ return D3D_OK;
+ }
+
+ int Direct3DVertexBuffer8::getLength() const
+ {
+ return length;
+ }
+
+ sw::Resource *Direct3DVertexBuffer8::getResource() const
+ {
+ return vertexBuffer;
+ }
+}
diff --git a/src/D3D8/Direct3DVertexBuffer8.hpp b/src/D3D8/Direct3DVertexBuffer8.hpp
new file mode 100644
index 0000000..435d012
--- /dev/null
+++ b/src/D3D8/Direct3DVertexBuffer8.hpp
@@ -0,0 +1,75 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef D3D8_Direct3DVertexBuffer8_hpp
+#define D3D8_Direct3DVertexBuffer8_hpp
+
+#include "Direct3DResource8.hpp"
+
+#include <d3d8.h>
+
+namespace sw
+{
+ class Resource;
+}
+
+namespace D3D8
+{
+ class Direct3DVertexBuffer8 : public IDirect3DVertexBuffer8, public Direct3DResource8
+ {
+ public:
+ Direct3DVertexBuffer8(Direct3DDevice8 *device, unsigned int length, unsigned long usage, long FVF, D3DPOOL pool);
+
+ virtual ~Direct3DVertexBuffer8();
+
+ // IUnknown methods
+ long __stdcall QueryInterface(const IID &iid, void **object);
+ unsigned long __stdcall AddRef();
+ unsigned long __stdcall Release();
+
+ // IDirect3DResource8 methods
+ long __stdcall FreePrivateData(const GUID &guid);
+ long __stdcall GetPrivateData(const GUID &guid, void *data, unsigned long *size);
+ void __stdcall PreLoad();
+ long __stdcall SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags);
+ long __stdcall GetDevice(IDirect3DDevice8 **device);
+ unsigned long __stdcall SetPriority(unsigned long newPriority);
+ unsigned long __stdcall GetPriority();
+ D3DRESOURCETYPE __stdcall GetType();
+
+ // IDirect3DVertexBuffer8 methods
+ long __stdcall Lock(unsigned int offset, unsigned int size, unsigned char **data, unsigned long flags);
+ long __stdcall Unlock();
+ long __stdcall GetDesc(D3DVERTEXBUFFER_DESC *description);
+
+ // Internal methods
+ int getLength() const;
+ sw::Resource *getResource() const;
+
+ private:
+ // Creation parameters
+ const unsigned int length;
+ const long usage;
+ const long FVF;
+ const D3DPOOL pool;
+
+ unsigned int lockOffset;
+ unsigned int lockSize;
+ unsigned char *lockData;
+
+ sw::Resource *vertexBuffer;
+ };
+}
+
+#endif // D3D8_Direct3DVertexBuffer8_hpp
diff --git a/src/D3D8/Direct3DVertexDeclaration8.cpp b/src/D3D8/Direct3DVertexDeclaration8.cpp
new file mode 100644
index 0000000..247af44
--- /dev/null
+++ b/src/D3D8/Direct3DVertexDeclaration8.cpp
@@ -0,0 +1,71 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "Direct3DVertexDeclaration8.hpp"
+
+#include "Debug.hpp"
+
+#include <d3d8types.h>
+
+namespace D3D8
+{
+ Direct3DVertexDeclaration8::Direct3DVertexDeclaration8(Direct3DDevice8 *device, const unsigned long *vertexElement) : device(device)
+ {
+ int size = sizeof(unsigned long);
+ const unsigned long *element = vertexElement;
+
+ while(*element != 0xFFFFFFFF)
+ {
+ size += sizeof(unsigned long);
+ element++;
+ }
+
+ declaration = new unsigned long[size / sizeof(unsigned long)];
+ memcpy(declaration, vertexElement, size);
+ }
+
+ Direct3DVertexDeclaration8::~Direct3DVertexDeclaration8()
+ {
+ delete[] declaration;
+ declaration = 0;
+ }
+
+ long Direct3DVertexDeclaration8::QueryInterface(const IID &iid, void **object)
+ {
+ TRACE("");
+
+ ASSERT(false); // Internal object
+
+ return NOINTERFACE(iid);
+ }
+
+ unsigned long Direct3DVertexDeclaration8::AddRef()
+ {
+ TRACE("");
+
+ return Unknown::AddRef();
+ }
+
+ unsigned long Direct3DVertexDeclaration8::Release()
+ {
+ TRACE("");
+
+ return Unknown::Release();
+ }
+
+ const unsigned long *Direct3DVertexDeclaration8::getDeclaration() const
+ {
+ return declaration;
+ }
+}
\ No newline at end of file
diff --git a/src/D3D8/Direct3DVertexDeclaration8.hpp b/src/D3D8/Direct3DVertexDeclaration8.hpp
new file mode 100644
index 0000000..2b5b665
--- /dev/null
+++ b/src/D3D8/Direct3DVertexDeclaration8.hpp
@@ -0,0 +1,48 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef D3D8_Direct3DVertexDeclaration8_hpp
+#define D3D8_Direct3DVertexDeclaration8_hpp
+
+#include "Unknown.hpp"
+
+#include <d3d8.h>
+
+namespace D3D8
+{
+ class Direct3DDevice8;
+
+ class Direct3DVertexDeclaration8 : protected Unknown
+ {
+ public:
+ Direct3DVertexDeclaration8(Direct3DDevice8 *device, const unsigned long *vertexElements);
+
+ virtual ~Direct3DVertexDeclaration8();
+
+ // IUnknown methods
+ long __stdcall QueryInterface(const IID &iid, void **object);
+ unsigned long __stdcall AddRef();
+ unsigned long __stdcall Release();
+
+ // Internal methods
+ const unsigned long *getDeclaration() const;
+
+ private:
+ // Creation parameters
+ Direct3DDevice8 *const device;
+ unsigned long *declaration;
+ };
+}
+
+#endif // D3D8_Direct3DVertexDeclaration8_hpp
\ No newline at end of file
diff --git a/src/D3D8/Direct3DVertexShader8.cpp b/src/D3D8/Direct3DVertexShader8.cpp
new file mode 100644
index 0000000..d696507
--- /dev/null
+++ b/src/D3D8/Direct3DVertexShader8.cpp
@@ -0,0 +1,92 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "Direct3DVertexShader8.hpp"
+
+#include "Debug.hpp"
+
+namespace D3D8
+{
+ Direct3DVertexShader8::Direct3DVertexShader8(Direct3DDevice8 *device, const unsigned long *declaration, const unsigned long *shaderToken) : device(device)
+ {
+ if(shaderToken)
+ {
+ vertexShader = new sw::VertexShader(shaderToken);
+
+ const unsigned long *token = shaderToken;
+ size = 0;
+
+ while(shaderToken[size] != 0x0000FFFF)
+ {
+ size++;
+ }
+
+ size++;
+
+ this->shaderToken = new unsigned long[size];
+ memcpy(this->shaderToken, shaderToken, size * sizeof(unsigned long));
+ }
+ else
+ {
+ vertexShader = 0;
+ this->shaderToken = 0;
+ }
+
+ this->declaration = new Direct3DVertexDeclaration8(device, declaration);
+ }
+
+ Direct3DVertexShader8::~Direct3DVertexShader8()
+ {
+ delete vertexShader;
+ vertexShader = 0;
+
+ delete[] shaderToken;
+ shaderToken = 0;
+
+ declaration->Release();
+ }
+
+ long Direct3DVertexShader8::QueryInterface(const IID &iid, void **object)
+ {
+ TRACE("");
+
+ ASSERT(false); // Internal object
+
+ return NOINTERFACE(iid);
+ }
+
+ unsigned long Direct3DVertexShader8::AddRef()
+ {
+ TRACE("");
+
+ return Unknown::AddRef();
+ }
+
+ unsigned long Direct3DVertexShader8::Release()
+ {
+ TRACE("");
+
+ return Unknown::Release();
+ }
+
+ const sw::VertexShader *Direct3DVertexShader8::getVertexShader() const
+ {
+ return vertexShader;
+ }
+
+ const unsigned long *Direct3DVertexShader8::getDeclaration()
+ {
+ return declaration->getDeclaration();
+ }
+}
\ No newline at end of file
diff --git a/src/D3D8/Direct3DVertexShader8.hpp b/src/D3D8/Direct3DVertexShader8.hpp
new file mode 100644
index 0000000..046f7b4
--- /dev/null
+++ b/src/D3D8/Direct3DVertexShader8.hpp
@@ -0,0 +1,54 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef D3D8_Direct3DVertexShader8_hpp
+#define D3D8_Direct3DVertexShader8_hpp
+
+#include "VertexShader.hpp"
+#include "Direct3DVertexDeclaration8.hpp"
+
+#include "Unknown.hpp"
+
+namespace D3D8
+{
+ class Direct3DDevice8;
+
+ class Direct3DVertexShader8 : public Unknown
+ {
+ public:
+ Direct3DVertexShader8(Direct3DDevice8 *device, const unsigned long *declaration, const unsigned long *shaderToken);
+
+ virtual ~Direct3DVertexShader8();
+
+ // IUnknown methods
+ long __stdcall QueryInterface(const IID &iid, void **object);
+ unsigned long __stdcall AddRef();
+ unsigned long __stdcall Release();
+
+ // Internal methods
+ const sw::VertexShader *getVertexShader() const;
+ const unsigned long *getDeclaration();
+
+ private:
+ // Creation parameters
+ Direct3DDevice8 *const device;
+ Direct3DVertexDeclaration8 *declaration;
+ unsigned long *shaderToken;
+ unsigned int size;
+
+ sw::VertexShader *vertexShader;
+ };
+}
+
+#endif // D3D8_Direct3DVertexShader8_hpp
\ No newline at end of file
diff --git a/src/D3D8/Direct3DVolume8.cpp b/src/D3D8/Direct3DVolume8.cpp
new file mode 100644
index 0000000..3fa78ad
--- /dev/null
+++ b/src/D3D8/Direct3DVolume8.cpp
@@ -0,0 +1,189 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "Direct3DVolume8.hpp"
+
+#include "Direct3DResource8.hpp"
+#include "Direct3DVolumeTexture8.hpp"
+#include "Direct3DSurface8.hpp"
+#include "Debug.hpp"
+
+#include <assert.h>
+
+namespace D3D8
+{
+ Direct3DVolume8::Direct3DVolume8(Direct3DDevice8 *device, Direct3DVolumeTexture8 *container, int width, int height, int depth, D3DFORMAT format, D3DPOOL pool, bool lockable, unsigned long usage) : Surface(container->getResource(), width, height, depth, translateFormat(format), lockable, false), container(container), width(width), height(height), depth(depth), format(format), pool(pool), lockable(lockable), usage(usage)
+ {
+ resource = new Direct3DResource8(device, D3DRTYPE_VOLUME, memoryUsage(width, height, depth, format));
+ }
+
+ Direct3DVolume8::~Direct3DVolume8()
+ {
+ resource->Release();
+ }
+
+ long __stdcall Direct3DVolume8::QueryInterface(const IID &iid, void **object)
+ {
+ TRACE("");
+
+ if(iid == IID_IDirect3DVolume8 ||
+ iid == IID_IUnknown)
+ {
+ AddRef();
+ *object = this;
+
+ return S_OK;
+ }
+
+ *object = 0;
+
+ return NOINTERFACE(iid);
+ }
+
+ unsigned long __stdcall Direct3DVolume8::AddRef()
+ {
+ TRACE("");
+
+ return container->AddRef();
+ }
+
+ unsigned long __stdcall Direct3DVolume8::Release()
+ {
+ TRACE("");
+
+ return container->Release();
+ }
+
+ long Direct3DVolume8::FreePrivateData(const GUID &guid)
+ {
+ TRACE("");
+
+ return resource->FreePrivateData(guid);
+ }
+
+ long Direct3DVolume8::GetContainer(const IID &iid, void **container)
+ {
+ TRACE("");
+
+ if(!container)
+ {
+ return INVALIDCALL();
+ }
+
+ long result = this->container->QueryInterface(iid, container);
+
+ if(result == S_OK)
+ {
+ return D3D_OK;
+ }
+
+ return INVALIDCALL();
+ }
+
+ long Direct3DVolume8::GetDesc(D3DVOLUME_DESC *description)
+ {
+ TRACE("");
+
+ if(!description)
+ {
+ return INVALIDCALL();
+ }
+
+ description->Format = format;
+ description->Type = D3DRTYPE_VOLUME;
+ description->Usage = usage;
+ description->Pool = pool;
+ description->Width = width;
+ description->Height = height;
+ description->Depth = depth;
+
+ return D3D_OK;
+ }
+
+ long Direct3DVolume8::GetDevice(IDirect3DDevice8 **device)
+ {
+ TRACE("");
+
+ return resource->GetDevice(device);
+ }
+
+ long Direct3DVolume8::GetPrivateData(const GUID &guid, void *data, unsigned long *size)
+ {
+ TRACE("");
+
+ return resource->GetPrivateData(guid, data, size);
+ }
+
+ long Direct3DVolume8::LockBox(D3DLOCKED_BOX *lockedVolume, const D3DBOX *box, unsigned long flags)
+ {
+ TRACE("");
+
+ if(!lockedVolume)
+ {
+ return INVALIDCALL();
+ }
+
+ lockedVolume->RowPitch = pitchB(getWidth(), getExternalFormat(), false);
+ lockedVolume->SlicePitch = sliceB(getWidth(), getHeight(), getExternalFormat(), false);
+
+ sw::Lock lock = sw::LOCK_READWRITE;
+
+ if(flags & D3DLOCK_DISCARD)
+ {
+ lock = sw::LOCK_DISCARD;
+ }
+
+ if(flags & D3DLOCK_READONLY)
+ {
+ lock = sw::LOCK_READONLY;
+ }
+
+ if(box)
+ {
+ lockedVolume->pBits = lockExternal(box->Left, box->Top, box->Front, lock, sw::PUBLIC);
+ }
+ else
+ {
+ lockedVolume->pBits = lockExternal(0, 0, 0, lock, sw::PUBLIC);
+ }
+
+ unlockExternal();
+
+ return D3D_OK;
+ }
+
+ long Direct3DVolume8::SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags)
+ {
+ TRACE("");
+
+ return SetPrivateData(guid, data, size, flags);
+ }
+
+ long Direct3DVolume8::UnlockBox()
+ {
+ TRACE("");
+
+ return D3D_OK;
+ }
+
+ sw::Format Direct3DVolume8::translateFormat(D3DFORMAT format)
+ {
+ return Direct3DSurface8::translateFormat(format);
+ }
+
+ unsigned int Direct3DVolume8::memoryUsage(int width, int height, int depth, D3DFORMAT format)
+ {
+ return Surface::size(width, height, depth, translateFormat(format));
+ }
+}
diff --git a/src/D3D8/Direct3DVolume8.hpp b/src/D3D8/Direct3DVolume8.hpp
new file mode 100644
index 0000000..9b85fc7
--- /dev/null
+++ b/src/D3D8/Direct3DVolume8.hpp
@@ -0,0 +1,70 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef D3D8_Direct3DVolume8_hpp
+#define D3D8_Direct3DVolume8_hpp
+
+#include "Unknown.hpp"
+
+#include "Surface.hpp"
+
+#include <d3d8.h>
+
+namespace D3D8
+{
+ class Direct3DDevice8;
+ class Direct3DResource8;
+ class Direct3DVolumeTexture8;
+
+ class Direct3DVolume8 : public IDirect3DVolume8, public Unknown, public sw::Surface
+ {
+ public:
+ Direct3DVolume8(Direct3DDevice8 *device, Direct3DVolumeTexture8 *container, int width, int height, int depth, D3DFORMAT format, D3DPOOL pool, bool locakble, unsigned long usage);
+
+ virtual ~Direct3DVolume8();
+
+ // IUnknown methods
+ long __stdcall QueryInterface(const IID &iid, void **object);
+ unsigned long __stdcall AddRef();
+ unsigned long __stdcall Release();
+
+ // IDirect3DVolume8 methods
+ long __stdcall FreePrivateData(const GUID &guid);
+ long __stdcall GetContainer(const IID &iid, void **container);
+ long __stdcall GetDesc(D3DVOLUME_DESC *description);
+ long __stdcall GetDevice(IDirect3DDevice8 **device);
+ long __stdcall GetPrivateData(const GUID &guid, void *data, unsigned long *size);
+ long __stdcall LockBox(D3DLOCKED_BOX *lockedVolume, const D3DBOX *box, unsigned long flags);
+ long __stdcall SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags);
+ long __stdcall UnlockBox();
+
+ private:
+ static sw::Format translateFormat(D3DFORMAT format);
+ static unsigned int memoryUsage(int width, int height, int depth, D3DFORMAT format);
+
+ // Creation parameters
+ Direct3DVolumeTexture8 *const container;
+ const int width;
+ const int height;
+ const int depth;
+ const D3DFORMAT format;
+ const D3DPOOL pool;
+ const bool lockable;
+ const unsigned long usage;
+
+ Direct3DResource8 *resource;
+ };
+}
+
+#endif // D3D8_Direct3DVolume8_hpp
diff --git a/src/D3D8/Direct3DVolumeTexture8.cpp b/src/D3D8/Direct3DVolumeTexture8.cpp
new file mode 100644
index 0000000..90cecde
--- /dev/null
+++ b/src/D3D8/Direct3DVolumeTexture8.cpp
@@ -0,0 +1,250 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "Direct3DVolumeTexture8.hpp"
+
+#include "Direct3DVolume8.hpp"
+#include "Resource.hpp"
+#include "Debug.hpp"
+
+#include <assert.h>
+
+namespace D3D8
+{
+ Direct3DVolumeTexture8::Direct3DVolumeTexture8(Direct3DDevice8 *device, unsigned int width, unsigned int height, unsigned int depth, unsigned int levels, unsigned long usage, D3DFORMAT format, D3DPOOL pool) : Direct3DBaseTexture8(device, D3DRTYPE_VOLUMETEXTURE, levels, usage), width(width), height(height), depth(depth), format(format), pool(pool)
+ {
+ if(levels == 0)
+ {
+ this->levels = sw::log2(sw::max((int)width, (int)height, (int)depth, 1)) + 1;
+ }
+
+ for(unsigned int level = 0; level < sw::MIPMAP_LEVELS; level++)
+ {
+ if(level < this->levels)
+ {
+ volumeLevel[level] = new Direct3DVolume8(device, this, width, height, depth, format, pool, true, usage);
+ volumeLevel[level]->bind();
+ }
+ else
+ {
+ volumeLevel[level] = 0;
+ }
+
+ width = sw::max(1, (int)width / 2);
+ height = sw::max(1, (int)height / 2);
+ depth = sw::max(1, (int)depth / 2);
+ }
+ }
+
+ Direct3DVolumeTexture8::~Direct3DVolumeTexture8()
+ {
+ resource->lock(sw::DESTRUCT);
+
+ for(int level = 0; level < sw::MIPMAP_LEVELS; level++)
+ {
+ if(volumeLevel[level])
+ {
+ volumeLevel[level]->unbind();
+ volumeLevel[level] = 0;
+ }
+ }
+
+ resource->unlock();
+ }
+
+ long Direct3DVolumeTexture8::QueryInterface(const IID &iid, void **object)
+ {
+ TRACE("");
+
+ if(iid == IID_IDirect3DVolumeTexture8 ||
+ iid == IID_IDirect3DBaseTexture8 ||
+ iid == IID_IDirect3DResource8 ||
+ iid == IID_IUnknown)
+ {
+ AddRef();
+ *object = this;
+
+ return S_OK;
+ }
+
+ *object = 0;
+
+ return NOINTERFACE(iid);
+ }
+
+ unsigned long Direct3DVolumeTexture8::AddRef()
+ {
+ TRACE("");
+
+ return Direct3DBaseTexture8::AddRef();
+ }
+
+ unsigned long Direct3DVolumeTexture8::Release()
+ {
+ TRACE("");
+
+ return Direct3DBaseTexture8::Release();
+ }
+
+ long Direct3DVolumeTexture8::FreePrivateData(const GUID &guid)
+ {
+ TRACE("");
+
+ return Direct3DBaseTexture8::FreePrivateData(guid);
+ }
+
+ long Direct3DVolumeTexture8::GetPrivateData(const GUID &guid, void *data, unsigned long *size)
+ {
+ TRACE("");
+
+ return Direct3DBaseTexture8::GetPrivateData(guid, data, size);
+ }
+
+ void Direct3DVolumeTexture8::PreLoad()
+ {
+ TRACE("");
+
+ Direct3DBaseTexture8::PreLoad();
+ }
+
+ long Direct3DVolumeTexture8::SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags)
+ {
+ TRACE("");
+
+ return Direct3DBaseTexture8::SetPrivateData(guid, data, size, flags);
+ }
+
+ long Direct3DVolumeTexture8::GetDevice(IDirect3DDevice8 **device)
+ {
+ TRACE("");
+
+ return Direct3DBaseTexture8::GetDevice(device);
+ }
+
+ unsigned long Direct3DVolumeTexture8::SetPriority(unsigned long newPriority)
+ {
+ TRACE("");
+
+ return Direct3DBaseTexture8::SetPriority(newPriority);
+ }
+
+ unsigned long Direct3DVolumeTexture8::GetPriority()
+ {
+ TRACE("");
+
+ return Direct3DBaseTexture8::GetPriority();
+ }
+
+ D3DRESOURCETYPE Direct3DVolumeTexture8::GetType()
+ {
+ TRACE("");
+
+ return Direct3DBaseTexture8::GetType();
+ }
+
+ unsigned long Direct3DVolumeTexture8::GetLevelCount()
+ {
+ TRACE("");
+
+ return Direct3DBaseTexture8::GetLevelCount();
+ }
+
+ unsigned long Direct3DVolumeTexture8::GetLOD()
+ {
+ TRACE("");
+
+ return Direct3DBaseTexture8::GetLOD();
+ }
+
+ unsigned long Direct3DVolumeTexture8::SetLOD(unsigned long newLOD)
+ {
+ TRACE("");
+
+ return Direct3DBaseTexture8::SetLOD(newLOD);
+ }
+
+ long Direct3DVolumeTexture8::GetVolumeLevel(unsigned int level, IDirect3DVolume8 **volume)
+ {
+ TRACE("");
+
+ *volume = 0; // FIXME: Verify
+
+ if(level >= GetLevelCount() || !volumeLevel[level])
+ {
+ return INVALIDCALL();
+ }
+
+ volumeLevel[level]->AddRef();
+ *volume = volumeLevel[level];
+
+ return D3D_OK;
+ }
+
+ long Direct3DVolumeTexture8::LockBox(unsigned int level, D3DLOCKED_BOX *lockedVolume, const D3DBOX *box, unsigned long flags)
+ {
+ TRACE("");
+
+ if(!lockedVolume || level >= GetLevelCount() || !volumeLevel[level])
+ {
+ return INVALIDCALL();
+ }
+
+ return volumeLevel[level]->LockBox(lockedVolume, box, flags);
+ }
+
+ long Direct3DVolumeTexture8::UnlockBox(unsigned int level)
+ {
+ TRACE("");
+
+ if(level >= GetLevelCount() || !volumeLevel[level])
+ {
+ return INVALIDCALL();
+ }
+
+ return volumeLevel[level]->UnlockBox();
+ }
+
+ long Direct3DVolumeTexture8::AddDirtyBox(const D3DBOX *dirtyBox)
+ {
+ TRACE("");
+
+ if(!dirtyBox)
+ {
+ return INVALIDCALL();
+ }
+
+ UNIMPLEMENTED();
+
+ return D3D_OK;
+ }
+
+ long Direct3DVolumeTexture8::GetLevelDesc(unsigned int level, D3DVOLUME_DESC *description)
+ {
+ TRACE("");
+
+ if(!description || level >= GetLevelCount() || !volumeLevel[level])
+ {
+ return INVALIDCALL();
+ }
+
+ volumeLevel[level]->GetDesc(description);
+
+ return D3D_OK;
+ }
+
+ Direct3DVolume8 *Direct3DVolumeTexture8::getInternalVolumeLevel(unsigned int level)
+ {
+ return volumeLevel[level];
+ }
+}
diff --git a/src/D3D8/Direct3DVolumeTexture8.hpp b/src/D3D8/Direct3DVolumeTexture8.hpp
new file mode 100644
index 0000000..fb0fbd7
--- /dev/null
+++ b/src/D3D8/Direct3DVolumeTexture8.hpp
@@ -0,0 +1,77 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef D3D8_Direct3DVolumeTexture8_hpp
+#define D3D8_Direct3DVolumeTexture8_hpp
+
+#include "Direct3DBaseTexture8.hpp"
+
+#include "Config.hpp"
+
+#include <d3d8.h>
+
+namespace D3D8
+{
+ class Direct3DVolume8;
+
+ class Direct3DVolumeTexture8 : public IDirect3DVolumeTexture8, public Direct3DBaseTexture8
+ {
+ public:
+ Direct3DVolumeTexture8(Direct3DDevice8 *device, unsigned int width, unsigned int height, unsigned int depth, unsigned int levels, unsigned long usage, D3DFORMAT format, D3DPOOL pool);
+
+ virtual ~Direct3DVolumeTexture8();
+
+ // IUnknown methods
+ long __stdcall QueryInterface(const IID &iid, void **object);
+ unsigned long __stdcall AddRef();
+ unsigned long __stdcall Release();
+
+ // IDirect3DResource8 methods
+ long __stdcall FreePrivateData(const GUID &guid);
+ long __stdcall GetPrivateData(const GUID &guid, void *data, unsigned long *size);
+ void __stdcall PreLoad();
+ long __stdcall SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags);
+ long __stdcall GetDevice(IDirect3DDevice8 **device);
+ unsigned long __stdcall SetPriority(unsigned long newPriority);
+ unsigned long __stdcall GetPriority();
+ D3DRESOURCETYPE __stdcall GetType();
+
+ // IDirect3DBaseTexture methods
+ unsigned long __stdcall GetLevelCount();
+ unsigned long __stdcall GetLOD();
+ unsigned long __stdcall SetLOD(unsigned long newLOD);
+
+ // IDirect3DVolumeTexture8 methods
+ long __stdcall GetLevelDesc(unsigned int level, D3DVOLUME_DESC *description);
+ long __stdcall GetVolumeLevel(unsigned int level, IDirect3DVolume8 **volume);
+ long __stdcall LockBox(unsigned int level, D3DLOCKED_BOX *lockedVolume, const D3DBOX *box, unsigned long flags);
+ long __stdcall UnlockBox(unsigned int level);
+ long __stdcall AddDirtyBox(const D3DBOX *dirtyBox);
+
+ // Internal methods
+ Direct3DVolume8 *getInternalVolumeLevel(unsigned int level);
+
+ private:
+ // Creation parameters
+ const unsigned int width;
+ const unsigned int height;
+ const unsigned int depth;
+ const D3DFORMAT format;
+ const D3DPOOL pool;
+
+ Direct3DVolume8 *volumeLevel[sw::MIPMAP_LEVELS];
+ };
+}
+
+#endif // D3D8_Direct3DVolumeTexture8_hpp
diff --git a/src/D3D8/Unknown.cpp b/src/D3D8/Unknown.cpp
new file mode 100644
index 0000000..09ce03f
--- /dev/null
+++ b/src/D3D8/Unknown.cpp
@@ -0,0 +1,88 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "Unknown.hpp"
+
+#include "Debug.hpp"
+
+#include <assert.h>
+
+namespace D3D8
+{
+ Unknown::Unknown()
+ {
+ referenceCount = 0;
+ bindCount = 0;
+ }
+
+ Unknown::~Unknown()
+ {
+ ASSERT(referenceCount == 0);
+ ASSERT(bindCount == 0);
+ }
+
+ long Unknown::QueryInterface(const IID &iid, void **object)
+ {
+ if(iid == IID_IUnknown)
+ {
+ AddRef();
+ *object = this;
+
+ return S_OK;
+ }
+
+ *object = 0;
+
+ return NOINTERFACE(iid);
+ }
+
+ unsigned long Unknown::AddRef()
+ {
+ return InterlockedIncrement(&referenceCount);
+ }
+
+ unsigned long Unknown::Release()
+ {
+ int current = referenceCount;
+
+ if(referenceCount > 0)
+ {
+ current = InterlockedDecrement(&referenceCount);
+ }
+
+ if(referenceCount == 0 && bindCount == 0)
+ {
+ delete this;
+ }
+
+ return current;
+ }
+
+ void Unknown::bind()
+ {
+ InterlockedIncrement(&bindCount);
+ }
+
+ void Unknown::unbind()
+ {
+ ASSERT(bindCount > 0);
+
+ InterlockedDecrement(&bindCount);
+
+ if(referenceCount == 0 && bindCount == 0)
+ {
+ delete this;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/D3D8/Unknown.hpp b/src/D3D8/Unknown.hpp
new file mode 100644
index 0000000..478a035
--- /dev/null
+++ b/src/D3D8/Unknown.hpp
@@ -0,0 +1,44 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef D3D8_Unknown_hpp
+#define D3D8_Unknown_hpp
+
+#include <unknwn.h>
+
+namespace D3D8
+{
+ class Unknown : IUnknown
+ {
+ public:
+ Unknown();
+
+ virtual ~Unknown();
+
+ // IUnknown methods
+ long __stdcall QueryInterface(const IID &iid, void **object);
+ unsigned long __stdcall AddRef();
+ unsigned long __stdcall Release();
+
+ // Internal methods
+ virtual void bind();
+ virtual void unbind();
+
+ private:
+ volatile long referenceCount;
+ volatile long bindCount;
+ };
+}
+
+#endif // D3D8_Unknown_hpp
diff --git a/src/D3D8/d3d8.def b/src/D3D8/d3d8.def
new file mode 100644
index 0000000..7586a78
--- /dev/null
+++ b/src/D3D8/d3d8.def
@@ -0,0 +1,7 @@
+LIBRARY D3D8
+EXPORTS
+ CheckFullscreen @1
+ DebugSetMute @4
+ Direct3DCreate8 @5
+ ValidatePixelShader @2
+ ValidateVertexShader @3
diff --git a/src/D3D8/resource.h b/src/D3D8/resource.h
new file mode 100644
index 0000000..27a9f6b
--- /dev/null
+++ b/src/D3D8/resource.h
@@ -0,0 +1,28 @@
+//{{NO_DEPENDENCIES}}
+// Microsoft Visual C++ generated include file.
+// Used by D3D8-dll.rc
+//
+#define IDD_DIALOG1 104
+#define IDD_DIALOG2 105
+#define IDC_CHECK1 1001
+#define IDC_SLIDER1 1002
+#define IDC_CHECK2 1003
+#define IDC_PROGRESS2 1006
+#define IDC_PROGRESS3 1007
+#define IDC_PROGRESS4 1008
+#define IDC_PROGRESS5 1009
+#define IDC_DATETIMEPICKER1 1011
+#define IDC_CHECK3 1012
+#define IDC_EDIT1 1013
+#define IDC_EDIT2 1014
+
+// Next default values for new objects
+//
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NEXT_RESOURCE_VALUE 106
+#define _APS_NEXT_COMMAND_VALUE 40001
+#define _APS_NEXT_CONTROL_VALUE 1015
+#define _APS_NEXT_SYMED_VALUE 101
+#endif
+#endif
diff --git a/src/D3D8/resource1.h b/src/D3D8/resource1.h
new file mode 100644
index 0000000..ecf3584
--- /dev/null
+++ b/src/D3D8/resource1.h
@@ -0,0 +1,14 @@
+//{{NO_DEPENDENCIES}}
+// Microsoft Visual C++ generated include file.
+// Used by D3D8.rc
+
+// Next default values for new objects
+//
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NEXT_RESOURCE_VALUE 101
+#define _APS_NEXT_COMMAND_VALUE 40001
+#define _APS_NEXT_CONTROL_VALUE 1001
+#define _APS_NEXT_SYMED_VALUE 101
+#endif
+#endif