1 #ifndef TEXTURES_H
2 #define TEXTURES_H
3
4 #include <retro_inline.h>
5
6 #include <glsm/glsmsym.h>
7
8 #include "convert.h"
9
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13
14 struct gDPTile;
15
16 typedef uint32_t (*GetTexelFunc)( uint64_t *src, uint16_t x, uint16_t i, uint8_t palette );
17
18 typedef struct CachedTexture
19 {
20 GLuint glName;
21 uint32_t address;
22 uint32_t crc;
23 float offsetS, offsetT;
24 uint32_t maskS, maskT;
25 uint32_t clampS, clampT;
26 uint32_t mirrorS, mirrorT;
27 uint32_t line;
28 uint32_t size;
29 uint32_t format;
30 uint32_t tMem;
31 uint32_t palette;
32 uint32_t width, height; // N64 width and height
33 uint32_t clampWidth, clampHeight; // Size to clamp to
34 uint32_t realWidth, realHeight; // Actual texture size
35 float scaleS, scaleT; // Scale to map to 0.0-1.0
36 float shiftScaleS, shiftScaleT; // Scale to shift
37 uint32_t textureBytes;
38
39 struct CachedTexture *lower, *higher;
40 uint32_t lastDList;
41 uint8_t max_level;
42 uint8_t frameBufferTexture;
43 } CachedTexture;
44
45 #define TEXTURECACHE_MAX (8 * 1024 * 1024)
46 #define TEXTUREBUFFER_SIZE (512 * 1024)
47
48 typedef struct TextureCache
49 {
50 CachedTexture *current[2];
51 CachedTexture *bottom, *top;
52 CachedTexture *dummy;
53
54 uint32_t cachedBytes;
55 uint32_t numCached;
56 uint32_t hits, misses;
57 GLuint glNoiseNames[32];
58 } TextureCache;
59
60 extern TextureCache cache;
61
TextureCache_SizeToBPP(uint8_t size)62 static INLINE uint8_t TextureCache_SizeToBPP(uint8_t size)
63 {
64 switch (size)
65 {
66 case 0:
67 return 4;
68 case 1:
69 return 8;
70 case 2:
71 return 16;
72 default:
73 break;
74 }
75
76 return 32;
77 }
78
pow2(uint32_t dim)79 static INLINE uint32_t pow2( uint32_t dim )
80 {
81 uint32_t i = 1;
82
83 while (i < dim) i <<= 1;
84
85 return i;
86 }
87
powof(uint32_t dim)88 static INLINE uint32_t powof( uint32_t dim )
89 {
90 uint32_t num, i;
91 num = 1;
92 i = 0;
93
94 while (num < dim)
95 {
96 num <<= 1;
97 i++;
98 }
99
100 return i;
101 }
102
103 CachedTexture *TextureCache_AddTop();
104 void TextureCache_MoveToTop( CachedTexture *newtop );
105 void TextureCache_Remove( CachedTexture *texture );
106 void TextureCache_RemoveBottom();
107 void TextureCache_Init();
108 void TextureCache_Destroy();
109 void TextureCache_Update( uint32_t t );
110 void TextureCache_ActivateTexture( uint32_t t, CachedTexture *texture );
111 void TextureCache_ActivateNoise( uint32_t t );
112 void TextureCache_ActivateDummy( uint32_t t );
113 bool TextureCache_Verify();
114
115 #ifdef __cplusplus
116 }
117 #endif
118
119 #endif
120
121