mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-16 18:59:48 +12:00
sample textures
This commit is contained in:
parent
b62a14d3ff
commit
3bb1ccd4d8
3 changed files with 72 additions and 6 deletions
|
@ -56,5 +56,5 @@ class RendererMTL final : public Renderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
MTL::Texture* getTexture(Metal::Texture& tex);
|
MTL::Texture* getTexture(Metal::Texture& tex);
|
||||||
void bindTexturesToSlots();
|
void bindTexturesToSlots(MTL::RenderCommandEncoder* encoder);
|
||||||
};
|
};
|
||||||
|
|
|
@ -211,7 +211,7 @@ void RendererMTL::drawVertices(PICA::PrimType primType, std::span<const PICA::Ve
|
||||||
renderCommandEncoder->setVertexBytes(vertices.data(), vertices.size_bytes(), VERTEX_BUFFER_BINDING_INDEX);
|
renderCommandEncoder->setVertexBytes(vertices.data(), vertices.size_bytes(), VERTEX_BUFFER_BINDING_INDEX);
|
||||||
|
|
||||||
// Bind resources
|
// Bind resources
|
||||||
bindTexturesToSlots();
|
bindTexturesToSlots(renderCommandEncoder);
|
||||||
|
|
||||||
// TODO: respect primitive type
|
// TODO: respect primitive type
|
||||||
renderCommandEncoder->drawPrimitives(MTL::PrimitiveTypeTriangle, NS::UInteger(0), NS::UInteger(vertices.size()));
|
renderCommandEncoder->drawPrimitives(MTL::PrimitiveTypeTriangle, NS::UInteger(0), NS::UInteger(vertices.size()));
|
||||||
|
@ -245,7 +245,7 @@ MTL::Texture* RendererMTL::getTexture(Metal::Texture& tex) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RendererMTL::bindTexturesToSlots() {
|
void RendererMTL::bindTexturesToSlots(MTL::RenderCommandEncoder* encoder) {
|
||||||
static constexpr std::array<u32, 3> ioBases = {
|
static constexpr std::array<u32, 3> ioBases = {
|
||||||
PICA::InternalRegs::Tex0BorderColor,
|
PICA::InternalRegs::Tex0BorderColor,
|
||||||
PICA::InternalRegs::Tex1BorderColor,
|
PICA::InternalRegs::Tex1BorderColor,
|
||||||
|
@ -269,8 +269,7 @@ void RendererMTL::bindTexturesToSlots() {
|
||||||
if (addr != 0) [[likely]] {
|
if (addr != 0) [[likely]] {
|
||||||
Metal::Texture targetTex(device, addr, static_cast<PICA::TextureFmt>(format), width, height, config);
|
Metal::Texture targetTex(device, addr, static_cast<PICA::TextureFmt>(format), width, height, config);
|
||||||
MTL::Texture* tex = getTexture(targetTex);
|
MTL::Texture* tex = getTexture(targetTex);
|
||||||
// TODO: bind the texture
|
encoder->setFragmentTexture(tex, i);
|
||||||
Helpers::warn("Wanted to bind texture %p at index %i", tex, i);
|
|
||||||
} else {
|
} else {
|
||||||
// TODO: bind a dummy texture?
|
// TODO: bind a dummy texture?
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,16 +32,83 @@ struct DrawVertexIn {
|
||||||
struct DrawVertexOut {
|
struct DrawVertexOut {
|
||||||
float4 position [[position]];
|
float4 position [[position]];
|
||||||
float4 color;
|
float4 color;
|
||||||
|
float3 texCoord0;
|
||||||
|
float2 texCoord1;
|
||||||
|
float2 texCoord2;
|
||||||
};
|
};
|
||||||
|
|
||||||
vertex DrawVertexOut vertexDraw(DrawVertexIn in [[stage_in]]) {
|
vertex DrawVertexOut vertexDraw(DrawVertexIn in [[stage_in]]) {
|
||||||
DrawVertexOut out;
|
DrawVertexOut out;
|
||||||
|
|
||||||
|
// Position
|
||||||
out.position = in.position;
|
out.position = in.position;
|
||||||
|
// HACK: rotate the position
|
||||||
|
out.position.xy = -out.position.yx;
|
||||||
// in.position.z is in range of [-1 ... 1], convert it to [0 ... 1]
|
// in.position.z is in range of [-1 ... 1], convert it to [0 ... 1]
|
||||||
out.position.z = (in.position.z + 1.0) * 0.5;
|
out.position.z = (in.position.z + 1.0) * 0.5;
|
||||||
|
|
||||||
|
// Color
|
||||||
out.color = in.color;
|
out.color = in.color;
|
||||||
|
|
||||||
|
// Texture coordinates
|
||||||
|
out.texCoord0 = float3(in.texCoord0, in.texCoord0W);
|
||||||
|
out.texCoord0.y = 1.0 - out.texCoord0.y;
|
||||||
|
out.texCoord1 = in.texCoord1;
|
||||||
|
out.texCoord1.y = 1.0 - out.texCoord1.y;
|
||||||
|
out.texCoord2 = in.texCoord2;
|
||||||
|
out.texCoord2.y = 1.0 - out.texCoord2.y;
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
fragment float4 fragmentDraw(DrawVertexOut in [[stage_in]]) { return in.color; }
|
fragment float4 fragmentDraw(DrawVertexOut in [[stage_in]], texture2d<float> tex0 [[texture(0)]], texture2d<float> tex1 [[texture(1)]], texture2d<float> tex2 [[texture(2)]]) {
|
||||||
|
// TODO: upload this as argument
|
||||||
|
sampler samplr;
|
||||||
|
|
||||||
|
float4 tevSources[16];
|
||||||
|
tevSources[0] = in.color;
|
||||||
|
// TODO: uncomment
|
||||||
|
//calcLighting(tevSources[1], tevSources[2]);
|
||||||
|
|
||||||
|
// TODO: uncomment
|
||||||
|
//uint textureConfig = readPicaReg(0x80u);
|
||||||
|
// HACK
|
||||||
|
uint textureConfig = 0b111u;
|
||||||
|
float2 texCoord2 = (textureConfig & (1u << 13)) != 0u ? in.texCoord1 : in.texCoord2;
|
||||||
|
|
||||||
|
if ((textureConfig & 1u) != 0u) tevSources[3] = tex0.sample(samplr, in.texCoord0.xy);
|
||||||
|
if ((textureConfig & 2u) != 0u) tevSources[4] = tex1.sample(samplr, in.texCoord1);
|
||||||
|
if ((textureConfig & 4u) != 0u) tevSources[5] = tex2.sample(samplr, texCoord2);
|
||||||
|
tevSources[13] = float4(0.0); // Previous buffer
|
||||||
|
tevSources[15] = in.color; // Previous combiner
|
||||||
|
|
||||||
|
// TODO: uncomment
|
||||||
|
//float4 tevNextPreviousBuffer = v_textureEnvBufferColor;
|
||||||
|
// HACK
|
||||||
|
float4 tevNextPreviousBuffer = float4(0.0);
|
||||||
|
// TODO: uncomment
|
||||||
|
//uint textureEnvUpdateBuffer = readPicaReg(0xE0u);
|
||||||
|
// HACK
|
||||||
|
uint textureEnvUpdateBuffer = 0b111111u;
|
||||||
|
|
||||||
|
for (int i = 0; i < 6; i++) {
|
||||||
|
// TODO: uncomment
|
||||||
|
tevSources[14] = float4(0.0);//v_textureEnvColor[i]; // Constant color
|
||||||
|
// TODO: uncomment
|
||||||
|
tevSources[15] = float4(1.0);//tevCalculateCombiner(i);
|
||||||
|
tevSources[13] = tevNextPreviousBuffer;
|
||||||
|
|
||||||
|
if (i < 4) {
|
||||||
|
if ((textureEnvUpdateBuffer & (0x100u << i)) != 0u) {
|
||||||
|
tevNextPreviousBuffer.rgb = tevSources[15].rgb;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((textureEnvUpdateBuffer & (0x1000u << i)) != 0u) {
|
||||||
|
tevNextPreviousBuffer.a = tevSources[15].a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HACK: should be tevSources[15]
|
||||||
|
return tevSources[3];
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue