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

sglTexture1D.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: sglTexture1D.hpp
00021  *  Created: 11 March 2000
00022  *  Summary: container for 1D image data used for texturing
00023  *****************************************************************************/
00024 
00025 #ifndef __SGL_TEXTURE_1D_HPP
00026 #define __SGL_TEXTURE_1D_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 sglTexture1D : public sglTexture
00040 {
00041 public:
00043    sglTexture1D();
00045    virtual ~sglTexture1D();
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    //   border = true if the image has a one pixel border
00052    // The num_s parameter should have the form 2^m +2b, where m is a
00053    //   non-negative integer and b is zero or one (depending on border).
00054    //   If num_s (minus the border) is not a power of two, or if the
00055    //   image is too large, the image will be automatically resized.
00056    // Returns false if the parameters are out of range.
00057    // Note: this will not free the memory from the previous image.
00058    // Note: this will clear the mipmap levels if not automatic.
00059    bool setImage(void  *image, ExternalFormatEnum format, TypeEnum type,
00060                  unsigned int  num_s, bool border = false);
00062    void getImage(void *&image, ExternalFormatEnum &format, TypeEnum &type,
00063                  unsigned int &num_s, bool &border) const;
00064 
00069    bool setMipmapLevels(const vector<void *> &images);
00070 
00072    //   sub_image = the new texels
00073    //   level     = mipmap level of image
00074    //   offset_x  = texel offset in the original image
00075    //   width     = width of the replacement image
00076    // Returns false if the parameters are out of range.
00077    // Note: sub-textures once loaded are forgotten and will not
00078    //   be restored if the base image parameters are changed.
00079    bool subloadImage(void *sub_image,
00080                      GLint level,
00081                      GLint offset_x,
00082                      GLint width);
00083 
00089    virtual bool replaceImage(void *new_image, GLint level = 0);
00090 
00092    inline void getSize(unsigned int &width) const { width  = m_width; }
00093 
00097    virtual unsigned int getIdealInternalSize() const;
00102    virtual unsigned int getLikelyInternalSize() const;
00103 
00105    void setWrapMode(WrapEnum s_repeat_flag);
00107    void getWrapMode(WrapEnum &s_repeat_flag) const;
00108 
00114    virtual bool checkProxy();
00115 
00121    virtual void bind();
00122 
00124    // The replacement texels are taken from the framebuffer.
00125    //   level     = mipmap level of image
00126    //   offset_x  = texel offset in the original image
00127    //   win_x     = origin of the replacement image in the frame buffer
00128    //   win_y     = origin of the replacement image in the frame buffer
00129    //   width     = width of the replacement image
00130    // Returns false if the parameters are out of range.
00131    // Note: sub-textures once loaded are forgotten and will not
00132    //   be restored if the base image parameters are changed.
00133    // Must be called by a thread with a current rendering context.
00134    bool copyTexSubImage(GLint level,
00135                         GLint offset_x,
00136                         GLint win_x, GLint win_y,
00137                         GLint width);
00138 
00144    virtual bool buildMipmaps(vector<void*> &mipmaps);
00145 
00159    static bool resizeImage(sglTexture::ExternalFormatEnum format,
00160                            sglTexture::TypeEnum type,
00161                            unsigned int old_s,
00162                            bool border,
00163                            unsigned int new_s,
00164                            void *old_image, void *&new_image);
00165 
00179    static bool halveImage(sglTexture::ExternalFormatEnum format,
00180                           sglTexture::TypeEnum type,
00181                           unsigned int &num_s,
00182                           bool border,
00183                           void *old_image, void *&new_image);
00184 
00185    // See sglObject::printInfo() for details.
00186    virtual void printInfo(ostream &ostrm, const char *indent_string) const;
00187 
00188 private:
00189    sglTexture1D(const sglTexture1D&);               // NOT IMPLEMENTED
00190    sglTexture1D& operator=(const sglTexture1D &);   // NOT IMPLEMENTED
00191 
00192    // used internally for sub tex loading
00193    struct SubloadImageStruct
00194    {
00195       SubloadImageStruct(void* sub_image,
00196                          GLint level, GLint offset_x, GLint width)
00197             : m_sub_image(sub_image), m_level(level),
00198               m_offset_x(offset_x), m_width(width) {};
00199 
00200       void *m_sub_image;
00201       GLint m_level;
00202       GLint m_offset_x;
00203       GLint m_width;
00204    };
00205 
00206 private:
00207    unsigned int m_width;
00208    GLint m_repeat_flag;
00209    GLint m_pow_s;
00210 
00211    vector <SubloadImageStruct*> m_subload_list;
00212 };
00213 
00214 #endif

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