summaryrefslogtreecommitdiff
path: root/include/egg/gfx/eggLightTextureMgr.h
blob: cd3ff842995b245d6e7aab19ce3ada6e9e4cf418 (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
#ifndef EGG_LIGHT_TEXTURE_MGR_H
#define EGG_LIGHT_TEXTURE_MGR_H

#include "common.h"
#include "egg/gfx/eggLightManager.h"
#include "egg/gfx/eggLightTexture.h"
#include "egg/prim/eggBinary.h"
#include "nw4r/g3d/res/g3d_resmat.h"
#include "nw4r/g3d/res/g3d_resmdl.h"

namespace EGG {

class LightManager;
class LightObject;

class LightTextureManager : public IBinary<LightTextureManager> {
public:
    struct BinData {
        u16 mDataCount;
        u8 _0x02[14];
        BinHeader mSubData[1];
    };
    LightTextureManager(const LightManager *lightMgr);
    virtual ~LightTextureManager();
    virtual void SetBinaryInner(const Bin &) override;
    virtual void GetBinaryInner(Bin *) const override;
    virtual size_t GetBinarySize() const override;

    u16 createTexture(const char *name);
    bool setBinaryToTexture(const void *data);
    bool deleteTexture(int idx);

    u16 replaceModelTextures(nw4r::g3d::ResMdl) const;
    u16 replaceModelTexture(int, nw4r::g3d::ResMdl) const;
    void drawAndCaptureTexture(f32, f32, f32, f32);
    void frameReset();
    void correctLightObject();

    // Inofficial
    static const void *getLtexFromLmap(const void *lmap, u16 index);
    int createTexturesFromBin(const void *bin);
    u16 createTextureFromBin(const void *bin);

    u16 getMaxNumLightTextures() const {
        return mMaxNumTextures;
    }

    u16 getNumLightTextures() const {
        return mTextureCount;
    }

    LightTexture *getTextureByName(const char *name) const {
        int idx = getTextureIndex(name);
        if (idx != -1) {
            return mpTextures[idx];
        } else {
            return nullptr;
        }
    }

    const nw4r::g3d::AmbLightObj &GetAmbientObj(int idx) const {
        return mpLightMgr->GetAmbientObject(idx)->mLightObj;
    }

    const LightObject *GetLightObject(u16 i) const {
        return mpObjects[i];
    }

    const LightObject *GetLightObject(u16 i) {
        return mpObjects[i];
    }

private:
    static void setupEnvmap(nw4r::g3d::ResMat, GXTexCoordID);
    int getTextureIndex(const char *name) const;

    bool getSomeTfRelatedBool() const {
        return (mFlags >> 5) & 1;
    }

    /* 0x04 */ u8 mFlags;
    /* 0x06 */ u16 mTextureCount;
    /* 0x08 */ LightTexture **mpTextures;
    /* 0x0C */ const LightManager *mpLightMgr;
    /* 0x10 */ u32 field_0x10;
    /* 0x14 */ u16 mMaxNumTextures;
    /* 0x16 */ u8 field_0x16;
    /* 0x18 */ const LightObject **mpObjects;
};

} // namespace EGG

#endif