Developer Documentation
Texture3DNode.cc
1 /*===========================================================================*\
2  * *
3  * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40 \*===========================================================================*/
41 
42 /*===========================================================================*\
43  * *
44  * $Revision$ *
45  * $Author$ *
46  * $Date$ *
47  * *
48 \*===========================================================================*/
49 
50 
51 
52 
53 //=============================================================================
54 //
55 // CLASS Texture3DNode - IMPLEMENTATION
56 //
57 //=============================================================================
58 
59 //=============================================================================
60 
61 
62 #include "Texture3DNode.hh"
63 
64 //=============================================================================
65 
66 namespace ACG {
67 namespace SceneGraph {
68 
69 //=============================================================================
70 
71 
72 Texture3DNode::Texture3DNode( BaseNode * _parent,
73  const std::string & _name )
74  : BaseNode( _parent, _name ),
75  texture_( 0 ),
76  tex_mode_( GL_MODULATE ),
77  border_color_( 0, 0, 0, 0 ),
78  wrap_mode_( GL_CLAMP ),
79  filter_( GL_LINEAR )
80 {}
81 
82 
83 //----------------------------------------------------------------------------
84 
85 
86 Texture3DNode::~Texture3DNode()
87 {
88  if ( glIsTexture( texture_ ) )
89  glDeleteTextures( 1, &texture_ );
90 }
91 
92 
93 //----------------------------------------------------------------------------
94 
95 
96 void
97 Texture3DNode::enter( GLState & /*_state */, const DrawModes::DrawMode& /* _drawmode */ )
98 {
99  if ( glIsTexture( texture_ ) )
100  {
101  ACG::GLState::bindTexture( GL_TEXTURE_3D, texture_ );
102  glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, tex_mode_);
103  glTexParameterfv( GL_TEXTURE_3D, GL_TEXTURE_BORDER_COLOR, border_color_.data() );
104 
105  glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, wrap_mode_ );
106  glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, wrap_mode_ );
107  glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, wrap_mode_ );
108 
109  glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, filter_ );
110  glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, filter_ );
111 
112  }
113 }
114 
115 
116 //----------------------------------------------------------------------------
117 
118 
119 void
120 Texture3DNode::leave( GLState & /* _state */ , const DrawModes::DrawMode& /* _drawmode */ )
121 {
122  ACG::GLState::bindTexture( GL_TEXTURE_3D, 0 );
123 }
124 
125 
126 //----------------------------------------------------------------------------
127 
128 
129 void
130 Texture3DNode::set_texture( unsigned int _width,
131  unsigned int _height,
132  unsigned int _depth,
133  unsigned char * _data )
134 {
135  glTexImage3D( GL_PROXY_TEXTURE_3D, 0, GL_RGBA,
136  _width, _height, _depth, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL );
137 
138  GLint test_width;
139  glGetTexLevelParameteriv( GL_PROXY_TEXTURE_3D, 0,
140  GL_TEXTURE_WIDTH, & test_width );
141 
142  GLint test_height;
143  glGetTexLevelParameteriv( GL_PROXY_TEXTURE_3D, 0,
144  GL_TEXTURE_HEIGHT, & test_height );
145 
146  GLint test_depth;
147  glGetTexLevelParameteriv( GL_PROXY_TEXTURE_3D, 0,
148  GL_TEXTURE_DEPTH, & test_depth );
149 
150  if ( ! test_width || ! test_height || ! test_depth )
151  {
152  std::cerr << "Can't load texture.\n";
153  return;
154  }
155 
156  glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 );
157  glPixelStorei( GL_UNPACK_SKIP_ROWS, 0 );
158  glPixelStorei( GL_UNPACK_SKIP_PIXELS, 0 );
159  glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
160  glPixelStorei( GL_PACK_ROW_LENGTH, 0 );
161  glPixelStorei( GL_PACK_SKIP_ROWS, 0 );
162  glPixelStorei( GL_PACK_SKIP_PIXELS, 0 );
163  glPixelStorei( GL_PACK_ALIGNMENT, 1 );
164 
165 
166  if ( glIsTexture( texture_ ) )
167  glDeleteTextures( 1, & texture_ );
168 
169  glGenTextures( 1, & texture_ );
170  ACG::GLState::bindTexture( GL_TEXTURE_3D, texture_ );
171 
172  glTexImage3D( GL_TEXTURE_3D, 0, GL_RGBA,
173  _width, _height, _depth, 0, GL_RGBA, GL_UNSIGNED_BYTE, _data );
174 
175  ACG::GLState::bindTexture( GL_TEXTURE_3D, 0 );
176 
177 }
178 
179 
180 //=============================================================================
181 } // namespace SceneGraph
182 } // namespace ACG
183 //=============================================================================
static void bindTexture(GLenum _target, GLuint _buffer)
replaces glBindTexture, supports locking
void enter(GLState &_state, const DrawModes::DrawMode &_drawmode)
set texture
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
static GLuint texture_
handle for the texture into which characters from qfont_ are painted in updateFont() ...
Definition: TextNode.hh:273
void leave(GLState &_state, const DrawModes::DrawMode &_drawmode)
restores original texture (or no-texture)