blob: fcaacb76d1a68a84123a7a7e52938ea0e64eea78 [file] [log] [blame]
Geoff Langd08f3b32016-09-23 15:56:30 -04001//
2// Copyright 2016 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// FramebufferNULL.cpp:
7// Implements the class methods for FramebufferNULL.
8//
9
10#include "libANGLE/renderer/null/FramebufferNULL.h"
11
Corentin Wallezaf11b532017-08-30 15:51:36 -040012#include "libANGLE/Context.h"
Geoff Lang2291c932016-11-18 14:10:17 -050013#include "libANGLE/formatutils.h"
Corentin Wallezaf11b532017-08-30 15:51:36 -040014#include "libANGLE/renderer/null/BufferNULL.h"
Geoff Lang2291c932016-11-18 14:10:17 -050015
Geoff Langd08f3b32016-09-23 15:56:30 -040016#include "common/debug.h"
17
18namespace rx
19{
20
21FramebufferNULL::FramebufferNULL(const gl::FramebufferState &state) : FramebufferImpl(state)
22{
23}
24
25FramebufferNULL::~FramebufferNULL()
26{
27}
28
Jamie Madill4928b7c2017-06-20 12:57:39 -040029gl::Error FramebufferNULL::discard(const gl::Context *context,
30 size_t count,
31 const GLenum *attachments)
Geoff Langd08f3b32016-09-23 15:56:30 -040032{
Geoff Lang76cdbd52016-09-23 16:51:04 -040033 return gl::NoError();
Geoff Langd08f3b32016-09-23 15:56:30 -040034}
35
Jamie Madill4928b7c2017-06-20 12:57:39 -040036gl::Error FramebufferNULL::invalidate(const gl::Context *context,
37 size_t count,
38 const GLenum *attachments)
Geoff Langd08f3b32016-09-23 15:56:30 -040039{
Geoff Lang76cdbd52016-09-23 16:51:04 -040040 return gl::NoError();
Geoff Langd08f3b32016-09-23 15:56:30 -040041}
42
Jamie Madill4928b7c2017-06-20 12:57:39 -040043gl::Error FramebufferNULL::invalidateSub(const gl::Context *context,
44 size_t count,
Geoff Langd08f3b32016-09-23 15:56:30 -040045 const GLenum *attachments,
46 const gl::Rectangle &area)
47{
Geoff Lang76cdbd52016-09-23 16:51:04 -040048 return gl::NoError();
Geoff Langd08f3b32016-09-23 15:56:30 -040049}
50
Jamie Madillc564c072017-06-01 12:45:42 -040051gl::Error FramebufferNULL::clear(const gl::Context *context, GLbitfield mask)
Geoff Langd08f3b32016-09-23 15:56:30 -040052{
Geoff Lang76cdbd52016-09-23 16:51:04 -040053 return gl::NoError();
Geoff Langd08f3b32016-09-23 15:56:30 -040054}
55
Jamie Madillc564c072017-06-01 12:45:42 -040056gl::Error FramebufferNULL::clearBufferfv(const gl::Context *context,
Geoff Langd08f3b32016-09-23 15:56:30 -040057 GLenum buffer,
58 GLint drawbuffer,
59 const GLfloat *values)
60{
Geoff Lang76cdbd52016-09-23 16:51:04 -040061 return gl::NoError();
Geoff Langd08f3b32016-09-23 15:56:30 -040062}
63
Jamie Madillc564c072017-06-01 12:45:42 -040064gl::Error FramebufferNULL::clearBufferuiv(const gl::Context *context,
Geoff Langd08f3b32016-09-23 15:56:30 -040065 GLenum buffer,
66 GLint drawbuffer,
67 const GLuint *values)
68{
Geoff Lang76cdbd52016-09-23 16:51:04 -040069 return gl::NoError();
Geoff Langd08f3b32016-09-23 15:56:30 -040070}
71
Jamie Madillc564c072017-06-01 12:45:42 -040072gl::Error FramebufferNULL::clearBufferiv(const gl::Context *context,
Geoff Langd08f3b32016-09-23 15:56:30 -040073 GLenum buffer,
74 GLint drawbuffer,
75 const GLint *values)
76{
Geoff Lang76cdbd52016-09-23 16:51:04 -040077 return gl::NoError();
Geoff Langd08f3b32016-09-23 15:56:30 -040078}
79
Jamie Madillc564c072017-06-01 12:45:42 -040080gl::Error FramebufferNULL::clearBufferfi(const gl::Context *context,
Geoff Langd08f3b32016-09-23 15:56:30 -040081 GLenum buffer,
82 GLint drawbuffer,
83 GLfloat depth,
84 GLint stencil)
85{
Geoff Lang76cdbd52016-09-23 16:51:04 -040086 return gl::NoError();
Geoff Langd08f3b32016-09-23 15:56:30 -040087}
88
Jamie Madill4928b7c2017-06-20 12:57:39 -040089GLenum FramebufferNULL::getImplementationColorReadFormat(const gl::Context *context) const
Geoff Langd08f3b32016-09-23 15:56:30 -040090{
Geoff Lang2291c932016-11-18 14:10:17 -050091 const gl::FramebufferAttachment *readAttachment = mState.getReadAttachment();
92 if (readAttachment == nullptr)
93 {
94 return GL_NONE;
95 }
96
97 const gl::Format &format = readAttachment->getFormat();
98 ASSERT(format.info != nullptr);
99 return format.info->getReadPixelsFormat();
Geoff Langd08f3b32016-09-23 15:56:30 -0400100}
101
Jamie Madill4928b7c2017-06-20 12:57:39 -0400102GLenum FramebufferNULL::getImplementationColorReadType(const gl::Context *context) const
Geoff Langd08f3b32016-09-23 15:56:30 -0400103{
Geoff Lang2291c932016-11-18 14:10:17 -0500104 const gl::FramebufferAttachment *readAttachment = mState.getReadAttachment();
105 if (readAttachment == nullptr)
106 {
107 return GL_NONE;
108 }
109
110 const gl::Format &format = readAttachment->getFormat();
111 ASSERT(format.info != nullptr);
112 return format.info->getReadPixelsType();
Geoff Langd08f3b32016-09-23 15:56:30 -0400113}
114
Jamie Madillc564c072017-06-01 12:45:42 -0400115gl::Error FramebufferNULL::readPixels(const gl::Context *context,
Corentin Wallezaf11b532017-08-30 15:51:36 -0400116 const gl::Rectangle &origArea,
Geoff Langd08f3b32016-09-23 15:56:30 -0400117 GLenum format,
118 GLenum type,
Corentin Wallezaf11b532017-08-30 15:51:36 -0400119 void *ptrOrOffset) const
Geoff Langd08f3b32016-09-23 15:56:30 -0400120{
Corentin Wallezaf11b532017-08-30 15:51:36 -0400121 const gl::PixelPackState &packState = context->getGLState().getPackState();
122
123 // Get the pointer to write to from the argument or the pack buffer
124 GLubyte *pixels = nullptr;
125 if (packState.pixelBuffer.get() != nullptr)
126 {
127 BufferNULL *pixelBuffer = GetImplAs<BufferNULL>(packState.pixelBuffer.get());
128 pixels = reinterpret_cast<GLubyte *>(pixelBuffer->getDataPtr());
129 pixels += reinterpret_cast<intptr_t>(ptrOrOffset);
130 }
131 else
132 {
133 pixels = reinterpret_cast<GLubyte *>(ptrOrOffset);
134 }
135
136 // Clip read area to framebuffer.
137 const gl::Extents fbSize = getState().getReadAttachment()->getSize();
138 const gl::Rectangle fbRect(0, 0, fbSize.width, fbSize.height);
139 gl::Rectangle area;
140 if (!ClipRectangle(origArea, fbRect, &area))
141 {
142 // nothing to read
143 return gl::NoError();
144 }
145
146 // Compute size of unclipped rows and initial skip
147 const gl::InternalFormat &glFormat = gl::GetInternalFormatInfo(format, type);
148
149 GLuint rowBytes = 0;
150 ANGLE_TRY_RESULT(
151 glFormat.computeRowPitch(type, origArea.width, packState.alignment, packState.rowLength),
152 rowBytes);
153
154 GLuint skipBytes = 0;
155 ANGLE_TRY_RESULT(glFormat.computeSkipBytes(rowBytes, 0, packState, false), skipBytes);
156 pixels += skipBytes;
157
158 // Skip OOB region up to first in bounds pixel
159 int leftClip = area.x - origArea.x;
160 int topClip = area.y - origArea.y;
161 pixels += leftClip * glFormat.pixelBytes + topClip * rowBytes;
162
163 // Write the in-bounds readpixels data with non-zero values
164 for (GLint y = area.y; y < area.y + area.height; ++y)
165 {
166 memset(pixels, 42, glFormat.pixelBytes * area.width);
167 pixels += rowBytes;
168 }
169
Geoff Lang76cdbd52016-09-23 16:51:04 -0400170 return gl::NoError();
Geoff Langd08f3b32016-09-23 15:56:30 -0400171}
172
Jamie Madillc564c072017-06-01 12:45:42 -0400173gl::Error FramebufferNULL::blit(const gl::Context *context,
Geoff Langd08f3b32016-09-23 15:56:30 -0400174 const gl::Rectangle &sourceArea,
175 const gl::Rectangle &destArea,
176 GLbitfield mask,
177 GLenum filter)
178{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400179 return gl::NoError();
Geoff Langd08f3b32016-09-23 15:56:30 -0400180}
181
182bool FramebufferNULL::checkStatus() const
183{
Geoff Lang76cdbd52016-09-23 16:51:04 -0400184 return true;
Geoff Langd08f3b32016-09-23 15:56:30 -0400185}
186
Jamie Madillc564c072017-06-01 12:45:42 -0400187void FramebufferNULL::syncState(const gl::Context *context,
Jamie Madilldd43e6c2017-03-24 14:18:49 -0400188 const gl::Framebuffer::DirtyBits &dirtyBits)
Geoff Langd08f3b32016-09-23 15:56:30 -0400189{
Geoff Langd08f3b32016-09-23 15:56:30 -0400190}
191
JiangYizhoubddc46b2016-12-09 09:50:51 +0800192gl::Error FramebufferNULL::getSamplePosition(size_t index, GLfloat *xy) const
193{
194 return gl::NoError();
195}
196
Geoff Langd08f3b32016-09-23 15:56:30 -0400197} // namespace rx