blob: 3d267efd6645b6cd5867c11fe8e0a071eb3def06 [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
2// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// Renderbuffer.cpp: the gl::Renderbuffer class and its derived classes
8// Colorbuffer, Depthbuffer and Stencilbuffer. Implements GL renderbuffer
9// objects and related functionality. [OpenGL ES 2.0.24] section 4.4.3 page 108.
10
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000011#include "libGLESv2/Renderbuffer.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000012
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000013#include "libGLESv2/main.h"
14#include "libGLESv2/utilities.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000015
16namespace gl
17{
18Renderbuffer::Renderbuffer()
19{
20 mWidth = 0;
21 mHeight = 0;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +000022 mFormat = GL_RGBA4; // default format, needs to be one of the expected renderbuffer formats
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000023}
24
25Renderbuffer::~Renderbuffer()
26{
27}
28
29bool Renderbuffer::isColorbuffer()
30{
31 return false;
32}
33
34bool Renderbuffer::isDepthbuffer()
35{
36 return false;
37}
38
39bool Renderbuffer::isStencilbuffer()
40{
41 return false;
42}
43
44IDirect3DSurface9 *Renderbuffer::getRenderTarget()
45{
46 return NULL;
47}
48
49IDirect3DSurface9 *Renderbuffer::getDepthStencil()
50{
51 return NULL;
52}
53
54int Renderbuffer::getWidth()
55{
56 return mWidth;
57}
58
59int Renderbuffer::getHeight()
60{
61 return mHeight;
62}
63
daniel@transgaming.com4901fca2010-04-20 18:52:41 +000064GLenum Renderbuffer::getFormat()
65{
66 return mFormat;
67}
68
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000069Colorbuffer::Colorbuffer(IDirect3DSurface9 *renderTarget) : mRenderTarget(renderTarget)
70{
71 if (renderTarget)
72 {
73 renderTarget->AddRef();
74
75 D3DSURFACE_DESC description;
76 renderTarget->GetDesc(&description);
77
78 mWidth = description.Width;
79 mHeight = description.Height;
80 }
81}
82
daniel@transgaming.com70d312a2010-04-20 18:52:38 +000083Colorbuffer::Colorbuffer(int width, int height, GLenum format)
84{
85 IDirect3DDevice9 *device = getDevice();
86
87 mRenderTarget = NULL;
88 HRESULT result = device->CreateRenderTarget(width, height, es2dx::ConvertRenderbufferFormat(format),
89 D3DMULTISAMPLE_NONE, 0, FALSE, &mRenderTarget, NULL);
90
91 if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY)
92 {
93 error(GL_OUT_OF_MEMORY);
94
95 return;
96 }
97
98 ASSERT(SUCCEEDED(result));
99
100 if (mRenderTarget)
101 {
102 mWidth = width;
103 mHeight = height;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +0000104 mFormat = format;
daniel@transgaming.com70d312a2010-04-20 18:52:38 +0000105 }
106 else
107 {
108 mWidth = 0;
109 mHeight = 0;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +0000110 mFormat = GL_RGBA4;
daniel@transgaming.com70d312a2010-04-20 18:52:38 +0000111 }
112}
113
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000114Colorbuffer::~Colorbuffer()
115{
116 if (mRenderTarget)
117 {
118 mRenderTarget->Release();
119 }
120}
121
122bool Colorbuffer::isColorbuffer()
123{
124 return true;
125}
126
127GLuint Colorbuffer::getRedSize()
128{
129 if (mRenderTarget)
130 {
131 D3DSURFACE_DESC description;
132 mRenderTarget->GetDesc(&description);
133
134 return es2dx::GetRedSize(description.Format);
135 }
136
137 return 0;
138}
139
140GLuint Colorbuffer::getGreenSize()
141{
142 if (mRenderTarget)
143 {
144 D3DSURFACE_DESC description;
145 mRenderTarget->GetDesc(&description);
146
147 return es2dx::GetGreenSize(description.Format);
148 }
149
150 return 0;
151}
152
153GLuint Colorbuffer::getBlueSize()
154{
155 if (mRenderTarget)
156 {
157 D3DSURFACE_DESC description;
158 mRenderTarget->GetDesc(&description);
159
160 return es2dx::GetBlueSize(description.Format);
161 }
162
163 return 0;
164}
165
166GLuint Colorbuffer::getAlphaSize()
167{
168 if (mRenderTarget)
169 {
170 D3DSURFACE_DESC description;
171 mRenderTarget->GetDesc(&description);
172
173 return es2dx::GetAlphaSize(description.Format);
174 }
175
176 return 0;
177}
178
179IDirect3DSurface9 *Colorbuffer::getRenderTarget()
180{
181 return mRenderTarget;
182}
183
184Depthbuffer::Depthbuffer(IDirect3DSurface9 *depthStencil) : mDepthStencil(depthStencil)
185{
186 if (depthStencil)
187 {
188 depthStencil->AddRef();
189
190 D3DSURFACE_DESC description;
191 depthStencil->GetDesc(&description);
192
193 mWidth = description.Width;
194 mHeight = description.Height;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +0000195 mFormat = GL_DEPTH_COMPONENT16; // If the renderbuffer parameters are queried, the calling function
196 // will expect one of the valid renderbuffer formats for use in
197 // glRenderbufferStorage
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000198 }
199}
200
201Depthbuffer::Depthbuffer(int width, int height)
202{
203 IDirect3DDevice9 *device = getDevice();
204
205 mDepthStencil = NULL;
206 HRESULT result = device->CreateDepthStencilSurface(width, height, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, 0, FALSE, &mDepthStencil, 0);
207
208 if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY)
209 {
210 error(GL_OUT_OF_MEMORY);
211
212 return;
213 }
214
215 ASSERT(SUCCEEDED(result));
216
217 if (mDepthStencil)
218 {
219 mWidth = width;
220 mHeight = height;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +0000221 mFormat = GL_DEPTH_COMPONENT16; // If the renderbuffer parameters are queried, the calling function
222 // will expect one of the valid renderbuffer formats for use in
223 // glRenderbufferStorage
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000224 }
225 else
226 {
227 mWidth = 0;
228 mHeight = 0;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +0000229 mFormat = GL_RGBA4; //default format
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000230 }
231}
232
233Depthbuffer::~Depthbuffer()
234{
235 if (mDepthStencil)
236 {
237 mDepthStencil->Release();
238 }
239}
240
241bool Depthbuffer::isDepthbuffer()
242{
243 return true;
244}
245
246GLuint Depthbuffer::getDepthSize()
247{
248 if (mDepthStencil)
249 {
250 D3DSURFACE_DESC description;
251 mDepthStencil->GetDesc(&description);
252
daniel@transgaming.com7a2c2802010-03-16 06:23:33 +0000253 return es2dx::GetDepthSize(description.Format);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000254 }
255
256 return 0;
257}
258
259IDirect3DSurface9 *Depthbuffer::getDepthStencil()
260{
261 return mDepthStencil;
262}
263
264Stencilbuffer::Stencilbuffer(IDirect3DSurface9 *depthStencil) : mDepthStencil(depthStencil)
daniel@transgaming.com4a9d65c2010-03-08 21:30:56 +0000265{
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000266 if (depthStencil)
267 {
268 depthStencil->AddRef();
269
270 D3DSURFACE_DESC description;
271 depthStencil->GetDesc(&description);
272
273 mWidth = description.Width;
274 mHeight = description.Height;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +0000275 mFormat = GL_STENCIL_INDEX8; // If the renderbuffer parameters are queried, the calling function
276 // will expect one of the valid renderbuffer formats for use in
277 // glRenderbufferStorage
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000278 }
daniel@transgaming.com4a9d65c2010-03-08 21:30:56 +0000279}
280
281Stencilbuffer::Stencilbuffer(int width, int height)
282{
283 IDirect3DDevice9 *device = getDevice();
284
285 mDepthStencil = NULL;
286 HRESULT result = device->CreateDepthStencilSurface(width, height, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, 0, FALSE, &mDepthStencil, 0);
287
288 if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY)
289 {
290 error(GL_OUT_OF_MEMORY);
291
292 return;
293 }
294
295 ASSERT(SUCCEEDED(result));
296
297 if (mDepthStencil)
298 {
299 mWidth = width;
300 mHeight = height;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +0000301 mFormat = GL_STENCIL_INDEX8; // If the renderbuffer parameters are queried, the calling function
302 // will expect one of the valid renderbuffer formats for use in
303 // glRenderbufferStorage
daniel@transgaming.com4a9d65c2010-03-08 21:30:56 +0000304 }
305 else
306 {
307 mWidth = 0;
308 mHeight = 0;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +0000309 mFormat = GL_RGBA4; //default format
daniel@transgaming.com4a9d65c2010-03-08 21:30:56 +0000310 }
311}
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000312
313Stencilbuffer::~Stencilbuffer()
314{
315 if (mDepthStencil)
316 {
317 mDepthStencil->Release();
318 }
319}
320
321GLuint Stencilbuffer::getStencilSize()
322{
323 if (mDepthStencil)
324 {
325 D3DSURFACE_DESC description;
326 mDepthStencil->GetDesc(&description);
327
328 return es2dx::GetStencilSize(description.Format);
329 }
330
331 return 0;
332}
333
334bool Stencilbuffer::isStencilbuffer()
335{
336 return true;
337}
338
339IDirect3DSurface9 *Stencilbuffer::getDepthStencil()
340{
341 return mDepthStencil;
342}
343}