00001 // Sh: A GPU metaprogramming language. 00002 // 00003 // Copyright 2003-2005 Serious Hack Inc. 00004 // 00005 // This software is provided 'as-is', without any express or implied 00006 // warranty. In no event will the authors be held liable for any damages 00007 // arising from the use of this software. 00008 // 00009 // Permission is granted to anyone to use this software for any purpose, 00010 // including commercial applications, and to alter it and redistribute it 00011 // freely, subject to the following restrictions: 00012 // 00013 // 1. The origin of this software must not be misrepresented; you must 00014 // not claim that you wrote the original software. If you use this 00015 // software in a product, an acknowledgment in the product documentation 00016 // would be appreciated but is not required. 00017 // 00018 // 2. Altered source versions must be plainly marked as such, and must 00019 // not be misrepresented as being the original software. 00020 // 00021 // 3. This notice may not be removed or altered from any source 00022 // distribution. 00024 #ifndef SH_GLTEXTURENAME_HPP 00025 #define SH_GLTEXTURENAME_HPP 00026 00027 #include "GlBackend.hpp" 00028 #include "ShMemory.hpp" 00029 00030 00031 namespace shgl { 00032 00033 class GlTextureName : public SH::ShRefCountable { 00034 public: 00035 GlTextureName(GLenum target); 00036 // Create an unmanaged texture name, i.e. one that is not allocated 00037 // and destroyed by this object 00038 GlTextureName(GLenum target, GLuint name); 00039 00040 ~GlTextureName(); 00041 00042 GLuint value() const { return m_name; } 00043 GLenum target() const { return m_target; } 00044 const SH::ShTextureTraits& params() const { return m_params; } 00045 void params(const SH::ShTextureTraits& params); 00046 00047 void addStorage(SH::ShStorage* storage); 00048 void removeStorage(SH::ShStorage* storage); 00049 00050 typedef std::list<SH::ShStorage*> StorageList; 00051 StorageList::const_iterator beginStorages() const { return m_storages.begin(); } 00052 StorageList::const_iterator endStorages() const { return m_storages.end(); } 00053 00054 typedef std::list<GlTextureName*> NameList; 00055 static NameList::const_iterator beginNames() { return m_names->begin(); } 00056 static NameList::const_iterator endNames() { return m_names->end(); } 00057 00058 // Utility class to bind texture temporarily 00059 struct Binding { 00060 Binding(const SH::ShPointer<const GlTextureName>& name); 00061 ~Binding(); 00062 00063 GLenum target; 00064 GLint last; 00065 }; 00066 00067 private: 00068 GLenum m_target; 00069 GLuint m_name; 00070 StorageList m_storages; 00071 static NameList* m_names; 00072 SH::ShTextureTraits m_params; 00073 00074 bool m_managed; // True if we generated our own name 00075 }; 00076 00077 typedef SH::ShPointer<GlTextureName> GlTextureNamePtr; 00078 00079 } 00080 00081 #endif
1.4.3-20050530