Commit c39901ec by Nicolas Capens

Refactor buffer clearing.

Bug 27460431 Change-Id: I90de3285c86c0d3187969270dcbd78a8b02feee9 Reviewed-on: https://swiftshader-review.googlesource.com/4978Tested-by: 's avatarNicolas Capens <capn@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent dc4ae86d
...@@ -383,7 +383,6 @@ namespace D3D9 ...@@ -383,7 +383,6 @@ namespace D3D9
count = 1; count = 1;
D3DRECT rect; D3DRECT rect;
rect.x1 = viewport.X; rect.x1 = viewport.X;
rect.x2 = viewport.X + viewport.Width; rect.x2 = viewport.X + viewport.Width;
rect.y1 = viewport.Y; rect.y1 = viewport.Y;
...@@ -394,36 +393,13 @@ namespace D3D9 ...@@ -394,36 +393,13 @@ namespace D3D9
for(unsigned int i = 0; i < count; i++) for(unsigned int i = 0; i < count; i++)
{ {
D3DRECT rect = rects[i]; sw::SliceRect clearRect(rects[i].x1, rects[i].y1, rects[i].x2, rects[i].y2, 0);
// Clamp against viewport
if(rect.x1 < (int)viewport.X) rect.x1 = viewport.X;
if(rect.x2 < (int)viewport.X) rect.x2 = viewport.X;
if(rect.x1 > (int)viewport.X + (int)viewport.Width) rect.x1 = viewport.X + viewport.Width;
if(rect.x2 > (int)viewport.X + (int)viewport.Width) rect.x2 = viewport.X + viewport.Width;
if(rect.y1 < (int)viewport.Y) rect.y1 = viewport.Y; clearRect.clip(viewport.X, viewport.Y, viewport.X + viewport.Width, viewport.Y + viewport.Height);
if(rect.y2 < (int)viewport.Y) rect.y2 = viewport.Y;
if(rect.y1 > (int)viewport.Y + (int)viewport.Height) rect.y1 = viewport.Y + viewport.Height;
if(rect.y2 > (int)viewport.Y + (int)viewport.Height) rect.y2 = viewport.Y + viewport.Height;
// Clamp against scissor rectangle
if(scissorEnable) if(scissorEnable)
{ {
if(rect.x1 < (int)scissorRect.left) rect.x1 = scissorRect.left; clearRect.clip(scissorRect.left, scissorRect.top, scissorRect.right, scissorRect.bottom);
if(rect.x2 < (int)scissorRect.left) rect.x2 = scissorRect.left;
if(rect.x1 > (int)scissorRect.right) rect.x1 = scissorRect.right;
if(rect.x2 > (int)scissorRect.right) rect.x2 = scissorRect.right;
if(rect.y1 < (int)scissorRect.top) rect.y1 = scissorRect.top;
if(rect.y2 < (int)scissorRect.top) rect.y2 = scissorRect.top;
if(rect.y1 > (int)scissorRect.bottom) rect.y1 = scissorRect.bottom;
if(rect.y2 > (int)scissorRect.bottom) rect.y2 = scissorRect.bottom;
}
if(flags & D3DCLEAR_STENCIL)
{
depthStencil->clearStencilBuffer(stencil, 0xFF, rect.x1, rect.y1, rect.x2 - rect.x1, rect.y2 - rect.y1);
} }
if(flags & D3DCLEAR_TARGET) if(flags & D3DCLEAR_TARGET)
...@@ -448,21 +424,20 @@ namespace D3D9 ...@@ -448,21 +424,20 @@ namespace D3D9
rgba[2] = sw::linearToSRGB(rgba[2]); rgba[2] = sw::linearToSRGB(rgba[2]);
} }
sw::SliceRect sliceRect; renderer->clear(rgba, sw::FORMAT_A32B32G32R32F, renderTarget[index], clearRect, 0xF);
if(renderTarget[index]->getClearRect(rect.x1, rect.y1, rect.x2 - rect.x1, rect.y2 - rect.y1, sliceRect))
{
renderer->clear(rgba, sw::FORMAT_A32B32G32R32F, renderTarget[index], sliceRect, 0xF);
}
} }
} }
} }
if(flags & D3DCLEAR_ZBUFFER) if(flags & D3DCLEAR_ZBUFFER)
{ {
if(z > 1) z = 1; z = sw::clamp01(z);
if(z < 0) z = 0; depthStencil->clearDepth(z, clearRect.x0, clearRect.y0, clearRect.width(), clearRect.height());
}
depthStencil->clearDepthBuffer(z, rect.x1, rect.y1, rect.x2 - rect.x1, rect.y2 - rect.y1); if(flags & D3DCLEAR_STENCIL)
{
depthStencil->clearStencil(stencil, 0xFF, clearRect.x0, clearRect.y0, clearRect.width(), clearRect.height());
} }
} }
......
...@@ -185,17 +185,11 @@ namespace gl ...@@ -185,17 +185,11 @@ namespace gl
return; return;
} }
int x0 = 0; sw::SliceRect clearRect = renderTarget->getRect();
int y0 = 0;
int width = renderTarget->getWidth();
int height = renderTarget->getHeight();
if(scissorEnable) // Clamp against scissor rectangle if(scissorEnable)
{ {
if(x0 < scissorRect.x0) x0 = scissorRect.x0; clearRect.clip(scissorRect.x0, scissorRect.y0, scissorRect.x1, scissorRect.y1);
if(y0 < scissorRect.y0) y0 = scissorRect.y0;
if(width > scissorRect.x1 - scissorRect.x0) width = scissorRect.x1 - scissorRect.x0;
if(height > scissorRect.y1 - scissorRect.y0) height = scissorRect.y1 - scissorRect.y0;
} }
float rgba[4]; float rgba[4];
...@@ -204,11 +198,7 @@ namespace gl ...@@ -204,11 +198,7 @@ namespace gl
rgba[2] = blue; rgba[2] = blue;
rgba[3] = alpha; rgba[3] = alpha;
sw::SliceRect sliceRect; clear(rgba, FORMAT_A32B32G32R32F, renderTarget, clearRect, rgbaMask);
if(renderTarget->getClearRect(x0, y0, width, height, sliceRect))
{
clear(rgba, FORMAT_A32B32G32R32F, renderTarget, sliceRect, rgbaMask);
}
} }
void Device::clearDepth(float z) void Device::clearDepth(float z)
...@@ -218,23 +208,15 @@ namespace gl ...@@ -218,23 +208,15 @@ namespace gl
return; return;
} }
if(z > 1) z = 1; z = clamp01(z);
if(z < 0) z = 0; sw::SliceRect clearRect = depthStencil->getRect();
int x0 = 0; if(scissorEnable)
int y0 = 0;
int width = depthStencil->getWidth();
int height = depthStencil->getHeight();
if(scissorEnable) // Clamp against scissor rectangle
{ {
if(x0 < scissorRect.x0) x0 = scissorRect.x0; clearRect.clip(scissorRect.x0, scissorRect.y0, scissorRect.x1, scissorRect.y1);
if(y0 < scissorRect.y0) y0 = scissorRect.y0;
if(width > scissorRect.x1 - scissorRect.x0) width = scissorRect.x1 - scissorRect.x0;
if(height > scissorRect.y1 - scissorRect.y0) height = scissorRect.y1 - scissorRect.y0;
} }
depthStencil->clearDepthBuffer(z, x0, y0, width, height); depthStencil->clearDepth(z, clearRect.x0, clearRect.y0, clearRect.width(), clearRect.height());
} }
void Device::clearStencil(unsigned int stencil, unsigned int mask) void Device::clearStencil(unsigned int stencil, unsigned int mask)
...@@ -244,20 +226,14 @@ namespace gl ...@@ -244,20 +226,14 @@ namespace gl
return; return;
} }
int x0 = 0; sw::SliceRect clearRect = depthStencil->getRect();
int y0 = 0;
int width = depthStencil->getWidth();
int height = depthStencil->getHeight();
if(scissorEnable) // Clamp against scissor rectangle if(scissorEnable)
{ {
if(x0 < scissorRect.x0) x0 = scissorRect.x0; clearRect.clip(scissorRect.x0, scissorRect.y0, scissorRect.x1, scissorRect.y1);
if(y0 < scissorRect.y0) y0 = scissorRect.y0;
if(width > scissorRect.x1 - scissorRect.x0) width = scissorRect.x1 - scissorRect.x0;
if(height > scissorRect.y1 - scissorRect.y0) height = scissorRect.y1 - scissorRect.y0;
} }
depthStencil->clearStencilBuffer(stencil, mask, x0, y0, width, height); depthStencil->clearStencil(stencil, mask, clearRect.x0, clearRect.y0, clearRect.width(), clearRect.height());
} }
Image *Device::createDepthStencilSurface(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool discard) Image *Device::createDepthStencilSurface(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool discard)
......
...@@ -150,30 +150,20 @@ namespace es1 ...@@ -150,30 +150,20 @@ namespace es1
return; return;
} }
int x0 = 0;
int y0 = 0;
int width = renderTarget->getWidth();
int height = renderTarget->getHeight();
if(scissorEnable) // Clamp against scissor rectangle
{
if(x0 < scissorRect.x0) x0 = scissorRect.x0;
if(y0 < scissorRect.y0) y0 = scissorRect.y0;
if(width > scissorRect.x1 - scissorRect.x0) width = scissorRect.x1 - scissorRect.x0;
if(height > scissorRect.y1 - scissorRect.y0) height = scissorRect.y1 - scissorRect.y0;
}
float rgba[4]; float rgba[4];
rgba[0] = red; rgba[0] = red;
rgba[1] = green; rgba[1] = green;
rgba[2] = blue; rgba[2] = blue;
rgba[3] = alpha; rgba[3] = alpha;
sw::SliceRect sliceRect; sw::SliceRect clearRect = renderTarget->getRect();
if(renderTarget->getClearRect(x0, y0, width, height, sliceRect))
if(scissorEnable)
{ {
clear(rgba, FORMAT_A32B32G32R32F, renderTarget, sliceRect, rgbaMask); clearRect.clip(scissorRect.x0, scissorRect.y0, scissorRect.x1, scissorRect.y1);
} }
clear(rgba, FORMAT_A32B32G32R32F, renderTarget, clearRect, rgbaMask);
} }
void Device::clearDepth(float z) void Device::clearDepth(float z)
...@@ -183,23 +173,15 @@ namespace es1 ...@@ -183,23 +173,15 @@ namespace es1
return; return;
} }
if(z > 1) z = 1; z = clamp01(z);
if(z < 0) z = 0; sw::SliceRect clearRect = depthBuffer->getRect();
int x0 = 0;
int y0 = 0;
int width = depthBuffer->getWidth();
int height = depthBuffer->getHeight();
if(scissorEnable) // Clamp against scissor rectangle if(scissorEnable)
{ {
if(x0 < scissorRect.x0) x0 = scissorRect.x0; clearRect.clip(scissorRect.x0, scissorRect.y0, scissorRect.x1, scissorRect.y1);
if(y0 < scissorRect.y0) y0 = scissorRect.y0;
if(width > scissorRect.x1 - scissorRect.x0) width = scissorRect.x1 - scissorRect.x0;
if(height > scissorRect.y1 - scissorRect.y0) height = scissorRect.y1 - scissorRect.y0;
} }
depthBuffer->clearDepthBuffer(z, x0, y0, width, height); depthBuffer->clearDepth(z, clearRect.x0, clearRect.y0, clearRect.width(), clearRect.height());
} }
void Device::clearStencil(unsigned int stencil, unsigned int mask) void Device::clearStencil(unsigned int stencil, unsigned int mask)
...@@ -209,20 +191,14 @@ namespace es1 ...@@ -209,20 +191,14 @@ namespace es1
return; return;
} }
int x0 = 0; sw::SliceRect clearRect = stencilBuffer->getRect();
int y0 = 0;
int width = stencilBuffer->getWidth();
int height = stencilBuffer->getHeight();
if(scissorEnable) // Clamp against scissor rectangle if(scissorEnable)
{ {
if(x0 < scissorRect.x0) x0 = scissorRect.x0; clearRect.clip(scissorRect.x0, scissorRect.y0, scissorRect.x1, scissorRect.y1);
if(y0 < scissorRect.y0) y0 = scissorRect.y0;
if(width > scissorRect.x1 - scissorRect.x0) width = scissorRect.x1 - scissorRect.x0;
if(height > scissorRect.y1 - scissorRect.y0) height = scissorRect.y1 - scissorRect.y0;
} }
stencilBuffer->clearStencilBuffer(stencil, mask, x0, y0, width, height); stencilBuffer->clearStencil(stencil, mask, clearRect.x0, clearRect.y0, clearRect.width(), clearRect.height());
} }
egl::Image *Device::createDepthStencilSurface(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool discard) egl::Image *Device::createDepthStencilSurface(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool discard)
......
...@@ -2754,18 +2754,6 @@ void Context::applyScissor(int width, int height) ...@@ -2754,18 +2754,6 @@ void Context::applyScissor(int width, int height)
} }
} }
egl::Image *Context::getScissoredImage(GLint drawbuffer, int &x0, int &y0, int &width, int &height, bool depthStencil)
{
Framebuffer* framebuffer = getDrawFramebuffer();
egl::Image* image = depthStencil ? framebuffer->getDepthStencil() : framebuffer->getRenderTarget(drawbuffer);
applyScissor(image->getWidth(), image->getHeight());
device->getScissoredRegion(image, x0, y0, width, height);
return image;
}
// Applies the render target surface, depth stencil surface, viewport rectangle and scissor rectangle // Applies the render target surface, depth stencil surface, viewport rectangle and scissor rectangle
bool Context::applyRenderTarget() bool Context::applyRenderTarget()
{ {
...@@ -3407,18 +3395,24 @@ void Context::clear(GLbitfield mask) ...@@ -3407,18 +3395,24 @@ void Context::clear(GLbitfield mask)
void Context::clearColorBuffer(GLint drawbuffer, void *value, sw::Format format) void Context::clearColorBuffer(GLint drawbuffer, void *value, sw::Format format)
{ {
unsigned int rgbaMask = getColorMask(); unsigned int rgbaMask = getColorMask();
if(device && rgbaMask && !mState.rasterizerDiscardEnabled) if(rgbaMask && !mState.rasterizerDiscardEnabled)
{ {
int x0(0), y0(0), width(0), height(0); Framebuffer *framebuffer = getDrawFramebuffer();
egl::Image* image = getScissoredImage(drawbuffer, x0, y0, width, height, false); egl::Image *colorbuffer = framebuffer->getRenderTarget(drawbuffer);
sw::SliceRect sliceRect; if(colorbuffer)
if(image->getClearRect(x0, y0, width, height, sliceRect))
{ {
device->clear(value, format, image, sliceRect, rgbaMask); sw::SliceRect clearRect = colorbuffer->getRect();
if(mState.scissorTestEnabled)
{
clearRect.clip(mState.scissorX, mState.scissorY, mState.scissorX + mState.scissorWidth, mState.scissorY + mState.scissorHeight);
} }
image->release(); device->clear(value, format, colorbuffer, clearRect, rgbaMask);
colorbuffer->release();
}
} }
} }
...@@ -3437,52 +3431,51 @@ void Context::clearColorBuffer(GLint drawbuffer, const GLfloat *value) ...@@ -3437,52 +3431,51 @@ void Context::clearColorBuffer(GLint drawbuffer, const GLfloat *value)
clearColorBuffer(drawbuffer, (void*)value, sw::FORMAT_A32B32G32R32F); clearColorBuffer(drawbuffer, (void*)value, sw::FORMAT_A32B32G32R32F);
} }
void Context::clearDepthBuffer(GLint drawbuffer, const GLfloat *value) void Context::clearDepthBuffer(const GLfloat value)
{ {
if(device && mState.depthMask && !mState.rasterizerDiscardEnabled) if(mState.depthMask && !mState.rasterizerDiscardEnabled)
{ {
int x0(0), y0(0), width(0), height(0); Framebuffer *framebuffer = getDrawFramebuffer();
egl::Image* image = getScissoredImage(drawbuffer, x0, y0, width, height, true); egl::Image *depthbuffer = framebuffer->getDepthStencil();
float depth = clamp01(value[0]);
image->clearDepthBuffer(depth, x0, y0, width, height);
image->release(); if(depthbuffer)
} {
} float depth = clamp01(value);
sw::SliceRect clearRect = depthbuffer->getRect();
void Context::clearStencilBuffer(GLint drawbuffer, const GLint *value) if(mState.scissorTestEnabled)
{
if(device && mState.stencilWritemask && !mState.rasterizerDiscardEnabled)
{ {
int x0(0), y0(0), width(0), height(0); clearRect.clip(mState.scissorX, mState.scissorY, mState.scissorX + mState.scissorWidth, mState.scissorY + mState.scissorHeight);
egl::Image* image = getScissoredImage(drawbuffer, x0, y0, width, height, true); }
unsigned char stencil = value[0] < 0 ? 0 : static_cast<unsigned char>(value[0] & 0x000000FF); depthbuffer->clearDepth(depth, clearRect.x0, clearRect.y0, clearRect.width(), clearRect.height());
image->clearStencilBuffer(stencil, static_cast<unsigned char>(mState.stencilWritemask), x0, y0, width, height);
image->release(); depthbuffer->release();
}
} }
} }
void Context::clearDepthStencilBuffer(GLint drawbuffer, GLfloat depth, GLint stencil) void Context::clearStencilBuffer(const GLint value)
{ {
if(device && (mState.depthMask || mState.stencilWritemask) && !mState.rasterizerDiscardEnabled) if(mState.stencilWritemask && !mState.rasterizerDiscardEnabled)
{ {
int x0(0), y0(0), width(0), height(0); Framebuffer *framebuffer = getDrawFramebuffer();
egl::Image* image = getScissoredImage(drawbuffer, x0, y0, width, height, true); egl::Image *stencilbuffer = framebuffer->getDepthStencil();
if(mState.stencilWritemask) if(stencilbuffer)
{ {
image->clearStencilBuffer(static_cast<unsigned char>(stencil & 0x000000FF), static_cast<unsigned char>(mState.stencilWritemask), x0, y0, width, height); unsigned char stencil = value < 0 ? 0 : static_cast<unsigned char>(value & 0x000000FF);
} sw::SliceRect clearRect = stencilbuffer->getRect();
if(mState.depthMask) if(mState.scissorTestEnabled)
{ {
image->clearDepthBuffer(clamp01(depth), x0, y0, width, height); clearRect.clip(mState.scissorX, mState.scissorY, mState.scissorX + mState.scissorWidth, mState.scissorY + mState.scissorHeight);
} }
image->release(); stencilbuffer->clearStencil(stencil, static_cast<unsigned char>(mState.stencilWritemask), clearRect.x0, clearRect.y0, clearRect.width(), clearRect.height());
stencilbuffer->release();
}
} }
} }
......
...@@ -644,9 +644,8 @@ public: ...@@ -644,9 +644,8 @@ public:
void clearColorBuffer(GLint drawbuffer, const GLint *value); void clearColorBuffer(GLint drawbuffer, const GLint *value);
void clearColorBuffer(GLint drawbuffer, const GLuint *value); void clearColorBuffer(GLint drawbuffer, const GLuint *value);
void clearColorBuffer(GLint drawbuffer, const GLfloat *value); void clearColorBuffer(GLint drawbuffer, const GLfloat *value);
void clearDepthBuffer(GLint drawbuffer, const GLfloat *value); void clearDepthBuffer(const GLfloat value);
void clearStencilBuffer(GLint drawbuffer, const GLint *value); void clearStencilBuffer(const GLint value);
void clearDepthStencilBuffer(GLint drawbuffer, GLfloat depth, GLint stencil);
void drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount = 1); void drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount = 1);
void drawElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices, GLsizei instanceCount = 1); void drawElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices, GLsizei instanceCount = 1);
void finish(); void finish();
...@@ -677,7 +676,6 @@ public: ...@@ -677,7 +676,6 @@ public:
private: private:
virtual ~Context(); virtual ~Context();
egl::Image *getScissoredImage(GLint drawbuffer, int &x0, int &y0, int &width, int &height, bool depthStencil);
void applyScissor(int width, int height); void applyScissor(int width, int height);
bool applyRenderTarget(); bool applyRenderTarget();
void applyState(GLenum drawMode); void applyState(GLenum drawMode);
......
...@@ -173,22 +173,6 @@ namespace es2 ...@@ -173,22 +173,6 @@ namespace es2
delete context; delete context;
} }
void Device::getScissoredRegion(egl::Image *sourceSurface, int &x0, int &y0, int& width, int& height) const
{
x0 = 0;
y0 = 0;
width = sourceSurface->getWidth();
height = sourceSurface->getHeight();
if(scissorEnable) // Clamp against scissor rectangle
{
if(x0 < scissorRect.x0) x0 = scissorRect.x0;
if(y0 < scissorRect.y0) y0 = scissorRect.y0;
if(width > scissorRect.x1 - scissorRect.x0) width = scissorRect.x1 - scissorRect.x0;
if(height > scissorRect.y1 - scissorRect.y0) height = scissorRect.y1 - scissorRect.y0;
}
}
void Device::clearColor(float red, float green, float blue, float alpha, unsigned int rgbaMask) void Device::clearColor(float red, float green, float blue, float alpha, unsigned int rgbaMask)
{ {
if(!rgbaMask) if(!rgbaMask)
...@@ -206,17 +190,17 @@ namespace es2 ...@@ -206,17 +190,17 @@ namespace es2
{ {
if(renderTarget[i]) if(renderTarget[i])
{ {
int x0(0), y0(0), width(0), height(0); sw::SliceRect clearRect = renderTarget[i]->getRect();
getScissoredRegion(renderTarget[i], x0, y0, width, height);
sw::SliceRect sliceRect; if(scissorEnable)
if(renderTarget[i]->getClearRect(x0, y0, width, height, sliceRect))
{ {
clearRect.clip(scissorRect.x0, scissorRect.y0, scissorRect.x1, scissorRect.y1);
}
int depth = sw::max(renderTarget[i]->getDepth(), 1); int depth = sw::max(renderTarget[i]->getDepth(), 1);
for(sliceRect.slice = 0; sliceRect.slice < depth; ++sliceRect.slice) for(clearRect.slice = 0; clearRect.slice < depth; clearRect.slice++)
{ {
clear(rgba, FORMAT_A32B32G32R32F, renderTarget[i], sliceRect, rgbaMask); clear(rgba, FORMAT_A32B32G32R32F, renderTarget[i], clearRect, rgbaMask);
}
} }
} }
} }
...@@ -229,13 +213,15 @@ namespace es2 ...@@ -229,13 +213,15 @@ namespace es2
return; return;
} }
if(z > 1) z = 1; z = clamp01(z);
if(z < 0) z = 0; sw::SliceRect clearRect = depthBuffer->getRect();
int x0(0), y0(0), width(0), height(0); if(scissorEnable)
getScissoredRegion(depthBuffer, x0, y0, width, height); {
clearRect.clip(scissorRect.x0, scissorRect.y0, scissorRect.x1, scissorRect.y1);
}
depthBuffer->clearDepthBuffer(z, x0, y0, width, height); depthBuffer->clearDepth(z, clearRect.x0, clearRect.y0, clearRect.width(), clearRect.height());
} }
void Device::clearStencil(unsigned int stencil, unsigned int mask) void Device::clearStencil(unsigned int stencil, unsigned int mask)
...@@ -245,10 +231,14 @@ namespace es2 ...@@ -245,10 +231,14 @@ namespace es2
return; return;
} }
int x0(0), y0(0), width(0), height(0); sw::SliceRect clearRect = stencilBuffer->getRect();
getScissoredRegion(stencilBuffer, x0, y0, width, height);
if(scissorEnable)
{
clearRect.clip(scissorRect.x0, scissorRect.y0, scissorRect.x1, scissorRect.y1);
}
stencilBuffer->clearStencilBuffer(stencil, mask, x0, y0, width, height); stencilBuffer->clearStencil(stencil, mask, clearRect.x0, clearRect.y0, clearRect.width(), clearRect.height());
} }
egl::Image *Device::createDepthStencilSurface(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool discard) egl::Image *Device::createDepthStencilSurface(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool discard)
......
...@@ -62,8 +62,6 @@ namespace es2 ...@@ -62,8 +62,6 @@ namespace es2
virtual bool stretchCube(sw::Surface *sourceSurface, sw::Surface *destSurface); virtual bool stretchCube(sw::Surface *sourceSurface, sw::Surface *destSurface);
virtual void finish(); virtual void finish();
void getScissoredRegion(egl::Image *sourceSurface, int &x0, int &y0, int& width, int& height) const;
private: private:
sw::Context *const context; sw::Context *const context;
......
...@@ -2586,7 +2586,7 @@ GL_APICALL void GL_APIENTRY glClearBufferiv(GLenum buffer, GLint drawbuffer, con ...@@ -2586,7 +2586,7 @@ GL_APICALL void GL_APIENTRY glClearBufferiv(GLenum buffer, GLint drawbuffer, con
} }
else else
{ {
context->clearStencilBuffer(drawbuffer, value); context->clearStencilBuffer(value[0]);
} }
break; break;
default: default:
...@@ -2650,7 +2650,7 @@ GL_APICALL void GL_APIENTRY glClearBufferfv(GLenum buffer, GLint drawbuffer, con ...@@ -2650,7 +2650,7 @@ GL_APICALL void GL_APIENTRY glClearBufferfv(GLenum buffer, GLint drawbuffer, con
} }
else else
{ {
context->clearDepthBuffer(drawbuffer, value); context->clearDepthBuffer(value[0]);
} }
break; break;
default: default:
...@@ -2677,7 +2677,8 @@ GL_APICALL void GL_APIENTRY glClearBufferfi(GLenum buffer, GLint drawbuffer, GLf ...@@ -2677,7 +2677,8 @@ GL_APICALL void GL_APIENTRY glClearBufferfi(GLenum buffer, GLint drawbuffer, GLf
} }
else else
{ {
context->clearDepthStencilBuffer(drawbuffer, depth, stencil); context->clearDepthBuffer(depth);
context->clearStencilBuffer(stencil);
} }
break; break;
default: default:
......
...@@ -3075,29 +3075,12 @@ namespace sw ...@@ -3075,29 +3075,12 @@ namespace sw
return (rect.x0 == 0 && rect.y0 == 0 && rect.x1 == internal.width && rect.y1 == internal.height && internal.depth == 1); return (rect.x0 == 0 && rect.y0 == 0 && rect.x1 == internal.width && rect.y1 == internal.height && internal.depth == 1);
} }
bool Surface::getClearRect(int x0, int y0, int width, int height, SliceRect& rect) const SliceRect Surface::getRect() const
{ {
// Not overlapping return SliceRect(0, 0, internal.width, internal.height, 0);
if(x0 > internal.width) return false;
if(y0 > internal.height) return false;
if(x0 + width < 0) return false;
if(y0 + height < 0) return false;
// Clip against dimensions
if(x0 < 0) { width += x0; x0 = 0; }
if(x0 + width > internal.width) width = internal.width - x0;
if(y0 < 0) { height += y0; y0 = 0; }
if(y0 + height > internal.height) height = internal.height - y0;
rect.x0 = x0;
rect.x1 = x0 + width;
rect.y0 = y0;
rect.y1 = y0 + height;
return true;
} }
void Surface::clearDepthBuffer(float depth, int x0, int y0, int width, int height) void Surface::clearDepth(float depth, int x0, int y0, int width, int height)
{ {
if(width == 0 || height == 0) return; if(width == 0 || height == 0) return;
...@@ -3222,7 +3205,7 @@ namespace sw ...@@ -3222,7 +3205,7 @@ namespace sw
} }
} }
void Surface::clearStencilBuffer(unsigned char s, unsigned char mask, int x0, int y0, int width, int height) void Surface::clearStencil(unsigned char s, unsigned char mask, int x0, int y0, int width, int height)
{ {
if(mask == 0 || width == 0 || height == 0) return; if(mask == 0 || width == 0 || height == 0) return;
......
...@@ -27,6 +27,9 @@ namespace sw ...@@ -27,6 +27,9 @@ namespace sw
void clip(int minX, int minY, int maxX, int maxY); void clip(int minX, int minY, int maxX, int maxY);
int width() const { return x1 - x0; }
int height() const { return y1 - y0; }
int x0; // Inclusive int x0; // Inclusive
int y0; // Inclusive int y0; // Inclusive
int x1; // Exclusive int x1; // Exclusive
...@@ -283,9 +286,9 @@ namespace sw ...@@ -283,9 +286,9 @@ namespace sw
inline int getSuperSampleCount() const; inline int getSuperSampleCount() const;
bool isEntire(const SliceRect& rect) const; bool isEntire(const SliceRect& rect) const;
bool getClearRect(int x0, int y0, int width, int height, SliceRect& rect) const; SliceRect getRect() const;
void clearDepthBuffer(float depth, int x0, int y0, int width, int height); void clearDepth(float depth, int x0, int y0, int width, int height);
void clearStencilBuffer(unsigned char stencil, unsigned char mask, int x0, int y0, int width, int height); void clearStencil(unsigned char stencil, unsigned char mask, int x0, int y0, int width, int height);
void fill(const Color<float> &color, int x0, int y0, int width, int height); void fill(const Color<float> &color, int x0, int y0, int width, int height);
Color<float> readExternal(int x, int y, int z) const; Color<float> readExternal(int x, int y, int z) const;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment