Coin  4.0.3
Coin3D core library
Loading...
Searching...
No Matches
SoGLImage.h
1#ifndef COIN_SOGLIMAGE_H
2#define COIN_SOGLIMAGE_H
3
4/**************************************************************************\
5 * Copyright (c) Kongsberg Oil & Gas Technologies AS
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
11 *
12 * Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 *
15 * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * Neither the name of the copyright holder nor the names of its
20 * contributors may be used to endorse or promote products derived from
21 * this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34\**************************************************************************/
35
36// WARNING: This is work in progress. Do not expect this class to have
37// a stable interface over a long period of time. It is installed
38// because we need it in an internal project.
39
40// FIXME: make sure we do a design review for this class for Coin v3.0
41// pederb, 2001-11-28
42
43#include <Inventor/SbBasic.h>
44#include <Inventor/SbVec2s.h>
45#include <Inventor/SbVec3s.h>
46#include <Inventor/SoType.h>
47#include <cstddef>
48
49class SoGLDisplayList;
50class SoState;
51class SbImage;
52
54public:
55
56 SoGLImage();
57 virtual void unref(SoState * state = NULL);
58
59 static SoType getClassTypeId(void);
60 virtual SoType getTypeId(void) const ;
61 virtual SbBool isOfType(SoType type) const;
62
63 enum Wrap {
64 REPEAT = 0,
65 CLAMP,
66 CLAMP_TO_EDGE,
67 CLAMP_TO_BORDER
68 };
69
71 IMAGE = 0,
72 SUBIMAGE,
73 MIPMAP
74 };
75
76 typedef SbBool SoGLImageResizeCB(SoState * state,
77 const SbVec3s &newsize,
78 unsigned char * destbuffer,
80 void * closure,
81 class SoGLImage * image);
82
83 void setGLDisplayList(SoGLDisplayList * dl,
84 SoState * state,
85 const Wrap wraps = REPEAT,
86 const Wrap wrapt = REPEAT,
87 const float quality = 0.5f);
88
89 void setPBuffer(SoState * state,
90 void * context,
91 const Wrap wraps = REPEAT,
92 const Wrap wrapt = REPEAT,
93 const float quality = 0.5f);
94
95 void setData(const unsigned char * bytes,
96 const SbVec2s & size,
97 const int numcomponents,
98 const Wrap wraps = REPEAT,
99 const Wrap wrapt = REPEAT,
100 const float quality = 0.5f,
101 const int border = 0,
103
104 void setData(const unsigned char * bytes,
105 const SbVec3s & size,
106 const int numcomponents,
107 const Wrap wraps = REPEAT,
108 const Wrap wrapt = REPEAT,
109 const Wrap wrapr = REPEAT,
110 const float quality = 0.5f,
111 const int border = 0,
113
114 virtual void setData(const SbImage * image,
115 const Wrap wraps = REPEAT,
116 const Wrap wrapt = REPEAT,
117 const float quality = 0.5f,
118 const int border = 0,
120
121 virtual void setData(const SbImage * image,
122 const Wrap wraps,
123 const Wrap wrapt,
124 const Wrap wrapr,
125 const float quality = 0.5f,
126 const int border = 0,
128
129 // these flags can be used to set texture properties.
130 enum Flags {
131 // mipmap, scaling and filtering settings
132 SCALE_DOWN = 0x0001,
133 NO_MIPMAP = 0x0002,
134 LINEAR_MAG_FILTER = 0x0004,
135 LINEAR_MIN_FILTER = 0x0008,
136 LINEAR_MIPMAP_FILTER = 0x0010,
137
138 // use if you know your image properties.
139 FORCE_TRANSPARENCY_TRUE = 0x0020,
140 FORCE_TRANSPARENCY_FALSE = 0x0040,
141 FORCE_ALPHA_TEST_TRUE = 0x0080,
142 FORCE_ALPHA_TEST_FALSE = 0x0100,
143
144 INVINCIBLE = 0x0200, // never die of old age
145
146 // use GL_NV_texture_rectangle or GL_EXT_texture_rectangle
147 RECTANGLE = 0x0400,
148
149 // Compress texture if available from OpenGL
150 COMPRESSED = 0x0800,
151
152 // use quality value to decide mipmap, filtering and scaling. This
153 // is the default.
154 USE_QUALITY_VALUE = 0X8000
155 };
156
157 void setFlags(const uint32_t flags);
158 uint32_t getFlags(void) const;
159
160 const SbImage * getImage(void) const;
161
162 virtual SoGLDisplayList * getGLDisplayList(SoState * state);
163 SbBool hasTransparency(void) const;
164 SbBool useAlphaTest(void) const;
165 Wrap getWrapS(void) const;
166 Wrap getWrapT(void) const;
167 Wrap getWrapR(void) const;
168
169 float getQuality(void) const;
170 uint32_t getGLImageId(void) const;
171
172protected:
173
174 void incAge(void) const;
175 void resetAge(void) const;
176 virtual void unrefOldDL(SoState * state, const uint32_t maxage);
177 virtual ~SoGLImage();
178
179private:
180
181 class SoGLImageP * pimpl;
182 friend class SoGLImageP;
183 static void cleanupClass(void);
184
185public:
186 // internal methods for texture resource management
187 static void beginFrame(SoState * state);
188 static void tagImage(SoState * state, SoGLImage * image);
189 static void endFrame(SoState * state);
190 static void setDisplayListMaxAge(const uint32_t maxage);
191 static void freeAllImages(SoState * state = NULL);
192
193 void setEndFrameCallback(void (*cb)(void *), void * closure);
194 int getNumFramesSinceUsed(void) const;
195
196public:
197 static void initClass(void);
198 static void setResizeCallback(SoGLImageResizeCB * f, void * closure);
199
200private:
201 static void registerImage(SoGLImage * image);
202 static void unregisterImage(SoGLImage * image);
203};
204
205#endif // !COIN_SOGLIMAGE_H
The SbImage class is an abstract data type for 2D and 3D images.
Definition SbImage.h:46
The SbList class is a template container class for lists.
Definition SbList.h:70
The SbVec2s class is a 2 dimensional vector with short integer coordinates.
Definition SbVec2s.h:51
The SbVec3s class is a 3 dimensional vector with short integer coordinates.
Definition SbVec3s.h:51
The SoGLDisplayList class stores and manages OpenGL display lists.
Definition SoGLDisplayList.h:43
The SoGLImage class is used to handle OpenGL 2D/3D textures.
Definition SoGLImage.h:53
ResizeReason
Definition SoGLImage.h:70
Flags
Definition SoGLImage.h:130
SbBool SoGLImageResizeCB(SoState *state, const SbVec3s &newsize, unsigned char *destbuffer, ResizeReason reason, void *closure, class SoGLImage *image)
Definition SoGLImage.h:76
Wrap
Definition SoGLImage.h:63
The SoState class manages the Coin scene graph traversal state data.
Definition SoState.h:44
The SoType class is the basis for the runtime type system in Coin.
Definition SoType.h:59