summaryrefslogtreecommitdiff
path: root/include/egg/gfx/eggCpuTexture.h
blob: d5300b4148bde7f681f355e7780ddd6d926157c5 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#ifndef EGG_CPU_TEXTURE_H
#define EGG_CPU_TEXTURE_H

#include "common.h"
#include "egg/core/eggHeap.h"
#include "egg/gfx/eggTexture.h"
#include "rvl/GX/GXTexture.h"
#include "rvl/GX/GXTypes.h"

namespace EGG {

class CpuTexture {
public:
    enum TexFlag {
        CONFIGURED = 0x1,
        HAS_HEADER = 0x2,
        NEEDS_BUFFER_FREE = 0x4,
    };

    virtual ~CpuTexture();    // at 0x8
    virtual void configure(); // at 0xC

    void getTexObj(GXTexObj *) const; // at 0x10
    void load(GXTexMapID) const;      // at 0x14

    CpuTexture();
    CpuTexture(u16 width, u16 height, GXTexFmt texFmt);
    CpuTexture(const GXTexObj *pObj);

    void checkTexBuffer() const;
    void invalidate() const;
    void flush() const;
    void alloc(Heap *heap);
    void allocWithHeaderDebug(Heap *heap);
    void allocate(Heap *heap);

    u32 getTexBufferSize() const;
    void buildHeader() const;
    ResTIMG *initHeader();

    void fillNormalMapSphere(f32, f32);
    void fillGradient(int op, int, u16, u16, const GXColor &, const GXColor &, bool, bool);

    void setColor(u16 x, u16 y, GXColor color);
    GXColor getColor(u16 x, u16 y) const;

    bool checkIsConfigure() const {
        return mFlags & CONFIGURED;
    }
    bool checkHasHeader() const {
        return mFlags & HAS_HEADER;
    }

    void setFlag(u8 flag) {
        mFlags |= flag;
    }
    void clearFlag(u8 flag) {
        mFlags &= ~flag;
    }

    u16 getWidth() const {
        return mWidth;
    }
    void setWidth(u16 w) {
        mWidth = w;
    }

    u16 getHeight() const {
        return mHeight;
    }
    // Needed for PostEffectMaskDOF::setUpGradation
    u16 getHeight2() {
        return mHeight;
    }
    void setHeight(u16 h) {
        mHeight = h;
    }

    GXTexFmt getFormat() const {
        return (GXTexFmt)mTexFormat;
    }
    void setFormat(GXTexFmt fmt) {
        mTexFormat = fmt;
    }

    void setWrapS(GXTexWrapMode wrap) {
        mWrapS = wrap;
    }
    void setWrapT(GXTexWrapMode wrap) {
        mWrapT = wrap;
    }

    GXTexWrapMode getWrapS() const {
        return (GXTexWrapMode)mWrapS;
    }
    GXTexWrapMode getWrapT() const {
        return (GXTexWrapMode)mWrapT;
    }

    void setWrap(GXTexWrapMode wrapS, GXTexWrapMode wrapT) {
        mWrapS = wrapS;
        mWrapT = wrapT;
    }

    void setFilt(GXTexFilter min, GXTexFilter mag) {
        mMinFilt = min;
        mMagFilt = mag;
    }

    void setMinFilt(GXTexFilter filt) {
        mMinFilt = filt;
    }
    void setMagFilt(GXTexFilter filt) {
        mMagFilt = filt;
    }

    GXTexFilter getMinFilt() const {
        return (GXTexFilter)mMinFilt;
    }
    GXTexFilter getMagFilt() const {
        return (GXTexFilter)mMagFilt;
    }

    ResTIMG *getHeader() const {
        return (ResTIMG *)((u8 *)dataPtr - sizeof(ResTIMG));
    }

    void *getBuffer() const {
        return dataPtr;
    }
    void setBuffer(void *pBuffer);

protected:
    u16 mWidth;    // at 0x4
    u16 mHeight;   // at 0x6
    u8 mFlags;     // at 0x8
    u8 mTexFormat; // at 0x9
    u8 mWrapS;     // at 0xA
    u8 mWrapT;     // at 0xB
    u8 mMinFilt;   // at 0xC
    u8 mMagFilt;   // at 0xD
    u8 UNK_0xE[2];
    void *dataPtr;  // at 0x10
    char *mpBuffer; // at 0x14
};

} // namespace EGG

#endif