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
12 #include "common/debug.h"
13 #include "libANGLE/Context.h"
14 #include "libANGLE/formatutils.h"
15 #include "libANGLE/renderer/null/BufferNULL.h"
16 #include "libANGLE/renderer/null/ContextNULL.h"
17
18 namespace rx
19 {
20
FramebufferNULL(const gl::FramebufferState & state)21 FramebufferNULL::FramebufferNULL(const gl::FramebufferState &state) : FramebufferImpl(state) {}
22
~FramebufferNULL()23 FramebufferNULL::~FramebufferNULL() {}
24
discard(const gl::Context * context,size_t count,const GLenum * attachments)25 angle::Result FramebufferNULL::discard(const gl::Context *context,
26 size_t count,
27 const GLenum *attachments)
28 {
29 return angle::Result::Continue;
30 }
31
invalidate(const gl::Context * context,size_t count,const GLenum * attachments)32 angle::Result FramebufferNULL::invalidate(const gl::Context *context,
33 size_t count,
34 const GLenum *attachments)
35 {
36 return angle::Result::Continue;
37 }
38
invalidateSub(const gl::Context * context,size_t count,const GLenum * attachments,const gl::Rectangle & area)39 angle::Result FramebufferNULL::invalidateSub(const gl::Context *context,
40 size_t count,
41 const GLenum *attachments,
42 const gl::Rectangle &area)
43 {
44 return angle::Result::Continue;
45 }
46
clear(const gl::Context * context,GLbitfield mask)47 angle::Result FramebufferNULL::clear(const gl::Context *context, GLbitfield mask)
48 {
49 return angle::Result::Continue;
50 }
51
clearBufferfv(const gl::Context * context,GLenum buffer,GLint drawbuffer,const GLfloat * values)52 angle::Result FramebufferNULL::clearBufferfv(const gl::Context *context,
53 GLenum buffer,
54 GLint drawbuffer,
55 const GLfloat *values)
56 {
57 return angle::Result::Continue;
58 }
59
clearBufferuiv(const gl::Context * context,GLenum buffer,GLint drawbuffer,const GLuint * values)60 angle::Result FramebufferNULL::clearBufferuiv(const gl::Context *context,
61 GLenum buffer,
62 GLint drawbuffer,
63 const GLuint *values)
64 {
65 return angle::Result::Continue;
66 }
67
clearBufferiv(const gl::Context * context,GLenum buffer,GLint drawbuffer,const GLint * values)68 angle::Result FramebufferNULL::clearBufferiv(const gl::Context *context,
69 GLenum buffer,
70 GLint drawbuffer,
71 const GLint *values)
72 {
73 return angle::Result::Continue;
74 }
75
clearBufferfi(const gl::Context * context,GLenum buffer,GLint drawbuffer,GLfloat depth,GLint stencil)76 angle::Result FramebufferNULL::clearBufferfi(const gl::Context *context,
77 GLenum buffer,
78 GLint drawbuffer,
79 GLfloat depth,
80 GLint stencil)
81 {
82 return angle::Result::Continue;
83 }
84
readPixels(const gl::Context * context,const gl::Rectangle & origArea,GLenum format,GLenum type,void * ptrOrOffset)85 angle::Result FramebufferNULL::readPixels(const gl::Context *context,
86 const gl::Rectangle &origArea,
87 GLenum format,
88 GLenum type,
89 void *ptrOrOffset)
90 {
91 const gl::PixelPackState &packState = context->getState().getPackState();
92 gl::Buffer *packBuffer = context->getState().getTargetBuffer(gl::BufferBinding::PixelPack);
93
94 // Get the pointer to write to from the argument or the pack buffer
95 GLubyte *pixels = nullptr;
96 if (packBuffer != nullptr)
97 {
98 BufferNULL *packBufferGL = GetImplAs<BufferNULL>(packBuffer);
99 pixels = reinterpret_cast<GLubyte *>(packBufferGL->getDataPtr());
100 pixels += reinterpret_cast<intptr_t>(ptrOrOffset);
101 }
102 else
103 {
104 pixels = reinterpret_cast<GLubyte *>(ptrOrOffset);
105 }
106
107 // Clip read area to framebuffer.
108 const gl::Extents fbSize = getState().getReadPixelsAttachment(format)->getSize();
109 const gl::Rectangle fbRect(0, 0, fbSize.width, fbSize.height);
110 gl::Rectangle area;
111 if (!ClipRectangle(origArea, fbRect, &area))
112 {
113 // nothing to read
114 return angle::Result::Continue;
115 }
116
117 // Compute size of unclipped rows and initial skip
118 const gl::InternalFormat &glFormat = gl::GetInternalFormatInfo(format, type);
119
120 ContextNULL *contextNull = GetImplAs<ContextNULL>(context);
121
122 GLuint rowBytes = 0;
123 ANGLE_CHECK_GL_MATH(contextNull,
124 glFormat.computeRowPitch(type, origArea.width, packState.alignment,
125 packState.rowLength, &rowBytes));
126
127 GLuint skipBytes = 0;
128 ANGLE_CHECK_GL_MATH(contextNull,
129 glFormat.computeSkipBytes(type, rowBytes, 0, packState, false, &skipBytes));
130 pixels += skipBytes;
131
132 // Skip OOB region up to first in bounds pixel
133 int leftClip = area.x - origArea.x;
134 int topClip = area.y - origArea.y;
135 pixels += leftClip * glFormat.pixelBytes + topClip * rowBytes;
136
137 // Write the in-bounds readpixels data with non-zero values
138 for (GLint y = area.y; y < area.y + area.height; ++y)
139 {
140 memset(pixels, 42, glFormat.pixelBytes * area.width);
141 pixels += rowBytes;
142 }
143
144 return angle::Result::Continue;
145 }
146
blit(const gl::Context * context,const gl::Rectangle & sourceArea,const gl::Rectangle & destArea,GLbitfield mask,GLenum filter)147 angle::Result FramebufferNULL::blit(const gl::Context *context,
148 const gl::Rectangle &sourceArea,
149 const gl::Rectangle &destArea,
150 GLbitfield mask,
151 GLenum filter)
152 {
153 return angle::Result::Continue;
154 }
155
checkStatus(const gl::Context * context) const156 bool FramebufferNULL::checkStatus(const gl::Context *context) const
157 {
158 return true;
159 }
160
syncState(const gl::Context * context,GLenum binding,const gl::Framebuffer::DirtyBits & dirtyBits)161 angle::Result FramebufferNULL::syncState(const gl::Context *context,
162 GLenum binding,
163 const gl::Framebuffer::DirtyBits &dirtyBits)
164 {
165 return angle::Result::Continue;
166 }
167
getSamplePosition(const gl::Context * context,size_t index,GLfloat * xy) const168 angle::Result FramebufferNULL::getSamplePosition(const gl::Context *context,
169 size_t index,
170 GLfloat *xy) const
171 {
172 return angle::Result::Continue;
173 }
174
175 } // namespace rx
176