GLES2N64 (from mupen64plus-ae) plugin. Compile and run on the OpenPandora
[mupen64plus-pandora.git] / source / gles2n64 / src / Textures.h
1 #ifndef TEXTURES_H
2 #define TEXTURES_H
3
4 #include <GLES2/gl2.h>
5
6 #include "Hash.h"
7 #include "convert.h"
8
9 struct CachedTexture
10 {
11     GLuint  glName;
12     u32     address;
13     u32     crc;
14     float   offsetS, offsetT;
15     u32     maskS, maskT;
16     u32     clampS, clampT;
17     u32     mirrorS, mirrorT;
18     u32     line;
19     u32     size;
20     u32     format;
21     u32     tMem;
22     u32     palette;
23     u32     width, height;            // N64 width and height
24     u32     clampWidth, clampHeight;  // Size to clamp to
25     u32     realWidth, realHeight;    // Actual texture size
26     f32     scaleS, scaleT;           // Scale to map to 0.0-1.0
27     f32     shiftScaleS, shiftScaleT; // Scale to shift
28     u32     textureBytes;
29
30     CachedTexture   *lower, *higher;
31     u32     lastDList;
32
33 };
34
35 #define TEXTURECACHE_MAX (8 * 1024 * 1024)
36 #define TEXTUREBUFFER_SIZE (512 * 1024)
37
38 struct TextureCache
39 {
40     CachedTexture   *current[2];
41     CachedTexture   *bottom, *top;
42     CachedTexture   *dummy;
43
44     u32             cachedBytes;
45     u32             numCached;
46     u32             hits, misses;
47     GLuint          glNoiseNames[32];
48
49     HashMap<CachedTexture>  hash;
50
51 };
52
53 extern TextureCache cache;
54
55 inline u32 pow2( u32 dim )
56 {
57     u32 i = 1;
58
59     while (i < dim) i <<= 1;
60
61     return i;
62 }
63
64 inline u32 powof( u32 dim )
65 {
66     u32 num = 1;
67     u32 i = 0;
68
69     while (num < dim)
70     {
71         num <<= 1;
72         i++;
73     }
74
75     return i;
76 }
77
78 CachedTexture *TextureCache_AddTop();
79 void TextureCache_MoveToTop( CachedTexture *newtop );
80 void TextureCache_Remove( CachedTexture *texture );
81 void TextureCache_RemoveBottom();
82 void TextureCache_Init();
83 void TextureCache_Destroy();
84 void TextureCache_Update( u32 t );
85 void TextureCache_ActivateTexture( u32 t, CachedTexture *texture );
86 void TextureCache_ActivateNoise( u32 t );
87 void TextureCache_ActivateDummy( u32 t );
88 bool TextureCache_Verify();
89
90 #endif
91