diff --git a/framework/platform-dx/effect.cpp b/framework/platform-dx/effect.cpp index a7e6cda..6a5c797 100644 --- a/framework/platform-dx/effect.cpp +++ b/framework/platform-dx/effect.cpp @@ -21,7 +21,7 @@ namespace xna { device->impl->_device, //ID3DX11Effect * *ppEffect &impl->dxEffect - ); + ); if FAILED(result) throw std::runtime_error("Effect::Effect: Unable to create an effect with memory data."); @@ -32,7 +32,7 @@ namespace xna { impl->dxEffect->GetDesc(&desc); auto tech = impl->dxEffect->GetTechniqueByIndex(0); - + auto technique = snew(); technique->impl->dxContext = m_device->impl->_context; technique->impl->dxContext->AddRef(); @@ -50,33 +50,42 @@ namespace xna { Int EffectAnnotation::ColumCount() const { auto type = impl->dxVariable->GetType(); D3DX11_EFFECT_TYPE_DESC desc{}; - type->GetDesc(&desc); + const auto hr = type->GetDesc(&desc); type->Release(); type = nullptr; + if FAILED(hr) + throw std::runtime_error("EffectAnnotation::ColumCount: error getting D3DX11_EFFECT_TYPE_DESC"); + return static_cast(desc.Columns); } String EffectAnnotation::Name() const { auto type = impl->dxVariable->GetType(); D3DX11_EFFECT_TYPE_DESC desc{}; - type->GetDesc(&desc); + const auto hr = type->GetDesc(&desc); type->Release(); type = nullptr; + if FAILED(hr) + throw std::runtime_error("EffectAnnotation::Name: error getting D3DX11_EFFECT_TYPE_DESC"); + return String(desc.TypeName); } EffectParameterClass EffectAnnotation::ParameterClass() const { auto type = impl->dxVariable->GetType(); D3DX11_EFFECT_TYPE_DESC desc{}; - type->GetDesc(&desc); + const auto hr = type->GetDesc(&desc); type->Release(); type = nullptr; + if FAILED(hr) + throw std::runtime_error("EffectAnnotation::ParameterClass: error getting D3DX11_EFFECT_TYPE_DESC"); + switch (desc.Class) { case D3D_SHADER_VARIABLE_CLASS::D3D_SVC_MATRIX_COLUMNS: @@ -91,18 +100,21 @@ namespace xna { case D3D_SHADER_VARIABLE_CLASS::D3D_SVC_VECTOR: return EffectParameterClass::Vector; default: - throw std::runtime_error(" EffectAnnotation::ParameterClass: invalid EffectParameterClass."); + throw std::runtime_error("EffectAnnotation::ParameterClass: invalid EffectParameterClass."); } } - Int EffectAnnotation::Rowcount() const { + Int EffectAnnotation::RowCount() const { auto type = impl->dxVariable->GetType(); D3DX11_EFFECT_TYPE_DESC desc{}; - type->GetDesc(&desc); + const auto hr = type->GetDesc(&desc); type->Release(); type = nullptr; + if FAILED(hr) + throw std::runtime_error("EffectAnnotation::RowCount: error getting D3DX11_EFFECT_TYPE_DESC"); + return static_cast(desc.Rows); } @@ -118,31 +130,31 @@ namespace xna { bool EffectAnnotation::GetValueBoolean() const { auto scalar = impl->dxVariable->AsScalar(); - - bool value = false; - auto hr = scalar->GetBool(&value); - if FAILED(hr) - throw std::runtime_error("EffectAnnotation::GetValueBoolean: Unable to get boolean value."); + bool value; + auto hr = scalar->GetBool(&value); scalar->Release(); scalar = nullptr; + if FAILED(hr) + throw std::runtime_error("EffectAnnotation::GetValueBoolean: Unable to get boolean value."); + return value; } Int EffectAnnotation::GetValueInt32() const { auto scalar = impl->dxVariable->AsScalar(); - int value = 0; + int value; auto hr = scalar->GetInt(&value); - if FAILED(hr) - throw std::runtime_error("EffectAnnotation::GetValueInt32: Unable to get interger value."); - scalar->Release(); scalar = nullptr; + if FAILED(hr) + throw std::runtime_error("EffectAnnotation::GetValueInt32: Unable to get interger value."); + return static_cast(value); } @@ -151,6 +163,8 @@ namespace xna { float values[16]; auto hr = matrix->GetMatrix(values); + matrix->Release(); + matrix = nullptr; if FAILED(hr) throw std::runtime_error("EffectAnnotation::GetValueMatrix: Unable to get matrix value."); @@ -173,36 +187,36 @@ namespace xna { m.M43 = values[14]; m.M44 = values[15]; - matrix->Release(); - matrix = nullptr; - return m; } float EffectAnnotation::GetValueSingle() const { auto scalar = impl->dxVariable->AsScalar(); - float value = 0; + float value; auto hr = scalar->GetFloat(&value); - if FAILED(hr) - throw std::runtime_error("EffectAnnotation::GetValueSingle: Unable to get float value."); - scalar->Release(); scalar = nullptr; + if FAILED(hr) + throw std::runtime_error("EffectAnnotation::GetValueSingle: Unable to get float value."); + return value; } String EffectAnnotation::GetValueString() const { auto str = impl->dxVariable->AsString(); - + LPCSTR data; - str->GetString(&data); - + const auto hr = str->GetString(&data); + str->Release(); str = nullptr; - + + if FAILED(hr) + throw std::runtime_error("EffectAnnotation::GetValueString: Unable to get string value."); + return String(data); } @@ -212,6 +226,9 @@ namespace xna { float values[2]; auto hr = scalar->GetFloatArray(values, 0, 2); + scalar->Release(); + scalar = nullptr; + if FAILED(hr) throw std::runtime_error("EffectAnnotation::GetValueVector2: Unable to get Vector2 value."); @@ -219,18 +236,18 @@ namespace xna { v.X = values[0]; v.Y = values[1]; - scalar->Release(); - scalar = nullptr; - return v; } - Vector3 EffectAnnotation::GetValueVector3() const { + Vector3 EffectAnnotation::GetValueVector3() const { auto scalar = impl->dxVariable->AsScalar(); float values[3]; auto hr = scalar->GetFloatArray(values, 0, 3); + scalar->Release(); + scalar = nullptr; + if FAILED(hr) throw std::runtime_error("EffectAnnotation::GetValueVector3: Unable to get Vector3 value."); @@ -239,20 +256,20 @@ namespace xna { v.Y = values[1]; v.Z = values[2]; - scalar->Release(); - scalar = nullptr; - return v; } - Vector4 EffectAnnotation::GetValueVector4() const { + Vector4 EffectAnnotation::GetValueVector4() const { auto scalar = impl->dxVariable->AsScalar(); float values[4]; auto hr = scalar->GetFloatArray(values, 0, 4); + scalar->Release(); + scalar = nullptr; + if FAILED(hr) - throw std::runtime_error("EffectAnnotation::GetValueVector4: Unable to get Vector4 value."); + throw std::runtime_error("EffectAnnotation::GetValueVector4: Unable to get Vector4 value."); Vector4 v; v.X = values[0]; @@ -260,9 +277,6 @@ namespace xna { v.Z = values[2]; v.W = values[3]; - scalar->Release(); - scalar = nullptr; - return v; } @@ -285,19 +299,22 @@ namespace xna { throw std::runtime_error("EffectPass::Annotations: The class was not initialized correctly"); D3DX11_PASS_DESC desc{}; - impl->dxPass->GetDesc(&desc); + const auto hr = impl->dxPass->GetDesc(&desc); + + if FAILED(hr) + throw std::runtime_error("EffectPass::Annotations: error getting D3DX11_PASS_DESC"); auto annotCount = desc.Annotations; if (annotCount == 0) return snew(); - + std::vector list(annotCount); for (size_t i = 0; i < annotCount; ++i) { auto current = impl->dxPass->GetAnnotationByIndex(i); auto annotation = snew(); - annotation->impl->dxVariable = current; + annotation->impl->dxVariable = current; annotation->impl->dxVariable->AddRef(); current->Release(); @@ -309,12 +326,15 @@ namespace xna { auto collection = snew(list); return collection; } - + void EffectPass::Apply() { if (!impl->dxPass) throw std::runtime_error("EffectPass::Apply: The class was not initialized correctly"); - impl->dxPass->Apply(0, impl->dxContext); + const auto hr = impl->dxPass->Apply(0, impl->dxContext); + + if FAILED(hr) + throw std::runtime_error("EffectPass::Apply: error to call Apply"); } EffectTechnique::EffectTechnique() { @@ -323,14 +343,20 @@ namespace xna { String EffectTechnique::Name() const { D3DX11_TECHNIQUE_DESC desc; - impl->dxTechnique->GetDesc(&desc); - + const auto hr = impl->dxTechnique->GetDesc(&desc); + + if FAILED(hr) + throw std::runtime_error("EffectTechnique::Name: error getting D3DX11_TECHNIQUE_DESC"); + return String(desc.Name); } PEffectAnnotationCollection EffectTechnique::Annotations() const { D3DX11_TECHNIQUE_DESC desc; - impl->dxTechnique->GetDesc(&desc); + const auto hr = impl->dxTechnique->GetDesc(&desc); + + if FAILED(hr) + throw std::runtime_error("EffectTechnique::Annotations: error getting D3DX11_TECHNIQUE_DESC"); auto annotCount = desc.Annotations; @@ -357,7 +383,10 @@ namespace xna { PEffectPassCollection EffectTechnique::Passes() const { D3DX11_TECHNIQUE_DESC desc; - impl->dxTechnique->GetDesc(&desc); + const auto hr = impl->dxTechnique->GetDesc(&desc); + + if FAILED(hr) + throw std::runtime_error("EffectTechnique::Passes: error getting D3DX11_TECHNIQUE_DESC"); auto passCount = desc.Passes; @@ -368,7 +397,7 @@ namespace xna { for (size_t i = 0; i < passCount; ++i) { auto current = impl->dxTechnique->GetPassByIndex(i); - + auto pass = snew(); pass->impl->dxPass = current; pass->impl->dxPass->AddRef(); @@ -385,4 +414,368 @@ namespace xna { auto collection = snew(list); return collection; } + + EffectParameter::EffectParameter() { + impl = unew(); + } + + PEffectAnnotationCollection EffectParameter::Annotations() const { + D3DX11_EFFECT_VARIABLE_DESC desc; + const auto hr = impl->dxVariable->GetDesc(&desc); + + if FAILED(hr) + throw std::runtime_error("EffectParameter::Annotations: error getting D3DX11_EFFECT_VARIABLE_DESC"); + + auto annotCount = desc.Annotations; + + if (annotCount == 0) + return snew(); + + std::vector list(annotCount); + + for (size_t i = 0; i < annotCount; ++i) { + auto current = impl->dxVariable->GetAnnotationByIndex(i); + auto annotation = snew(); + annotation->impl->dxVariable = current; + annotation->impl->dxVariable->AddRef(); + + current->Release(); + current = nullptr; + + list[i] = annotation; + } + + auto collection = snew(list); + return collection; + } + + Int EffectParameter::ColumnCount() const { + auto type = impl->dxVariable->GetType(); + D3DX11_EFFECT_TYPE_DESC desc{}; + const auto hr = type->GetDesc(&desc); + + type->Release(); + type = nullptr; + + if FAILED(hr) + throw std::runtime_error("EffectParameter::ColumnCount: error getting D3DX11_EFFECT_VARIABLE_DESC"); + + return static_cast(desc.Columns); + } + + Int EffectParameter::RowCount() const { + auto type = impl->dxVariable->GetType(); + D3DX11_EFFECT_TYPE_DESC desc{}; + const auto hr = type->GetDesc(&desc); + + type->Release(); + type = nullptr; + + if FAILED(hr) + throw std::runtime_error("EffectParameter::RowCount: error getting D3DX11_EFFECT_TYPE_DESC"); + + return static_cast(desc.Rows); + } + + String EffectParameter::Semantic() const { + auto type = impl->dxVariable->GetType(); + auto semantic = type->GetMemberSemantic(0); + + type->Release(); + type = nullptr; + + return std::string(semantic); + } + + EffectParameterType EffectParameter::ParameterType() const { + auto type = impl->dxVariable->GetType(); + D3DX11_EFFECT_TYPE_DESC desc{}; + const auto hr = type->GetDesc(&desc); + + type->Release(); + type = nullptr; + + if FAILED(hr) + throw std::runtime_error("EffectParameter::ParameterType: error getting D3DX11_EFFECT_TYPE_DESC"); + + switch (desc.Type) + { + case D3D_SHADER_VARIABLE_TYPE::D3D_SVT_BOOL: + return EffectParameterType::Bool; + case D3D_SHADER_VARIABLE_TYPE::D3D_SVT_INT: + return EffectParameterType::Int32; + case D3D_SHADER_VARIABLE_TYPE::D3D_SVT_FLOAT: + return EffectParameterType::Single; + case D3D_SHADER_VARIABLE_TYPE::D3D_SVT_STRING: + return EffectParameterType::String; + case D3D_SHADER_VARIABLE_TYPE::D3D_SVT_TEXTURE: + return EffectParameterType::Texture; + case D3D_SHADER_VARIABLE_TYPE::D3D_SVT_TEXTURE1D: + return EffectParameterType::Texture1D; + case D3D_SHADER_VARIABLE_TYPE::D3D_SVT_TEXTURE2D: + return EffectParameterType::Texture2D; + case D3D_SHADER_VARIABLE_TYPE::D3D_SVT_TEXTURE3D: + return EffectParameterType::Texture3D; + case D3D_SHADER_VARIABLE_TYPE::D3D_SVT_TEXTURECUBE: + return EffectParameterType::TextureCube; + case D3D_SHADER_VARIABLE_TYPE::D3D_SVT_VOID: + return EffectParameterType::Void; + default: + throw std::runtime_error("EffectParameter::ParameterType: invalid EffectParameterType."); + } + } + + EffectParameterClass EffectParameter::ParameterClass() const { + auto type = impl->dxVariable->GetType(); + D3DX11_EFFECT_TYPE_DESC desc{}; + const auto hr = type->GetDesc(&desc); + + type->Release(); + type = nullptr; + + if FAILED(hr) + throw std::runtime_error("EffectParameter::ParameterClass: error getting D3DX11_EFFECT_TYPE_DESC"); + + switch (desc.Class) + { + case D3D_SHADER_VARIABLE_CLASS::D3D_SVC_MATRIX_COLUMNS: + case D3D_SHADER_VARIABLE_CLASS::D3D_SVC_MATRIX_ROWS: + return EffectParameterClass::Matrix; + case D3D_SHADER_VARIABLE_CLASS::D3D_SVC_OBJECT: + return EffectParameterClass::Object; + case D3D_SHADER_VARIABLE_CLASS::D3D_SVC_SCALAR: + return EffectParameterClass::Scalar; + case D3D_SHADER_VARIABLE_CLASS::D3D_SVC_STRUCT: + return EffectParameterClass::Struct; + case D3D_SHADER_VARIABLE_CLASS::D3D_SVC_VECTOR: + return EffectParameterClass::Vector; + default: + throw std::runtime_error("EffectParameter::ParameterClass: invalid EffectParameterClass."); + } + } + + String EffectParameter::Name() const { + auto type = impl->dxVariable->GetType(); + D3DX11_EFFECT_TYPE_DESC desc{}; + const auto hr = type->GetDesc(&desc); + + type->Release(); + type = nullptr; + + if FAILED(hr) + throw std::runtime_error("EffectParameter::Name: error getting D3DX11_EFFECT_TYPE_DESC"); + + return String(desc.TypeName); + } + + sptr EffectParameter::Elements() const { + uint32_t index = 0; + + auto collection = snew(); + + while (true) { + auto el = impl->dxVariable->GetElement(index); + + if (!el) + break; + + auto efparam = snew(); + efparam->impl->dxVariable = el; + efparam->impl->dxVariable->AddRef(); + + el->Release(); + el = nullptr; + } + + + return collection; + } + + sptr EffectParameter::StructureMembers() const { + uint32_t index = 0; + + auto collection = snew(); + + while (true) { + auto member = impl->dxVariable->GetMemberByIndex(index); + + if (!member) + break; + + auto efparam = snew(); + efparam->impl->dxVariable = member; + efparam->impl->dxVariable->AddRef(); + + member->Release(); + member = nullptr; + } + + + return collection; + } + + bool EffectParameter::GetValueBoolean() const { + auto scalar = impl->dxVariable->AsScalar(); + + bool value; + const auto hr = scalar->GetBool(&value); + scalar->Release(); + scalar = nullptr; + + if FAILED(hr) + throw std::runtime_error("EffectParameter::GetValueBoolean: Unable to get boolean value."); + + return value; + } + + std::vector EffectParameter::GetValueBooleanArray(size_t count) const { + auto scalar = impl->dxVariable->AsScalar(); + auto arr = std::make_unique(count); + + const auto hr = scalar->GetBoolArray(arr.get(), 0, count); + scalar->Release(); + scalar = nullptr; + + if FAILED(hr) + throw std::runtime_error("EffectParameter::GetValueBooleanArray: Unable to get boolean value."); + + std::vector data(count); + + for (size_t i = 0; i < count; ++i) { + data[i] = arr[i]; + } + + return data; + } + + Int EffectParameter::GetValueInt32() const { + auto scalar = impl->dxVariable->AsScalar(); + + Int value; + const auto hr = scalar->GetInt(&value); + scalar->Release(); + scalar = nullptr; + + if FAILED(hr) + throw std::runtime_error("EffectParameter::GetValueInt32: Unable to get int value."); + + return value; + } + + std::vector EffectParameter::GetValueInt32Array(size_t count) const { + auto scalar = impl->dxVariable->AsScalar(); + std::vector data(count); + + const auto hr = scalar->GetIntArray(data.data(), 0, count); + scalar->Release(); + scalar = nullptr; + + if FAILED(hr) + throw std::runtime_error("EffectParameter::GetValueInt32Array: Unable to get int value."); + + return data; + } + + Matrix EffectParameter::GetValueMatrix() const { + auto matrix = impl->dxVariable->AsMatrix(); + float values[16]; + auto hr = matrix->GetMatrix(values); + matrix->Release(); + matrix = nullptr; + + if FAILED(hr) + throw std::runtime_error("EffectParameter::GetValueIntMatrix: Unable to get matrix value."); + + Matrix m; + m.M11 = values[0]; + m.M12 = values[1]; + m.M13 = values[2]; + m.M14 = values[3]; + m.M21 = values[4]; + m.M22 = values[5]; + m.M23 = values[6]; + m.M24 = values[7]; + m.M31 = values[8]; + m.M32 = values[9]; + m.M33 = values[10]; + m.M34 = values[11]; + m.M41 = values[12]; + m.M42 = values[13]; + m.M43 = values[14]; + m.M44 = values[15]; + + return m; + } + + std::vector EffectParameter::GetValueMatrixArray(size_t count) const { + auto matrix = impl->dxVariable->AsMatrix(); + const auto elements = count * 16; + auto arr = std::make_unique(count * elements); + + auto hr = matrix->GetMatrixArray(arr.get(), 0, elements); + matrix->Release(); + matrix = nullptr; + + if FAILED(hr) + throw std::runtime_error("EffectParameter::GetValuetMatrixArray: Unable to get matrix value."); + + auto index = 0; + std::vector data(count); + + for (size_t i = 0; i < elements; ++i) { + Matrix m; + m.M11 = arr[i]; + m.M12 = arr[++i]; + m.M13 = arr[++i]; + m.M14 = arr[++i]; + m.M21 = arr[++i]; + m.M22 = arr[++i]; + m.M23 = arr[++i]; + m.M24 = arr[++i]; + m.M31 = arr[++i]; + m.M32 = arr[++i]; + m.M33 = arr[++i]; + m.M34 = arr[++i]; + m.M41 = arr[++i]; + m.M42 = arr[++i]; + m.M43 = arr[++i]; + m.M44 = arr[++i]; + + data[index] = m; + ++index; + } + + return data; + } + + Matrix EffectParameter::GetValueMatrixTranspose() const { + auto matrix = impl->dxVariable->AsMatrix(); + float values[16]; + auto hr = matrix->GetMatrixTranspose(values); + matrix->Release(); + matrix = nullptr; + + if FAILED(hr) + throw std::runtime_error("EffectParameter::GetValueIntMatrix: Unable to get matrix value."); + + Matrix m; + m.M11 = values[0]; + m.M12 = values[1]; + m.M13 = values[2]; + m.M14 = values[3]; + m.M21 = values[4]; + m.M22 = values[5]; + m.M23 = values[6]; + m.M24 = values[7]; + m.M31 = values[8]; + m.M32 = values[9]; + m.M33 = values[10]; + m.M34 = values[11]; + m.M41 = values[12]; + m.M42 = values[13]; + m.M43 = values[14]; + m.M44 = values[15]; + + return m; + } } \ No newline at end of file diff --git a/inc/xna/forward.hpp b/inc/xna/forward.hpp index 5247bd2..2313c0e 100644 --- a/inc/xna/forward.hpp +++ b/inc/xna/forward.hpp @@ -70,6 +70,8 @@ namespace xna { class SwapChain; class Texture; class Texture2D; + class Texture3D; + class TextureCube; class RasterizerState; class SamplerState; class Shader; diff --git a/inc/xna/graphics/effect.hpp b/inc/xna/graphics/effect.hpp index 1f46571..9cc4f30 100644 --- a/inc/xna/graphics/effect.hpp +++ b/inc/xna/graphics/effect.hpp @@ -5,189 +5,296 @@ #include "../default.hpp" #include "gresource.hpp" -namespace xna { - //Represents an annotation to an EffectParameter. - class EffectAnnotation { - public: - Int ColumCount() const; - String Name() const; - EffectParameterClass ParameterClass() const; - Int Rowcount() const; - String Semantic() const; - bool GetValueBoolean() const; - Int GetValueInt32() const; - Matrix GetValueMatrix() const; - float GetValueSingle() const; - String GetValueString() const; - Vector2 GetValueVector2() const; - Vector3 GetValueVector3() const; - Vector4 GetValueVector4() const; +namespace xna { + //Represents an annotation to an EffectParameter. + class EffectAnnotation { + public: + Int ColumCount() const; + String Name() const; + EffectParameterClass ParameterClass() const; + Int RowCount() const; + String Semantic() const; + bool GetValueBoolean() const; + Int GetValueInt32() const; + Matrix GetValueMatrix() const; + float GetValueSingle() const; + String GetValueString() const; + Vector2 GetValueVector2() const; + Vector3 GetValueVector3() const; + Vector4 GetValueVector4() const; - public: - struct PlatformImplementation; - uptr impl; + public: + struct PlatformImplementation; + uptr impl; - public: - EffectAnnotation(); - }; + public: + EffectAnnotation(); + }; + using PEffectAnnotation = sptr; - using PEffectAnnotation = sptr; + class EffectAnnotationCollection { + public: + EffectAnnotationCollection() {} - class EffectAnnotationCollection { - public: - EffectAnnotationCollection(){} - - EffectAnnotationCollection(std::vector const& data) : data(data) - { - } + EffectAnnotationCollection(std::vector const& data) : data(data) + { + } - constexpr size_t Count() const { - return data.size(); - } + constexpr size_t Count() const { + return data.size(); + } - PEffectAnnotation operator[](size_t index) { - if (index >= data.size()) - return nullptr; + PEffectAnnotation operator[](size_t index) { + if (index >= data.size()) + return nullptr; - return data[index]; - } + return data[index]; + } - PEffectAnnotation operator[](String const& name) { - for (size_t i = 0; i < data.size(); ++i) { - const auto& p = data[i]; + PEffectAnnotation operator[](String const& name) { + for (size_t i = 0; i < data.size(); ++i) { + const auto& p = data[i]; - if (p->Name() == name) - return p; - } + if (p->Name() == name) + return p; + } - return nullptr; - } + return nullptr; + } - public: - std::vector data; - }; + public: + std::vector data; + }; + using PEffectAnnotationCollection = sptr; - using PEffectAnnotationCollection = sptr; + class EffectPass { + public: + //Gets the name of this pass. + String Name() const; + //The EffectAnnotationCollection containing EffectAnnotation objects for this EffectPass. + PEffectAnnotationCollection Annotations() const; - class EffectPass { - public: - //Gets the name of this pass. - String Name() const; - //The EffectAnnotationCollection containing EffectAnnotation objects for this EffectPass. - PEffectAnnotationCollection Annotations() const; + //Begins this pass. + void Apply(); + public: + struct PlatformImplementation; + uptr impl; - //Begins this pass. - void Apply(); - public: - struct PlatformImplementation; - uptr impl; + public: + EffectPass(); + }; + using PEffectPass = sptr; - public: - EffectPass(); - }; + class EffectPassCollection { + public: + EffectPassCollection() {} - using PEffectPass = sptr; + EffectPassCollection(std::vector const& data) : data(data) + { + } - class EffectPassCollection { - public: - EffectPassCollection(){} + constexpr size_t Count() const { + return data.size(); + } - EffectPassCollection(std::vector const& data) : data(data) - { - } + PEffectPass operator[](size_t index) { + if (index >= data.size()) + return nullptr; - constexpr size_t Count() const { - return data.size(); - } + return data[index]; + } - PEffectPass operator[](size_t index) { - if (index >= data.size()) - return nullptr; + PEffectPass operator[](String const& name) { + for (size_t i = 0; i < data.size(); ++i) { + const auto& p = data[i]; - return data[index]; - } + if (p->Name() == name) + return p; + } - PEffectPass operator[](String const& name) { - for (size_t i = 0; i < data.size(); ++i) { - const auto& p = data[i]; + return nullptr; + } - if (p->Name() == name) - return p; - } + public: + std::vector data; + }; + using PEffectPassCollection = sptr; - return nullptr; - } + class EffectTechnique { + public: + PEffectAnnotationCollection Annotations() const; + String Name() const; + PEffectPassCollection Passes() const; - public: - std::vector data; - }; + public: + struct PlatformImplementation; + uptr impl; - using PEffectPassCollection = sptr; + public: + EffectTechnique(); + }; + using PEffectTechnique = sptr; - class EffectTechnique { - public: - PEffectAnnotationCollection Annotations() const; - String Name() const; - PEffectPassCollection Passes() const; + class EffectParameterCollection; - public: - struct PlatformImplementation; - uptr impl; + class EffectParameter { + public: + //Gets the collection of EffectAnnotation objects for this parameter. + PEffectAnnotationCollection Annotations() const; + //Gets the number of columns in the parameter description. + Int ColumnCount() const; + //Gets the number of rows in the parameter description. + Int RowCount() const; + //Gets the semantic meaning, or usage, of the parameter. + String Semantic() const; + //Gets the type of the parameter. + EffectParameterType ParameterType() const; + //Gets the class of the parameter. + EffectParameterClass ParameterClass() const; + //Gets the name of the parameter. + String Name() const; + //Gets the collection of effect parameters. + sptr Elements() const; + //Gets the collection of structure members. + sptr StructureMembers() const; - public: - EffectTechnique(); - }; + bool GetValueBoolean() const; + std::vector GetValueBooleanArray(size_t count) const; + Int GetValueInt32() const; + std::vector GetValueInt32Array(size_t count) const; + Matrix GetValueMatrix() const; + std::vector GetValueMatrixArray(size_t count) const; + Matrix GetValueMatrixTranspose() const; + std::vector GetValueMatrixTransposeArray(size_t count) const; + Quaternion GetValueQuaternion() const; + std::vector GetValueQuaternionArray() const; + float GetValueSingle() const; + std::vector GetValueSingleArray() const; + String GetValueString() const; + sptr GetValueTexture2D() const; + sptr GetValueTexture3D() const; + sptr GetValueTextureCube() const; + Vector2 GetValueVector2() const; + std::vector GetValueVector2Array() const; + Vector3 GetValueVector3() const; + std::vector GetValueVector3Array() const; + Vector4 GetValueVector4() const; + std::vector GetValueVector4Array() const; - using PEffectTechnique = sptr; + void SetValue(bool value); + void SetValue(std::vector const& value); + void SetValue(Int value); + void SetValue(std::vector const& value); + void SetValue(float value); + void SetValue(std::vector const& value); + void SetValue(Matrix const& value); + void SetValue(std::vector const& value); + void SetValue(Quaternion const& value); + void SetValue(std::vector const& value); + void SetValue(Vector2 const& value); + void SetValue(std::vector const& value); + void SetValue(Vector3 const& value); + void SetValue(std::vector const& value); + void SetValue(Vector4 const& value); + void SetValue(std::vector const& value); + void SetValue(String const& value); + void SetValue(sptr const& value); - class Effect : public GraphicsResource { - Effect(sptr const& device, std::vector const& effectCode); + void SetValueTranspose(Matrix const& value); + void SetValueTranspose(std::vector const& value); - PEffectTechnique CurrentTechnique() const; + public: + struct PlatformImplementation; + uptr impl; - public: - struct PlatformImplementation; - uptr impl; - }; + public: + EffectParameter(); + }; + using PEffectParameter = sptr; - class IEffectMatrices { - virtual Matrix World() const = 0; - virtual Matrix View() const = 0; - virtual Matrix Projection() const = 0; + class EffectParameterCollection { + public: + EffectParameterCollection() {} - virtual void World(Matrix const& value) = 0; - virtual void View(Matrix const& value) = 0; - virtual void Projection(Matrix const& value) = 0; - }; + EffectParameterCollection(std::vector const& data) : data(data) + { + } - class DirectionalLight; + constexpr size_t Count() const { + return data.size(); + } - class IEffectLights { - virtual DirectionalLight DirectionalLight0() const = 0; - virtual DirectionalLight DirectionalLight1() const = 0; - virtual DirectionalLight DirectionalLight2() const = 0; + PEffectParameter operator[](size_t index) { + if (index >= data.size()) + return nullptr; - virtual Vector3 AmbientLightColor() const = 0; - virtual void AmbientLightColor(Vector3 const& value) = 0; + return data[index]; + } - virtual bool LightingEnabled() const = 0; - virtual void LightingEnabled(bool value) = 0; + PEffectParameter operator[](String const& name) { + for (size_t i = 0; i < data.size(); ++i) { + const auto& p = data[i]; - virtual void EnableDefaultLighting() = 0; - }; + if (p->Name() == name) + return p; + } - class IEffectFog - { - virtual bool FogEnabled() const = 0; - virtual float FogStart() const = 0; - virtual float FogEnd() const = 0; - virtual Vector3 FogColor() const = 0; + return nullptr; + } - virtual void FogEnabled(bool value) const = 0; - virtual void FogStart(float value) const = 0; - virtual void FogEnd(float value) const = 0; - virtual void FogColor(Vector3 const& value) const = 0; - }; + public: + std::vector data; + }; + using PEffectPassCollection = sptr; + + class Effect : public GraphicsResource { + Effect(sptr const& device, std::vector const& effectCode); + + PEffectTechnique CurrentTechnique() const; + + public: + struct PlatformImplementation; + uptr impl; + }; + + class IEffectMatrices { + virtual Matrix World() const = 0; + virtual Matrix View() const = 0; + virtual Matrix Projection() const = 0; + + virtual void World(Matrix const& value) = 0; + virtual void View(Matrix const& value) = 0; + virtual void Projection(Matrix const& value) = 0; + }; + + class DirectionalLight; + + class IEffectLights { + virtual DirectionalLight DirectionalLight0() const = 0; + virtual DirectionalLight DirectionalLight1() const = 0; + virtual DirectionalLight DirectionalLight2() const = 0; + + virtual Vector3 AmbientLightColor() const = 0; + virtual void AmbientLightColor(Vector3 const& value) = 0; + + virtual bool LightingEnabled() const = 0; + virtual void LightingEnabled(bool value) = 0; + + virtual void EnableDefaultLighting() = 0; + }; + + class IEffectFog + { + virtual bool FogEnabled() const = 0; + virtual float FogStart() const = 0; + virtual float FogEnd() const = 0; + virtual Vector3 FogColor() const = 0; + + virtual void FogEnabled(bool value) const = 0; + virtual void FogStart(float value) const = 0; + virtual void FogEnd(float value) const = 0; + virtual void FogColor(Vector3 const& value) const = 0; + }; } #endif \ No newline at end of file diff --git a/inc/xna/platform-dx/dx.hpp b/inc/xna/platform-dx/dx.hpp index 33e303e..871ff04 100644 --- a/inc/xna/platform-dx/dx.hpp +++ b/inc/xna/platform-dx/dx.hpp @@ -963,6 +963,11 @@ namespace xna { dxPass->Release(); dxPass = nullptr; } + + if (dxContext) { + dxContext->Release(); + dxContext = nullptr; + } } ID3DX11EffectPass* dxPass = nullptr; @@ -975,12 +980,35 @@ namespace xna { dxTechnique->Release(); dxTechnique = nullptr; } + + if (dxContext) { + dxContext->Release(); + dxContext = nullptr; + } } ID3DX11EffectTechnique* dxTechnique = nullptr; ID3D11DeviceContext* dxContext = nullptr; }; + struct EffectParameter::PlatformImplementation { + PlatformImplementation(){} + + PlatformImplementation(ID3DX11EffectVariable* value) { + dxVariable = value; + dxVariable->AddRef(); + } + + ~PlatformImplementation() { + if (dxVariable) { + dxVariable->Release(); + dxVariable = nullptr; + } + } + + ID3DX11EffectVariable* dxVariable = nullptr; + }; + template inline bool IndexBuffer::Initialize(std::vector const& data, xna_error_ptr_arg) { if (!impl || !m_device || !m_device->impl->_device || data.empty()) {