Skip to content

Commit 172f88e

Browse files
committed
pending changes
1 parent 9989113 commit 172f88e

5 files changed

Lines changed: 80 additions & 10 deletions

File tree

include/driver/display/Renderer.tcc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ namespace love
4949
protected:
5050
struct ContextBase
5151
{
52-
CullMode cullMode;
52+
CullMode cullMode = CULL_MAX_ENUM;
5353
ColorChannelMask colorMask;
5454
BlendState blendState;
5555
StencilState stencilState;

platform/ctr/include/driver/display/citro3d.hpp

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
#pragma once
22

33
#include <3ds/gpu/enums.h>
4+
#include <c3d/framebuffer.h>
45
#include <citro3d.h>
6+
#include <cstdint>
57

68
#include "common/Map.hpp"
79
#include "common/config.hpp"
10+
#include "common/int.hpp"
811
#include "common/pixelformat.hpp"
912

1013
#include "driver/display/Framebuffer.hpp"
@@ -30,6 +33,20 @@ namespace love
3033
TEXENV_MODE_MAX_ENUM
3134
};
3235

36+
class CleanClearState
37+
{
38+
public:
39+
CleanClearState(C3D_ClearBits flags);
40+
~CleanClearState();
41+
42+
private:
43+
C3D_ClearBits flags;
44+
uint32_t colorWriteMask;
45+
uint32_t stencilWriteMask;
46+
bool depthWrites;
47+
bool scissor;
48+
};
49+
3350
citro3d();
3451

3552
virtual void init() override;
@@ -65,6 +82,36 @@ namespace love
6582

6683
virtual void present() override;
6784

85+
void setDepthWrites(bool enabled)
86+
{
87+
this->state.depthWritesEnabled = enabled;
88+
}
89+
90+
bool hasDepthWrites() const
91+
{
92+
return this->state.depthWritesEnabled;
93+
}
94+
95+
void setStencilWriteMask(uint32_t mask)
96+
{
97+
this->state.stencilWriteMask = mask;
98+
}
99+
100+
bool getStencilWriteMask() const
101+
{
102+
return this->state.stencilWriteMask;
103+
}
104+
105+
void setColorWriteMask(uint32_t mask)
106+
{
107+
this->state.colorWriteMask = mask;
108+
}
109+
110+
bool getColorWriteMask() const
111+
{
112+
return this->state.colorWriteMask;
113+
}
114+
68115
C3D_RenderTarget* getFramebuffer();
69116

70117
C3D_RenderTarget* getInternalBackbuffer() const;
@@ -111,7 +158,12 @@ namespace love
111158

112159
// clang-format off
113160

114-
ENUMMAP_DECLARE(PrimitiveModes, PrimitiveType, GPU_Primitive_t,
161+
ENUMMAP_DECLARE(FilterModes, SamplerState::FilterMode, GPU_TEXTURE_FILTER_PARAM,
162+
{ SamplerState::FILTER_LINEAR, GPU_LINEAR },
163+
{ SamplerState::FILTER_NEAREST, GPU_NEAREST }
164+
);
165+
166+
ENUMMAP_DECLARE(PrimitiveModes, PrimitiveType, GPU_Primitive_t,
115167
{ PRIMITIVE_TRIANGLES, GPU_TRIANGLES },
116168
{ PRIMITIVE_TRIANGLE_STRIP, GPU_TRIANGLE_STRIP },
117169
{ PRIMITIVE_TRIANGLE_FAN, GPU_TRIANGLE_FAN }
@@ -230,6 +282,15 @@ namespace love
230282

231283
std::vector<std::function<void()>> deferred;
232284
std::array<C3D_TexEnv, TEXENV_MODE_MAX_ENUM> environments;
285+
286+
struct
287+
{
288+
GPU_CULLMODE faceCullMode;
289+
uint32_t enabledAttribArrays;
290+
bool depthWritesEnabled = true;
291+
uint32_t stencilWriteMask = LOVE_UINT32_MAX;
292+
uint32_t colorWriteMask = LOVE_UINT32_MAX;
293+
} state;
233294
};
234295

235296
extern citro3d c3d;

platform/ctr/source/driver/display/Framebuffer.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
#include <algorithm>
2-
3-
#include "common/Exception.hpp"
4-
51
#include "driver/display/Framebuffer.hpp"
6-
#include "driver/display/citro3d.hpp"
2+
#include "common/Exception.hpp"
73

84
namespace love
95
{

platform/ctr/source/driver/display/citro3d.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,16 @@
55
#include "modules/graphics/Shader.hpp"
66
#include "modules/graphics/vertex.hpp"
77
#include <3ds/gpu/enums.h>
8+
#include <c3d/effect.h>
89

910
namespace love
1011
{
12+
citro3d::CleanClearState::CleanClearState(C3D_ClearBits flags) : flags(flags)
13+
{}
14+
15+
citro3d::CleanClearState::~CleanClearState()
16+
{}
17+
1118
citro3d::citro3d() : context {}
1219
{
1320
this->targets.reserve(3);
@@ -240,8 +247,11 @@ namespace love
240247

241248
void citro3d::setSamplerState(C3D_Tex* texture, SamplerState state)
242249
{
243-
auto magFilter = (state.minFilter == SamplerState::FILTER_NEAREST) ? GPU_NEAREST : GPU_LINEAR;
244-
auto minFilter = (state.magFilter == SamplerState::FILTER_NEAREST) ? GPU_NEAREST : GPU_LINEAR;
250+
GPU_TEXTURE_FILTER_PARAM magFilter;
251+
citro3d::getConstant(state.magFilter, magFilter);
252+
253+
GPU_TEXTURE_FILTER_PARAM minFilter;
254+
citro3d::getConstant(state.minFilter, minFilter);
245255

246256
C3D_TexSetFilter(texture, magFilter, minFilter);
247257

@@ -306,7 +316,8 @@ namespace love
306316
const auto& format = love::getDataFormatInfo(attribute.getFormat());
307317

308318
GPU_FORMATS attributeFormat;
309-
citro3d::getConstant(format.baseType, attributeFormat);
319+
if (!citro3d::getConstant(format.baseType, attributeFormat))
320+
throw love::Exception("Invalid data base type: {:d}.", (int)format.baseType);
310321

311322
AttrInfo_AddLoader(&info, i, attributeFormat, format.components);
312323
}

platform/ctr/source/modules/graphics/Graphics.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,7 @@ namespace love
618618
c3d.setTexEnvMode(command.texture, command.isFont);
619619
c3d.setVertexAttributes(attributes, *command.buffers);
620620
c3d.bindTextureToUnit(command.texture, 0);
621+
c3d.setCullMode(command.cullMode);
621622

622623
const auto* indices = (const uint16_t*)command.indexBuffer->getHandle();
623624
const int index = BUFFER_OFFSET(command.indexBufferOffset);
@@ -640,6 +641,7 @@ namespace love
640641
c3d.setTexEnvMode(command.texture, command.isFont);
641642
c3d.setVertexAttributes(attributes, *command.buffers);
642643
c3d.bindTextureToUnit(command.texture, 0);
644+
c3d.setCullMode(command.cullMode);
643645

644646
GPU_Primitive_t primitive;
645647
citro3d::getConstant(command.primitiveType, primitive);

0 commit comments

Comments
 (0)