blob: 86796f024d82cfc0e82608590ac09f94cb9e4ac2 [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;
22}
23
24Renderbuffer::~Renderbuffer()
25{
26}
27
28bool Renderbuffer::isColorbuffer()
29{
30 return false;
31}
32
33bool Renderbuffer::isDepthbuffer()
34{
35 return false;
36}
37
38bool Renderbuffer::isStencilbuffer()
39{
40 return false;
41}
42
43IDirect3DSurface9 *Renderbuffer::getRenderTarget()
44{
45 return NULL;
46}
47
48IDirect3DSurface9 *Renderbuffer::getDepthStencil()
49{
50 return NULL;
51}
52
53int Renderbuffer::getWidth()
54{
55 return mWidth;
56}
57
58int Renderbuffer::getHeight()
59{
60 return mHeight;
61}
62
63Colorbuffer::Colorbuffer(IDirect3DSurface9 *renderTarget) : mRenderTarget(renderTarget)
64{
65 if (renderTarget)
66 {
67 renderTarget->AddRef();
68
69 D3DSURFACE_DESC description;
70 renderTarget->GetDesc(&description);
71
72 mWidth = description.Width;
73 mHeight = description.Height;
74 }
75}
76
daniel@transgaming.com70d312a2010-04-20 18:52:38 +000077Colorbuffer::Colorbuffer(int width, int height, GLenum format)
78{
79 IDirect3DDevice9 *device = getDevice();
80
81 mRenderTarget = NULL;
82 HRESULT result = device->CreateRenderTarget(width, height, es2dx::ConvertRenderbufferFormat(format),
83 D3DMULTISAMPLE_NONE, 0, FALSE, &mRenderTarget, NULL);
84
85 if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY)
86 {
87 error(GL_OUT_OF_MEMORY);
88
89 return;
90 }
91
92 ASSERT(SUCCEEDED(result));
93
94 if (mRenderTarget)
95 {
96 mWidth = width;
97 mHeight = height;
98 }
99 else
100 {
101 mWidth = 0;
102 mHeight = 0;
103 }
104}
105
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000106Colorbuffer::~Colorbuffer()
107{
108 if (mRenderTarget)
109 {
110 mRenderTarget->Release();
111 }
112}
113
114bool Colorbuffer::isColorbuffer()
115{
116 return true;
117}
118
119GLuint Colorbuffer::getRedSize()
120{
121 if (mRenderTarget)
122 {
123 D3DSURFACE_DESC description;
124 mRenderTarget->GetDesc(&description);
125
126 return es2dx::GetRedSize(description.Format);
127 }
128
129 return 0;
130}
131
132GLuint Colorbuffer::getGreenSize()
133{
134 if (mRenderTarget)
135 {
136 D3DSURFACE_DESC description;
137 mRenderTarget->GetDesc(&description);
138
139 return es2dx::GetGreenSize(description.Format);
140 }
141
142 return 0;
143}
144
145GLuint Colorbuffer::getBlueSize()
146{
147 if (mRenderTarget)
148 {
149 D3DSURFACE_DESC description;
150 mRenderTarget->GetDesc(&description);
151
152 return es2dx::GetBlueSize(description.Format);
153 }
154
155 return 0;
156}
157
158GLuint Colorbuffer::getAlphaSize()
159{
160 if (mRenderTarget)
161 {
162 D3DSURFACE_DESC description;
163 mRenderTarget->GetDesc(&description);
164
165 return es2dx::GetAlphaSize(description.Format);
166 }
167
168 return 0;
169}
170
171IDirect3DSurface9 *Colorbuffer::getRenderTarget()
172{
173 return mRenderTarget;
174}
175
176Depthbuffer::Depthbuffer(IDirect3DSurface9 *depthStencil) : mDepthStencil(depthStencil)
177{
178 if (depthStencil)
179 {
180 depthStencil->AddRef();
181
182 D3DSURFACE_DESC description;
183 depthStencil->GetDesc(&description);
184
185 mWidth = description.Width;
186 mHeight = description.Height;
187 }
188}
189
190Depthbuffer::Depthbuffer(int width, int height)
191{
192 IDirect3DDevice9 *device = getDevice();
193
194 mDepthStencil = NULL;
195 HRESULT result = device->CreateDepthStencilSurface(width, height, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, 0, FALSE, &mDepthStencil, 0);
196
197 if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY)
198 {
199 error(GL_OUT_OF_MEMORY);
200
201 return;
202 }
203
204 ASSERT(SUCCEEDED(result));
205
206 if (mDepthStencil)
207 {
208 mWidth = width;
209 mHeight = height;
210 }
211 else
212 {
213 mWidth = 0;
214 mHeight = 0;
215 }
216}
217
218Depthbuffer::~Depthbuffer()
219{
220 if (mDepthStencil)
221 {
222 mDepthStencil->Release();
223 }
224}
225
226bool Depthbuffer::isDepthbuffer()
227{
228 return true;
229}
230
231GLuint Depthbuffer::getDepthSize()
232{
233 if (mDepthStencil)
234 {
235 D3DSURFACE_DESC description;
236 mDepthStencil->GetDesc(&description);
237
daniel@transgaming.com7a2c2802010-03-16 06:23:33 +0000238 return es2dx::GetDepthSize(description.Format);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000239 }
240
241 return 0;
242}
243
244IDirect3DSurface9 *Depthbuffer::getDepthStencil()
245{
246 return mDepthStencil;
247}
248
249Stencilbuffer::Stencilbuffer(IDirect3DSurface9 *depthStencil) : mDepthStencil(depthStencil)
daniel@transgaming.com4a9d65c2010-03-08 21:30:56 +0000250{
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000251 if (depthStencil)
252 {
253 depthStencil->AddRef();
254
255 D3DSURFACE_DESC description;
256 depthStencil->GetDesc(&description);
257
258 mWidth = description.Width;
259 mHeight = description.Height;
260 }
daniel@transgaming.com4a9d65c2010-03-08 21:30:56 +0000261}
262
263Stencilbuffer::Stencilbuffer(int width, int height)
264{
265 IDirect3DDevice9 *device = getDevice();
266
267 mDepthStencil = NULL;
268 HRESULT result = device->CreateDepthStencilSurface(width, height, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, 0, FALSE, &mDepthStencil, 0);
269
270 if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY)
271 {
272 error(GL_OUT_OF_MEMORY);
273
274 return;
275 }
276
277 ASSERT(SUCCEEDED(result));
278
279 if (mDepthStencil)
280 {
281 mWidth = width;
282 mHeight = height;
283 }
284 else
285 {
286 mWidth = 0;
287 mHeight = 0;
288 }
289}
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000290
291Stencilbuffer::~Stencilbuffer()
292{
293 if (mDepthStencil)
294 {
295 mDepthStencil->Release();
296 }
297}
298
299GLuint Stencilbuffer::getStencilSize()
300{
301 if (mDepthStencil)
302 {
303 D3DSURFACE_DESC description;
304 mDepthStencil->GetDesc(&description);
305
306 return es2dx::GetStencilSize(description.Format);
307 }
308
309 return 0;
310}
311
312bool Stencilbuffer::isStencilbuffer()
313{
314 return true;
315}
316
317IDirect3DSurface9 *Stencilbuffer::getDepthStencil()
318{
319 return mDepthStencil;
320}
321}