blob: a97ec2cdcb1297355c3dca9b844f1e7dcb6c5e09 [file] [log] [blame]
John Bauman66b8ab22014-05-06 15:57:45 -04001// SwiftShader Software Renderer
2//
3// Copyright(c) 2005-2013 TransGaming Inc.
4//
5// All rights reserved. No part of this software may be copied, distributed, transmitted,
6// transcribed, stored in a retrieval system, translated into any human or computer
7// language by any means, or disclosed to third parties without the explicit written
8// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
9// or implied, including but not limited to any patent rights, are granted to you.
10//
11
12// Framebuffer.cpp: Implements the Framebuffer class. Implements GL framebuffer
13// objects and related functionality. [OpenGL ES 2.0.24] section 4.4 page 105.
14
15#include "Framebuffer.h"
16
17#include "main.h"
18#include "Renderbuffer.h"
19#include "Texture.h"
20#include "utilities.h"
21
Nicolas Capens14ee7622014-10-28 23:48:41 -040022namespace es2
John Bauman66b8ab22014-05-06 15:57:45 -040023{
24
25Framebuffer::Framebuffer()
26{
Alexis Hetu1b2f6282015-04-16 16:27:42 -040027 for(int i = 0; i < IMPLEMENTATION_MAX_COLOR_ATTACHMENTS; ++i)
28 {
29 mColorbufferType[i] = GL_NONE;
30 }
John Bauman66b8ab22014-05-06 15:57:45 -040031 mDepthbufferType = GL_NONE;
32 mStencilbufferType = GL_NONE;
33}
34
35Framebuffer::~Framebuffer()
36{
Alexis Hetu1b2f6282015-04-16 16:27:42 -040037 for(int i = 0; i < IMPLEMENTATION_MAX_COLOR_ATTACHMENTS; ++i)
38 {
39 mColorbufferPointer[i] = NULL;
40 }
Nicolas Capensd7d9b4b2015-01-29 23:46:44 -050041 mDepthbufferPointer = NULL;
42 mStencilbufferPointer = NULL;
John Bauman66b8ab22014-05-06 15:57:45 -040043}
44
Alexis Hetu8af50072015-04-29 14:29:49 -040045Renderbuffer *Framebuffer::lookupRenderbuffer(GLenum type, GLuint handle, GLint level, GLint layer) const
John Bauman66b8ab22014-05-06 15:57:45 -040046{
47 Context *context = getContext();
48 Renderbuffer *buffer = NULL;
49
50 if(type == GL_NONE)
51 {
52 buffer = NULL;
53 }
54 else if(type == GL_RENDERBUFFER)
55 {
56 buffer = context->getRenderbuffer(handle);
57 }
58 else if(IsTextureTarget(type))
59 {
Alexis Hetu8af50072015-04-29 14:29:49 -040060 buffer = context->getTexture(handle)->getRenderbuffer(type, level, layer);
John Bauman66b8ab22014-05-06 15:57:45 -040061 }
Nicolas Capens3713cd42015-06-22 10:41:54 -040062 else UNREACHABLE(type);
John Bauman66b8ab22014-05-06 15:57:45 -040063
64 return buffer;
65}
66
Alexis Hetu8af50072015-04-29 14:29:49 -040067void Framebuffer::setColorbuffer(GLenum type, GLuint colorbuffer, GLuint index, GLint level, GLint layer)
John Bauman66b8ab22014-05-06 15:57:45 -040068{
Alexis Hetu1b2f6282015-04-16 16:27:42 -040069 mColorbufferType[index] = (colorbuffer != 0) ? type : GL_NONE;
Alexis Hetu8af50072015-04-29 14:29:49 -040070 mColorbufferPointer[index] = lookupRenderbuffer(type, colorbuffer, level, layer);
John Bauman66b8ab22014-05-06 15:57:45 -040071}
72
Alexis Hetu8af50072015-04-29 14:29:49 -040073void Framebuffer::setDepthbuffer(GLenum type, GLuint depthbuffer, GLint level, GLint layer)
John Bauman66b8ab22014-05-06 15:57:45 -040074{
75 mDepthbufferType = (depthbuffer != 0) ? type : GL_NONE;
Alexis Hetu8af50072015-04-29 14:29:49 -040076 mDepthbufferPointer = lookupRenderbuffer(type, depthbuffer, level, layer);
John Bauman66b8ab22014-05-06 15:57:45 -040077}
78
Alexis Hetu8af50072015-04-29 14:29:49 -040079void Framebuffer::setStencilbuffer(GLenum type, GLuint stencilbuffer, GLint level, GLint layer)
John Bauman66b8ab22014-05-06 15:57:45 -040080{
81 mStencilbufferType = (stencilbuffer != 0) ? type : GL_NONE;
Alexis Hetu8af50072015-04-29 14:29:49 -040082 mStencilbufferPointer = lookupRenderbuffer(type, stencilbuffer, level, layer);
John Bauman66b8ab22014-05-06 15:57:45 -040083}
84
85void Framebuffer::detachTexture(GLuint texture)
86{
Alexis Hetu1b2f6282015-04-16 16:27:42 -040087 for(int i = 0; i < IMPLEMENTATION_MAX_COLOR_ATTACHMENTS; ++i)
John Bauman66b8ab22014-05-06 15:57:45 -040088 {
Alexis Hetu1b2f6282015-04-16 16:27:42 -040089 if(mColorbufferPointer[i].name() == texture && IsTextureTarget(mColorbufferType[i]))
90 {
91 mColorbufferType[i] = GL_NONE;
92 mColorbufferPointer[i] = NULL;
93 }
John Bauman66b8ab22014-05-06 15:57:45 -040094 }
95
Nicolas Capens7cc75e12015-01-29 14:44:24 -050096 if(mDepthbufferPointer.name() == texture && IsTextureTarget(mDepthbufferType))
John Bauman66b8ab22014-05-06 15:57:45 -040097 {
98 mDepthbufferType = GL_NONE;
Nicolas Capensd7d9b4b2015-01-29 23:46:44 -050099 mDepthbufferPointer = NULL;
John Bauman66b8ab22014-05-06 15:57:45 -0400100 }
101
Nicolas Capens7cc75e12015-01-29 14:44:24 -0500102 if(mStencilbufferPointer.name() == texture && IsTextureTarget(mStencilbufferType))
John Bauman66b8ab22014-05-06 15:57:45 -0400103 {
104 mStencilbufferType = GL_NONE;
Nicolas Capensd7d9b4b2015-01-29 23:46:44 -0500105 mStencilbufferPointer = NULL;
John Bauman66b8ab22014-05-06 15:57:45 -0400106 }
107}
108
109void Framebuffer::detachRenderbuffer(GLuint renderbuffer)
110{
Alexis Hetu1b2f6282015-04-16 16:27:42 -0400111 for(int i = 0; i < IMPLEMENTATION_MAX_COLOR_ATTACHMENTS; ++i)
John Bauman66b8ab22014-05-06 15:57:45 -0400112 {
Alexis Hetu1b2f6282015-04-16 16:27:42 -0400113 if(mColorbufferPointer[i].name() == renderbuffer && mColorbufferType[i] == GL_RENDERBUFFER)
114 {
115 mColorbufferType[i] = GL_NONE;
116 mColorbufferPointer[i] = NULL;
117 }
John Bauman66b8ab22014-05-06 15:57:45 -0400118 }
119
Nicolas Capens7cc75e12015-01-29 14:44:24 -0500120 if(mDepthbufferPointer.name() == renderbuffer && mDepthbufferType == GL_RENDERBUFFER)
John Bauman66b8ab22014-05-06 15:57:45 -0400121 {
122 mDepthbufferType = GL_NONE;
Nicolas Capensd7d9b4b2015-01-29 23:46:44 -0500123 mDepthbufferPointer = NULL;
John Bauman66b8ab22014-05-06 15:57:45 -0400124 }
125
Nicolas Capens7cc75e12015-01-29 14:44:24 -0500126 if(mStencilbufferPointer.name() == renderbuffer && mStencilbufferType == GL_RENDERBUFFER)
John Bauman66b8ab22014-05-06 15:57:45 -0400127 {
128 mStencilbufferType = GL_NONE;
Nicolas Capensd7d9b4b2015-01-29 23:46:44 -0500129 mStencilbufferPointer = NULL;
John Bauman66b8ab22014-05-06 15:57:45 -0400130 }
131}
132
133// Increments refcount on surface.
134// caller must Release() the returned surface
Alexis Hetu1b2f6282015-04-16 16:27:42 -0400135egl::Image *Framebuffer::getRenderTarget(GLuint index)
John Bauman66b8ab22014-05-06 15:57:45 -0400136{
Alexis Hetu1b2f6282015-04-16 16:27:42 -0400137 Renderbuffer *colorbuffer = mColorbufferPointer[index];
John Bauman66b8ab22014-05-06 15:57:45 -0400138
139 if(colorbuffer)
140 {
141 return colorbuffer->getRenderTarget();
142 }
143
144 return NULL;
145}
146
Alexis Hetu1b2f6282015-04-16 16:27:42 -0400147egl::Image *Framebuffer::getReadRenderTarget()
148{
149 Context *context = getContext();
150 return getRenderTarget(context->getReadFramebufferColorIndex());
151}
152
John Bauman66b8ab22014-05-06 15:57:45 -0400153// Increments refcount on surface.
154// caller must Release() the returned surface
Nicolas Capensead7ac52014-10-27 23:56:02 -0400155egl::Image *Framebuffer::getDepthStencil()
John Bauman66b8ab22014-05-06 15:57:45 -0400156{
Nicolas Capensd7d9b4b2015-01-29 23:46:44 -0500157 Renderbuffer *depthstencilbuffer = mDepthbufferPointer;
John Bauman66b8ab22014-05-06 15:57:45 -0400158
159 if(!depthstencilbuffer)
160 {
Nicolas Capensd7d9b4b2015-01-29 23:46:44 -0500161 depthstencilbuffer = mStencilbufferPointer;
John Bauman66b8ab22014-05-06 15:57:45 -0400162 }
163
164 if(depthstencilbuffer)
165 {
166 return depthstencilbuffer->getRenderTarget();
167 }
168
169 return NULL;
170}
171
Alexis Hetu1b2f6282015-04-16 16:27:42 -0400172Renderbuffer *Framebuffer::getColorbuffer(GLuint index)
John Bauman66b8ab22014-05-06 15:57:45 -0400173{
Alexis Hetu1b2f6282015-04-16 16:27:42 -0400174 return (index < MAX_COLOR_ATTACHMENTS) ? mColorbufferPointer[index] : (Renderbuffer*)NULL;
175}
176
177Renderbuffer *Framebuffer::getReadColorbuffer()
178{
179 Context *context = getContext();
180 return getColorbuffer(context->getReadFramebufferColorIndex());
John Bauman66b8ab22014-05-06 15:57:45 -0400181}
182
183Renderbuffer *Framebuffer::getDepthbuffer()
184{
Nicolas Capensd7d9b4b2015-01-29 23:46:44 -0500185 return mDepthbufferPointer;
John Bauman66b8ab22014-05-06 15:57:45 -0400186}
187
188Renderbuffer *Framebuffer::getStencilbuffer()
189{
Nicolas Capensd7d9b4b2015-01-29 23:46:44 -0500190 return mStencilbufferPointer;
John Bauman66b8ab22014-05-06 15:57:45 -0400191}
192
Alexis Hetu1b2f6282015-04-16 16:27:42 -0400193GLenum Framebuffer::getColorbufferType(GLuint index)
John Bauman66b8ab22014-05-06 15:57:45 -0400194{
Alexis Hetu1b2f6282015-04-16 16:27:42 -0400195 return mColorbufferType[index];
John Bauman66b8ab22014-05-06 15:57:45 -0400196}
197
198GLenum Framebuffer::getDepthbufferType()
199{
200 return mDepthbufferType;
201}
202
203GLenum Framebuffer::getStencilbufferType()
204{
205 return mStencilbufferType;
206}
207
Alexis Hetu1b2f6282015-04-16 16:27:42 -0400208GLuint Framebuffer::getColorbufferName(GLuint index)
John Bauman66b8ab22014-05-06 15:57:45 -0400209{
Alexis Hetu1b2f6282015-04-16 16:27:42 -0400210 return mColorbufferPointer[index].name();
John Bauman66b8ab22014-05-06 15:57:45 -0400211}
212
Nicolas Capens7cc75e12015-01-29 14:44:24 -0500213GLuint Framebuffer::getDepthbufferName()
John Bauman66b8ab22014-05-06 15:57:45 -0400214{
Nicolas Capens7cc75e12015-01-29 14:44:24 -0500215 return mDepthbufferPointer.name();
John Bauman66b8ab22014-05-06 15:57:45 -0400216}
217
Nicolas Capens7cc75e12015-01-29 14:44:24 -0500218GLuint Framebuffer::getStencilbufferName()
John Bauman66b8ab22014-05-06 15:57:45 -0400219{
Nicolas Capens7cc75e12015-01-29 14:44:24 -0500220 return mStencilbufferPointer.name();
John Bauman66b8ab22014-05-06 15:57:45 -0400221}
222
Alexis Hetu074c6412015-06-22 15:57:27 -0400223GLint Framebuffer::getColorbufferLayer(GLuint index)
224{
225 Renderbuffer *colorbuffer = mColorbufferPointer[index];
Alexis Hetu0fecd6f2015-07-22 16:49:31 -0400226 return colorbuffer ? colorbuffer->getLayer() : 0;
227}
228
229GLint Framebuffer::getDepthbufferLayer()
230{
231 return mDepthbufferPointer ? mDepthbufferPointer->getLayer() : 0;
232}
233
234GLint Framebuffer::getStencilbufferLayer()
235{
236 return mStencilbufferPointer ? mStencilbufferPointer->getLayer() : 0;
Alexis Hetu074c6412015-06-22 15:57:27 -0400237}
238
John Bauman66b8ab22014-05-06 15:57:45 -0400239bool Framebuffer::hasStencil()
240{
241 if(mStencilbufferType != GL_NONE)
242 {
243 Renderbuffer *stencilbufferObject = getStencilbuffer();
244
245 if(stencilbufferObject)
246 {
247 return stencilbufferObject->getStencilSize() > 0;
248 }
249 }
250
251 return false;
252}
253
254GLenum Framebuffer::completeness()
255{
256 int width;
257 int height;
258 int samples;
259
260 return completeness(width, height, samples);
261}
262
263GLenum Framebuffer::completeness(int &width, int &height, int &samples)
264{
265 width = -1;
266 height = -1;
267 samples = -1;
268
Alexis Hetu1b2f6282015-04-16 16:27:42 -0400269 for(int i = 0; i < IMPLEMENTATION_MAX_COLOR_ATTACHMENTS; ++i)
John Bauman66b8ab22014-05-06 15:57:45 -0400270 {
Alexis Hetu1b2f6282015-04-16 16:27:42 -0400271 if(mColorbufferType[i] != GL_NONE)
John Bauman66b8ab22014-05-06 15:57:45 -0400272 {
Alexis Hetu1b2f6282015-04-16 16:27:42 -0400273 Renderbuffer *colorbuffer = getColorbuffer(i);
John Bauman66b8ab22014-05-06 15:57:45 -0400274
Alexis Hetu1b2f6282015-04-16 16:27:42 -0400275 if(!colorbuffer)
John Bauman66b8ab22014-05-06 15:57:45 -0400276 {
277 return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
278 }
John Bauman66b8ab22014-05-06 15:57:45 -0400279
Alexis Hetue23029a2015-12-04 17:12:35 -0500280 if(colorbuffer->getWidth() == 0 || colorbuffer->getHeight() == 0 || (colorbuffer->getDepth() <= colorbuffer->getLayer()))
John Bauman66b8ab22014-05-06 15:57:45 -0400281 {
282 return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
283 }
John Bauman66b8ab22014-05-06 15:57:45 -0400284
Alexis Hetu1b2f6282015-04-16 16:27:42 -0400285 if(mColorbufferType[i] == GL_RENDERBUFFER)
286 {
Alexis Hetuc8f95e82015-11-12 16:36:34 -0500287 if(!es2::IsColorRenderable(colorbuffer->getFormat(), egl::getClientVersion()))
Alexis Hetu1b2f6282015-04-16 16:27:42 -0400288 {
289 return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
290 }
291 }
292 else if(IsTextureTarget(mColorbufferType[i]))
293 {
294 GLenum format = colorbuffer->getFormat();
295
Alexis Hetu460e41f2015-09-01 10:58:37 -0400296 if(IsCompressed(format, egl::getClientVersion()) ||
Alexis Hetu1b2f6282015-04-16 16:27:42 -0400297 format == GL_ALPHA ||
298 format == GL_LUMINANCE ||
299 format == GL_LUMINANCE_ALPHA)
300 {
301 return GL_FRAMEBUFFER_UNSUPPORTED;
302 }
303
304 if(es2::IsDepthTexture(format) || es2::IsStencilTexture(format))
305 {
306 return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
307 }
308 }
309 else
310 {
Nicolas Capens3713cd42015-06-22 10:41:54 -0400311 UNREACHABLE(mColorbufferType[i]);
Alexis Hetu1b2f6282015-04-16 16:27:42 -0400312 return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
313 }
314
315 width = colorbuffer->getWidth();
316 height = colorbuffer->getHeight();
Alexis Hetu137364a2015-12-08 11:24:21 -0500317
318 if(samples == -1)
319 {
320 samples = colorbuffer->getSamples();
321 }
322 else if(samples != colorbuffer->getSamples())
323 {
324 return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_ANGLE;
325 }
326
Alexis Hetu1b2f6282015-04-16 16:27:42 -0400327 }
John Bauman66b8ab22014-05-06 15:57:45 -0400328 }
329
330 Renderbuffer *depthbuffer = NULL;
331 Renderbuffer *stencilbuffer = NULL;
332
333 if(mDepthbufferType != GL_NONE)
334 {
335 depthbuffer = getDepthbuffer();
336
337 if(!depthbuffer)
338 {
339 return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
340 }
341
342 if(depthbuffer->getWidth() == 0 || depthbuffer->getHeight() == 0)
343 {
344 return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
345 }
346
347 if(mDepthbufferType == GL_RENDERBUFFER)
348 {
Nicolas Capens14ee7622014-10-28 23:48:41 -0400349 if(!es2::IsDepthRenderable(depthbuffer->getFormat()))
John Bauman66b8ab22014-05-06 15:57:45 -0400350 {
351 return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
352 }
353 }
354 else if(IsTextureTarget(mDepthbufferType))
355 {
Nicolas Capens14ee7622014-10-28 23:48:41 -0400356 if(!es2::IsDepthTexture(depthbuffer->getFormat()))
John Bauman66b8ab22014-05-06 15:57:45 -0400357 {
358 return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
359 }
360 }
361 else
362 {
Nicolas Capens3713cd42015-06-22 10:41:54 -0400363 UNREACHABLE(mDepthbufferType);
John Bauman66b8ab22014-05-06 15:57:45 -0400364 return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
365 }
366
367 if(width == -1 || height == -1)
368 {
369 width = depthbuffer->getWidth();
370 height = depthbuffer->getHeight();
371 samples = depthbuffer->getSamples();
372 }
373 else if(width != depthbuffer->getWidth() || height != depthbuffer->getHeight())
374 {
375 return GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS;
376 }
377 else if(samples != depthbuffer->getSamples())
378 {
379 return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_ANGLE;
380 }
381 }
382
383 if(mStencilbufferType != GL_NONE)
384 {
385 stencilbuffer = getStencilbuffer();
386
387 if(!stencilbuffer)
388 {
389 return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
390 }
391
392 if(stencilbuffer->getWidth() == 0 || stencilbuffer->getHeight() == 0)
393 {
394 return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
395 }
396
397 if(mStencilbufferType == GL_RENDERBUFFER)
398 {
Nicolas Capens14ee7622014-10-28 23:48:41 -0400399 if(!es2::IsStencilRenderable(stencilbuffer->getFormat()))
John Bauman66b8ab22014-05-06 15:57:45 -0400400 {
401 return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
402 }
403 }
404 else if(IsTextureTarget(mStencilbufferType))
405 {
406 GLenum internalformat = stencilbuffer->getFormat();
407
Nicolas Capens14ee7622014-10-28 23:48:41 -0400408 if(!es2::IsStencilTexture(internalformat))
John Bauman66b8ab22014-05-06 15:57:45 -0400409 {
410 return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
411 }
412 }
413 else
414 {
Nicolas Capens3713cd42015-06-22 10:41:54 -0400415 UNREACHABLE(mStencilbufferType);
John Bauman66b8ab22014-05-06 15:57:45 -0400416 return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
417 }
418
419 if(width == -1 || height == -1)
420 {
421 width = stencilbuffer->getWidth();
422 height = stencilbuffer->getHeight();
423 samples = stencilbuffer->getSamples();
424 }
425 else if(width != stencilbuffer->getWidth() || height != stencilbuffer->getHeight())
426 {
427 return GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS;
428 }
429 else if(samples != stencilbuffer->getSamples())
430 {
431 return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_ANGLE;
432 }
433 }
434
435 // If we have both a depth and stencil buffer, they must refer to the same object
436 // since we only support packed_depth_stencil and not separate depth and stencil
437 if(depthbuffer && stencilbuffer && (depthbuffer != stencilbuffer))
438 {
439 return GL_FRAMEBUFFER_UNSUPPORTED;
440 }
441
442 // We need to have at least one attachment to be complete
443 if(width == -1 || height == -1)
444 {
445 return GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;
446 }
447
448 return GL_FRAMEBUFFER_COMPLETE;
449}
450
Nicolas Capens4b8df2f2015-01-29 13:20:27 -0500451GLenum Framebuffer::getImplementationColorReadFormat()
452{
Alexis Hetu1b2f6282015-04-16 16:27:42 -0400453 Renderbuffer *colorbuffer = getReadColorbuffer();
Nicolas Capens4b8df2f2015-01-29 13:20:27 -0500454
455 if(colorbuffer)
456 {
Nicolas Capensde6b75c2015-03-29 00:27:33 -0400457 // Don't return GL_RGBA since that's always supported. Provide a second option here.
Nicolas Capens4b8df2f2015-01-29 13:20:27 -0500458 switch(colorbuffer->getInternalFormat())
459 {
Alexis Hetuc8f95e82015-11-12 16:36:34 -0500460 case sw::FORMAT_A8B8G8R8I:
461 case sw::FORMAT_A8B8G8R8UI:
462 case sw::FORMAT_A16B16G16R16I:
463 case sw::FORMAT_A16B16G16R16UI:
464 case sw::FORMAT_A32B32G32R32I:
465 case sw::FORMAT_A32B32G32R32UI:return GL_RGBA_INTEGER;
466 case sw::FORMAT_A2B10G10R10: return GL_RGB10_A2;
467 case sw::FORMAT_A8B8G8R8I_SNORM:
468 case sw::FORMAT_A16B16G16R16F:
469 case sw::FORMAT_A32B32G32R32F:
470 case sw::FORMAT_A8R8G8B8:
471 case sw::FORMAT_A8B8G8R8:
Nicolas Capens4b8df2f2015-01-29 13:20:27 -0500472 case sw::FORMAT_A1R5G5B5: return GL_BGRA_EXT;
Alexis Hetuc8f95e82015-11-12 16:36:34 -0500473 case sw::FORMAT_X8B8G8R8I:
474 case sw::FORMAT_X8B8G8R8UI:
475 case sw::FORMAT_X16B16G16R16I:
476 case sw::FORMAT_X16B16G16R16UI:
477 case sw::FORMAT_X32B32G32R32I:
478 case sw::FORMAT_X32B32G32R32UI:return GL_RGB_INTEGER;
Alexis Hetue7277752015-12-04 11:16:35 -0500479 case sw::FORMAT_B16G16R16F:
Alexis Hetuc8f95e82015-11-12 16:36:34 -0500480 case sw::FORMAT_X8B8G8R8I_SNORM:
481 case sw::FORMAT_X8B8G8R8:
482 case sw::FORMAT_X8R8G8B8:
Nicolas Capens4b8df2f2015-01-29 13:20:27 -0500483 case sw::FORMAT_R5G6B5: return 0x80E0; // GL_BGR_EXT
Alexis Hetuc8f95e82015-11-12 16:36:34 -0500484 case sw::FORMAT_G8R8I:
485 case sw::FORMAT_G8R8UI:
486 case sw::FORMAT_G16R16I:
487 case sw::FORMAT_G16R16UI:
488 case sw::FORMAT_G32R32I:
489 case sw::FORMAT_G32R32UI: return GL_RG_INTEGER;
490 case sw::FORMAT_G8R8:
491 case sw::FORMAT_G8R8I_SNORM:
492 case sw::FORMAT_G16R16F:
493 case sw::FORMAT_G32R32F: return GL_RG;
494 case sw::FORMAT_R8I:
495 case sw::FORMAT_R8UI:
496 case sw::FORMAT_R16I:
497 case sw::FORMAT_R16UI:
498 case sw::FORMAT_R32I:
499 case sw::FORMAT_R32UI: return GL_RED_INTEGER;
500 case sw::FORMAT_R8:
501 case sw::FORMAT_R8I_SNORM:
502 case sw::FORMAT_R16F:
503 case sw::FORMAT_R32F: return GL_RED;
Nicolas Capens4b8df2f2015-01-29 13:20:27 -0500504 default:
Nicolas Capens3713cd42015-06-22 10:41:54 -0400505 UNREACHABLE(colorbuffer->getInternalFormat());
Nicolas Capens4b8df2f2015-01-29 13:20:27 -0500506 }
507 }
508
509 return GL_RGBA;
510}
511
Nicolas Capensdddc4ab2015-01-13 15:49:15 -0500512GLenum Framebuffer::getImplementationColorReadType()
513{
Alexis Hetu1b2f6282015-04-16 16:27:42 -0400514 Renderbuffer *colorbuffer = getReadColorbuffer();
Nicolas Capens4b8df2f2015-01-29 13:20:27 -0500515
516 if(colorbuffer)
517 {
518 switch(colorbuffer->getInternalFormat())
519 {
Alexis Hetuc8f95e82015-11-12 16:36:34 -0500520 case sw::FORMAT_R16F:
521 case sw::FORMAT_G16R16F:
522 case sw::FORMAT_B16G16R16F:
523 case sw::FORMAT_A16B16G16R16F:
524 case sw::FORMAT_R32F:
525 case sw::FORMAT_G32R32F:
526 case sw::FORMAT_B32G32R32F:
Nicolas Capens4b8df2f2015-01-29 13:20:27 -0500527 case sw::FORMAT_A32B32G32R32F: return GL_FLOAT;
Alexis Hetuc8f95e82015-11-12 16:36:34 -0500528 case sw::FORMAT_R8I_SNORM:
529 case sw::FORMAT_G8R8I_SNORM:
530 case sw::FORMAT_X8B8G8R8I_SNORM:
531 case sw::FORMAT_A8B8G8R8I_SNORM:return GL_BYTE;
532 case sw::FORMAT_R8:
533 case sw::FORMAT_G8R8:
534 case sw::FORMAT_A8R8G8B8:
535 case sw::FORMAT_A8B8G8R8:
536 case sw::FORMAT_X8R8G8B8:
Nicolas Capensde6b75c2015-03-29 00:27:33 -0400537 case sw::FORMAT_X8B8G8R8: return GL_UNSIGNED_BYTE;
Alexis Hetuc8f95e82015-11-12 16:36:34 -0500538 case sw::FORMAT_R8I:
539 case sw::FORMAT_G8R8I:
540 case sw::FORMAT_X8B8G8R8I:
541 case sw::FORMAT_A8B8G8R8I:
542 case sw::FORMAT_R16I:
543 case sw::FORMAT_G16R16I:
544 case sw::FORMAT_X16B16G16R16I:
545 case sw::FORMAT_A16B16G16R16I:
546 case sw::FORMAT_R32I:
547 case sw::FORMAT_G32R32I:
548 case sw::FORMAT_X32B32G32R32I:
549 case sw::FORMAT_A32B32G32R32I: return GL_INT;
550 case sw::FORMAT_R8UI:
551 case sw::FORMAT_G8R8UI:
552 case sw::FORMAT_X8B8G8R8UI:
553 case sw::FORMAT_A8B8G8R8UI:
554 case sw::FORMAT_R16UI:
555 case sw::FORMAT_G16R16UI:
556 case sw::FORMAT_X16B16G16R16UI:
557 case sw::FORMAT_A16B16G16R16UI:
558 case sw::FORMAT_R32UI:
559 case sw::FORMAT_G32R32UI:
560 case sw::FORMAT_X32B32G32R32UI:
561 case sw::FORMAT_A32B32G32R32UI:return GL_UNSIGNED_INT;
562 case sw::FORMAT_A2B10G10R10: return GL_UNSIGNED_INT_10_10_10_2_OES;
Nicolas Capens4b8df2f2015-01-29 13:20:27 -0500563 case sw::FORMAT_A1R5G5B5: return GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT;
564 case sw::FORMAT_R5G6B5: return GL_UNSIGNED_SHORT_5_6_5;
565 default:
Nicolas Capens3713cd42015-06-22 10:41:54 -0400566 UNREACHABLE(colorbuffer->getInternalFormat());
Nicolas Capens4b8df2f2015-01-29 13:20:27 -0500567 }
Nicolas Capens9703d1a2015-01-14 15:55:33 -0500568 }
569
570 return GL_UNSIGNED_BYTE;
Nicolas Capensdddc4ab2015-01-13 15:49:15 -0500571}
572
John Bauman66b8ab22014-05-06 15:57:45 -0400573DefaultFramebuffer::DefaultFramebuffer(Colorbuffer *colorbuffer, DepthStencilbuffer *depthStencil)
574{
Alexis Hetu1b2f6282015-04-16 16:27:42 -0400575 mColorbufferPointer[0] = new Renderbuffer(0, colorbuffer);
576 mColorbufferType[0] = GL_RENDERBUFFER;
577
578 for(int i = 1; i < IMPLEMENTATION_MAX_COLOR_ATTACHMENTS; ++i)
579 {
580 mColorbufferPointer[i] = nullptr;
581 mColorbufferType[i] = GL_NONE;
582 }
John Bauman66b8ab22014-05-06 15:57:45 -0400583
584 Renderbuffer *depthStencilRenderbuffer = new Renderbuffer(0, depthStencil);
Nicolas Capensd7d9b4b2015-01-29 23:46:44 -0500585 mDepthbufferPointer = depthStencilRenderbuffer;
586 mStencilbufferPointer = depthStencilRenderbuffer;
John Bauman66b8ab22014-05-06 15:57:45 -0400587
John Bauman66b8ab22014-05-06 15:57:45 -0400588 mDepthbufferType = (depthStencilRenderbuffer->getDepthSize() != 0) ? GL_RENDERBUFFER : GL_NONE;
589 mStencilbufferType = (depthStencilRenderbuffer->getStencilSize() != 0) ? GL_RENDERBUFFER : GL_NONE;
590}
591
John Bauman66b8ab22014-05-06 15:57:45 -0400592}