-
Notifications
You must be signed in to change notification settings - Fork 20
/
GLTextures.h
122 lines (102 loc) · 4.67 KB
/
GLTextures.h
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
110
111
112
113
114
115
116
117
118
119
120
121
122
/***********************************************************************
GLTextures - Overloaded versions of the glTexImage... family of
functions for type-safe texture image handling and more flexible layout
of texture images in application memory.
Copyright (c) 1999-2006 Oliver Kreylos
This file is part of the 3D Data Visualization Library (3DVis).
The 3D Data Visualization Library is free software; you can redistribute
it and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The 3D Data Visualization Library is distributed in the hope that it
will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with the 3D Data Visualization Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA
***********************************************************************/
#ifndef GLTEXTURES_INCLUDED
#define GLTEXTURES_INCLUDED
#include <GL/gl.h>
/*******************************************
Overloaded versions of glTexImage functions:
*******************************************/
inline void glTexImage2D(GLenum target,GLint level,GLint internalFormat,GLsizei width,GLsizei height,GLint border,GLenum format,const GLubyte* pixels)
{
glTexImage2D(target,level,internalFormat,width,height,border,format,GL_UNSIGNED_BYTE,pixels);
}
inline void glTexImage2D(GLenum target,GLint level,GLint internalFormat,GLsizei width,GLsizei height,GLint border,GLenum format,const GLbyte* pixels)
{
glTexImage2D(target,level,internalFormat,width,height,border,format,GL_BYTE,pixels);
}
inline void glTexImage2D(GLenum target,GLint level,GLint internalFormat,GLsizei width,GLsizei height,GLint border,GLenum format,const GLushort* pixels)
{
glTexImage2D(target,level,internalFormat,width,height,border,format,GL_UNSIGNED_SHORT,pixels);
}
inline void glTexImage2D(GLenum target,GLint level,GLint internalFormat,GLsizei width,GLsizei height,GLint border,GLenum format,const GLshort* pixels)
{
glTexImage2D(target,level,internalFormat,width,height,border,format,GL_SHORT,pixels);
}
inline void glTexImage2D(GLenum target,GLint level,GLint internalFormat,GLsizei width,GLsizei height,GLint border,GLenum format,const GLuint* pixels)
{
glTexImage2D(target,level,internalFormat,width,height,border,format,GL_UNSIGNED_INT,pixels);
}
inline void glTexImage2D(GLenum target,GLint level,GLint internalFormat,GLsizei width,GLsizei height,GLint border,GLenum format,const GLint* pixels)
{
glTexImage2D(target,level,internalFormat,width,height,border,format,GL_INT,pixels);
}
inline void glTexImage2D(GLenum target,GLint level,GLint internalFormat,GLsizei width,GLsizei height,GLint border,GLenum format,const GLfloat* pixels)
{
glTexImage2D(target,level,internalFormat,width,height,border,format,GL_FLOAT,pixels);
}
/****************************************************************************
Version of glTexSubImage2D with more flexible in-memory texture image layout:
****************************************************************************/
template <class TexelType>
inline
void
glTexSubImage2D(
GLenum target,
GLint level,
GLint xoffset,
GLint yoffset,
GLsizei width,
GLsizei height,
GLint columnStride, // Distance between adjacent texels in the same row (==1 if rows are stored consecutively)
GLint rowStride, // Distance between adjacent texels in the same column (==width for compact images)
GLenum format,
GLenum type,
const TexelType* pixels)
{
/* Set the common pixel pipeline parameters: */
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glPixelStorei(GL_UNPACK_SKIP_PIXELS,0);
glPixelStorei(GL_UNPACK_SKIP_ROWS,0);
if(columnStride==1)
{
/* Upload the texture image directly: */
glPixelStorei(GL_UNPACK_ROW_LENGTH,rowStride);
glTexSubImage2D(target,level,xoffset,yoffset,width,height,format,type,pixels);
}
else
{
/* Copy the texture image to a contiguous buffer: */
TexelType* tempPixels=new TexelType[width*height];
TexelType* tempPixelPtr=tempPixels;
const TexelType* rowPtr=pixels;
for(int y=0;y<height;++y,rowPtr+=rowStride)
{
const TexelType* columnPtr=rowPtr;
for(int x=0;x<width;++x,++tempPixelPtr,columnPtr+=columnStride)
*tempPixelPtr=*columnPtr;
}
/* Upload the temporary texture image: */
glPixelStorei(GL_UNPACK_ROW_LENGTH,0);
glTexSubImage2D(target,level,xoffset,yoffset,width,height,format,type,tempPixels);
/* Delete the temporary texture image: */
delete[] tempPixels;
}
}
#endif