1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2009
4 // This file is part of Scorched3D.
6 // Scorched3D is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // Scorched3D is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with Scorched3D; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ////////////////////////////////////////////////////////////////////////////////
21 #include <common/Defines.h>
22 #include <GLEXT/GLState.h>
23 #include <GLEXT/GLTextureCubeMap.h>
26 GLTextureCubeMap::GLTextureCubeMap()
28 memset(cubeTexNum_
, 0, sizeof(GLuint
) * 6);
31 GLTextureCubeMap::~GLTextureCubeMap()
35 glDeleteTextures(6, cubeTexNum_
);
36 memset(cubeTexNum_
, 0, sizeof(GLuint
) * 6);
40 bool GLTextureCubeMap::textureValid()
42 return (glIsTexture(cubeTexNum_
[0]) == GL_TRUE
);
45 void GLTextureCubeMap::draw(bool force
)
47 if ((this != lastBind_
) || force
)
53 bool GLTextureCubeMap::create(Image
&bitmap
,
57 (bitmap
.getComponents()==1)?GL_LUMINANCE
:
58 ((bitmap
.getComponents() == 3)?GL_RGB
:GL_RGBA
);
60 bool success
= create(bitmap
.getBits(),
63 bitmap
.getComponents(),
64 bitmap
.getAlignment(),
71 bool GLTextureCubeMap::create(const void *data
,
84 glGenTextures(6, cubeTexNum_
);
87 // Generate a texture GL_TEXTURE_CUBE_MAP_EXT and bind it
88 glBindTexture(GL_TEXTURE_CUBE_MAP_EXT
, cubeTexNum_
[0]);
90 success
= createTexture(data
, width
, height
, components
, alignment
, format
, mipMap
);
96 bool GLTextureCubeMap::createTexture(const void * data
,
104 glPixelStorei(GL_UNPACK_ALIGNMENT
, alignment
);
105 glPixelStorei(GL_UNPACK_ROW_LENGTH
, 0);
106 glPixelStorei(GL_UNPACK_SKIP_ROWS
, 0);
107 glPixelStorei(GL_UNPACK_SKIP_PIXELS
, 0);
108 glTexEnvf(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_MODULATE
);
110 GLenum texDefines
[] = {
111 GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT
,
112 GL_TEXTURE_CUBE_MAP_NEGATIVE_X_EXT
,
113 GL_TEXTURE_CUBE_MAP_POSITIVE_Y_EXT
,
114 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT
,
115 GL_TEXTURE_CUBE_MAP_POSITIVE_Z_EXT
,
116 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT
};
118 // Load all six cube maps
119 for (int i
=0; i
<6; i
++)
124 // Texture parameters
125 glTexParameterf(GL_TEXTURE_CUBE_MAP_EXT
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
126 glTexParameterf(GL_TEXTURE_CUBE_MAP_EXT
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
127 glTexParameterf(GL_TEXTURE_CUBE_MAP_EXT
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
128 glTexParameterf(GL_TEXTURE_CUBE_MAP_EXT
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR_MIPMAP_LINEAR
);
130 gluBuild2DMipmaps(texDefines
[i
], components
, width
,
131 height
, format
, GL_UNSIGNED_BYTE
, data
);
135 // Texture parameters
136 glTexParameterf(GL_TEXTURE_CUBE_MAP_EXT
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
137 glTexParameterf(GL_TEXTURE_CUBE_MAP_EXT
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
138 glTexParameterf(GL_TEXTURE_CUBE_MAP_EXT
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
139 glTexParameterf(GL_TEXTURE_CUBE_MAP_EXT
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
141 glTexImage2D(texDefines
[i
], 0, components
, width
,
142 height
, 0, format
, GL_UNSIGNED_BYTE
, data
);