Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

GlTextureStorage.cpp

00001 // Sh: A GPU metaprogramming language. 00002 // 00003 // Copyright (c) 2003 University of Waterloo Computer Graphics Laboratory 00004 // Project administrator: Michael D. McCool 00005 // Authors: Zheng Qin, Stefanus Du Toit, Kevin Moule, Tiberiu S. Popa, 00006 // Michael D. McCool 00007 // 00008 // This software is provided 'as-is', without any express or implied 00009 // warranty. In no event will the authors be held liable for any damages 00010 // arising from the use of this software. 00011 // 00012 // Permission is granted to anyone to use this software for any purpose, 00013 // including commercial applications, and to alter it and redistribute it 00014 // freely, subject to the following restrictions: 00015 // 00016 // 1. The origin of this software must not be misrepresented; you must 00017 // not claim that you wrote the original software. If you use this 00018 // software in a product, an acknowledgment in the product documentation 00019 // would be appreciated but is not required. 00020 // 00021 // 2. Altered source versions must be plainly marked as such, and must 00022 // not be misrepresented as being the original software. 00023 // 00024 // 3. This notice may not be removed or altered from any source 00025 // distribution. 00027 #include "GlTextureStorage.hpp" 00028 00029 namespace shgl { 00030 00031 using namespace SH; 00032 00033 GlTextureStorage::GlTextureStorage(int context, 00034 ShMemory* memory, GLenum target, 00035 GLenum format, GLint internalFormat, 00036 int width, int height, int depth, 00037 GlTextureNamePtr name) 00038 : ShStorage(memory), m_context(context), 00039 m_name(name), m_target(target), m_format(format), 00040 m_internalFormat(internalFormat), 00041 m_width(width), m_height(height), m_depth(depth) 00042 { 00043 m_name->addStorage(this); 00044 } 00045 00046 GlTextureStorage::~GlTextureStorage() 00047 { 00048 m_name->removeStorage(this); 00049 } 00050 00051 class HostGlTextureTransfer : public ShTransfer { 00052 HostGlTextureTransfer() 00053 : ShTransfer("host", "opengl:texture") 00054 { 00055 } 00056 00057 bool transfer(const ShStorage* from, ShStorage* to) 00058 { 00059 const ShHostStorage* host = dynamic_cast<const ShHostStorage*>(from); 00060 GlTextureStorage* texture = dynamic_cast<GlTextureStorage*>(to); 00061 00062 // Bind texture name for this scope. 00063 GlTextureName::Binding binding(texture->texName()); 00064 00065 switch(texture->target()) { 00066 case GL_TEXTURE_1D: 00067 SH_GL_CHECK_ERROR(glTexImage1D(texture->target(), 0, 00068 texture->internalFormat(), 00069 texture->width(), 0, texture->format(), GL_FLOAT, 00070 host->data())); 00071 break; 00072 case GL_TEXTURE_2D: 00073 case GL_TEXTURE_CUBE_MAP_POSITIVE_X: 00074 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: 00075 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: 00076 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: 00077 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: 00078 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: 00079 case GL_TEXTURE_RECTANGLE_NV: 00080 SH_GL_CHECK_ERROR(glTexImage2D(texture->target(), 0, 00081 texture->internalFormat(), 00082 texture->width(), texture->height(), 0, texture->format(), 00083 GL_FLOAT, host->data())); 00084 break; 00085 case GL_TEXTURE_3D: 00086 SH_GL_CHECK_ERROR(glTexImage3D(texture->target(), 0, 00087 texture->internalFormat(), 00088 texture->width(), texture->height(), 00089 texture->depth(), 0, texture->format(), 00090 GL_FLOAT, host->data())); 00091 break; 00092 default: 00093 SH_DEBUG_WARN("Texture target " << texture->target() << " not handled by GL backend"); 00094 break; 00095 } 00096 return true; 00097 } 00098 00099 int cost() 00100 { 00101 // Texture downloads are expensive! 00102 return 100; 00103 } 00104 00105 static HostGlTextureTransfer* instance; 00106 }; 00107 00108 HostGlTextureTransfer* HostGlTextureTransfer::instance = new HostGlTextureTransfer(); 00109 00110 }

Generated on Mon Oct 18 14:17:38 2004 for Sh by doxygen 1.3.7