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 
45 
46 
47 //=============================================================================
48 //
49 // CLASS Texture3DNode - IMPLEMENTATION
50 //
51 //=============================================================================
52 
53 //=============================================================================
54 
55 
56 #include "Texture3DNode.hh"
57 
58 //=============================================================================
59 
60 namespace ACG {
61 namespace SceneGraph {
62 
63 //=============================================================================
64 
65 
66 Texture3DNode::Texture3DNode( BaseNode * _parent,
67  const std::string & _name )
68  : BaseNode( _parent, _name ),
69  texture_( 0 ),
70  tex_mode_( GL_MODULATE ),
71  border_color_( 0, 0, 0, 0 ),
72  wrap_mode_( GL_CLAMP ),
73  filter_( GL_LINEAR )
74 {}
75 
76 
77 //----------------------------------------------------------------------------
78 
79 
80 Texture3DNode::~Texture3DNode()
81 {
82  if ( glIsTexture( texture_ ) )
83  glDeleteTextures( 1, &texture_ );
84 }
85 
86 
87 //----------------------------------------------------------------------------
88 
89 
90 void
91 Texture3DNode::enter( GLState & /*_state */, const DrawModes::DrawMode& /* _drawmode */ )
92 {
93  if ( glIsTexture( texture_ ) )
94  {
95  ACG::GLState::bindTexture( GL_TEXTURE_3D, texture_ );
96  glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, tex_mode_);
97  glTexParameterfv( GL_TEXTURE_3D, GL_TEXTURE_BORDER_COLOR, border_color_.data() );
98 
99  glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, wrap_mode_ );
100  glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, wrap_mode_ );
101  glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, wrap_mode_ );
102 
103  glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, filter_ );
104  glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, filter_ );
105 
106  }
107 }
108 
109 
110 //----------------------------------------------------------------------------
111 
112 
113 void
114 Texture3DNode::leave( GLState & /* _state */ , const DrawModes::DrawMode& /* _drawmode */ )
115 {
116  ACG::GLState::bindTexture( GL_TEXTURE_3D, 0 );
117 }
118 
119 
120 //----------------------------------------------------------------------------
121 
122 
123 void
124 Texture3DNode::set_texture( unsigned int _width,
125  unsigned int _height,
126  unsigned int _depth,
127  unsigned char * _data )
128 {
129  glTexImage3D( GL_PROXY_TEXTURE_3D, 0, GL_RGBA,
130  _width, _height, _depth, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL );
131 
132  GLint test_width;
133  glGetTexLevelParameteriv( GL_PROXY_TEXTURE_3D, 0,
134  GL_TEXTURE_WIDTH, & test_width );
135 
136  GLint test_height;
137  glGetTexLevelParameteriv( GL_PROXY_TEXTURE_3D, 0,
138  GL_TEXTURE_HEIGHT, & test_height );
139 
140  GLint test_depth;
141  glGetTexLevelParameteriv( GL_PROXY_TEXTURE_3D, 0,
142  GL_TEXTURE_DEPTH, & test_depth );
143 
144  if ( ! test_width || ! test_height || ! test_depth )
145  {
146  std::cerr << "Can't load texture.\n";
147  return;
148  }
149 
150  glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 );
151  glPixelStorei( GL_UNPACK_SKIP_ROWS, 0 );
152  glPixelStorei( GL_UNPACK_SKIP_PIXELS, 0 );
153  glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
154  glPixelStorei( GL_PACK_ROW_LENGTH, 0 );
155  glPixelStorei( GL_PACK_SKIP_ROWS, 0 );
156  glPixelStorei( GL_PACK_SKIP_PIXELS, 0 );
157  glPixelStorei( GL_PACK_ALIGNMENT, 1 );
158 
159 
160  if ( glIsTexture( texture_ ) )
161  glDeleteTextures( 1, & texture_ );
162 
163  glGenTextures( 1, & texture_ );
164  ACG::GLState::bindTexture( GL_TEXTURE_3D, texture_ );
165 
166  glTexImage3D( GL_TEXTURE_3D, 0, GL_RGBA,
167  _width, _height, _depth, 0, GL_RGBA, GL_UNSIGNED_BYTE, _data );
168 
169  ACG::GLState::bindTexture( GL_TEXTURE_3D, 0 );
170 
171 }
172 
173 
174 //=============================================================================
175 } // namespace SceneGraph
176 } // namespace ACG
177 //=============================================================================
Namespace providing different geometric functions concerning angles.
void leave(GLState &_state, const DrawModes::DrawMode &_drawmode)
restores original texture (or no-texture)
void enter(GLState &_state, const DrawModes::DrawMode &_drawmode)
set texture
static void bindTexture(GLenum _target, GLuint _buffer)
replaces glBindTexture, supports locking
static GLuint texture_
handle for the texture into which characters from qfont_ are painted in updateFont() ...
Definition: TextNode.hh:266