mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Implementa EffectAnnotation
This commit is contained in:
parent
da0a300999
commit
8fef38fd70
@ -41,7 +41,7 @@ add_library (Xn65 STATIC
|
||||
"platform-dx/displaymode.cpp"
|
||||
"platform-dx/init.cpp"
|
||||
"platform-dx/buffer.cpp"
|
||||
"platform-dx/audioengine.cpp" "graphics/gresource.cpp")
|
||||
"platform-dx/audioengine.cpp" "graphics/gresource.cpp" "platform-dx/effect.cpp")
|
||||
|
||||
if (CMAKE_VERSION VERSION_GREATER 3.12)
|
||||
set_property(TARGET Xn65 PROPERTY CXX_STANDARD 20)
|
||||
@ -52,6 +52,7 @@ endif()
|
||||
find_package(directxtk CONFIG REQUIRED)
|
||||
|
||||
target_link_libraries(
|
||||
Xn65 D3d11.lib dxgi.lib dxguid.lib d3dcompiler.lib Microsoft::DirectXTK
|
||||
Xn65 D3d11.lib dxgi.lib dxguid.lib d3dcompiler.lib Microsoft::DirectXTK dxguid.lib
|
||||
"${PROJECT_INCLUDES_DIR}/libmspack/mspack.lib"
|
||||
"${PROJECT_INCLUDES_DIR}/effects11/Effects11.lib"
|
||||
)
|
||||
|
214
framework/platform-dx/effect.cpp
Normal file
214
framework/platform-dx/effect.cpp
Normal file
@ -0,0 +1,214 @@
|
||||
#include "xna/graphics/effect.hpp"
|
||||
#include "xna/platform-dx/dx.hpp"
|
||||
|
||||
namespace xna {
|
||||
Effect::Effect(sptr<GraphicsDevice> const& device, std::vector<Byte> const& effectCode) :
|
||||
GraphicsResource(device) {
|
||||
|
||||
if (!device)
|
||||
throw std::invalid_argument("Effect::Effect: invalid argument (device).");
|
||||
|
||||
impl = unew<PlatformImplementation>();
|
||||
|
||||
const auto result = D3DX11CreateEffectFromMemory(
|
||||
//void* pData,
|
||||
effectCode.data(),
|
||||
//SIZE_T DataLength,
|
||||
effectCode.size(),
|
||||
//UINT FXFlags,
|
||||
0,
|
||||
//ID3D11Device * pDevice,
|
||||
device->impl->_device,
|
||||
//ID3DX11Effect * *ppEffect
|
||||
&impl->dxEffect
|
||||
);
|
||||
|
||||
if FAILED(result)
|
||||
throw std::runtime_error("Effect::Effect: Unable to create an effect with memory data.");
|
||||
}
|
||||
|
||||
EffectAnnotation::EffectAnnotation() {
|
||||
impl = unew<PlatformImplementation>();
|
||||
}
|
||||
|
||||
Int EffectAnnotation::ColumCount() const {
|
||||
auto type = impl->dxVariable->GetType();
|
||||
D3DX11_EFFECT_TYPE_DESC desc{};
|
||||
type->GetDesc(&desc);
|
||||
|
||||
return static_cast<Int>(desc.Columns);
|
||||
}
|
||||
|
||||
String EffectAnnotation::Name() const {
|
||||
auto type = impl->dxVariable->GetType();
|
||||
D3DX11_EFFECT_TYPE_DESC desc{};
|
||||
type->GetDesc(&desc);
|
||||
|
||||
return String(desc.TypeName);
|
||||
}
|
||||
|
||||
EffectParameterClass EffectAnnotation::ParameterClass() const {
|
||||
auto type = impl->dxVariable->GetType();
|
||||
D3DX11_EFFECT_TYPE_DESC desc{};
|
||||
type->GetDesc(&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(" EffectAnnotation::ParameterClass: invalid EffectParameterClass.");
|
||||
}
|
||||
}
|
||||
|
||||
Int EffectAnnotation::Rowcount() const {
|
||||
auto type = impl->dxVariable->GetType();
|
||||
D3DX11_EFFECT_TYPE_DESC desc{};
|
||||
type->GetDesc(&desc);
|
||||
|
||||
return static_cast<Int>(desc.Rows);
|
||||
}
|
||||
|
||||
String EffectAnnotation::Semantic() const {
|
||||
auto type = impl->dxVariable->GetType();
|
||||
auto semantic = type->GetMemberSemantic(0);
|
||||
return std::string(semantic);
|
||||
}
|
||||
|
||||
bool EffectAnnotation::GetValueBoolean() const {
|
||||
auto type = impl->dxVariable->GetType();
|
||||
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.");
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
Int EffectAnnotation::GetValueInt32() const {
|
||||
auto type = impl->dxVariable->GetType();
|
||||
auto scalar = impl->dxVariable->AsScalar();
|
||||
|
||||
int value = 0;
|
||||
auto hr = scalar->GetInt(&value);
|
||||
|
||||
if FAILED(hr)
|
||||
throw std::runtime_error("EffectAnnotation::GetValueBoolean: Unable to get interger value.");
|
||||
|
||||
return static_cast<Int>(value);
|
||||
}
|
||||
|
||||
Matrix EffectAnnotation::GetValueMatrix() const {
|
||||
auto type = impl->dxVariable->GetType();
|
||||
auto matrix = impl->dxVariable->AsMatrix();
|
||||
|
||||
float values[16];
|
||||
auto hr = matrix->GetMatrix(values);
|
||||
|
||||
if FAILED(hr)
|
||||
throw std::runtime_error("EffectAnnotation::GetValueBoolean: 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;
|
||||
}
|
||||
|
||||
float EffectAnnotation::GetValueSingle() const {
|
||||
auto type = impl->dxVariable->GetType();
|
||||
auto scalar = impl->dxVariable->AsScalar();
|
||||
|
||||
float value = 0;
|
||||
auto hr = scalar->GetFloat(&value);
|
||||
|
||||
if FAILED(hr)
|
||||
throw std::runtime_error("EffectAnnotation::GetValueBoolean: Unable to get float value.");
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
String EffectAnnotation::GetValueString() const {
|
||||
return {};
|
||||
}
|
||||
|
||||
Vector2 EffectAnnotation::GetValueVector2() const {
|
||||
auto type = impl->dxVariable->GetType();
|
||||
auto scalar = impl->dxVariable->AsScalar();
|
||||
|
||||
float values[2];
|
||||
auto hr = scalar->GetFloatArray(values, 0, 2);
|
||||
|
||||
if FAILED(hr)
|
||||
throw std::runtime_error("EffectAnnotation::GetValueBoolean: Unable to get Vector2 value.");
|
||||
|
||||
Vector2 v;
|
||||
v.X = values[0];
|
||||
v.Y = values[1];
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
Vector3 EffectAnnotation::GetValueVector3() const {
|
||||
auto type = impl->dxVariable->GetType();
|
||||
auto scalar = impl->dxVariable->AsScalar();
|
||||
|
||||
float values[3];
|
||||
auto hr = scalar->GetFloatArray(values, 0, 3);
|
||||
|
||||
if FAILED(hr)
|
||||
throw std::runtime_error("EffectAnnotation::GetValueBoolean: Unable to get Vector3 value.");
|
||||
|
||||
Vector3 v;
|
||||
v.X = values[0];
|
||||
v.Y = values[1];
|
||||
v.Z = values[2];
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
Vector4 EffectAnnotation::GetValueVector4() const {
|
||||
auto type = impl->dxVariable->GetType();
|
||||
auto scalar = impl->dxVariable->AsScalar();
|
||||
|
||||
float values[4];
|
||||
auto hr = scalar->GetFloatArray(values, 0, 4);
|
||||
|
||||
if FAILED(hr)
|
||||
throw std::runtime_error("EffectAnnotation::GetValueBoolean: Unable to get Vector4 value.");
|
||||
|
||||
Vector4 v;
|
||||
v.X = values[0];
|
||||
v.Y = values[1];
|
||||
v.Z = values[2];
|
||||
v.W = values[3];
|
||||
|
||||
return v;
|
||||
}
|
||||
}
|
BIN
inc/effects11/Effects11.lib
Normal file
BIN
inc/effects11/Effects11.lib
Normal file
Binary file not shown.
1212
inc/effects11/d3dx11effect.h
Normal file
1212
inc/effects11/d3dx11effect.h
Normal file
File diff suppressed because it is too large
Load Diff
@ -197,6 +197,27 @@ namespace xna {
|
||||
Stretched = 2
|
||||
};
|
||||
|
||||
enum class EffectParameterClass {
|
||||
Matrix,
|
||||
Object,
|
||||
Scalar,
|
||||
Struct,
|
||||
Vector
|
||||
};
|
||||
|
||||
enum class EffectParameterType {
|
||||
Bool,
|
||||
Int32,
|
||||
Single,
|
||||
String,
|
||||
Texture,
|
||||
Texture1D,
|
||||
Texture2D,
|
||||
Texture3D,
|
||||
TextureCube,
|
||||
Void
|
||||
};
|
||||
|
||||
enum class FileMode {
|
||||
CreateNew,
|
||||
Create,
|
||||
|
79
inc/xna/graphics/effect.hpp
Normal file
79
inc/xna/graphics/effect.hpp
Normal file
@ -0,0 +1,79 @@
|
||||
#ifndef XNA_GRAPHICS_EFFECT_HPP
|
||||
#define XNA_GRAPHICS_EFFECT_HPP
|
||||
|
||||
#include "../common/numerics.hpp"
|
||||
#include "../default.hpp"
|
||||
#include "gresource.hpp"
|
||||
|
||||
namespace xna {
|
||||
class EffectAnnotation {
|
||||
public:
|
||||
EffectAnnotation();
|
||||
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<PlatformImplementation> impl;
|
||||
};
|
||||
|
||||
class Effect : public GraphicsResource {
|
||||
Effect(sptr<GraphicsDevice> const& device, std::vector<Byte> const& effectCode);
|
||||
|
||||
public:
|
||||
struct PlatformImplementation;
|
||||
uptr<PlatformImplementation> 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
|
@ -6,12 +6,18 @@
|
||||
//--------------------------------//
|
||||
|
||||
//DirectX
|
||||
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||
#include <d3d11_x.h>
|
||||
#define NO_D3D11_DEBUG_NAME
|
||||
#endif
|
||||
#include "dxgi.h"
|
||||
#include "d3d11.h"
|
||||
#include <d3d11_1.h>
|
||||
#include <d3d11_2.h>
|
||||
//HSLS
|
||||
//HSLS AND EFFECTS
|
||||
#include <d3dcompiler.h>
|
||||
#include <d3d11shader.h>
|
||||
#include "effects11/d3dx11effect.h"
|
||||
//DirectXTK
|
||||
#include <DirectXMath.h>
|
||||
#include <Audio.h>
|
||||
@ -62,6 +68,7 @@ using comptr = Microsoft::WRL::ComPtr<T>;
|
||||
#include "../graphics/depthstencilstate.hpp"
|
||||
#include "../graphics/displaymode.hpp"
|
||||
#include "../graphics/sprite.hpp"
|
||||
#include "../graphics/effect.hpp"
|
||||
#include "../graphics/samplerstate.hpp"
|
||||
#include "../input/gamepad.hpp"
|
||||
#include "../input/keyboard.hpp"
|
||||
@ -928,6 +935,21 @@ namespace xna {
|
||||
uptr<DirectX::SoundEffect> _dxSoundEffect = nullptr;
|
||||
};
|
||||
|
||||
struct Effect::PlatformImplementation {
|
||||
~PlatformImplementation() {
|
||||
if (dxEffect) {
|
||||
dxEffect->Release();
|
||||
dxEffect = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
ID3DX11Effect* dxEffect = nullptr;
|
||||
};
|
||||
|
||||
struct EffectAnnotation::PlatformImplementation {
|
||||
ID3DX11EffectVariable* dxVariable = 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()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user