Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ if(NN_GFX_TARGET)
src/NintendoSDK/gfx/detail/gfx_CommonHelper.h
src/NintendoSDK/gfx/util/gfx_PrimitiveShape.cpp

src/NintendoWare/g3d/ResMaterial.cpp

src/NintendoSDK/gfx/gfx_BufferInfo.cpp
src/NintendoSDK/gfx/gfx_CommandBufferInfo.cpp
src/NintendoSDK/gfx/gfx_DescriptorPoolInfo.cpp
Expand Down
2 changes: 1 addition & 1 deletion include/nn/g3d/ResFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ResModel;
class ResMaterialAnim;
class ResShapeAnim;
class ResSceneAnim;
typedef void* TextureRef;
struct TextureRef;

class ResFile : public nn::util::BinaryFileHeader {
public:
Expand Down
130 changes: 127 additions & 3 deletions include/nn/g3d/ResMaterial.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,148 @@

#pragma once

#include <cstring>

#include <nn/gfx/gfx_Types.h>
#include <nn/types.h>

namespace nn {
namespace gfx {
class SamplerInfo;
}
namespace g3d {
typedef void* TextureRef;

struct TextureRef {
void* pTexture;
void* pUserData;
};

class ResShaderParam {
public:
enum Type {
kTypeBool1 = 0x00,
kTypeBool2,
kTypeBool3,
kTypeBool4,
kTypeS321,
kTypeS322,
kTypeS323,
kTypeS324,
kTypeU321,
kTypeU322,
kTypeU323,
kTypeU324,
kTypeF321,
kTypeF322,
kTypeF323,
kTypeF324,
kTypeF32_2x1,
kTypeF32_2x2,
kTypeF32_2x3,
kTypeF32_2x4,
kTypeF32_3x1,
kTypeF32_3x2,
kTypeF32_3x3,
kTypeF32_3x4,
kTypeF32_4x1,
kTypeF32_4x2,
kTypeF32_4x3,
kTypeF32_4x4,
kTypeSrt2d = 0x1c,
kTypeSrt3d,
kTypeTexSrt,
kTypeTexSrtEx,
};

typedef u64 (*ConvertFunc)(void* pDst, const void* pSrc, const ResShaderParam* pParam,
const void* pUserData);

template <bool T>
void Convert(void* pDst, const void* pSrc) const {
u32 type = m_Type;
if (type <= kTypeF324) {
memcpy(pDst, pSrc, ((type & 3) + 1) * sizeof(f32));
return;
}
if (type <= kTypeF32_4x4) {
size_t srcRowSize = ((type & 3) + 1) * sizeof(f32);
s32 rowCount = ((static_cast<s32>(type) - kTypeF32_2x1) >> 2) + 2;
for (s32 row = 0; row < rowCount; row++) {
memcpy(pDst, pSrc, srcRowSize);
pDst = static_cast<u8*>(pDst) + 0x10;
pSrc = static_cast<const u8*>(pSrc) + srcRowSize;
}
}
}

static u64 GetSize(Type type);
static u64 GetSrcSize(Type type);
bool SetDependPointer(void* pDependPointer, const void* pSrc) const;
bool GetDependPointer(void** ppDependPointer, const void* pSrc) const;

static u64 ConvertSrt2dCallback(void* pDst, const void* pSrc, const ResShaderParam* pParam,
const void* pUserData);
static u64 ConvertSrt3dCallback(void* pDst, const void* pSrc, const ResShaderParam* pParam,
const void* pUserData);
static u64 ConvertSrt2dExCallback(void* pDst, const void* pSrc, const ResShaderParam* pParam,
const void* pUserData);
static u64 ConvertTexSrtCallback(void* pDst, const void* pSrc, const ResShaderParam* pParam,
const void* pUserData);
static u64 ConvertTexSrtExCallback(void* pDst, const void* pSrc, const ResShaderParam* pParam,
const void* pUserData);

private:
u8 _0[0x10];
u8 m_Type; // 0x10
u8 _11; // 0x11
u16 _12;
u32 _14;
u32 _18; // 0x18
u32 _1c;
};

class ResMaterial {
public:
struct ShaderParamEntry {
ResShaderParam::ConvertFunc pConvertFunc; // 0x00
u64 _8;
u8 type; // 0x10
u8 _11[3];
s32 _14; // 0x14
u32 _18;
u8 _1c; // 0x1c
u8 _1d[3];
};
static_assert(sizeof(ShaderParamEntry) == 0x20);

u64 BindTexture(nn::g3d::TextureRef (*)(char const*, void*), void*);
void ForceBindTexture(nn::g3d::TextureRef const&, char const*);
bool ForceBindTexture(nn::g3d::TextureRef const&, char const*);
void ReleaseTexture();
void Setup(gfx::Device*);
void Cleanup(gfx::Device*);
void Reset();
void Reset(u32);

u8 _0[0xB4];
u8 _0[0x30];
void** m_pTextureRefs; // 0x30
const char* const* m_pTextureNames; // 0x38
gfx::Sampler* m_pSamplers; // 0x40
gfx::SamplerInfo* m_pSamplerInfos; // 0x48
u64 _50;
ShaderParamEntry* m_pShaderParams; // 0x58
u8 _60[0x20];
void* m_pShaderParamFlags; // 0x80
void* _88; // 0x88
u8 _90[8];
s64* m_pTextureStatus; // 0x98
u8 _a0[8];
u8 m_TextureCount; // 0xa8
u8 _a9;
u16 m_ShaderParamCount; // 0xaa
u16 _ac;
u16 _ae;
u16 _b0;
u16 _b2;
};
} // namespace g3d
} // namespace nn
2 changes: 1 addition & 1 deletion include/nn/g3d/ResMaterialAnim.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace nn {
namespace g3d {
typedef void* TextureRef;
struct TextureRef;

class ResMaterialAnim {
public:
Expand Down
2 changes: 1 addition & 1 deletion include/nn/g3d/ResModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace nn {
namespace g3d {
class ResMaterial;

typedef void* TextureRef;
struct TextureRef;

class ResModel {
public:
Expand Down
9 changes: 6 additions & 3 deletions include/nn/gfx/gfx_Sampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <nn/gfx/detail/gfx_Sampler-api.nvn.8.h>
#include <nn/gfx/gfx_Common.h>
#include <nn/gfx/gfx_Device.h>

namespace nn::gfx {

Expand All @@ -12,9 +13,11 @@ class TSampler : public detail::SamplerImpl<TTarget> {
public:
typedef SamplerInfo InfoType;

TSampler();
void Initialize(TDevice<TTarget>*, const InfoType&);
void Finalize(TDevice<TTarget>*);
TSampler() = default;
void Initialize(TDevice<TTarget>* pDevice, const InfoType& info) {
detail::SamplerImpl<TTarget>::Initialize(pDevice, info);
}
void Finalize(TDevice<TTarget>* pDevice) { detail::SamplerImpl<TTarget>::Finalize(pDevice); }
void SetUserPtr(void*);
void* GetUserPtr();
const void* GetUserPtr() const;
Expand Down
44 changes: 44 additions & 0 deletions include/nn/util/util_Arithmetic.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,48 @@ inline float CosTable(AngleIndex angleIndex) {
return table->cosValue + table->cosDelta * rest;
}

struct SinCosTable {
float sinValue;
float cosValue;
};

inline SinCosTable CalcSinCos(float radian) {
float angleIndex = radian * detail::Float1Divided2Pi;
angleIndex =
static_cast<float>(static_cast<int64_t>(angleIndex + (angleIndex >= 0.0f ? 0.5f : -0.5f)));
float x = radian - angleIndex * detail::Float2Pi;

float sign = 1.0f;
if (x > detail::FloatPiDivided2) {
x = detail::FloatPi - x;
sign = -1.0f;
}
if (x < -detail::FloatPiDivided2) {
x = -detail::FloatPi - x;
sign = -sign;
}

float x2 = x * x;

float sinAcc = detail::SinCoefficients[1] - x2 * detail::SinCoefficients[0];
sinAcc = -detail::SinCoefficients[2] + x2 * sinAcc;
sinAcc = detail::SinCoefficients[3] + x2 * sinAcc;
sinAcc = -detail::SinCoefficients[4] + x2 * sinAcc;
float sinValue = x * (1.0f + x2 * sinAcc);

float cosAcc = detail::CosCoefficients[1] - x2 * detail::CosCoefficients[0];
cosAcc = -detail::CosCoefficients[2] + x2 * cosAcc;
cosAcc = detail::CosCoefficients[3] + x2 * cosAcc;
cosAcc = -detail::CosCoefficients[4] + x2 * cosAcc;
float cosValue = (1.0f + x2 * cosAcc) * sign;

return {sinValue, cosValue};
}

inline void SinCosF32(float* pSin, float* pCos, float radian) {
AngleIndex angleIndex = RadianToAngleIndex(radian);
*pSin = SinTable(angleIndex);
*pCos = CosTable(angleIndex);
}

} // namespace nn::util
Loading