blob: 5cf829c70ab57f8712d5c2b4a2c5aa3c0e86b274 [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.com51887312011-03-21 16:39:03 +0000131 virtual GLenum getType() const;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000132
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000133 virtual D3DFORMAT getD3DFormat() const;
134
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000135 private:
136 DISALLOW_COPY_AND_ASSIGN(Colorbuffer);
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000137
138 IDirect3DSurface9 *mRenderTarget;
139 Texture *mTexture;
140 GLenum mTarget;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000141};
142
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000143class DepthStencilbuffer : public RenderbufferStorage
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +0000144{
145 public:
146 explicit DepthStencilbuffer(IDirect3DSurface9 *depthStencil);
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000147 DepthStencilbuffer(GLsizei width, GLsizei height, GLsizei samples);
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +0000148
149 ~DepthStencilbuffer();
150
daniel@transgaming.com9ecb9f92010-07-28 19:21:12 +0000151 virtual bool isDepthbuffer() const;
152 virtual bool isStencilbuffer() const;
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +0000153
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000154 virtual IDirect3DSurface9 *getDepthStencil();
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +0000155
156 private:
157 DISALLOW_COPY_AND_ASSIGN(DepthStencilbuffer);
158 IDirect3DSurface9 *mDepthStencil;
159};
160
161class Depthbuffer : public DepthStencilbuffer
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000162{
163 public:
daniel@transgaming.com70d312a2010-04-20 18:52:38 +0000164 explicit Depthbuffer(IDirect3DSurface9 *depthStencil);
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000165 Depthbuffer(GLsizei width, GLsizei height, GLsizei samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000166
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000167 virtual ~Depthbuffer();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000168
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000169 virtual bool isDepthbuffer() const;
170 virtual bool isStencilbuffer() const;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000171
172 private:
173 DISALLOW_COPY_AND_ASSIGN(Depthbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000174};
175
daniel@transgaming.comcdacc8e2010-07-28 19:20:50 +0000176class Stencilbuffer : public DepthStencilbuffer
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000177{
178 public:
daniel@transgaming.com70d312a2010-04-20 18:52:38 +0000179 explicit Stencilbuffer(IDirect3DSurface9 *depthStencil);
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000180 Stencilbuffer(GLsizei width, GLsizei height, GLsizei samples);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000181
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000182 virtual ~Stencilbuffer();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000183
daniel@transgaming.comd2fd4f22011-02-01 18:49:11 +0000184 virtual bool isDepthbuffer() const;
185 virtual bool isStencilbuffer() const;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000186
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000187 private:
188 DISALLOW_COPY_AND_ASSIGN(Stencilbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000189};
190}
191
192#endif // LIBGLESV2_RENDERBUFFER_H_