1
0
mirror of https://github.com/borgesdan/xn65 synced 2024-12-29 21:54:47 +01:00

Implementa EffectPass

This commit is contained in:
Danilo 2024-06-09 20:18:13 -03:00
parent 8fef38fd70
commit 75e7a7273d
4 changed files with 132 additions and 2 deletions

View File

@ -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<PlatformImplementation>();
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<EffectAnnotationCollection>();
std::vector<PEffectAnnotation> list(annotCount);
for (size_t i = 0; i < annotCount; ++i) {
auto current = impl->dxPass->GetAnnotationByIndex(i);
auto annotation = snew<EffectAnnotation>();
annotation->impl->dxVariable = current;
list[i] = annotation;
}
auto collection = snew<EffectAnnotationCollection>(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);
}
}

View File

@ -24,6 +24,8 @@ namespace xna {
struct PlatformImplementation;
uptr<PlatformImplementation> impl = nullptr;
};
using PGraphicsDevice = sptr<GraphicsDevice>;
}
#endif

View File

@ -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<PlatformImplementation> impl;
public:
EffectAnnotation();
};
using PEffectAnnotation = sptr<EffectAnnotation>;
class EffectAnnotationCollection {
public:
EffectAnnotationCollection();
EffectAnnotationCollection(std::vector<PEffectAnnotation> 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<PEffectAnnotation> data;
};
using PEffectAnnotationCollection = sptr<EffectAnnotationCollection>;
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<PlatformImplementation> impl;
public:
EffectPass(sptr<GraphicsDevice> const& device);
};
class Effect : public GraphicsResource {

View File

@ -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 <typename T>
inline bool IndexBuffer::Initialize(std::vector<T> const& data, xna_error_ptr_arg) {
if (!impl || !m_device || !m_device->impl->_device || data.empty()) {