2011-10-25 05:03:10 +00:00
|
|
|
//
|
|
|
|
|
// KRTextureManager.h
|
2012-03-15 20:09:01 +00:00
|
|
|
// KREngine
|
2011-10-25 05:03:10 +00:00
|
|
|
//
|
2012-03-15 20:09:01 +00:00
|
|
|
// Copyright 2012 Kearwood Gilbert. All rights reserved.
|
2011-10-25 06:16:47 +00:00
|
|
|
//
|
|
|
|
|
// Redistribution and use in source and binary forms, with or without modification, are
|
|
|
|
|
// permitted provided that the following conditions are met:
|
|
|
|
|
//
|
|
|
|
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
|
|
|
|
// conditions and the following disclaimer.
|
|
|
|
|
//
|
|
|
|
|
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
|
|
|
|
// of conditions and the following disclaimer in the documentation and/or other materials
|
|
|
|
|
// provided with the distribution.
|
|
|
|
|
//
|
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
|
|
|
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
|
|
|
|
|
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
|
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
|
|
|
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
|
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
|
|
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
//
|
|
|
|
|
// The views and conclusions contained in the software and documentation are those of the
|
|
|
|
|
// authors and should not be interpreted as representing official policies, either expressed
|
|
|
|
|
// or implied, of Kearwood Gilbert.
|
2011-10-25 05:03:10 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#ifndef KRTEXTUREMANAGER_H
|
|
|
|
|
#define KRTEXTUREMANAGER_H
|
|
|
|
|
|
2013-01-11 03:21:19 +00:00
|
|
|
#include "KREngine-common.h"
|
|
|
|
|
|
2011-10-25 05:03:10 +00:00
|
|
|
#include "KRTexture.h"
|
2012-08-17 01:04:49 +00:00
|
|
|
#include "KRContextObject.h"
|
2012-10-05 21:22:47 +00:00
|
|
|
#include "KREngine-common.h"
|
|
|
|
|
#include "KRDataBlock.h"
|
2012-10-19 23:17:43 +00:00
|
|
|
#include "KRContext.h"
|
2013-11-02 01:08:51 -07:00
|
|
|
#include "KRTextureStreamer.h"
|
2011-10-25 05:03:10 +00:00
|
|
|
|
2012-08-17 01:04:49 +00:00
|
|
|
class KRTextureManager : public KRContextObject {
|
2011-10-25 05:03:10 +00:00
|
|
|
public:
|
2012-08-17 01:04:49 +00:00
|
|
|
KRTextureManager(KRContext &context);
|
|
|
|
|
virtual ~KRTextureManager();
|
2011-10-25 05:03:10 +00:00
|
|
|
|
2013-11-30 02:01:02 -08:00
|
|
|
void primeTexture(KRTexture *pTexture);
|
2012-11-17 00:15:52 +00:00
|
|
|
void selectTexture(int iTextureUnit, KRTexture *pTexture);
|
2012-09-11 03:06:35 +00:00
|
|
|
|
2012-10-25 03:15:28 +00:00
|
|
|
KRTexture *loadTexture(const char *szName, const char *szExtension, KRDataBlock *data);
|
2012-10-06 01:43:11 +00:00
|
|
|
KRTexture *getTextureCube(const char *szName);
|
2013-04-24 12:48:55 -07:00
|
|
|
KRTexture *getTexture(const std::string &name);
|
2011-10-25 05:03:10 +00:00
|
|
|
|
2012-11-17 00:15:52 +00:00
|
|
|
long getMemUsed();
|
2013-03-21 17:32:26 -07:00
|
|
|
long getMemActive();
|
2012-11-17 00:15:52 +00:00
|
|
|
|
|
|
|
|
long getMemoryTransferedThisFrame();
|
|
|
|
|
void addMemoryTransferredThisFrame(long memoryTransferred);
|
2012-09-26 20:07:48 +00:00
|
|
|
|
2012-11-17 00:15:52 +00:00
|
|
|
void memoryChanged(long memoryDelta);
|
|
|
|
|
|
2012-12-07 01:49:17 +00:00
|
|
|
void startFrame(float deltaTime);
|
|
|
|
|
void endFrame(float deltaTime);
|
2012-09-11 04:32:04 +00:00
|
|
|
|
2013-04-25 17:23:36 -07:00
|
|
|
unordered_map<std::string, KRTexture *> &getTextures();
|
2012-12-20 01:23:57 +00:00
|
|
|
|
2014-01-23 21:40:29 -08:00
|
|
|
void compress(bool premultiply_alpha = false);
|
2012-12-20 01:23:57 +00:00
|
|
|
|
2013-03-21 13:21:04 -07:00
|
|
|
std::set<KRTexture *> &getActiveTextures();
|
2013-03-21 17:32:26 -07:00
|
|
|
std::set<KRTexture *> &getPoolTextures();
|
2013-03-21 13:21:04 -07:00
|
|
|
|
2013-04-24 15:51:57 -07:00
|
|
|
void _setActiveTexture(int i);
|
|
|
|
|
void _setWrapModeS(GLuint i, GLuint wrap_mode);
|
|
|
|
|
void _setWrapModeT(GLuint i, GLuint wrap_mode);
|
|
|
|
|
void _setMaxAnisotropy(int i, float max_anisotropy);
|
|
|
|
|
|
|
|
|
|
void _clearGLState();
|
2013-05-02 11:10:56 -07:00
|
|
|
void setMaxAnisotropy(float max_anisotropy);
|
2013-04-24 15:51:57 -07:00
|
|
|
|
2013-11-13 23:52:17 -08:00
|
|
|
void doStreaming();
|
|
|
|
|
|
2011-10-25 05:03:10 +00:00
|
|
|
private:
|
2013-04-24 15:51:57 -07:00
|
|
|
int m_iActiveTexture;
|
|
|
|
|
|
2012-11-17 00:15:52 +00:00
|
|
|
long m_memoryTransferredThisFrame;
|
2012-09-26 20:07:48 +00:00
|
|
|
|
2013-04-25 17:23:36 -07:00
|
|
|
unordered_map<std::string, KRTexture *> m_textures;
|
2012-09-11 03:06:35 +00:00
|
|
|
|
2012-09-13 20:09:19 +00:00
|
|
|
KRTexture *m_boundTextures[KRENGINE_MAX_TEXTURE_UNITS];
|
2013-04-24 15:51:57 -07:00
|
|
|
GLuint m_wrapModeS[KRENGINE_MAX_TEXTURE_UNITS];
|
|
|
|
|
GLuint m_wrapModeT[KRENGINE_MAX_TEXTURE_UNITS];
|
|
|
|
|
float m_maxAnisotropy[KRENGINE_MAX_TEXTURE_UNITS];
|
2013-11-13 23:52:17 -08:00
|
|
|
|
|
|
|
|
|
2012-09-13 20:09:19 +00:00
|
|
|
std::set<KRTexture *> m_activeTextures;
|
|
|
|
|
std::set<KRTexture *> m_poolTextures;
|
2012-09-11 04:32:04 +00:00
|
|
|
|
2013-11-13 23:52:17 -08:00
|
|
|
std::set<KRTexture *> m_activeTextures_streamer;
|
|
|
|
|
std::set<KRTexture *> m_poolTextures_streamer;
|
|
|
|
|
std::set<KRTexture *> m_activeTextures_streamer_copy;
|
|
|
|
|
std::set<KRTexture *> m_poolTextures_streamer_copy;
|
|
|
|
|
|
2013-11-16 02:34:18 -08:00
|
|
|
std::atomic<long> m_textureMemUsed;
|
2012-09-26 20:07:48 +00:00
|
|
|
|
2012-11-17 00:15:52 +00:00
|
|
|
void rotateBuffers();
|
|
|
|
|
void balanceTextureMemory();
|
2013-11-02 01:08:51 -07:00
|
|
|
|
|
|
|
|
KRTextureStreamer m_streamer;
|
2013-11-13 23:52:17 -08:00
|
|
|
|
|
|
|
|
std::mutex m_streamerFenceMutex;
|
2011-10-25 05:03:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|