VR-Vantage 3.1 API Documentation
Home
Modules
Namespaces
Classes
Files
Libraries
Examples
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
sensorFx
include
RenderTexture.h
Go to the documentation of this file.
1
#ifndef RENDER_TEXTURE__H
2
#define RENDER_TEXTURE__H
3
#include "shared/pbuffer.h"
4
5
// simple wrapper to encapsulate a pbuffer using render-to-texture and its associated texture object
6
// v1.1 - updated to work with multiple draw buffers
7
8
class
RenderTexture
{
9
public
:
10
RenderTexture
(
char
*strMode,
int
iWidth
,
int
iHeight
,
GLenum
target
) :
m_target
(target)
11
{
12
m_pbuffer
=
new
PBuffer(strMode);
13
m_pbuffer
->Initialize(iWidth, iHeight,
false
,
true
);
14
15
for
(
int
i=0; i<
max_buffers
; i++) {
16
m_tex
[i] = 0;
17
}
18
};
19
20
~RenderTexture
()
21
{
22
delete
m_pbuffer
;
23
for
(
int
i=0; i<
max_buffers
; i++) {
24
if
(
m_tex
[i]) {
25
glDeleteTextures
(1, &
m_tex
[i]);
26
}
27
}
28
}
29
30
void
Activate
() {
m_pbuffer
->Activate(); }
31
void
Deactivate
() {
m_pbuffer
->Deactivate(); }
32
33
void
Bind
(
int
iBuffer
=
WGL_FRONT_LEFT_ARB
)
34
{
35
int
tex_no =
iBuffer
-
WGL_FRONT_LEFT_ARB
;
36
if
(
m_tex
[tex_no] == 0) {
37
// lazily allocate texture objects on demand
38
CreateTexture
(
m_tex
[tex_no]);
39
}
40
glBindTexture
(
m_target
,
m_tex
[tex_no]);
41
m_pbuffer
->Bind(
iBuffer
);
42
}
43
44
void
Release
(
int
iBuffer
=
WGL_FRONT_LEFT_ARB
) {
45
glBindTexture
(
m_target
,
m_tex
[
iBuffer
-
WGL_FRONT_LEFT_ARB
]);
46
m_pbuffer
->Release(
iBuffer
);
47
}
48
49
inline
int
GetWidth
() {
return
m_pbuffer
->GetWidth(); }
50
inline
int
GetHeight
() {
return
m_pbuffer
->GetHeight(); }
51
52
private
:
53
void
CreateTexture
(
GLuint
&tex)
54
{
55
glGenTextures
(1, &tex);
56
glBindTexture
(
m_target
, tex);
57
glTexParameteri
(
m_target
,
GL_TEXTURE_WRAP_S
,
GL_CLAMP_TO_EDGE
);
58
glTexParameteri
(
m_target
,
GL_TEXTURE_WRAP_T
,
GL_CLAMP_TO_EDGE
);
59
glTexParameteri
(
m_target
,
GL_TEXTURE_MAG_FILTER
,
GL_NEAREST
);
60
glTexParameteri
(
m_target
,
GL_TEXTURE_MIN_FILTER
,
GL_NEAREST
);
61
}
62
63
const
static
int
max_buffers
= 14;
// WGL_FRONT_LEFT_ARB - WGL_AUX9_ARB
64
PBuffer *
m_pbuffer
;
65
GLuint
m_tex
[
max_buffers
];
// texture for each buffer
66
GLenum
m_target
;
67
};
68
#endif
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (
www.mak.com
)