Arachnoid GLESv1.1 plugin. Compile and run (a bit glitchy and no frameskip) on the...
[mupen64plus-pandora.git] / source / mupen64plus-video-arachnoid / src / texture / TextureCache.h
1 /******************************************************************************
2  * Arachnoid Graphics Plugin for Mupen64Plus
3  * http://bitbucket.org/wahrhaft/mupen64plus-video-arachnoid/
4  *
5  * Copyright (C) 2007 Kristofer Karlsson, Rickard Niklasson
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20  *****************************************************************************/
21
22 #ifndef TEXTURE_CACHE_H_
23 #define TEXTURE_CACHE_H_
24
25 #include "CachedTexture.h"
26 #include "CRCCalculator2.h"
27 #include "ImageFormatSelector.h"
28 #include <list>
29
30 //Forward declarations
31 class Memory;
32 class RSP;
33 class RDP;
34
35 //*****************************************************************************
36 //* Texture Cache
37 //! Class used to activate textures and store used textures for reuse.
38 //! @details Nintendo64 has a texture cache of 4 KiB
39 //*****************************************************************************
40 class TextureCache
41 {
42 public:
43
44     //Constructor / Destructor
45     TextureCache();
46     ~TextureCache();
47
48     //Functions
49     bool initialize(RSP* rsp, RDP* rdp, Memory* memory, unsigned int textureBitDepth, unsigned int cacheSize=(32 * 1048576));
50     void update(unsigned int tile);
51     void dispose();
52
53     void setMipmap( int value ) { m_mipmap = value; } 
54
55     //Add and Remove
56     CachedTexture* addTop();
57     void removeBottom();
58     void remove( CachedTexture *texture );
59
60     //Move Texture to top
61     void moveToTop( CachedTexture *newtop );
62
63     //Get Current Texture
64     CachedTexture* getCurrentTexture(int index) { return m_currentTextures[index]; }
65     
66 private:
67
68     void _loadTexture(CachedTexture* texture);
69     void _calculateTextureSize(unsigned int tile, CachedTexture* out, unsigned int& maskWidth, unsigned int& maskHeight);
70     void _activateTexture( unsigned int t, CachedTexture *texture );
71     unsigned int _calculateCRC(unsigned int t, unsigned int width, unsigned int height);
72
73 private:
74 //public:
75
76     RSP*    m_rsp;                         //!< Pointer to Reality Signal Processor 
77     RDP*    m_rdp;                         //!< Pointer to Reality Drawing Processor 
78     Memory* m_memory;                      //!< Pointer to Memory manager (handles RDRAM, Texture Memory...)
79
80     ImageFormatSelector m_formatSelector;  //!< Image Format Selector used when decoding textures
81     CRCCalculator2      m_crcCalculator;   //!< Hash value calculator for textures
82
83     unsigned int m_maxBytes;              //!< Maximum number of bytes this cache have
84     unsigned int m_cachedBytes;           //!< Current number of bytes in cache
85     unsigned int m_bitDepth;              //!<
86     int m_mipmap;
87
88     //Cached textures
89     typedef std::list<CachedTexture*> TextureList;
90     TextureList m_cachedTextures;          //!< List of cached textures
91
92     //Pointers to current textures
93     CachedTexture* m_currentTextures[2];   //!< Two textures for multi-texturing.
94     
95 };
96
97 #endif