summaryrefslogtreecommitdiff
path: root/src/egg/gfx/eggCapTexture.cpp
blob: d1194d85e770b53c15d6fb55a22fffe5efac852f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "egg/gfx/eggCapTexture.h"

#include "egg/gfx/eggCpuTexture.h"
#include "egg/gfx/eggStateGX.h"
#include "rvl/GX/GXFrameBuf.h"
#include "rvl/GX/GXPixel.h"
#include "rvl/GX/GXTypes.h"

namespace {
static const GXColor DEFUALT_CLEAR_COLOR = {0, 0, 0, 0};
static const u8 SAMPLE_PATTERN_OFF[12][2] = {};

} // namespace
namespace EGG {

const CopyFilter CapTexture::VFILTER_BLUR = {
    {0x15, 0, 0, 0x16, 0, 0x15, 0}
};

const CopyFilter CapTexture::VFILTER_OFF = {
    {0, 0, 1, 0x3F, 0, 0, 0}
};

void CapTexture::configure() {
    CpuTexture::configure();
    mCapFlags = 0;
    mClearColor = DEFUALT_CLEAR_COLOR;
    field_0x20 = 0xFFFFFF;
    mCopyFilterArg = VFILTER_OFF;
}

void CapTexture::capture(u16 x, u16 y, bool upscale, int format) {
    GXTexFmt fmt = format == -1 ? getFormat() : static_cast<GXTexFmt>(format);
    u16 width = upscale ? getWidth() * 2 : getWidth();
    u16 height = upscale ? getHeight() * 2 : getHeight();

    GXSetTexCopySrc(x, y, width, height);
    GXSetTexCopyDst(mWidth, mHeight, fmt, upscale);

    GXSetCopyFilter(
        0, SAMPLE_PATTERN_OFF, (mCapFlags & 8) ? true : false,
        (mCapFlags & 8) ? mCopyFilterArg.values : VFILTER_OFF.values
    );

    StateGX::ScopedColor colorUpdate((mCapFlags & 1) != 0);
    StateGX::ScopedAlpha alphaUpdate((mCapFlags & 2) != 0);
    GXSetZMode(true, GX_ALWAYS, (mCapFlags & 4) != 0);
    GXSetCopyClear(mClearColor, field_0x20);
    GXSetCopyClamp(3);
    StateGX::GXCopyTex_(dataPtr, true);
    GXSetCopyFilter(0, SAMPLE_PATTERN_OFF, 0, VFILTER_OFF.values);

    if ((mCapFlags & 0x10) != 0) {
        GXPixModeSync();
    }

    if ((mCapFlags & 0x20) != 0) {
        StateGX::invalidateTexAllGX();
    }
}

void CapTexture::fn_8049D9D0(u8 arg) {
    onCapFlag(0x8);

    CopyFilter v;
    v.values[0] = arg;
    v.values[1] = 0;
    v.values[2] = 1;
    v.values[3] = 64 - (2 * arg) - 1;
    v.values[4] = 0;
    v.values[5] = arg;
    v.values[6] = 0;
    setCopyFilter(v);
}

} // namespace EGG