src/ResourceManager/TextureResource.cpp

Go to the documentation of this file.
00001 /* Crown and Cutlass
00002  * TextureResource Code
00003  */
00004 
00005 #include <string>
00006 #include "../Log.h"
00007 #include "../GLee.h"
00008 #include "../image.h"
00009 #include "IResource.h"
00010 #include "TextureResource.h"
00011 
00012 using namespace std;
00013 
00014 const string TextureResource::s_type = string("Texture");
00015 
00016 TextureResource::TextureResource(string name, string filename, GLuint tileMode, bool genMipMaps, bool tryCompress, bool tryAlpha): IResource(name) {
00017   m_filename = filename;
00018   m_texture = 0;
00019   m_tileMode = tileMode;
00020   m_genMipMaps = genMipMaps;
00021   m_tryCompress = tryCompress;
00022   m_tryAlpha = tryAlpha;
00023   m_loaded = false;
00024 
00025   Log::s_log->Message("TextureResource %s created (Key: %s)", m_filename.c_str(), GetKey().c_str());
00026 }
00027 
00028 TextureResource::~TextureResource() {
00029   if (m_loaded) {
00030     Log::s_log->Message("Warning: %s texture resource deleted before unload", m_filename.c_str());
00031     Unload();
00032   }
00033   Log::s_log->Message("TextureResource %s destroyed", m_filename.c_str());
00034 }
00035 
00036 string TextureResource::GetType() {
00037   return s_type;
00038 }
00039 
00040 void TextureResource::Load() {
00041   if (m_loaded) {
00042     Log::s_log->Message("Warning: Load called on already loaded texture");
00043     Unload();
00044   }
00045 
00046   m_loaded = BuildTexture(m_filename.c_str(), &m_texture, m_tileMode, m_genMipMaps, m_tryCompress, m_tryAlpha);
00047   if (m_loaded) {
00048     Log::s_log->Message("TextureResource %s loaded", m_filename.c_str());
00049   } else {
00050     Log::s_log->Message("Warning: Could not load TextureResource %s", m_filename.c_str());
00051   }
00052 }
00053 
00054 void TextureResource::Unload() {
00055   if (!m_loaded) {
00056     Log::s_log->Message("Warning: Unload called on unloaded texture");
00057     return;
00058   }
00059 
00060   glDeleteTextures(1, &m_texture);
00061   m_texture = 0;
00062   m_loaded = false;
00063   Log::s_log->Message("TextureResource %s unloaded", m_filename.c_str());
00064 }
00065 
00066 GLuint TextureResource::GetTexture() {
00067   return m_texture;
00068 }

Generated on Mon Jan 8 22:34:12 2007 for CrownandCutlass by  doxygen 1.4.7