mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-07 22:55:40 +12:00
[PICA] We now know how to convert attributes to f32
This commit is contained in:
parent
dcad7846eb
commit
93e5c268e8
2 changed files with 35 additions and 24 deletions
|
@ -23,13 +23,13 @@ namespace Floats {
|
||||||
template <unsigned M, unsigned E>
|
template <unsigned M, unsigned E>
|
||||||
struct Float {
|
struct Float {
|
||||||
public:
|
public:
|
||||||
static Float<M, E> FromFloat32(float val) {
|
static Float<M, E> fromFloat32(float val) {
|
||||||
Float<M, E> ret;
|
Float<M, E> ret;
|
||||||
ret.value = val;
|
ret.value = val;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Float<M, E> FromRaw(u32 hex) {
|
static Float<M, E> fromRaw(u32 hex) {
|
||||||
Float<M, E> res;
|
Float<M, E> res;
|
||||||
|
|
||||||
const int width = M + E + 1;
|
const int width = M + E + 1;
|
||||||
|
@ -54,34 +54,34 @@ namespace Floats {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Float<M, E> Zero() {
|
static Float<M, E> zero() {
|
||||||
return FromFloat32(0.f);
|
return fromFloat32(0.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not recommended for anything but logging
|
// Not recommended for anything but logging
|
||||||
float ToFloat32() const {
|
float toFloat32() const {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
Float<M, E> operator*(const Float<M, E>& flt) const {
|
Float<M, E> operator*(const Float<M, E>& flt) const {
|
||||||
float result = value * flt.ToFloat32();
|
float result = value * flt.toFloat32();
|
||||||
// PICA gives 0 instead of NaN when multiplying by inf
|
// PICA gives 0 instead of NaN when multiplying by inf
|
||||||
if (std::isnan(result))
|
if (std::isnan(result))
|
||||||
if (!std::isnan(value) && !std::isnan(flt.ToFloat32()))
|
if (!std::isnan(value) && !std::isnan(flt.toFloat32()))
|
||||||
result = 0.f;
|
result = 0.f;
|
||||||
return Float<M, E>::FromFloat32(result);
|
return Float<M, E>::fromFloat32(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
Float<M, E> operator/(const Float<M, E>& flt) const {
|
Float<M, E> operator/(const Float<M, E>& flt) const {
|
||||||
return Float<M, E>::FromFloat32(ToFloat32() / flt.ToFloat32());
|
return Float<M, E>::fromFloat32(toFloat32() / flt.toFloat32());
|
||||||
}
|
}
|
||||||
|
|
||||||
Float<M, E> operator+(const Float<M, E>& flt) const {
|
Float<M, E> operator+(const Float<M, E>& flt) const {
|
||||||
return Float<M, E>::FromFloat32(ToFloat32() + flt.ToFloat32());
|
return Float<M, E>::fromFloat32(toFloat32() + flt.toFloat32());
|
||||||
}
|
}
|
||||||
|
|
||||||
Float<M, E> operator-(const Float<M, E>& flt) const {
|
Float<M, E> operator-(const Float<M, E>& flt) const {
|
||||||
return Float<M, E>::FromFloat32(ToFloat32() - flt.ToFloat32());
|
return Float<M, E>::fromFloat32(toFloat32() - flt.toFloat32());
|
||||||
}
|
}
|
||||||
|
|
||||||
Float<M, E>& operator*=(const Float<M, E>& flt) {
|
Float<M, E>& operator*=(const Float<M, E>& flt) {
|
||||||
|
@ -90,46 +90,46 @@ namespace Floats {
|
||||||
}
|
}
|
||||||
|
|
||||||
Float<M, E>& operator/=(const Float<M, E>& flt) {
|
Float<M, E>& operator/=(const Float<M, E>& flt) {
|
||||||
value /= flt.ToFloat32();
|
value /= flt.toFloat32();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Float<M, E>& operator+=(const Float<M, E>& flt) {
|
Float<M, E>& operator+=(const Float<M, E>& flt) {
|
||||||
value += flt.ToFloat32();
|
value += flt.toFloat32();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Float<M, E>& operator-=(const Float<M, E>& flt) {
|
Float<M, E>& operator-=(const Float<M, E>& flt) {
|
||||||
value -= flt.ToFloat32();
|
value -= flt.toFloat32();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Float<M, E> operator-() const {
|
Float<M, E> operator-() const {
|
||||||
return Float<M, E>::FromFloat32(-ToFloat32());
|
return Float<M, E>::fromFloat32(-toFloat32());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator<(const Float<M, E>& flt) const {
|
bool operator<(const Float<M, E>& flt) const {
|
||||||
return ToFloat32() < flt.ToFloat32();
|
return toFloat32() < flt.toFloat32();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator>(const Float<M, E>& flt) const {
|
bool operator>(const Float<M, E>& flt) const {
|
||||||
return ToFloat32() > flt.ToFloat32();
|
return toFloat32() > flt.toFloat32();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator>=(const Float<M, E>& flt) const {
|
bool operator>=(const Float<M, E>& flt) const {
|
||||||
return ToFloat32() >= flt.ToFloat32();
|
return toFloat32() >= flt.toFloat32();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator<=(const Float<M, E>& flt) const {
|
bool operator<=(const Float<M, E>& flt) const {
|
||||||
return ToFloat32() <= flt.ToFloat32();
|
return toFloat32() <= flt.toFloat32();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const Float<M, E>& flt) const {
|
bool operator==(const Float<M, E>& flt) const {
|
||||||
return ToFloat32() == flt.ToFloat32();
|
return toFloat32() == flt.toFloat32();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator!=(const Float<M, E>& flt) const {
|
bool operator!=(const Float<M, E>& flt) const {
|
||||||
return ToFloat32() != flt.ToFloat32();
|
return toFloat32() != flt.toFloat32();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -142,8 +142,8 @@ namespace Floats {
|
||||||
float value;
|
float value;
|
||||||
};
|
};
|
||||||
|
|
||||||
using float24 = Float<16, 7>;
|
using f24 = Float<16, 7>;
|
||||||
using float20 = Float<12, 7>;
|
using f20 = Float<12, 7>;
|
||||||
using float16 = Float<10, 5>;
|
using f16 = Float<10, 5>;
|
||||||
|
|
||||||
} // namespace Pica
|
} // namespace Pica
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
#include "PICA/gpu.hpp"
|
#include "PICA/gpu.hpp"
|
||||||
|
#include "PICA/float_types.hpp"
|
||||||
#include "PICA/regs.hpp"
|
#include "PICA/regs.hpp"
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
|
using namespace Floats;
|
||||||
|
|
||||||
void GPU::reset() {
|
void GPU::reset() {
|
||||||
regs.fill(0);
|
regs.fill(0);
|
||||||
shaderUnit.reset();
|
shaderUnit.reset();
|
||||||
|
@ -16,5 +19,13 @@ void GPU::drawArrays() {
|
||||||
const u32 vertexCount = regs[PICAInternalRegs::VertexCountReg];
|
const u32 vertexCount = regs[PICAInternalRegs::VertexCountReg];
|
||||||
const u32 vertexOffset = regs[PICAInternalRegs::VertexOffsetReg];
|
const u32 vertexOffset = regs[PICAInternalRegs::VertexOffsetReg];
|
||||||
|
|
||||||
|
|
||||||
|
u32* attrBuffer = ®s[0x233];
|
||||||
|
auto a = f24::fromRaw(attrBuffer[0] >> 8);
|
||||||
|
auto b = f24::fromRaw(((attrBuffer[0] & 0xFF) << 16) | ((attrBuffer[1] >> 16) & 0xFFFF));
|
||||||
|
auto g = f24::fromRaw(((attrBuffer[1] & 0xFFFF) << 8) | ((attrBuffer[2] >> 24) & 0xFF));
|
||||||
|
auto r = f24::fromRaw(attrBuffer[2] & 0xFFFFFF);
|
||||||
|
|
||||||
printf("PICA::DrawArrays(vertex count = %d, vertexOffset = %d)\n", vertexCount, vertexOffset);
|
printf("PICA::DrawArrays(vertex count = %d, vertexOffset = %d)\n", vertexCount, vertexOffset);
|
||||||
|
printf("(r: %f, g: %f, b: %f, a: %f)\n", r.toFloat32(), g.toFloat32(), b.toFloat32(), a.toFloat32());
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue