blob: d6415bbd38e20976a5dfaa9aae0fa2a5ef18df95 [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
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +00007// Renderbuffer.h: Defines the wrapper class gl::Renderbuffer, as well as the
8// class hierarchy used to store its contents: RenderbufferStorage, Colorbuffer,
9// DepthStencilbuffer, Depthbuffer and Stencilbuffer. Implements GL renderbuffer
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000010// objects and related functionality. [OpenGL ES 2.0.24] section 4.4.3 page 108.
11
12#ifndef LIBGLESV2_RENDERBUFFER_H_
13#define LIBGLESV2_RENDERBUFFER_H_
14
15#define GL_APICALL
16#include <GLES2/gl2.h>
17#include <d3d9.h>
18
alokp@chromium.orgea0e1af2010-03-22 19:33:14 +000019#include "common/angleutils.h"
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000020#include "libGLESv2/RefCountObject.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000021
22namespace gl
23{
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +000024class Texture;
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000025
26// A class derived from RenderbufferStorage is created whenever glRenderbufferStorage
27// is called. The specific concrete type depends on whether the internal format is
28// colour depth, stencil or packed depth/stencil.
29class RenderbufferStorage
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000030{
31 public:
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000032 RenderbufferStorage();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000033
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000034 virtual ~RenderbufferStorage() = 0;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000035
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000036 virtual bool isColorbuffer() const;
37 virtual bool isDepthbuffer() const;
38 virtual bool isStencilbuffer() const;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000039
40 virtual IDirect3DSurface9 *getRenderTarget();
41 virtual IDirect3DSurface9 *getDepthStencil();
42
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +000043 virtual GLsizei getWidth() const;
44 virtual GLsizei getHeight() const;
45 virtual GLenum getInternalFormat() const;
46 GLuint getRedSize() const;
47 GLuint getGreenSize() const;
48 GLuint getBlueSize() const;
49 GLuint getAlphaSize() const;
50 GLuint getDepthSize() const;
51 GLuint getStencilSize() const;
52 virtual GLsizei getSamples() const;
53
54 virtual D3DFORMAT getD3DFormat() const;
55
daniel@transgaming.com092bd482010-05-12 03:39:36 +000056 unsigned int getSerial() const;
57
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000058 protected:
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +000059 GLsizei mWidth;
60 GLsizei mHeight;
61 GLenum mInternalFormat;
daniel@transgaming.comca7c0082010-08-24 19:20:20 +000062 D3DFORMAT mD3DFormat;
daniel@transgaming.com1f135d82010-08-24 19:20:36 +000063 GLsizei mSamples;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000064
65 private:
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000066 DISALLOW_COPY_AND_ASSIGN(RenderbufferStorage);
daniel@transgaming.com092bd482010-05-12 03:39:36 +000067
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +000068 static unsigned int issueSerial();
daniel@transgaming.com866f3182010-05-20 19:28:22 +000069
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +000070 const unsigned int mSerial;
71
72 static unsigned int mCurrentSerial;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000073};
74
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000075// Renderbuffer implements the GL renderbuffer object.
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +000076// It's only a proxy for a RenderbufferStorage instance; the internal object
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +000077// can change whenever glRenderbufferStorage is called.
78class Renderbuffer : public RefCountObject
79{
80 public:
81 Renderbuffer(GLuint id, RenderbufferStorage *storage);
82
83 ~Renderbuffer();
84
85 bool isColorbuffer() const;
86 bool isDepthbuffer() const;
87 bool isStencilbuffer() const;
88
89 IDirect3DSurface9 *getRenderTarget();
90 IDirect3DSurface9 *getDepthStencil();
91
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +000092 GLsizei getWidth() const;
93 GLsizei getHeight() const;
94 GLenum getInternalFormat() const;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +000095 D3DFORMAT getD3DFormat() const;
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +000096 GLuint getRedSize() const;
97 GLuint getGreenSize() const;
98 GLuint getBlueSize() const;
99 GLuint getAlphaSize() const;
100 GLuint getDepthSize() const;
101 GLuint getStencilSize() const;
102 GLsizei getSamples() const;
103
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000104 unsigned int getSerial() const;
105
106 void setStorage(RenderbufferStorage *newStorage);
107 RenderbufferStorage *getStorage() { return mStorage; }
108
109 private:
110 DISALLOW_COPY_AND_ASSIGN(Renderbuffer);
111
112 RenderbufferStorage *mStorage;
113};
114
115class Colorbuffer : public RenderbufferStorage
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000116{
117 public:
daniel@transgaming.com70d312a2010-04-20 18:52:38 +0000118 explicit Colorbuffer(IDirect3DSurface9 *renderTarget);
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000119 Colorbuffer(Texture *texture, GLenum target);
120 Colorbuffer(GLsizei width, GLsizei height, GLenum format, GLsizei samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000121
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000122 virtual ~Colorbuffer();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000123
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000124 virtual bool isColorbuffer() const;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000125
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000126 virtual IDirect3DSurface9 *getRenderTarget();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000127
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000128 virtual GLsizei getWidth() const;
129 virtual GLsizei getHeight() const;
130 virtual GLenum getInternalFormat() const;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000131
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000132 virtual D3DFORMAT getD3DFormat() const;
133
134 bool isFloatingPoint() const;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000135
136 private:
137 DISALLOW_COPY_AND_ASSIGN(Colorbuffer);
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000138
139 IDirect3DSurface9 *mRenderTarget;
140 Texture *mTexture;
141 GLenum mTarget;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000142};
143
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000144class DepthStencilbuffer : public RenderbufferStorage
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +0000145{
146 public:
147 explicit DepthStencilbuffer(IDirect3DSurface9 *depthStencil);
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000148 DepthStencilbuffer(GLsizei width, GLsizei height, GLsizei samples);
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +0000149
150 ~DepthStencilbuffer();
151
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000152 virtual bool isDepthbuffer() const;
153 virtual bool isStencilbuffer() const;
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +0000154
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000155 virtual IDirect3DSurface9 *getDepthStencil();
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +0000156
157 private:
158 DISALLOW_COPY_AND_ASSIGN(DepthStencilbuffer);
159 IDirect3DSurface9 *mDepthStencil;
160};
161
162class Depthbuffer : public DepthStencilbuffer
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000163{
164 public:
daniel@transgaming.com70d312a2010-04-20 18:52:38 +0000165 explicit Depthbuffer(IDirect3DSurface9 *depthStencil);
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000166 Depthbuffer(GLsizei width, GLsizei height, GLsizei samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000167
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000168 virtual ~Depthbuffer();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000169
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000170 virtual bool isDepthbuffer() const;
171 virtual bool isStencilbuffer() const;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000172
173 private:
174 DISALLOW_COPY_AND_ASSIGN(Depthbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000175};
176
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +0000177class Stencilbuffer : public DepthStencilbuffer
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000178{
179 public:
daniel@transgaming.com70d312a2010-04-20 18:52:38 +0000180 explicit Stencilbuffer(IDirect3DSurface9 *depthStencil);
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000181 Stencilbuffer(GLsizei width, GLsizei height, GLsizei samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000182
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000183 virtual ~Stencilbuffer();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000184
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000185 virtual bool isDepthbuffer() const;
186 virtual bool isStencilbuffer() const;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000187
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000188 private:
189 DISALLOW_COPY_AND_ASSIGN(Stencilbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000190};
191}
192
193#endif // LIBGLESV2_RENDERBUFFER_H_