1 /*
2  * NodeImageTexture.h
3  *
4  * Copyright (C) 1999 Stephen F. White
5  *
6  * Modified by Aaron Cram - Now uses DevIL to load textures
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program (see the file "COPYING" for details); if
20  * not, write to the Free Software Foundation, Inc., 675 Mass Ave,
21  * Cambridge, MA 02139, USA.
22  */
23 
24 #pragma once
25 
26 #include "Node.h"
27 #include "ProtoMacros.h"
28 #include "Proto.h"
29 #include "SFMFTypes.h"
30 #include "KambiTextureCommonFields.h"
31 
32 #ifdef HAVE_LIBDEVIL
33 # include <IL/il.h>
34 #endif
35 
36 class ProtoImageTexture : public WonderlandExportProto {
37 public:
38                     ProtoImageTexture(Scene *scene);
39     virtual Node   *create(Scene *scene);
40 
getType()41     virtual int     getType() const { return VRML_IMAGE_TEXTURE; }
getNodeClass()42     virtual int     getNodeClass() const
43                        { return TEXTURE_NODE | TEXTURE_2D_NODE | URL_NODE; }
44 
isDeclaredInRwd_h()45     virtual bool    isDeclaredInRwd_h() { return true; }
46 
47     FieldIndex url;
48     FieldIndex repeatS;
49     FieldIndex repeatT;
50     FieldIndex environment;
51     FieldIndex blendMode;
52     FieldIndex filterMode;
53     FieldIndex anisotropy;
54 #ifdef HAVE_TEXTUREIMAGE_MODE
55     FieldIndex mode;
56 #endif
57     FieldIndex textureProperties;
58     kambiTextureCommonFieldIndex()
59     kambiVrmlTextureCommonFieldIndex()
60     FieldIndex crossOrigin;
61     FieldIndex hideChildren;
62     FieldIndex origChannelCount;
63     FieldIndex scale;
64 };
65 
66 class NodeImageTexture : public Node {
67 public:
68                     NodeImageTexture(Scene *scene, Proto *proto);
69                     NodeImageTexture(const NodeImageTexture &node);
70     virtual        ~NodeImageTexture();
71 
getProfile(void)72     virtual int     getProfile(void) const { return PROFILE_INTERCHANGE; }
getX3dVersion(void)73     virtual int     getX3dVersion(void) const { return 0; }
copy()74     virtual Node   *copy() const { return new NodeImageTexture(*this); }
75     virtual void    setField(int field, FieldValue *value, int cf = -1);
76 
hasNumbers4kids(void)77     virtual bool    hasNumbers4kids(void) { return true; }
78 
79     virtual void    update();
80 
81     virtual void    load();
82     virtual void    unload();
83 
84     int             isLoaded();
85 
isInvalidChildNode(void)86     virtual bool    isInvalidChildNode(void) { return true; }
87 
88     virtual void    bind(GLuint textureId, GLuint textureName);
89     virtual void    bind();
90     virtual void    unbind();
91 
getWasScaleRequired(void)92     virtual bool    getWasScaleRequired(void) { return m_scaleRequired; }
getNumComponents(void)93     virtual int     getNumComponents(void) { return m_components; }
94 
isTransparent(void)95     virtual bool    isTransparent(void) { return m_isTransparent; }
96 
hasCoverFields(void)97     virtual bool    hasCoverFields(void) { return true; }
98 
textureGlColorMode(void)99     virtual int     textureGlColorMode(void) { return m_glColorMode; }
100 
101     Node           *getPixelTexture(void);
102 
103     fieldMacros(MFString, url,               ProtoImageTexture)
104     fieldMacros(SFBool,   repeatS,           ProtoImageTexture)
105     fieldMacros(SFBool,   repeatT,           ProtoImageTexture)
106     fieldMacros(SFBool,   environment,       ProtoImageTexture)
107     fieldMacros(SFInt32,  blendMode,         ProtoImageTexture)
108     fieldMacros(SFInt32,  filterMode,        ProtoImageTexture)
109     fieldMacros(SFInt32,  anisotropy,        ProtoImageTexture)
110 #ifdef HAVE_TEXTUREIMAGE_MODE
111     fieldMacros(SFInt32,  mode,              ProtoImageTexture)
112 #endif
113     fieldMacros(SFNode,   textureProperties, ProtoImageTexture);
114     kambiTextureCommonFieldMacros(ProtoImageTexture)
115     kambiVrmlTextureCommonFieldMacros(       ProtoImageTexture)
116     fieldMacros(SFString, crossOrigin,       ProtoImageTexture);
117     fieldMacros(SFBool,   hideChildren,      ProtoImageTexture);
118     fieldMacros(SFInt32,  origChannelCount,  ProtoImageTexture);
119     fieldMacros(SFBool,   scale,             ProtoImageTexture);
120 
121 #ifdef HAVE_LIBDEVIL
122     void            reportLoadError(char* filename, const char *error_msg);
123 #endif
124 
125 protected:
126     unsigned char  *m_image;
127     MyString        m_baseURL;
128     int             m_imageStatus;
129     int             m_textureWidth;
130     int             m_textureHeight;
131     int             m_components;
132     int             m_glColorMode;
133     GLuint          m_textureName;
134     bool            m_scaleRequired;
135     bool            m_isTransparent;
136     MyString        m_path;
137 
138 #ifdef HAVE_LIBDEVIL
139     ILuint          m_imageName;
140 #endif
141 };
142 
143