GlTextureStorage.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
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
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
1.3.7