blob: fa74e400f23762aabae809b4a3582c7b4db8768b [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
11#include "Renderbuffer.h"
12
13#include "main.h"
14#include "utilities.h"
15
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
77Colorbuffer::~Colorbuffer()
78{
79 if (mRenderTarget)
80 {
81 mRenderTarget->Release();
82 }
83}
84
85bool Colorbuffer::isColorbuffer()
86{
87 return true;
88}
89
90GLuint Colorbuffer::getRedSize()
91{
92 if (mRenderTarget)
93 {
94 D3DSURFACE_DESC description;
95 mRenderTarget->GetDesc(&description);
96
97 return es2dx::GetRedSize(description.Format);
98 }
99
100 return 0;
101}
102
103GLuint Colorbuffer::getGreenSize()
104{
105 if (mRenderTarget)
106 {
107 D3DSURFACE_DESC description;
108 mRenderTarget->GetDesc(&description);
109
110 return es2dx::GetGreenSize(description.Format);
111 }
112
113 return 0;
114}
115
116GLuint Colorbuffer::getBlueSize()
117{
118 if (mRenderTarget)
119 {
120 D3DSURFACE_DESC description;
121 mRenderTarget->GetDesc(&description);
122
123 return es2dx::GetBlueSize(description.Format);
124 }
125
126 return 0;
127}
128
129GLuint Colorbuffer::getAlphaSize()
130{
131 if (mRenderTarget)
132 {
133 D3DSURFACE_DESC description;
134 mRenderTarget->GetDesc(&description);
135
136 return es2dx::GetAlphaSize(description.Format);
137 }
138
139 return 0;
140}
141
142IDirect3DSurface9 *Colorbuffer::getRenderTarget()
143{
144 return mRenderTarget;
145}
146
147Depthbuffer::Depthbuffer(IDirect3DSurface9 *depthStencil) : mDepthStencil(depthStencil)
148{
149 if (depthStencil)
150 {
151 depthStencil->AddRef();
152
153 D3DSURFACE_DESC description;
154 depthStencil->GetDesc(&description);
155
156 mWidth = description.Width;
157 mHeight = description.Height;
158 }
159}
160
161Depthbuffer::Depthbuffer(int width, int height)
162{
163 IDirect3DDevice9 *device = getDevice();
164
165 mDepthStencil = NULL;
166 HRESULT result = device->CreateDepthStencilSurface(width, height, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, 0, FALSE, &mDepthStencil, 0);
167
168 if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY)
169 {
170 error(GL_OUT_OF_MEMORY);
171
172 return;
173 }
174
175 ASSERT(SUCCEEDED(result));
176
177 if (mDepthStencil)
178 {
179 mWidth = width;
180 mHeight = height;
181 }
182 else
183 {
184 mWidth = 0;
185 mHeight = 0;
186 }
187}
188
189Depthbuffer::~Depthbuffer()
190{
191 if (mDepthStencil)
192 {
193 mDepthStencil->Release();
194 }
195}
196
197bool Depthbuffer::isDepthbuffer()
198{
199 return true;
200}
201
202GLuint Depthbuffer::getDepthSize()
203{
204 if (mDepthStencil)
205 {
206 D3DSURFACE_DESC description;
207 mDepthStencil->GetDesc(&description);
208
daniel@transgaming.com7a2c2802010-03-16 06:23:33 +0000209 return es2dx::GetDepthSize(description.Format);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000210 }
211
212 return 0;
213}
214
215IDirect3DSurface9 *Depthbuffer::getDepthStencil()
216{
217 return mDepthStencil;
218}
219
220Stencilbuffer::Stencilbuffer(IDirect3DSurface9 *depthStencil) : mDepthStencil(depthStencil)
daniel@transgaming.com4a9d65c2010-03-08 21:30:56 +0000221{
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000222 if (depthStencil)
223 {
224 depthStencil->AddRef();
225
226 D3DSURFACE_DESC description;
227 depthStencil->GetDesc(&description);
228
229 mWidth = description.Width;
230 mHeight = description.Height;
231 }
daniel@transgaming.com4a9d65c2010-03-08 21:30:56 +0000232}
233
234Stencilbuffer::Stencilbuffer(int width, int height)
235{
236 IDirect3DDevice9 *device = getDevice();
237
238 mDepthStencil = NULL;
239 HRESULT result = device->CreateDepthStencilSurface(width, height, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, 0, FALSE, &mDepthStencil, 0);
240
241 if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY)
242 {
243 error(GL_OUT_OF_MEMORY);
244
245 return;
246 }
247
248 ASSERT(SUCCEEDED(result));
249
250 if (mDepthStencil)
251 {
252 mWidth = width;
253 mHeight = height;
254 }
255 else
256 {
257 mWidth = 0;
258 mHeight = 0;
259 }
260}
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000261
262Stencilbuffer::~Stencilbuffer()
263{
264 if (mDepthStencil)
265 {
266 mDepthStencil->Release();
267 }
268}
269
270GLuint Stencilbuffer::getStencilSize()
271{
272 if (mDepthStencil)
273 {
274 D3DSURFACE_DESC description;
275 mDepthStencil->GetDesc(&description);
276
277 return es2dx::GetStencilSize(description.Format);
278 }
279
280 return 0;
281}
282
283bool Stencilbuffer::isStencilbuffer()
284{
285 return true;
286}
287
288IDirect3DSurface9 *Stencilbuffer::getDepthStencil()
289{
290 return mDepthStencil;
291}
292}