1 | #include ".\rendertexture.h"
|
---|
2 |
|
---|
3 |
|
---|
4 | RenderTexture::RenderTexture(void)
|
---|
5 | {
|
---|
6 | }
|
---|
7 |
|
---|
8 | RenderTexture::~RenderTexture(void)
|
---|
9 | {
|
---|
10 | }
|
---|
11 |
|
---|
12 | int RenderTexture::Initialize(int width, int height,const char *strMode, bool rect, bool linearfilter)
|
---|
13 | {
|
---|
14 | m_pBuffer=new PBuffer(strMode,false);
|
---|
15 | bool ret=m_pBuffer->Initialize(width,height,false,true);
|
---|
16 |
|
---|
17 | if(!ret)return 0;
|
---|
18 |
|
---|
19 | if(rect)m_textype=GL_TEXTURE_RECTANGLE_NV;
|
---|
20 | else m_textype=GL_TEXTURE_2D;
|
---|
21 |
|
---|
22 | glGenTextures(1, &m_pbufferColorTextureID);
|
---|
23 | glBindTexture(m_textype, m_pbufferColorTextureID);
|
---|
24 |
|
---|
25 | unsigned int filtermode;
|
---|
26 | if(linearfilter)
|
---|
27 | filtermode=GL_LINEAR;
|
---|
28 | else
|
---|
29 | filtermode=GL_NEAREST;
|
---|
30 |
|
---|
31 | glTexParameteri(m_textype, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
---|
32 | glTexParameteri(m_textype, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
---|
33 | glTexParameteri(m_textype, GL_TEXTURE_MAG_FILTER, filtermode);
|
---|
34 | glTexParameteri(m_textype, GL_TEXTURE_MIN_FILTER, filtermode);
|
---|
35 |
|
---|
36 | if(m_pBuffer->m_HasDepthTexture)
|
---|
37 | {
|
---|
38 | glGenTextures(1, &m_pbufferDepthTextureID);
|
---|
39 | glBindTexture(m_textype, m_pbufferDepthTextureID);
|
---|
40 |
|
---|
41 | glTexParameteri(m_textype, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
---|
42 | glTexParameteri(m_textype, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
---|
43 | glTexParameteri(m_textype, GL_TEXTURE_MAG_FILTER, filtermode);
|
---|
44 | glTexParameteri(m_textype, GL_TEXTURE_MIN_FILTER, filtermode);
|
---|
45 | }
|
---|
46 |
|
---|
47 | if(m_pBuffer->m_HasAuxBuffers)
|
---|
48 | {
|
---|
49 | glGenTextures(1, &m_pbufferAux1ID);
|
---|
50 | glBindTexture(m_textype, m_pbufferAux1ID);
|
---|
51 |
|
---|
52 | glTexParameteri(m_textype, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
---|
53 | glTexParameteri(m_textype, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
---|
54 | glTexParameteri(m_textype, GL_TEXTURE_MAG_FILTER, filtermode);
|
---|
55 | glTexParameteri(m_textype, GL_TEXTURE_MIN_FILTER, filtermode);
|
---|
56 |
|
---|
57 | glGenTextures(1, &m_pbufferAux2ID);
|
---|
58 | glBindTexture(m_textype, m_pbufferAux1ID);
|
---|
59 |
|
---|
60 | glTexParameteri(m_textype, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
---|
61 | glTexParameteri(m_textype, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
---|
62 | glTexParameteri(m_textype, GL_TEXTURE_MAG_FILTER, filtermode);
|
---|
63 | glTexParameteri(m_textype, GL_TEXTURE_MIN_FILTER, filtermode);
|
---|
64 |
|
---|
65 | glGenTextures(1, &m_pbufferAux3ID);
|
---|
66 | glBindTexture(m_textype, m_pbufferAux1ID);
|
---|
67 |
|
---|
68 | glTexParameteri(m_textype, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
---|
69 | glTexParameteri(m_textype, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
---|
70 | glTexParameteri(m_textype, GL_TEXTURE_MAG_FILTER, filtermode);
|
---|
71 | glTexParameteri(m_textype, GL_TEXTURE_MIN_FILTER, filtermode);
|
---|
72 |
|
---|
73 | glGenTextures(1, &m_pbufferAux4ID);
|
---|
74 | glBindTexture(m_textype, m_pbufferAux1ID);
|
---|
75 |
|
---|
76 | glTexParameteri(m_textype, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
---|
77 | glTexParameteri(m_textype, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
---|
78 | glTexParameteri(m_textype, GL_TEXTURE_MAG_FILTER, filtermode);
|
---|
79 | glTexParameteri(m_textype, GL_TEXTURE_MIN_FILTER, filtermode);
|
---|
80 |
|
---|
81 | }
|
---|
82 |
|
---|
83 | }
|
---|
84 |
|
---|
85 | int RenderTexture::EnableTarget(void)
|
---|
86 | {
|
---|
87 | m_pBuffer->Activate();
|
---|
88 |
|
---|
89 | return 1;
|
---|
90 | }
|
---|
91 |
|
---|
92 | int RenderTexture::DisableTarget(void)
|
---|
93 | {
|
---|
94 | m_pBuffer->Deactivate();
|
---|
95 |
|
---|
96 | return 1;
|
---|
97 | }
|
---|
98 |
|
---|
99 | GLuint RenderTexture::getColorTextureID(void)
|
---|
100 | {
|
---|
101 | return m_pbufferColorTextureID;
|
---|
102 | }
|
---|
103 |
|
---|
104 | GLuint RenderTexture::getDepthTextureID(void)
|
---|
105 | {
|
---|
106 | return m_pbufferDepthTextureID;
|
---|
107 | }
|
---|