Geoff Lang | d08f3b3 | 2016-09-23 15:56:30 -0400 | [diff] [blame] | 1 | // |
| 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 Wallez | af11b53 | 2017-08-30 15:51:36 -0400 | [diff] [blame] | 12 | #include "libANGLE/Context.h" |
Geoff Lang | 2291c93 | 2016-11-18 14:10:17 -0500 | [diff] [blame] | 13 | #include "libANGLE/formatutils.h" |
Corentin Wallez | af11b53 | 2017-08-30 15:51:36 -0400 | [diff] [blame] | 14 | #include "libANGLE/renderer/null/BufferNULL.h" |
Geoff Lang | 2291c93 | 2016-11-18 14:10:17 -0500 | [diff] [blame] | 15 | |
Geoff Lang | d08f3b3 | 2016-09-23 15:56:30 -0400 | [diff] [blame] | 16 | #include "common/debug.h" |
| 17 | |
| 18 | namespace rx |
| 19 | { |
| 20 | |
| 21 | FramebufferNULL::FramebufferNULL(const gl::FramebufferState &state) : FramebufferImpl(state) |
| 22 | { |
| 23 | } |
| 24 | |
| 25 | FramebufferNULL::~FramebufferNULL() |
| 26 | { |
| 27 | } |
| 28 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 29 | gl::Error FramebufferNULL::discard(const gl::Context *context, |
| 30 | size_t count, |
| 31 | const GLenum *attachments) |
Geoff Lang | d08f3b3 | 2016-09-23 15:56:30 -0400 | [diff] [blame] | 32 | { |
Geoff Lang | 76cdbd5 | 2016-09-23 16:51:04 -0400 | [diff] [blame] | 33 | return gl::NoError(); |
Geoff Lang | d08f3b3 | 2016-09-23 15:56:30 -0400 | [diff] [blame] | 34 | } |
| 35 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 36 | gl::Error FramebufferNULL::invalidate(const gl::Context *context, |
| 37 | size_t count, |
| 38 | const GLenum *attachments) |
Geoff Lang | d08f3b3 | 2016-09-23 15:56:30 -0400 | [diff] [blame] | 39 | { |
Geoff Lang | 76cdbd5 | 2016-09-23 16:51:04 -0400 | [diff] [blame] | 40 | return gl::NoError(); |
Geoff Lang | d08f3b3 | 2016-09-23 15:56:30 -0400 | [diff] [blame] | 41 | } |
| 42 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 43 | gl::Error FramebufferNULL::invalidateSub(const gl::Context *context, |
| 44 | size_t count, |
Geoff Lang | d08f3b3 | 2016-09-23 15:56:30 -0400 | [diff] [blame] | 45 | const GLenum *attachments, |
| 46 | const gl::Rectangle &area) |
| 47 | { |
Geoff Lang | 76cdbd5 | 2016-09-23 16:51:04 -0400 | [diff] [blame] | 48 | return gl::NoError(); |
Geoff Lang | d08f3b3 | 2016-09-23 15:56:30 -0400 | [diff] [blame] | 49 | } |
| 50 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 51 | gl::Error FramebufferNULL::clear(const gl::Context *context, GLbitfield mask) |
Geoff Lang | d08f3b3 | 2016-09-23 15:56:30 -0400 | [diff] [blame] | 52 | { |
Geoff Lang | 76cdbd5 | 2016-09-23 16:51:04 -0400 | [diff] [blame] | 53 | return gl::NoError(); |
Geoff Lang | d08f3b3 | 2016-09-23 15:56:30 -0400 | [diff] [blame] | 54 | } |
| 55 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 56 | gl::Error FramebufferNULL::clearBufferfv(const gl::Context *context, |
Geoff Lang | d08f3b3 | 2016-09-23 15:56:30 -0400 | [diff] [blame] | 57 | GLenum buffer, |
| 58 | GLint drawbuffer, |
| 59 | const GLfloat *values) |
| 60 | { |
Geoff Lang | 76cdbd5 | 2016-09-23 16:51:04 -0400 | [diff] [blame] | 61 | return gl::NoError(); |
Geoff Lang | d08f3b3 | 2016-09-23 15:56:30 -0400 | [diff] [blame] | 62 | } |
| 63 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 64 | gl::Error FramebufferNULL::clearBufferuiv(const gl::Context *context, |
Geoff Lang | d08f3b3 | 2016-09-23 15:56:30 -0400 | [diff] [blame] | 65 | GLenum buffer, |
| 66 | GLint drawbuffer, |
| 67 | const GLuint *values) |
| 68 | { |
Geoff Lang | 76cdbd5 | 2016-09-23 16:51:04 -0400 | [diff] [blame] | 69 | return gl::NoError(); |
Geoff Lang | d08f3b3 | 2016-09-23 15:56:30 -0400 | [diff] [blame] | 70 | } |
| 71 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 72 | gl::Error FramebufferNULL::clearBufferiv(const gl::Context *context, |
Geoff Lang | d08f3b3 | 2016-09-23 15:56:30 -0400 | [diff] [blame] | 73 | GLenum buffer, |
| 74 | GLint drawbuffer, |
| 75 | const GLint *values) |
| 76 | { |
Geoff Lang | 76cdbd5 | 2016-09-23 16:51:04 -0400 | [diff] [blame] | 77 | return gl::NoError(); |
Geoff Lang | d08f3b3 | 2016-09-23 15:56:30 -0400 | [diff] [blame] | 78 | } |
| 79 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 80 | gl::Error FramebufferNULL::clearBufferfi(const gl::Context *context, |
Geoff Lang | d08f3b3 | 2016-09-23 15:56:30 -0400 | [diff] [blame] | 81 | GLenum buffer, |
| 82 | GLint drawbuffer, |
| 83 | GLfloat depth, |
| 84 | GLint stencil) |
| 85 | { |
Geoff Lang | 76cdbd5 | 2016-09-23 16:51:04 -0400 | [diff] [blame] | 86 | return gl::NoError(); |
Geoff Lang | d08f3b3 | 2016-09-23 15:56:30 -0400 | [diff] [blame] | 87 | } |
| 88 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 89 | GLenum FramebufferNULL::getImplementationColorReadFormat(const gl::Context *context) const |
Geoff Lang | d08f3b3 | 2016-09-23 15:56:30 -0400 | [diff] [blame] | 90 | { |
Geoff Lang | 2291c93 | 2016-11-18 14:10:17 -0500 | [diff] [blame] | 91 | 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 Lang | d08f3b3 | 2016-09-23 15:56:30 -0400 | [diff] [blame] | 100 | } |
| 101 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 102 | GLenum FramebufferNULL::getImplementationColorReadType(const gl::Context *context) const |
Geoff Lang | d08f3b3 | 2016-09-23 15:56:30 -0400 | [diff] [blame] | 103 | { |
Geoff Lang | 2291c93 | 2016-11-18 14:10:17 -0500 | [diff] [blame] | 104 | 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); |
Geoff Lang | c71ea66 | 2017-09-26 17:06:02 -0400 | [diff] [blame^] | 112 | return format.info->getReadPixelsType(context->getClientVersion()); |
Geoff Lang | d08f3b3 | 2016-09-23 15:56:30 -0400 | [diff] [blame] | 113 | } |
| 114 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 115 | gl::Error FramebufferNULL::readPixels(const gl::Context *context, |
Corentin Wallez | af11b53 | 2017-08-30 15:51:36 -0400 | [diff] [blame] | 116 | const gl::Rectangle &origArea, |
Geoff Lang | d08f3b3 | 2016-09-23 15:56:30 -0400 | [diff] [blame] | 117 | GLenum format, |
| 118 | GLenum type, |
Jamie Madill | d482615 | 2017-09-21 11:18:59 -0400 | [diff] [blame] | 119 | void *ptrOrOffset) |
Geoff Lang | d08f3b3 | 2016-09-23 15:56:30 -0400 | [diff] [blame] | 120 | { |
Corentin Wallez | af11b53 | 2017-08-30 15:51:36 -0400 | [diff] [blame] | 121 | 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 Lang | 76cdbd5 | 2016-09-23 16:51:04 -0400 | [diff] [blame] | 170 | return gl::NoError(); |
Geoff Lang | d08f3b3 | 2016-09-23 15:56:30 -0400 | [diff] [blame] | 171 | } |
| 172 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 173 | gl::Error FramebufferNULL::blit(const gl::Context *context, |
Geoff Lang | d08f3b3 | 2016-09-23 15:56:30 -0400 | [diff] [blame] | 174 | const gl::Rectangle &sourceArea, |
| 175 | const gl::Rectangle &destArea, |
| 176 | GLbitfield mask, |
| 177 | GLenum filter) |
| 178 | { |
Geoff Lang | 76cdbd5 | 2016-09-23 16:51:04 -0400 | [diff] [blame] | 179 | return gl::NoError(); |
Geoff Lang | d08f3b3 | 2016-09-23 15:56:30 -0400 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | bool FramebufferNULL::checkStatus() const |
| 183 | { |
Geoff Lang | 76cdbd5 | 2016-09-23 16:51:04 -0400 | [diff] [blame] | 184 | return true; |
Geoff Lang | d08f3b3 | 2016-09-23 15:56:30 -0400 | [diff] [blame] | 185 | } |
| 186 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 187 | void FramebufferNULL::syncState(const gl::Context *context, |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 188 | const gl::Framebuffer::DirtyBits &dirtyBits) |
Geoff Lang | d08f3b3 | 2016-09-23 15:56:30 -0400 | [diff] [blame] | 189 | { |
Geoff Lang | d08f3b3 | 2016-09-23 15:56:30 -0400 | [diff] [blame] | 190 | } |
| 191 | |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 192 | gl::Error FramebufferNULL::getSamplePosition(size_t index, GLfloat *xy) const |
| 193 | { |
| 194 | return gl::NoError(); |
| 195 | } |
| 196 | |
Geoff Lang | d08f3b3 | 2016-09-23 15:56:30 -0400 | [diff] [blame] | 197 | } // namespace rx |