Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   Related Pages  

sglTexture2D.hpp

00001 /*****************************************************************************
00002  * SGL: A Scene Graph Library
00003  *
00004  * Copyright (C) 1997-2001  Scott McMillan   All Rights Reserved.
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Library General Public
00017  * License along with this library; if not, write to the Free
00018  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  *****************************************************************************
00020  *     File: sglTexture2D.hpp
00021  *  Created: 11 March 2000
00022  *  Summary: container for 2D image data used for texturing
00023  *****************************************************************************/
00024 
00025 #ifndef __SGL_TEXTURE_2D_HPP
00026 #define __SGL_TEXTURE_2D_HPP
00027 
00028 #include <sgl.h>
00029 #include <vector>
00030 #include <sglObject.hpp>
00031 #include <sglVector.hpp>
00032 #include <sglTexture.hpp>
00033 
00034 //============================================================================
00035 
00039 class SGL_DLL_API sglTexture2D : public sglTexture
00040 {
00041 public:
00043    sglTexture2D();
00045    virtual ~sglTexture2D();
00046 
00048    //   format = format of each texel in the image
00049    //   type   = data type of texel data
00050    //   num_s  = width of the image
00051    //   num_t  = height of the image
00052    //   border = true if the image has a one pixel border
00053    // Both num_s and num_t should have the form 2^m +2b, where m is a
00054    //   non-negative integer (which can be different for s and t) and
00055    //   b is zero or one (depending on border).  If num_s or num_t
00056    //   (minus the border) are not powers of two, or if the image is
00057    //   too large, the image will be automatically resized.
00058    // Returns false if the parameters are out of range.
00059    // Note: this will not free the memory from the previous image.
00060    // Note: this will clear the mipmap levels if not automatic.
00061    bool setImage(void *image, ExternalFormatEnum format, TypeEnum type,
00062                  unsigned int num_s, unsigned int num_t,
00063                  bool border = false);
00065    void getImage(void *&image, ExternalFormatEnum &format, TypeEnum &type,
00066                  unsigned int &num_s, unsigned int &num_t,
00067                  bool &border) const;
00068 
00073    bool setMipmapLevels(const vector<void *> &images);
00074 
00076    //   sub_image = the new texels
00077    //   level     = mipmap level of image
00078    //   offset_x  = texel offset in the original image
00079    //   offset_y  = texel offset in the original image
00080    //   width     = width of the replacement image
00081    //   height    = height of the replacement image
00082    // Returns false if the parameters are out of range.
00083    // Note: sub-textures once loaded are forgotten and will not
00084    //   be restored if the base image parameters are changed.
00085    bool subloadImage(void *sub_image,
00086                      GLint level,
00087                      GLint offset_x, GLint offset_y,
00088                      GLint width, GLint height);
00089 
00095    virtual bool replaceImage(void *new_image, GLint level = 0);
00096 
00098    inline void getSize(unsigned int &width, unsigned int &height) const
00099       {
00100          width  = m_width; height = m_height;
00101       }
00102 
00106    virtual unsigned int getIdealInternalSize() const;
00111    virtual unsigned int getLikelyInternalSize() const;
00112 
00114    void setWrapMode(WrapEnum s_repeat_flag, WrapEnum t_repeat_flag);
00116    void getWrapMode(WrapEnum &s_repeat_flag, WrapEnum &t_repeat_flag) const;
00117 
00123    virtual bool checkProxy();
00124 
00130    virtual void bind();
00131 
00133    // The replacement texels are taken from the framebuffer.
00134    //   level     = mipmap level of image
00135    //   offset_x  = texel offset in the original image
00136    //   offset_y  = texel offset in the original image
00137    //   win_x     = origin of the replacement image in the frame buffer
00138    //   win_y     = origin of the replacement image in the frame buffer
00139    //   width     = width of the replacement image
00140    //   height    = height of the replacement image
00141    // Returns false if the parameters are out of range.
00142    // Note: sub-textures once loaded are forgotten and will not
00143    //   be restored if the base image parameters are changed.
00144    // Must be called by a thread with a current rendering context.
00145    bool copyTexSubImage(GLint level,
00146                         GLint offset_x, GLint offset_y,
00147                         GLint win_x, GLint win_y,
00148                         GLint width, GLint height);
00149 
00155    virtual bool buildMipmaps(vector<void*> &mipmaps);
00156 
00172    static bool resizeImage(sglTexture::ExternalFormatEnum format,
00173                            sglTexture::TypeEnum type,
00174                            unsigned int old_s, unsigned int old_t,
00175                            bool border,
00176                            unsigned int new_s, unsigned int new_t,
00177                            void *old_image, void *&new_image);
00178 
00194    static bool halveImage(sglTexture::ExternalFormatEnum format,
00195                           sglTexture::TypeEnum type,
00196                           unsigned int &num_s, unsigned int &num_t,
00197                           bool border,
00198                           void *old_image, void *&new_image);
00199 
00200    // See sglObject::printInfo() for details.
00201    virtual void printInfo(ostream &ostrm, const char *indent_string) const;
00202 
00203 private:
00204    sglTexture2D(const sglTexture2D&);               // NOT IMPLEMENTED
00205    sglTexture2D& operator=(const sglTexture2D &);   // NOT IMPLEMENTED
00206 
00207    // helper function for get*InternalSize
00208    unsigned int getNumTexels() const;
00209 
00210    // used internally for sub tex loading
00211    struct SubloadImageStruct
00212    {
00213       SubloadImageStruct(void* sub_image,
00214                          GLint level,
00215                          GLint offset_x, GLint offset_y,
00216                          GLint width, GLint height)
00217             : m_sub_image(sub_image), m_level(level),
00218               m_offset_x(offset_x), m_offset_y(offset_y),
00219               m_width(width), m_height(height) {};
00220 
00221       void *m_sub_image;
00222       GLint m_level;
00223       GLint m_offset_x, m_offset_y;
00224       GLint m_width, m_height;
00225    };
00226 
00227 private:
00228    unsigned int m_width, m_height;
00229    GLint m_repeat_flag[2];
00230    GLint m_pow_s, m_pow_t;
00231 
00232    vector <SubloadImageStruct*> m_subload_list;
00233 };
00234 
00235 #endif

Generated at Mon Jul 1 18:00:06 2002 for SGL by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001