diff --git a/framework/platform-dx/effect.cpp b/framework/platform-dx/effect.cpp index 5789fd9..cff8121 100644 --- a/framework/platform-dx/effect.cpp +++ b/framework/platform-dx/effect.cpp @@ -262,4 +262,62 @@ namespace xna { impl->dxPass->Apply(0, impl->graphicsDevice->impl->_context); } + + EffectTechnique::EffectTechnique(sptr const& device) { + impl = unew(); + impl->graphicsDevice = device; + } + + String EffectTechnique::Name() const { + D3DX11_TECHNIQUE_DESC desc; + impl->dxTechnique->GetDesc(&desc); + + return String(desc.Name); + } + + PEffectAnnotationCollection EffectTechnique::Annotations() const { + D3DX11_TECHNIQUE_DESC desc; + impl->dxTechnique->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->dxTechnique->GetAnnotationByIndex(i); + auto annotation = snew(); + annotation->impl->dxVariable = current; + + list[i] = annotation; + } + + auto collection = snew(list); + return collection; + } + + PEffectPassCollection EffectTechnique::Passes() const { + D3DX11_TECHNIQUE_DESC desc; + impl->dxTechnique->GetDesc(&desc); + + auto passCount = desc.Passes; + + if (passCount == 0) + return snew(); + + std::vector list(passCount); + + for (size_t i = 0; i < passCount; ++i) { + auto current = impl->dxTechnique->GetPassByIndex(i); + auto pass = snew(impl->graphicsDevice); + pass->impl->dxPass = current; + + list[i] = pass; + } + + auto collection = snew(list); + return collection; + } } \ No newline at end of file diff --git a/inc/xna/graphics/effect.hpp b/inc/xna/graphics/effect.hpp index 8213d44..dba8ccf 100644 --- a/inc/xna/graphics/effect.hpp +++ b/inc/xna/graphics/effect.hpp @@ -35,7 +35,7 @@ namespace xna { class EffectAnnotationCollection { public: - EffectAnnotationCollection(); + EffectAnnotationCollection(){} EffectAnnotationCollection(std::vector const& data) : data(data) { @@ -94,6 +94,58 @@ namespace xna { uptr impl; }; + using PEffectPass = sptr; + + class EffectPassCollection { + public: + EffectPassCollection(){} + + EffectPassCollection(std::vector const& data) : data(data) + { + } + + constexpr size_t Count() const { + return data.size(); + } + + PEffectPass operator[](size_t index) { + if (index >= data.size()) + return nullptr; + + return data[index]; + } + + PEffectPass 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 PEffectPassCollection = sptr; + + class EffectTechnique { + public: + PEffectAnnotationCollection Annotations() const; + String Name() const; + PEffectPassCollection Passes() const; + + public: + struct PlatformImplementation; + uptr impl; + + public: + EffectTechnique(sptr const& device); + }; + class IEffectMatrices { virtual Matrix World() const = 0; virtual Matrix View() const = 0; diff --git a/inc/xna/platform-dx/dx.hpp b/inc/xna/platform-dx/dx.hpp index 5a8c350..4f951e6 100644 --- a/inc/xna/platform-dx/dx.hpp +++ b/inc/xna/platform-dx/dx.hpp @@ -969,6 +969,18 @@ namespace xna { PGraphicsDevice graphicsDevice = nullptr; }; + struct EffectTechnique::PlatformImplementation { + ~PlatformImplementation() { + if (dxTechnique) { + dxTechnique->Release(); + dxTechnique = nullptr; + } + } + + ID3DX11EffectTechnique* dxTechnique = 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()) {