diff --git a/framework/platform-dx/effect.cpp b/framework/platform-dx/effect.cpp index d4c8446..5789fd9 100644 --- a/framework/platform-dx/effect.cpp +++ b/framework/platform-dx/effect.cpp @@ -211,4 +211,55 @@ namespace xna { return v; } + + EffectPass::EffectPass(PGraphicsDevice const& device) { + if (!device || !device->impl || !device->impl->_context) + throw std::invalid_argument("EffectPass::EffectPass: device is null"); + + impl = unew(); + impl->graphicsDevice = device; + } + + String EffectPass::Name() const { + if (!impl->dxPass) + throw std::runtime_error("EffectPass::Name: The class was not initialized correctly"); + + D3DX11_PASS_DESC desc{}; + impl->dxPass->GetDesc(&desc); + + return String(desc.Name); + } + + PEffectAnnotationCollection EffectPass::Annotations() const { + if (!impl->dxPass) + throw std::runtime_error("EffectPass::Annotations: The class was not initialized correctly"); + + D3DX11_PASS_DESC desc{}; + impl->dxPass->GetDesc(&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; + + list[i] = annotation; + } + + 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->graphicsDevice->impl->_context); + } } \ No newline at end of file diff --git a/inc/xna/graphics/device.hpp b/inc/xna/graphics/device.hpp index ae70e06..1ca5b04 100644 --- a/inc/xna/graphics/device.hpp +++ b/inc/xna/graphics/device.hpp @@ -24,6 +24,8 @@ namespace xna { struct PlatformImplementation; uptr impl = nullptr; }; + + using PGraphicsDevice = sptr; } #endif \ No newline at end of file diff --git a/inc/xna/graphics/effect.hpp b/inc/xna/graphics/effect.hpp index 7dafb49..8213d44 100644 --- a/inc/xna/graphics/effect.hpp +++ b/inc/xna/graphics/effect.hpp @@ -6,9 +6,9 @@ #include "gresource.hpp" namespace xna { + //Represents an annotation to an EffectParameter. class EffectAnnotation { - public: - EffectAnnotation(); + public: Int ColumCount() const; String Name() const; EffectParameterClass ParameterClass() const; @@ -26,6 +26,64 @@ namespace xna { public: struct PlatformImplementation; uptr impl; + + public: + EffectAnnotation(); + }; + + using PEffectAnnotation = sptr; + + class EffectAnnotationCollection { + public: + EffectAnnotationCollection(); + + EffectAnnotationCollection(std::vector const& data) : data(data) + { + } + + constexpr size_t Count() const { + return data.size(); + } + + PEffectAnnotation operator[](size_t index) { + if (index >= data.size()) + return nullptr; + + return data[index]; + } + + 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; + } + + return nullptr; + } + + public: + std::vector data; + }; + + 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; + + //Begins this pass. + void Apply(); + public: + struct PlatformImplementation; + uptr impl; + + public: + EffectPass(sptr const& device); }; class Effect : public GraphicsResource { diff --git a/inc/xna/platform-dx/dx.hpp b/inc/xna/platform-dx/dx.hpp index fd45d4c..5a8c350 100644 --- a/inc/xna/platform-dx/dx.hpp +++ b/inc/xna/platform-dx/dx.hpp @@ -947,9 +947,28 @@ namespace xna { }; struct EffectAnnotation::PlatformImplementation { + ~PlatformImplementation() { + if (dxVariable) { + dxVariable->Release(); + dxVariable = nullptr; + } + } + ID3DX11EffectVariable* dxVariable = nullptr; }; + struct EffectPass::PlatformImplementation { + ~PlatformImplementation() { + if (dxPass) { + dxPass->Release(); + dxPass = nullptr; + } + } + + ID3DX11EffectPass* dxPass = nullptr; + PGraphicsDevice graphicsDevice = nullptr; + }; + template inline bool IndexBuffer::Initialize(std::vector const& data, xna_error_ptr_arg) { if (!impl || !m_device || !m_device->impl->_device || data.empty()) {