-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCubeMapTexture.cpp
More file actions
109 lines (89 loc) · 2.32 KB
/
CubeMapTexture.cpp
File metadata and controls
109 lines (89 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#ifndef GLEW_STATIC
#define GLEW_STATIC
#endif
#include <gl/glew.h>
#include <gl/gl.h>
#include <cassert>
#include "CubeMapTexture.h"
void CubeMapTexture::bind( unsigned int unit )
{
glActiveTexture( GL_TEXTURE0 + unit );
glBindTexture( GL_TEXTURE_CUBE_MAP, getId() );
}
void CubeMapTexture::loadImage( TexturePart part, Image &image )
{
glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT );
glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
unsigned char depth = image.getDepth() / 8;
unsigned short format;
unsigned short components;
switch( depth )
{
case 1:
format = GL_LUMINANCE;
components = GL_LUMINANCE;
break;
case 3:
format = GL_BGR;
components = GL_RGB;
break;
case 4:
format = GL_BGRA;
components = GL_RGBA;
break;
default:
assert( false );
break;
}
glTexImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_X + part,
0,
components,
image.getWidth(),
image.getHeight(),
0,
format,
GL_UNSIGNED_BYTE,
image.getBuffer() );
}
void CubeMapTexture::loadImage( Image &image )
{
glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT );
glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
unsigned char depth = image.getDepth() / 8;
unsigned short format;
unsigned short components;
switch( depth )
{
case 1:
format = GL_LUMINANCE;
components = GL_LUMINANCE;
break;
case 3:
format = GL_BGR;
components = GL_RGB;
break;
case 4:
format = GL_BGRA;
components = GL_RGBA;
break;
default:
assert( false );
break;
}
for( unsigned int i = POS_X_PART; i <= NEG_Z_PART; i++ )
glTexImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
0,
components,
image.getWidth(),
image.getHeight(),
0,
format,
GL_UNSIGNED_BYTE,
image.getBuffer() );
}