casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
GLPCTexture.h
Go to the documentation of this file.
00001 //# GLPCTexture.h:      Holds data for displaying images as textures.
00002 //# Copyright (C) 2001
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id$
00027 
00028 #ifndef TRIALDISPLAY_GLPCTEXTURE_H
00029 #define TRIALDISPLAY_GLPCTEXTURE_H
00030 
00031 #include <graphics/X11/X_enter.h>
00032 #include <GL/gl.h>
00033 #include <X11/Xlib.h>
00034 #include <X11/Intrinsic.h>
00035 #include <graphics/X11/X_exit.h>
00036 #include <casa/aips.h>
00037 #include <display/Display/GLPCDisplayList.h>
00038 
00039 namespace casa { //# NAMESPACE CASA - BEGIN
00040 
00041 // <summary>
00042 // Holds parameters for setting glTexParameteri variables.
00043 // </summary>
00044 // <visibility=local>
00045 // <synopsis>
00046 // Holds parameters for setting glTexParameteri variables. See the man
00047 // page for glTexParameteri for description. This class is not needed
00048 // unless the caller wishes to change the defaults for a textured image.
00049 // maxtexturesize is used to specify the maximum texture size used for
00050 // an image. The value used will be the smallest power of 2 that
00051 // is >= maxtexturesize. By default, the display hosts' maximum texture
00052 // size will be used. Again, this isn't normally changed.
00053 // GLPCTextureParams may be deleted after GLPCTexturedImage is created.
00054 class GLPCTextureParams {
00055   public:
00056         GLPCTextureParams();
00057         GLPCTextureParams(const GLPCTextureParams &);
00058         GLPCTextureParams(const GLPCTextureParams *);
00059         void copy(const GLPCTextureParams &p);
00060         ~GLPCTextureParams();
00061         // Set min/mag filters. If magFilter is 0, use min Filter.
00062         void filter(GLint minFilter, GLint magFilter=0);
00063         // Set wrap parameters. If wrapT is 0, use wrapS.
00064         void wrap(GLint wrapS, GLint wrapT=0);
00065 
00066         // Set value to use for max texture size. Value will be rounded
00067         // up to a power of 2 >= maxTextureSize.
00068         void maxTextureSize(GLint maxtexturesize);
00069         void format(GLenum fmt);
00070         
00071         // For glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, mode);
00072         void environMode(GLenum mode);
00073   public:
00074         // glTexParameteri(GL_TEXTURE_2D, x, y).
00075         GLint   min_filter_;    // GL_TEXTURE_MIN_FILTER
00076         GLint   mag_filter_;    // GL_TEXTURE_MAG_FILTER
00077         GLint   wrap_s_;        // GL_TEXTURE_WRAP_S
00078         GLint   wrap_t_;        // GL_TEXTURE_WRAP_T
00079 
00080         // Maximum texture size to use. Default is host's max texture size.
00081         GLuint  maxtexturesize_;
00082         GLenum  envmode_;       // GL_DECAL, GL_BLEND or GL_MODULATE.
00083         GLenum  format_;        // GL_RGB or GL_COLOR_INDEX.
00084   private:
00085         void init();
00086 };
00087 
00088 class GLPCTextureObject;
00089 
00090 // <prerequisite>
00091 // <li> <linkto class="GLPCDisplayListEntry">GLPCDisplayListEntry</linkto>
00092 // </prerequisite>
00093 // <synopsis>
00094 // GLPCTexturedImage is used to convert an image to texture objects for
00095 // display. The pixels array contains pixels stored as RGB triples.
00096 // This class is typically only used by
00097 // <linkto class="GLPixelCanvas">GLPixelCanvas</linkto>
00098 // If the image is larger than the maximum texture size, it will be broken
00099 // into pieces that fit.
00100 // </synopsis>
00101 //<thrown><li> AipsError </thrown>
00102 class GLPCTexturedImage : public GLPCDisplayListEntry {
00103   public:
00104         GLPCTexturedImage(GLsizei width, GLsizei height,
00105                           const GLushort *pixels,
00106                           const GLPCTextureParams* = NULL);
00107         ~GLPCTexturedImage();
00108         void draw();    // Draw image using current values.
00109         // Draw image and save values for later.
00110         void draw(GLfloat x, GLfloat y, GLfloat z=0.0,
00111                   GLfloat xscale=1.0, GLfloat yscale=1.0);
00112 
00113         void envmode(GLenum mode);
00114         GLenum envmode()const{return params_->envmode_;}
00115         GLPCTextureParams *params()const {return params_;}
00116   private:
00117         void createTextures(GLsizei dWidth, GLsizei dHeight);
00118         void storeImage(GLsizei dWidth, GLsizei dHeight,
00119                         const GLushort *pixels);
00120         int     ntx_, nty_;
00121         int     numTextures_;           // ntx_*nty_;
00122         GLPCTextureObject **textures_;  // numtexures entries.
00123         GLfloat x_, y_, z_;
00124         GLfloat xscale_, yscale_;
00125         GLsizei dWidth_, dHeight_;
00126         GLPCTextureParams *params_;
00127         GLint   maxTextureSize_;
00128 };
00129 
00130 
00131 } //# NAMESPACE CASA - END
00132 
00133 #endif