Commit 3b4a25c5 by Nicolas Capens Committed by Nicolas Capens

Fix texture upload and internalformat handling.

We weren't handling several of the format/type/internalformat combos from table 3.2 of the OpenGL ES 3.0.5 spec. In particular those where the format/type of a glTexSubImage2D() call can be used to update images with an internal format not directly corresponding to it. Some of these cases were handled using the blitter, but not all GL formats have a SwiftShader equivalent. Also, the blitter is slower than specialized C++ pixel transfer code, and the blitter's fallback path is even slower. This patch provides specialized pixel rectangle transfer code for each combination of formats. We also now only store the effective sized internal format of the images. Validation also happens using the sized internal format wherever feasible, instead of unsized formats or SwiftShader formats. Change-Id: Id55db490002ab8fc2f16f766c43b43f121e5768e Reviewed-on: https://swiftshader-review.googlesource.com/17429Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 9e8bfcaf
......@@ -36,11 +36,9 @@
#define SW_YV12_BT709 0x48315659 // YCrCb 4:2:0 Planar, 16-byte aligned, BT.709 color space, studio swing
#define SW_YV12_JFIF 0x4A315659 // YCrCb 4:2:0 Planar, 16-byte aligned, BT.601 color space, full swing
namespace egl
namespace gl
{
class Context;
struct PixelStorageModes
{
GLint rowLength = 0;
......@@ -51,20 +49,27 @@ struct PixelStorageModes
GLint skipImages = 0;
};
sw::Format ConvertFormatType(GLenum format, GLenum type);
sw::Format SelectInternalFormat(GLenum format, GLenum type);
GLint GetSizedInternalFormat(GLint internalFormat, GLenum type);
sw::Format ConvertReadFormatType(GLenum format, GLenum type);
sw::Format SelectInternalFormat(GLint format);
bool IsUnsizedInternalFormat(GLint internalformat);
GLenum GetBaseInternalFormat(GLint internalformat);
GLsizei ComputePitch(GLsizei width, GLenum format, GLenum type, GLint alignment);
GLsizei ComputeCompressedSize(GLsizei width, GLsizei height, GLenum format);
size_t ComputePackingOffset(GLenum format, GLenum type, GLsizei width, GLsizei height, const PixelStorageModes &storageModes);
}
namespace egl
{
class [[clang::lto_visibility_public]] Image : public sw::Surface, public gl::Object
{
protected:
// 2D texture image
Image(Texture *parentTexture, GLsizei width, GLsizei height, GLenum format, GLenum type)
: sw::Surface(parentTexture->getResource(), width, height, 1, 0, 1, SelectInternalFormat(format, type), true, true),
width(width), height(height), depth(1), format(format), type(type), internalFormat(SelectInternalFormat(format, type)),
parentTexture(parentTexture)
Image(Texture *parentTexture, GLsizei width, GLsizei height, GLint internalformat)
: sw::Surface(parentTexture->getResource(), width, height, 1, 0, 1, gl::SelectInternalFormat(internalformat), true, true),
width(width), height(height), depth(1), internalformat(internalformat), parentTexture(parentTexture)
{
shared = false;
Object::addRef();
......@@ -72,10 +77,9 @@ protected:
}
// 3D/Cube texture image
Image(Texture *parentTexture, GLsizei width, GLsizei height, GLsizei depth, int border, GLenum format, GLenum type)
: sw::Surface(parentTexture->getResource(), width, height, depth, border, 1, SelectInternalFormat(format, type), true, true),
width(width), height(height), depth(depth), format(format), type(type), internalFormat(SelectInternalFormat(format, type)),
parentTexture(parentTexture)
Image(Texture *parentTexture, GLsizei width, GLsizei height, GLsizei depth, int border, GLint internalformat)
: sw::Surface(parentTexture->getResource(), width, height, depth, border, 1, gl::SelectInternalFormat(internalformat), true, true),
width(width), height(height), depth(depth), internalformat(internalformat), parentTexture(parentTexture)
{
shared = false;
Object::addRef();
......@@ -83,20 +87,18 @@ protected:
}
// Native EGL image
Image(GLsizei width, GLsizei height, GLenum format, GLenum type, int pitchP)
: sw::Surface(nullptr, width, height, 1, 0, 1, SelectInternalFormat(format, type), true, true, pitchP),
width(width), height(height), depth(1), format(format), type(type), internalFormat(SelectInternalFormat(format, type)),
parentTexture(nullptr)
Image(GLsizei width, GLsizei height, GLint internalformat, int pitchP)
: sw::Surface(nullptr, width, height, 1, 0, 1, gl::SelectInternalFormat(internalformat), true, true, pitchP),
width(width), height(height), depth(1), internalformat(internalformat), parentTexture(nullptr)
{
shared = true;
Object::addRef();
}
// Render target
Image(GLsizei width, GLsizei height, sw::Format internalFormat, int multiSampleDepth, bool lockable)
: sw::Surface(nullptr, width, height, 1, 0, multiSampleDepth, internalFormat, lockable, true),
width(width), height(height), depth(1), format(0 /*GL_NONE*/), type(0 /*GL_NONE*/), internalFormat(internalFormat),
parentTexture(nullptr)
Image(GLsizei width, GLsizei height, GLint internalformat, int multiSampleDepth, bool lockable)
: sw::Surface(nullptr, width, height, 1, 0, multiSampleDepth, gl::SelectInternalFormat(internalformat), lockable, true),
width(width), height(height), depth(1), internalformat(internalformat), parentTexture(nullptr)
{
shared = false;
Object::addRef();
......@@ -104,16 +106,16 @@ protected:
public:
// 2D texture image
static Image *create(Texture *parentTexture, GLsizei width, GLsizei height, GLenum format, GLenum type);
static Image *create(Texture *parentTexture, GLsizei width, GLsizei height, GLint internalformat);
// 3D/Cube texture image
static Image *create(Texture *parentTexture, GLsizei width, GLsizei height, GLsizei depth, int border, GLenum format, GLenum type);
static Image *create(Texture *parentTexture, GLsizei width, GLsizei height, GLsizei depth, int border, GLint internalformat);
// Native EGL image
static Image *create(GLsizei width, GLsizei height, GLenum format, GLenum type, int pitchP);
static Image *create(GLsizei width, GLsizei height, GLint internalformat, int pitchP);
// Render target
static Image *create(GLsizei width, GLsizei height, sw::Format internalFormat, int multiSampleDepth, bool lockable);
static Image *create(GLsizei width, GLsizei height, GLint internalformat, int multiSampleDepth, bool lockable);
GLsizei getWidth() const
{
......@@ -132,19 +134,9 @@ public:
return depth;
}
GLenum getFormat() const
GLint getFormat() const
{
return format;
}
GLenum getType() const
{
return type;
}
sw::Format getInternalFormat() const
{
return internalFormat;
return internalformat;
}
bool isShared() const
......@@ -180,7 +172,7 @@ public:
void *lockInternal(int x, int y, int z, sw::Lock lock, sw::Accessor client) override = 0;
void unlockInternal() override = 0;
void loadImageData(Context *context, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const PixelStorageModes &unpackParameters, const void *pixels);
void loadImageData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const gl::PixelStorageModes &unpackParameters, const void *pixels);
void loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels);
void release() override = 0;
......@@ -198,9 +190,7 @@ protected:
const GLsizei width;
const GLsizei height;
const int depth;
const GLenum format;
const GLenum type;
const sw::Format internalFormat;
const GLint internalformat;
bool shared; // Used as an EGLImage
......@@ -208,8 +198,8 @@ protected:
~Image() override = 0;
void loadD24S8ImageData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, int inputPitch, int inputHeight, const void *input, void *buffer);
void loadD32FS8ImageData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, int inputPitch, int inputHeight, const void *input, void *buffer);
void loadImageData(GLsizei width, GLsizei height, GLsizei depth, int inputPitch, int inputHeight, GLenum format, GLenum type, const void *input, void *buffer);
void loadStencilData(GLsizei width, GLsizei height, GLsizei depth, int inputPitch, int inputHeight, GLenum format, GLenum type, const void *input, void *buffer);
};
#ifdef __ANDROID__
......@@ -236,35 +226,12 @@ inline GLenum GLPixelFormatFromAndroid(int halFormat)
}
}
inline GLenum GLPixelTypeFromAndroid(int halFormat)
{
switch(halFormat)
{
case HAL_PIXEL_FORMAT_RGBA_8888: return GL_UNSIGNED_BYTE;
#if ANDROID_PLATFORM_SDK_VERSION > 16
case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED: return GL_UNSIGNED_BYTE;
#endif
case HAL_PIXEL_FORMAT_RGBX_8888: return GL_UNSIGNED_BYTE;
case HAL_PIXEL_FORMAT_BGRA_8888: return GL_UNSIGNED_BYTE;
case HAL_PIXEL_FORMAT_RGB_565: return GL_UNSIGNED_SHORT_5_6_5;
case HAL_PIXEL_FORMAT_YV12: return GL_UNSIGNED_BYTE;
#ifdef GRALLOC_MODULE_API_VERSION_0_2
case HAL_PIXEL_FORMAT_YCbCr_420_888: return GL_UNSIGNED_BYTE;
#endif
case HAL_PIXEL_FORMAT_RGB_888: // Unsupported.
default:
ALOGE("Unsupported EGL image format %d", halFormat); ASSERT(false);
return GL_NONE;
}
}
class AndroidNativeImage : public egl::Image
{
public:
explicit AndroidNativeImage(ANativeWindowBuffer *nativeBuffer)
: egl::Image(nativeBuffer->width, nativeBuffer->height,
GLPixelFormatFromAndroid(nativeBuffer->format),
GLPixelTypeFromAndroid(nativeBuffer->format),
nativeBuffer->stride),
nativeBuffer(nativeBuffer)
{
......
......@@ -40,8 +40,6 @@ public:
virtual egl::Image *getRenderTarget() = 0;
virtual egl::Image *getDepthStencil() = 0;
virtual sw::Format getInternalFormat() const = 0;
virtual EGLint getWidth() const = 0;
virtual EGLint getHeight() const = 0;
......
......@@ -182,11 +182,6 @@ EGLenum Surface::getSurfaceType() const
return config->mSurfaceType;
}
sw::Format Surface::getInternalFormat() const
{
return config->mRenderTargetFormat;
}
EGLint Surface::getWidth() const
{
return width;
......
......@@ -45,7 +45,6 @@ public:
virtual EGLint getConfigID() const;
virtual EGLenum getSurfaceType() const;
sw::Format getInternalFormat() const override;
EGLint getWidth() const override;
EGLint getHeight() const override;
......
......@@ -181,7 +181,7 @@ void Texture::setImage(GLenum format, GLenum type, GLint unpackAlignment, const
void Texture::setCompressedImage(GLsizei imageSize, const void *pixels, Image *image)
{
if(pixels && image && (imageSize > 0)) // imageSize's correlation to width and height is already validated with egl::ComputeCompressedSize() at the API level
if(pixels && image && (imageSize > 0)) // imageSize's correlation to width and height is already validated with gl::ComputeCompressedSize() at the API level
{
image->loadCompressedData(0, 0, 0, image->getWidth(), image->getHeight(), 1, imageSize, pixels);
}
......@@ -232,7 +232,7 @@ void Texture::subImageCompressed(GLint xoffset, GLint yoffset, GLsizei width, GL
return error(GL_INVALID_OPERATION);
}
if(pixels && (imageSize > 0)) // imageSize's correlation to width and height is already validated with egl::ComputeCompressedSize() at the API level
if(pixels && (imageSize > 0)) // imageSize's correlation to width and height is already validated with gl::ComputeCompressedSize() at the API level
{
image->loadCompressedData(xoffset, yoffset, 0, width, height, 1, imageSize, pixels);
}
......
......@@ -2413,7 +2413,7 @@ void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height,
}
}
GLsizei outputPitch = egl::ComputePitch(width, format, type, mState.packAlignment);
GLsizei outputPitch = gl::ComputePitch(width, format, type, mState.packAlignment);
// Sized query sanity check
if(bufSize)
......
......@@ -217,69 +217,6 @@ namespace es1
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)
{
if(height > OUTLINE_RESOLUTION)
{
ERR("Invalid parameters: %dx%d", width, height);
return nullptr;
}
bool lockable = true;
switch(format)
{
// case FORMAT_D15S1:
case FORMAT_D24S8:
case FORMAT_D24X8:
// case FORMAT_D24X4S4:
case FORMAT_D24FS8:
case FORMAT_D32:
case FORMAT_D16:
lockable = false;
break;
// case FORMAT_S8_LOCKABLE:
// case FORMAT_D16_LOCKABLE:
case FORMAT_D32F_LOCKABLE:
// case FORMAT_D32_LOCKABLE:
case FORMAT_DF24S8:
case FORMAT_DF16S8:
lockable = true;
break;
default:
UNREACHABLE(format);
}
egl::Image *surface = egl::Image::create(width, height, format, multiSampleDepth, lockable);
if(!surface)
{
ERR("Out of memory");
return nullptr;
}
return surface;
}
egl::Image *Device::createRenderTarget(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool lockable)
{
if(height > OUTLINE_RESOLUTION)
{
ERR("Invalid parameters: %dx%d", width, height);
return nullptr;
}
egl::Image *surface = egl::Image::create(width, height, format, multiSampleDepth, lockable);
if(!surface)
{
ERR("Out of memory");
return nullptr;
}
return surface;
}
void Device::drawIndexedPrimitive(sw::DrawType type, unsigned int indexOffset, unsigned int primitiveCount)
{
if(!bindResources() || !primitiveCount)
......
......@@ -49,8 +49,6 @@ namespace es1
void clearColor(float red, float green, float blue, float alpha, unsigned int rgbaMask);
void clearDepth(float z);
void clearStencil(unsigned int stencil, unsigned int mask);
egl::Image *createDepthStencilSurface(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool discard);
egl::Image *createRenderTarget(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool lockable);
void drawIndexedPrimitive(sw::DrawType type, unsigned int indexOffset, unsigned int primitiveCount);
void drawPrimitive(sw::DrawType type, unsigned int primiveCount);
void setScissorEnable(bool enable);
......
......@@ -405,16 +405,16 @@ GLenum Framebuffer::getImplementationColorReadFormat()
if(colorbuffer)
{
switch(colorbuffer->getInternalFormat())
switch(colorbuffer->getFormat())
{
case sw::FORMAT_A8R8G8B8: return GL_BGRA_EXT;
case sw::FORMAT_A8B8G8R8: return GL_RGBA;
case sw::FORMAT_X8R8G8B8: return GL_BGRA_EXT;
case sw::FORMAT_X8B8G8R8: return GL_RGBA;
case sw::FORMAT_A1R5G5B5: return GL_BGRA_EXT;
case sw::FORMAT_R5G6B5: return GL_RGB;
case GL_BGRA8_EXT: return GL_BGRA_EXT;
case GL_RGBA4_OES: return GL_RGBA;
case GL_RGB5_A1_OES: return GL_RGBA;
case GL_RGBA8_OES: return GL_RGBA;
case GL_RGB565_OES: return GL_RGBA;
case GL_RGB8_OES: return GL_RGB;
default:
UNREACHABLE(colorbuffer->getInternalFormat());
UNREACHABLE(colorbuffer->getFormat());
}
}
......@@ -427,16 +427,16 @@ GLenum Framebuffer::getImplementationColorReadType()
if(colorbuffer)
{
switch(colorbuffer->getInternalFormat())
switch(colorbuffer->getFormat())
{
case sw::FORMAT_A8R8G8B8: return GL_UNSIGNED_BYTE;
case sw::FORMAT_A8B8G8R8: return GL_UNSIGNED_BYTE;
case sw::FORMAT_X8R8G8B8: return GL_UNSIGNED_BYTE;
case sw::FORMAT_X8B8G8R8: return GL_UNSIGNED_BYTE;
case sw::FORMAT_A1R5G5B5: return GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT;
case sw::FORMAT_R5G6B5: return GL_UNSIGNED_SHORT_5_6_5;
case GL_BGRA8_EXT: return GL_UNSIGNED_BYTE;
case GL_RGBA4_OES: return GL_UNSIGNED_SHORT_4_4_4_4;
case GL_RGB5_A1_OES: return GL_UNSIGNED_SHORT_5_5_5_1;
case GL_RGBA8_OES: return GL_UNSIGNED_BYTE;
case GL_RGB565_OES: return GL_UNSIGNED_SHORT_5_6_5;
case GL_RGB8_OES: return GL_UNSIGNED_BYTE;
default:
UNREACHABLE(colorbuffer->getInternalFormat());
UNREACHABLE(colorbuffer->getFormat());
}
}
......
......@@ -41,32 +41,32 @@ void RenderbufferInterface::releaseProxy(const Renderbuffer *proxy)
GLuint RenderbufferInterface::getRedSize() const
{
return sw2es::GetRedSize(getInternalFormat());
return GetRedSize(getFormat());
}
GLuint RenderbufferInterface::getGreenSize() const
{
return sw2es::GetGreenSize(getInternalFormat());
return GetGreenSize(getFormat());
}
GLuint RenderbufferInterface::getBlueSize() const
{
return sw2es::GetBlueSize(getInternalFormat());
return GetBlueSize(getFormat());
}
GLuint RenderbufferInterface::getAlphaSize() const
{
return sw2es::GetAlphaSize(getInternalFormat());
return GetAlphaSize(getFormat());
}
GLuint RenderbufferInterface::getDepthSize() const
{
return sw2es::GetDepthSize(getInternalFormat());
return GetDepthSize(getFormat());
}
GLuint RenderbufferInterface::getStencilSize() const
{
return sw2es::GetStencilSize(getInternalFormat());
return GetStencilSize(getFormat());
}
///// RenderbufferTexture2D Implementation ////////
......@@ -127,11 +127,6 @@ GLenum RenderbufferTexture2D::getFormat() const
return mTexture2D->getFormat(GL_TEXTURE_2D, 0);
}
sw::Format RenderbufferTexture2D::getInternalFormat() const
{
return mTexture2D->getInternalFormat(GL_TEXTURE_2D, 0);
}
GLsizei RenderbufferTexture2D::getSamples() const
{
return 0;
......@@ -200,11 +195,6 @@ GLenum Renderbuffer::getFormat() const
return mInstance->getFormat();
}
sw::Format Renderbuffer::getInternalFormat() const
{
return mInstance->getInternalFormat();
}
GLuint Renderbuffer::getRedSize() const
{
return mInstance->getRedSize();
......@@ -252,8 +242,7 @@ RenderbufferStorage::RenderbufferStorage()
{
mWidth = 0;
mHeight = 0;
format = GL_RGBA4_OES;
internalFormat = sw::FORMAT_A8B8G8R8;
format = GL_NONE;
mSamples = 0;
}
......@@ -276,11 +265,6 @@ GLenum RenderbufferStorage::getFormat() const
return format;
}
sw::Format RenderbufferStorage::getInternalFormat() const
{
return internalFormat;
}
GLsizei RenderbufferStorage::getSamples() const
{
return mSamples;
......@@ -294,22 +278,24 @@ Colorbuffer::Colorbuffer(egl::Image *renderTarget) : mRenderTarget(renderTarget)
mWidth = renderTarget->getWidth();
mHeight = renderTarget->getHeight();
internalFormat = renderTarget->getInternalFormat();
format = sw2es::ConvertBackBufferFormat(internalFormat);
format = renderTarget->getFormat();
mSamples = renderTarget->getDepth() & ~1;
}
}
Colorbuffer::Colorbuffer(int width, int height, GLenum format, GLsizei samples) : mRenderTarget(nullptr)
Colorbuffer::Colorbuffer(int width, int height, GLenum internalformat, GLsizei samples) : mRenderTarget(nullptr)
{
Device *device = getDevice();
sw::Format requestedFormat = es2sw::ConvertRenderbufferFormat(format);
int supportedSamples = Context::getSupportedMultisampleCount(samples);
if(width > 0 && height > 0)
{
mRenderTarget = device->createRenderTarget(width, height, requestedFormat, supportedSamples, false);
if(height > sw::OUTLINE_RESOLUTION)
{
error(GL_OUT_OF_MEMORY);
return;
}
mRenderTarget = egl::Image::create(width, height, internalformat, supportedSamples, false);
if(!mRenderTarget)
{
......@@ -320,8 +306,7 @@ Colorbuffer::Colorbuffer(int width, int height, GLenum format, GLsizei samples)
mWidth = width;
mHeight = height;
this->format = format;
internalFormat = requestedFormat;
format = internalformat;
mSamples = supportedSamples;
}
......@@ -371,21 +356,24 @@ DepthStencilbuffer::DepthStencilbuffer(egl::Image *depthStencil) : mDepthStencil
mWidth = depthStencil->getWidth();
mHeight = depthStencil->getHeight();
internalFormat = depthStencil->getInternalFormat();
format = sw2es::ConvertDepthStencilFormat(internalFormat);
format = depthStencil->getFormat();
mSamples = depthStencil->getDepth() & ~1;
}
}
DepthStencilbuffer::DepthStencilbuffer(int width, int height, GLsizei samples) : mDepthStencil(nullptr)
DepthStencilbuffer::DepthStencilbuffer(int width, int height, GLenum internalformat, GLsizei samples) : mDepthStencil(nullptr)
{
Device *device = getDevice();
int supportedSamples = Context::getSupportedMultisampleCount(samples);
if(width > 0 && height > 0)
{
mDepthStencil = device->createDepthStencilSurface(width, height, sw::FORMAT_D24S8, supportedSamples, false);
if(height > sw::OUTLINE_RESOLUTION)
{
error(GL_OUT_OF_MEMORY);
return;
}
mDepthStencil = egl::Image::create(width, height, internalformat, supportedSamples, false);
if(!mDepthStencil)
{
......@@ -396,8 +384,7 @@ DepthStencilbuffer::DepthStencilbuffer(int width, int height, GLsizei samples) :
mWidth = width;
mHeight = height;
format = GL_DEPTH24_STENCIL8_OES;
internalFormat = sw::FORMAT_D24S8;
format = internalformat;
mSamples = supportedSamples;
}
......@@ -441,22 +428,10 @@ bool DepthStencilbuffer::isShared() const
Depthbuffer::Depthbuffer(egl::Image *depthStencil) : DepthStencilbuffer(depthStencil)
{
if(depthStencil)
{
format = GL_DEPTH_COMPONENT16_OES; // If the renderbuffer parameters are queried, the calling function
// will expect one of the valid renderbuffer formats for use in
// glRenderbufferStorage
}
}
Depthbuffer::Depthbuffer(int width, int height, GLsizei samples) : DepthStencilbuffer(width, height, samples)
Depthbuffer::Depthbuffer(int width, int height, GLenum internalformat, GLsizei samples) : DepthStencilbuffer(width, height, internalformat, samples)
{
if(mDepthStencil)
{
format = GL_DEPTH_COMPONENT16_OES; // If the renderbuffer parameters are queried, the calling function
// will expect one of the valid renderbuffer formats for use in
// glRenderbufferStorage
}
}
Depthbuffer::~Depthbuffer()
......@@ -465,22 +440,10 @@ Depthbuffer::~Depthbuffer()
Stencilbuffer::Stencilbuffer(egl::Image *depthStencil) : DepthStencilbuffer(depthStencil)
{
if(depthStencil)
{
format = GL_STENCIL_INDEX8_OES; // If the renderbuffer parameters are queried, the calling function
// will expect one of the valid renderbuffer formats for use in
// glRenderbufferStorage
}
}
Stencilbuffer::Stencilbuffer(int width, int height, GLsizei samples) : DepthStencilbuffer(width, height, samples)
Stencilbuffer::Stencilbuffer(int width, int height, GLsizei samples) : DepthStencilbuffer(width, height, GL_STENCIL_INDEX8_OES, samples)
{
if(mDepthStencil)
{
format = GL_STENCIL_INDEX8_OES; // If the renderbuffer parameters are queried, the calling function
// will expect one of the valid renderbuffer formats for use in
// glRenderbufferStorage
}
}
Stencilbuffer::~Stencilbuffer()
......
......@@ -49,7 +49,6 @@ public:
virtual GLsizei getWidth() const = 0;
virtual GLsizei getHeight() const = 0;
virtual GLenum getFormat() const = 0;
virtual sw::Format getInternalFormat() const = 0;
virtual GLsizei getSamples() const = 0;
GLuint getRedSize() const;
......@@ -77,7 +76,6 @@ public:
virtual GLsizei getWidth() const;
virtual GLsizei getHeight() const;
virtual GLenum getFormat() const;
virtual sw::Format getInternalFormat() const;
virtual GLsizei getSamples() const;
private:
......@@ -101,14 +99,12 @@ public:
virtual GLsizei getWidth() const;
virtual GLsizei getHeight() const;
virtual GLenum getFormat() const;
virtual sw::Format getInternalFormat() const;
virtual GLsizei getSamples() const;
protected:
GLsizei mWidth;
GLsizei mHeight;
GLenum format;
sw::Format internalFormat;
GLsizei mSamples;
};
......@@ -136,7 +132,6 @@ public:
GLsizei getWidth() const;
GLsizei getHeight() const;
GLenum getFormat() const;
sw::Format getInternalFormat() const;
GLuint getRedSize() const;
GLuint getGreenSize() const;
GLuint getBlueSize() const;
......@@ -155,7 +150,7 @@ class Colorbuffer : public RenderbufferStorage
{
public:
explicit Colorbuffer(egl::Image *renderTarget);
Colorbuffer(GLsizei width, GLsizei height, GLenum format, GLsizei samples);
Colorbuffer(GLsizei width, GLsizei height, GLenum internalformat, GLsizei samples);
virtual ~Colorbuffer();
......@@ -171,7 +166,7 @@ class DepthStencilbuffer : public RenderbufferStorage
{
public:
explicit DepthStencilbuffer(egl::Image *depthStencil);
DepthStencilbuffer(GLsizei width, GLsizei height, GLsizei samples);
DepthStencilbuffer(GLsizei width, GLsizei height, GLenum internalformat, GLsizei samples);
~DepthStencilbuffer();
......@@ -187,7 +182,7 @@ class Depthbuffer : public DepthStencilbuffer
{
public:
explicit Depthbuffer(egl::Image *depthStencil);
Depthbuffer(GLsizei width, GLsizei height, GLsizei samples);
Depthbuffer(GLsizei width, GLsizei height, GLenum internalformat, GLsizei samples);
virtual ~Depthbuffer();
};
......
......@@ -227,25 +227,25 @@ egl::Image *Texture::createSharedImage(GLenum target, unsigned int level)
return image;
}
void Texture::setImage(egl::Context *context, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels, egl::Image *image)
void Texture::setImage(GLenum format, GLenum type, GLint unpackAlignment, const void *pixels, egl::Image *image)
{
if(pixels && image)
{
egl::PixelStorageModes unpackParameters;
gl::PixelStorageModes unpackParameters;
unpackParameters.alignment = unpackAlignment;
image->loadImageData(context, 0, 0, 0, image->getWidth(), image->getHeight(), 1, format, type, unpackParameters, pixels);
image->loadImageData(0, 0, 0, image->getWidth(), image->getHeight(), 1, format, type, unpackParameters, pixels);
}
}
void Texture::setCompressedImage(GLsizei imageSize, const void *pixels, egl::Image *image)
{
if(pixels && image && (imageSize > 0)) // imageSize's correlation to width and height is already validated with egl::ComputeCompressedSize() at the API level
if(pixels && image && (imageSize > 0)) // imageSize's correlation to width and height is already validated with gl::ComputeCompressedSize() at the API level
{
image->loadCompressedData(0, 0, 0, image->getWidth(), image->getHeight(), 1, imageSize, pixels);
}
}
void Texture::subImage(egl::Context *context, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels, egl::Image *image)
void Texture::subImage(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels, egl::Image *image)
{
if(!image)
{
......@@ -269,9 +269,9 @@ void Texture::subImage(egl::Context *context, GLint xoffset, GLint yoffset, GLsi
if(pixels)
{
egl::PixelStorageModes unpackParameters;
gl::PixelStorageModes unpackParameters;
unpackParameters.alignment = unpackAlignment;
image->loadImageData(context, xoffset, yoffset, 0, width, height, 1, format, type, unpackParameters, pixels);
image->loadImageData(xoffset, yoffset, 0, width, height, 1, format, type, unpackParameters, pixels);
}
}
......@@ -292,7 +292,7 @@ void Texture::subImageCompressed(GLint xoffset, GLint yoffset, GLsizei width, GL
return error(GL_INVALID_OPERATION);
}
if(pixels && (imageSize > 0)) // imageSize's correlation to width and height is already validated with egl::ComputeCompressedSize() at the API level
if(pixels && (imageSize > 0)) // imageSize's correlation to width and height is already validated with gl::ComputeCompressedSize() at the API level
{
image->loadCompressedData(xoffset, yoffset, 0, width, height, 1, imageSize, pixels);
}
......@@ -426,18 +426,12 @@ GLsizei Texture2D::getHeight(GLenum target, GLint level) const
return image[level] ? image[level]->getHeight() : 0;
}
GLenum Texture2D::getFormat(GLenum target, GLint level) const
GLint Texture2D::getFormat(GLenum target, GLint level) const
{
ASSERT(target == GL_TEXTURE_2D);
return image[level] ? image[level]->getFormat() : GL_NONE;
}
GLenum Texture2D::getType(GLenum target, GLint level) const
{
ASSERT(target == GL_TEXTURE_2D);
return image[level] ? image[level]->getType() : GL_NONE;
}
sw::Format Texture2D::getInternalFormat(GLenum target, GLint level) const
{
ASSERT(target == GL_TEXTURE_2D);
......@@ -457,37 +451,25 @@ int Texture2D::getTopLevel() const
return level - 1;
}
void Texture2D::setImage(egl::Context *context, GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels)
void Texture2D::setImage(GLint level, GLsizei width, GLsizei height, GLint internalformat, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels)
{
if(image[level])
{
image[level]->release();
}
image[level] = egl::Image::create(this, width, height, format, type);
image[level] = egl::Image::create(this, width, height, internalformat);
if(!image[level])
{
return error(GL_OUT_OF_MEMORY);
}
Texture::setImage(context, format, type, unpackAlignment, pixels, image[level]);
Texture::setImage(format, type, unpackAlignment, pixels, image[level]);
}
void Texture2D::bindTexImage(gl::Surface *surface)
{
switch(surface->getInternalFormat())
{
case sw::FORMAT_A8R8G8B8:
case sw::FORMAT_A8B8G8R8:
case sw::FORMAT_X8B8G8R8:
case sw::FORMAT_X8R8G8B8:
break;
default:
UNIMPLEMENTED();
return;
}
for(int level = 0; level < IMPLEMENTATION_MAX_TEXTURE_LEVELS; level++)
{
if(image[level])
......@@ -522,7 +504,7 @@ void Texture2D::setCompressedImage(GLint level, GLenum format, GLsizei width, GL
image[level]->release();
}
image[level] = egl::Image::create(this, width, height, format, GL_UNSIGNED_BYTE);
image[level] = egl::Image::create(this, width, height, format);
if(!image[level])
{
......@@ -532,9 +514,9 @@ void Texture2D::setCompressedImage(GLint level, GLenum format, GLsizei width, GL
Texture::setCompressedImage(imageSize, pixels, image[level]);
}
void Texture2D::subImage(egl::Context *context, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels)
void Texture2D::subImage(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels)
{
Texture::subImage(context, xoffset, yoffset, width, height, format, type, unpackAlignment, pixels, image[level]);
Texture::subImage(xoffset, yoffset, width, height, format, type, unpackAlignment, pixels, image[level]);
}
void Texture2D::subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels)
......@@ -557,7 +539,7 @@ void Texture2D::copyImage(GLint level, GLenum format, GLint x, GLint y, GLsizei
image[level]->release();
}
image[level] = egl::Image::create(this, width, height, format, GL_UNSIGNED_BYTE);
image[level] = egl::Image::create(this, width, height, format);
if(!image[level])
{
......@@ -662,11 +644,6 @@ bool Texture2D::isMipmapComplete() const
return false;
}
if(image[level]->getType() != image[0]->getType())
{
return false;
}
if(image[level]->getWidth() != std::max(1, width >> level))
{
return false;
......@@ -707,7 +684,7 @@ void Texture2D::generateMipmaps()
image[i]->release();
}
image[i] = egl::Image::create(this, std::max(image[0]->getWidth() >> i, 1), std::max(image[0]->getHeight() >> i, 1), image[0]->getFormat(), image[0]->getType());
image[i] = egl::Image::create(this, std::max(image[0]->getWidth() >> i, 1), std::max(image[0]->getHeight() >> i, 1), image[0]->getFormat());
if(!image[i])
{
......
......@@ -76,8 +76,7 @@ public:
virtual GLsizei getWidth(GLenum target, GLint level) const = 0;
virtual GLsizei getHeight(GLenum target, GLint level) const = 0;
virtual GLenum getFormat(GLenum target, GLint level) const = 0;
virtual GLenum getType(GLenum target, GLint level) const = 0;
virtual GLint getFormat(GLenum target, GLint level) const = 0;
virtual sw::Format getInternalFormat(GLenum target, GLint level) const = 0;
virtual int getTopLevel() const = 0;
......@@ -98,8 +97,8 @@ public:
protected:
~Texture() override;
void setImage(egl::Context *context, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels, egl::Image *image);
void subImage(egl::Context *context, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels, egl::Image *image);
void setImage(GLenum format, GLenum type, GLint unpackAlignment, const void *pixels, egl::Image *image);
void subImage(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels, egl::Image *image);
void setCompressedImage(GLsizei imageSize, const void *pixels, egl::Image *image);
void subImageCompressed(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels, egl::Image *image);
......@@ -134,14 +133,13 @@ public:
GLsizei getWidth(GLenum target, GLint level) const override;
GLsizei getHeight(GLenum target, GLint level) const override;
GLenum getFormat(GLenum target, GLint level) const override;
GLenum getType(GLenum target, GLint level) const override;
GLint getFormat(GLenum target, GLint level) const override;
sw::Format getInternalFormat(GLenum target, GLint level) const override;
int getTopLevel() const override;
void setImage(egl::Context *context, GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
void setImage(GLint level, GLsizei width, GLsizei height, GLint internalformat, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
void setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels);
void subImage(egl::Context *context, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
void subImage(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
void subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels);
void copyImage(GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
......
......@@ -755,7 +755,7 @@ void CompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLs
return error(GL_INVALID_ENUM);
}
if(imageSize != egl::ComputeCompressedSize(width, height, internalformat))
if(imageSize != gl::ComputeCompressedSize(width, height, internalformat))
{
return error(GL_INVALID_VALUE);
}
......@@ -817,7 +817,7 @@ void CompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yo
if(context)
{
if(imageSize != egl::ComputeCompressedSize(width, height, format))
if(imageSize != gl::ComputeCompressedSize(width, height, format))
{
return error(GL_INVALID_VALUE);
}
......@@ -889,7 +889,7 @@ void CopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x,
es1::Renderbuffer *source = framebuffer->getColorbuffer();
GLenum colorbufferFormat = source->getFormat();
// [OpenGL ES 2.0.24] table 3.9
// [OpenGL ES 1.1.12] table 3.9
switch(internalformat)
{
case GL_ALPHA:
......@@ -936,6 +936,22 @@ void CopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x,
return error(GL_INVALID_ENUM);
}
// Determine the sized internal format.
if(gl::GetBaseInternalFormat(colorbufferFormat) == internalformat)
{
internalformat = colorbufferFormat;
}
else if(GetRedSize(colorbufferFormat) == 8)
{
internalformat = gl::GetSizedInternalFormat(internalformat, GL_UNSIGNED_BYTE);
}
else
{
UNIMPLEMENTED();
return error(GL_INVALID_OPERATION);
}
if(target == GL_TEXTURE_2D)
{
es1::Texture2D *texture = context->getTexture2D();
......@@ -1863,7 +1879,12 @@ void GetRenderbufferParameterivOES(GLenum target, GLenum pname, GLint* params)
{
case GL_RENDERBUFFER_WIDTH_OES: *params = renderbuffer->getWidth(); break;
case GL_RENDERBUFFER_HEIGHT_OES: *params = renderbuffer->getHeight(); break;
case GL_RENDERBUFFER_INTERNAL_FORMAT_OES: *params = renderbuffer->getFormat(); break;
case GL_RENDERBUFFER_INTERNAL_FORMAT_OES:
{
GLint internalformat = renderbuffer->getFormat();
*params = (internalformat == GL_NONE) ? GL_RGBA4_OES : internalformat;
}
break;
case GL_RENDERBUFFER_RED_SIZE_OES: *params = renderbuffer->getRedSize(); break;
case GL_RENDERBUFFER_GREEN_SIZE_OES: *params = renderbuffer->getGreenSize(); break;
case GL_RENDERBUFFER_BLUE_SIZE_OES: *params = renderbuffer->getBlueSize(); break;
......@@ -3428,9 +3449,6 @@ void RenderbufferStorageOES(GLenum target, GLenum internalformat, GLsizei width,
switch(internalformat)
{
case GL_DEPTH_COMPONENT16_OES:
context->setRenderbufferStorage(new es1::Depthbuffer(width, height, 0));
break;
case GL_RGBA4_OES:
case GL_RGB5_A1_OES:
case GL_RGB565_OES:
......@@ -3438,11 +3456,14 @@ void RenderbufferStorageOES(GLenum target, GLenum internalformat, GLsizei width,
case GL_RGBA8_OES:
context->setRenderbufferStorage(new es1::Colorbuffer(width, height, internalformat, 0));
break;
case GL_DEPTH_COMPONENT16_OES:
context->setRenderbufferStorage(new es1::Depthbuffer(width, height, internalformat, 0));
break;
case GL_STENCIL_INDEX8_OES:
context->setRenderbufferStorage(new es1::Stencilbuffer(width, height, 0));
break;
case GL_DEPTH24_STENCIL8_OES:
context->setRenderbufferStorage(new es1::DepthStencilbuffer(width, height, 0));
context->setRenderbufferStorage(new es1::DepthStencilbuffer(width, height, internalformat, 0));
break;
default:
return error(GL_INVALID_ENUM);
......@@ -4270,6 +4291,8 @@ void TexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width,
return error(GL_INVALID_VALUE);
}
GLenum sizedInternalFormat = gl::GetSizedInternalFormat(internalformat, type);
es1::Context *context = es1::getContext();
if(context)
......@@ -4296,7 +4319,7 @@ void TexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width,
return error(GL_INVALID_OPERATION);
}
texture->setImage(context, level, width, height, format, type, context->getUnpackAlignment(), pixels);
texture->setImage(level, width, height, sizedInternalFormat, format, type, context->getUnpackAlignment(), pixels);
}
else UNREACHABLE(target);
}
......@@ -4533,7 +4556,7 @@ void TexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLs
if(validateSubImageParams(false, width, height, xoffset, yoffset, target, level, format, texture))
{
texture->subImage(context, level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getUnpackAlignment(), pixels);
}
}
else UNREACHABLE(target);
......
......@@ -42,6 +42,13 @@ namespace es1
bool IsDepthRenderable(GLenum internalformat);
bool IsStencilRenderable(GLenum internalformat);
GLuint GetAlphaSize(GLint internalformat);
GLuint GetRedSize(GLint internalformat);
GLuint GetGreenSize(GLint internalformat);
GLuint GetBlueSize(GLint internalformat);
GLuint GetDepthSize(GLint internalformat);
GLuint GetStencilSize(GLint internalformat);
bool IsAlpha(GLenum texFormat);
bool IsRGB(GLenum texFormat);
bool IsRGBA(GLenum texFormat);
......@@ -63,7 +70,6 @@ namespace es2sw
sw::MipmapType ConvertMipMapFilter(GLenum minFilter);
sw::FilterType ConvertTextureFilter(GLenum minFilter, GLenum magFilter, float maxAnisotropy);
bool ConvertPrimitiveType(GLenum primitiveType, GLsizei elementCount, GLenum elementType, sw::DrawType &swPrimitiveType, int &primitiveCount);
sw::Format ConvertRenderbufferFormat(GLenum format);
sw::TextureStage::StageOperation ConvertCombineOperation(GLenum operation);
sw::TextureStage::SourceArgument ConvertSourceArgument(GLenum argument);
sw::TextureStage::ArgumentModifier ConvertSourceOperand(GLenum operand);
......@@ -71,13 +77,6 @@ namespace es2sw
namespace sw2es
{
GLuint GetAlphaSize(sw::Format colorFormat);
GLuint GetRedSize(sw::Format colorFormat);
GLuint GetGreenSize(sw::Format colorFormat);
GLuint GetBlueSize(sw::Format colorFormat);
GLuint GetDepthSize(sw::Format depthFormat);
GLuint GetStencilSize(sw::Format stencilFormat);
GLenum ConvertBackBufferFormat(sw::Format format);
GLenum ConvertDepthStencilFormat(sw::Format format);
}
......
......@@ -842,7 +842,7 @@ void Context::setUnpackAlignment(GLint alignment)
mState.unpackParameters.alignment = alignment;
}
const egl::PixelStorageModes &Context::getUnpackParameters() const
const gl::PixelStorageModes &Context::getUnpackParameters() const
{
return mState.unpackParameters;
}
......@@ -1568,7 +1568,7 @@ Buffer *Context::getGenericUniformBuffer() const
GLsizei Context::getRequiredBufferSize(GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type) const
{
GLsizei inputWidth = (mState.unpackParameters.rowLength == 0) ? width : mState.unpackParameters.rowLength;
GLsizei inputPitch = egl::ComputePitch(inputWidth, format, type, mState.unpackParameters.alignment);
GLsizei inputPitch = gl::ComputePitch(inputWidth, format, type, mState.unpackParameters.alignment);
GLsizei inputHeight = (mState.unpackParameters.imageHeight == 0) ? height : mState.unpackParameters.imageHeight;
return inputPitch * inputHeight * depth;
}
......@@ -3315,10 +3315,10 @@ void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum
}
GLsizei outputWidth = (mState.packParameters.rowLength > 0) ? mState.packParameters.rowLength : width;
GLsizei outputPitch = egl::ComputePitch(outputWidth, format, type, mState.packParameters.alignment);
GLsizei outputPitch = gl::ComputePitch(outputWidth, format, type, mState.packParameters.alignment);
GLsizei outputHeight = (mState.packParameters.imageHeight == 0) ? height : mState.packParameters.imageHeight;
pixels = getPixelPackBuffer() ? (unsigned char*)getPixelPackBuffer()->data() + (ptrdiff_t)pixels : (unsigned char*)pixels;
pixels = ((char*)pixels) + egl::ComputePackingOffset(format, type, outputWidth, outputHeight, mState.packParameters);
pixels = ((char*)pixels) + gl::ComputePackingOffset(format, type, outputWidth, outputHeight, mState.packParameters);
// Sized query sanity check
if(bufSize)
......@@ -3350,7 +3350,7 @@ void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum
sw::Rect dstRect(0, 0, width, height);
rect.clip(0.0f, 0.0f, (float)renderTarget->getWidth(), (float)renderTarget->getHeight());
sw::Surface *externalSurface = sw::Surface::create(width, height, 1, egl::ConvertFormatType(format, type), pixels, outputPitch, outputPitch * outputHeight);
sw::Surface *externalSurface = sw::Surface::create(width, height, 1, gl::ConvertReadFormatType(format, type), pixels, outputPitch, outputPitch * outputHeight);
sw::SliceRectF sliceRect(rect);
sw::SliceRect dstSliceRect(dstRect);
device->blit(renderTarget, sliceRect, externalSurface, dstSliceRect, false, false, false);
......
......@@ -422,8 +422,8 @@ struct State
gl::BindingPointer<Texture> samplerTexture[TEXTURE_TYPE_COUNT][MAX_COMBINED_TEXTURE_IMAGE_UNITS];
gl::BindingPointer<Query> activeQuery[QUERY_TYPE_COUNT];
egl::PixelStorageModes unpackParameters;
egl::PixelStorageModes packParameters;
gl::PixelStorageModes unpackParameters;
gl::PixelStorageModes packParameters;
};
class [[clang::lto_visibility_public]] Context : public egl::Context
......@@ -533,7 +533,7 @@ public:
void setUnpackSkipPixels(GLint skipPixels);
void setUnpackSkipRows(GLint skipRows);
void setUnpackSkipImages(GLint skipImages);
const egl::PixelStorageModes &getUnpackParameters() const;
const gl::PixelStorageModes &getUnpackParameters() const;
void setPackAlignment(GLint alignment);
void setPackRowLength(GLint rowLength);
......
......@@ -249,47 +249,6 @@ namespace es2
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)
{
ASSERT(sw::Surface::isDepth(format) || sw::Surface::isStencil(format));
if(height > OUTLINE_RESOLUTION)
{
ERR("Invalid parameters: %dx%d", width, height);
return nullptr;
}
bool lockable = !sw::Surface::hasQuadLayout(format);
egl::Image *surface = egl::Image::create(width, height, format, multiSampleDepth, lockable);
if(!surface)
{
ERR("Out of memory");
return nullptr;
}
return surface;
}
egl::Image *Device::createRenderTarget(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool lockable)
{
if(height > OUTLINE_RESOLUTION)
{
ERR("Invalid parameters: %dx%d", width, height);
return nullptr;
}
egl::Image *surface = egl::Image::create(width, height, format, multiSampleDepth, lockable);
if(!surface)
{
ERR("Out of memory");
return nullptr;
}
return surface;
}
void Device::drawIndexedPrimitive(sw::DrawType type, unsigned int indexOffset, unsigned int primitiveCount)
{
if(!bindResources() || !primitiveCount)
......
......@@ -58,8 +58,6 @@ namespace es2
void clearColor(float red, float green, float blue, float alpha, unsigned int rgbaMask);
void clearDepth(float z);
void clearStencil(unsigned int stencil, unsigned int mask);
egl::Image *createDepthStencilSurface(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool discard);
egl::Image *createRenderTarget(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool lockable);
void drawIndexedPrimitive(sw::DrawType type, unsigned int indexOffset, unsigned int primitiveCount);
void drawPrimitive(sw::DrawType type, unsigned int primiveCount);
void setPixelShader(const sw::PixelShader *shader);
......
......@@ -545,8 +545,6 @@ GLenum Framebuffer::getImplementationColorReadFormat() const
switch(colorbuffer->getFormat())
{
case GL_BGRA8_EXT: return GL_BGRA_EXT;
case GL_BGRA4_ANGLE: return GL_BGRA_EXT;
case GL_BGR5_A1_ANGLE: return GL_BGRA_EXT;
case GL_RGBA4: return GL_RGBA;
case GL_RGB5_A1: return GL_RGBA;
case GL_RGBA8: return GL_RGBA;
......@@ -608,8 +606,6 @@ GLenum Framebuffer::getImplementationColorReadType() const
switch(colorbuffer->getFormat())
{
case GL_BGRA8_EXT: return GL_UNSIGNED_BYTE;
case GL_BGRA4_ANGLE: return GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT;
case GL_BGR5_A1_ANGLE: return GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT;
case GL_RGBA4: return GL_UNSIGNED_SHORT_4_4_4_4;
case GL_RGB5_A1: return GL_UNSIGNED_SHORT_5_5_5_1;
case GL_RGBA8: return GL_UNSIGNED_BYTE;
......
......@@ -422,25 +422,26 @@ Colorbuffer::Colorbuffer(egl::Image *renderTarget) : mRenderTarget(renderTarget)
{
renderTarget->addRef();
sw::Format implementationFormat = renderTarget->getInternalFormat();
format = sw2es::ConvertBackBufferFormat(implementationFormat);
mWidth = renderTarget->getWidth();
mHeight = renderTarget->getHeight();
format = renderTarget->getFormat();
mSamples = renderTarget->getDepth() & ~1;
}
}
Colorbuffer::Colorbuffer(int width, int height, GLenum internalformat, GLsizei samples) : mRenderTarget(nullptr)
{
Device *device = getDevice();
sw::Format implementationFormat = es2sw::ConvertRenderbufferFormat(internalformat);
int supportedSamples = Context::getSupportedMultisampleCount(samples);
if(width > 0 && height > 0)
{
mRenderTarget = device->createRenderTarget(width, height, implementationFormat, supportedSamples, false);
if(height > sw::OUTLINE_RESOLUTION)
{
error(GL_OUT_OF_MEMORY);
return;
}
mRenderTarget = egl::Image::create(width, height, internalformat, supportedSamples, false);
if(!mRenderTarget)
{
......@@ -499,41 +500,26 @@ DepthStencilbuffer::DepthStencilbuffer(egl::Image *depthStencil) : mDepthStencil
{
depthStencil->addRef();
sw::Format implementationFormat = depthStencil->getInternalFormat();
format = sw2es::ConvertDepthStencilFormat(implementationFormat);
mWidth = depthStencil->getWidth();
mHeight = depthStencil->getHeight();
format = depthStencil->getFormat();
mSamples = depthStencil->getDepth() & ~1;
}
}
DepthStencilbuffer::DepthStencilbuffer(int width, int height, GLenum internalformat, GLsizei samples) : mDepthStencil(nullptr)
{
format = internalformat;
sw::Format implementationFormat = sw::FORMAT_D24S8;
switch(internalformat)
{
case GL_STENCIL_INDEX8: implementationFormat = sw::FORMAT_S8; break;
case GL_DEPTH_COMPONENT24: implementationFormat = sw::FORMAT_D24X8; break;
case GL_DEPTH24_STENCIL8_OES: implementationFormat = sw::FORMAT_D24S8; break;
case GL_DEPTH32F_STENCIL8: implementationFormat = sw::FORMAT_D32FS8; break;
case GL_DEPTH_COMPONENT16: implementationFormat = sw::FORMAT_D16; break;
case GL_DEPTH_COMPONENT32_OES: implementationFormat = sw::FORMAT_D32; break;
case GL_DEPTH_COMPONENT32F: implementationFormat = sw::FORMAT_D32F; break;
default:
UNREACHABLE(internalformat);
format = GL_DEPTH24_STENCIL8_OES;
implementationFormat = sw::FORMAT_D24S8;
}
Device *device = getDevice();
int supportedSamples = Context::getSupportedMultisampleCount(samples);
if(width > 0 && height > 0)
{
mDepthStencil = device->createDepthStencilSurface(width, height, implementationFormat, supportedSamples, false);
if(height > sw::OUTLINE_RESOLUTION)
{
error(GL_OUT_OF_MEMORY);
return;
}
mDepthStencil = egl::Image::create(width, height, internalformat, supportedSamples, false);
if(!mDepthStencil)
{
......@@ -544,6 +530,7 @@ DepthStencilbuffer::DepthStencilbuffer(int width, int height, GLenum internalfor
mWidth = width;
mHeight = height;
format = internalformat;
mSamples = supportedSamples;
}
......
......@@ -27,10 +27,6 @@
namespace es2
{
// Sized internal formats corresponding to GL_BGRA_EXT/GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT and
// GL_BGRA_EXT/GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT format/type combinations, respectively.
const GLint GL_BGRA4_ANGLE = 0x6ABC;
const GLint GL_BGR5_A1_ANGLE = 0x6ABD;
class Texture2D;
class Texture3D;
......
......@@ -94,7 +94,6 @@ public:
virtual GLsizei getHeight(GLenum target, GLint level) const = 0;
virtual GLsizei getDepth(GLenum target, GLint level) const;
virtual GLenum getFormat(GLenum target, GLint level) const = 0;
virtual GLenum getType(GLenum target, GLint level) const = 0;
virtual int getTopLevel() const = 0;
virtual bool isSamplerComplete() const = 0;
......@@ -112,8 +111,8 @@ public:
protected:
~Texture() override;
void setImage(egl::Context *context, GLenum format, GLenum type, const egl::PixelStorageModes &unpackParameters, const void *pixels, egl::Image *image);
void subImage(egl::Context *context, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const egl::PixelStorageModes &unpackParameters, const void *pixels, egl::Image *image);
void setImage(GLenum format, GLenum type, const gl::PixelStorageModes &unpackParameters, const void *pixels, egl::Image *image);
void subImage(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const gl::PixelStorageModes &unpackParameters, const void *pixels, egl::Image *image);
void setCompressedImage(GLsizei imageSize, const void *pixels, egl::Image *image);
void subImageCompressed(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *pixels, egl::Image *image);
......@@ -157,14 +156,13 @@ public:
GLsizei getWidth(GLenum target, GLint level) const override;
GLsizei getHeight(GLenum target, GLint level) const override;
GLenum getFormat(GLenum target, GLint level) const override;
GLenum getType(GLenum target, GLint level) const override;
int getTopLevel() const override;
void setImage(egl::Context *context, GLint level, GLsizei width, GLsizei height, GLint internalformat, GLenum format, GLenum type, const egl::PixelStorageModes &unpackParameters, const void *pixels);
void setImage(GLint level, GLsizei width, GLsizei height, GLint internalformat, GLenum format, GLenum type, const gl::PixelStorageModes &unpackParameters, const void *pixels);
void setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels);
void subImage(egl::Context *context, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const egl::PixelStorageModes &unpackParameters, const void *pixels);
void subImage(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const gl::PixelStorageModes &unpackParameters, const void *pixels);
void subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels);
void copyImage(GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Renderbuffer *source);
void copyImage(GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, Renderbuffer *source);
void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, Renderbuffer *source) override;
void setSharedImage(egl::Image *image);
......@@ -223,15 +221,14 @@ public:
GLsizei getWidth(GLenum target, GLint level) const override;
GLsizei getHeight(GLenum target, GLint level) const override;
GLenum getFormat(GLenum target, GLint level) const override;
GLenum getType(GLenum target, GLint level) const override;
int getTopLevel() const override;
void setImage(egl::Context *context, GLenum target, GLint level, GLsizei width, GLsizei height, GLint internalformat, GLenum format, GLenum type, const egl::PixelStorageModes &unpackParameters, const void *pixels);
void setImage(GLenum target, GLint level, GLsizei width, GLsizei height, GLint internalformat, GLenum format, GLenum type, const gl::PixelStorageModes &unpackParameters, const void *pixels);
void setCompressedImage(GLenum target, GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels);
void subImage(egl::Context *context, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const egl::PixelStorageModes &unpackParameters, const void *pixels);
void subImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const gl::PixelStorageModes &unpackParameters, const void *pixels);
void subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels);
void copyImage(GLenum target, GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Renderbuffer *source);
void copyImage(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, Renderbuffer *source);
void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, Renderbuffer *source) override;
bool isSamplerComplete() const override;
......@@ -285,14 +282,13 @@ public:
GLsizei getHeight(GLenum target, GLint level) const override;
GLsizei getDepth(GLenum target, GLint level) const override;
GLenum getFormat(GLenum target, GLint level) const override;
GLenum getType(GLenum target, GLint level) const override;
int getTopLevel() const override;
void setImage(egl::Context *context, GLint level, GLsizei width, GLsizei height, GLsizei depth, GLint internalformat, GLenum format, GLenum type, const egl::PixelStorageModes &unpackParameters, const void *pixels);
void setImage(GLint level, GLsizei width, GLsizei height, GLsizei depth, GLint internalformat, GLenum format, GLenum type, const gl::PixelStorageModes &unpackParameters, const void *pixels);
void setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels);
void subImage(egl::Context *context, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const egl::PixelStorageModes &unpackParameters, const void *pixels);
void subImage(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const gl::PixelStorageModes &unpackParameters, const void *pixels);
void subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *pixels);
void copyImage(GLint level, GLenum format, GLint x, GLint y, GLint z, GLsizei width, GLsizei height, GLsizei depth, Renderbuffer *source);
void copyImage(GLint level, GLenum internalformat, GLint x, GLint y, GLint z, GLsizei width, GLsizei height, GLsizei depth, Renderbuffer *source);
void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, Renderbuffer *source);
void setSharedImage(egl::Image *image);
......
......@@ -42,8 +42,8 @@ namespace es2
int AllocateFirstFreeBits(unsigned int *bits, unsigned int allocationSize, unsigned int bitsSize);
bool IsCompressed(GLenum format, GLint clientVersion);
GLint GetSizedInternalFormat(GLint internalFormat, GLenum type);
bool IsCompressed(GLint intenalformat, GLint clientVersion);
bool IsSizedInternalFormat(GLint internalformat); // Not compressed.
GLenum ValidateSubImageParams(bool compressed, bool copy, GLenum target, GLint level, GLint xoffset, GLint yoffset,
GLsizei width, GLsizei height, GLenum format, GLenum type, Texture *texture, GLint clientVersion);
GLenum ValidateSubImageParams(bool compressed, bool copy, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
......@@ -55,9 +55,8 @@ namespace es2
bool IsCubemapTextureTarget(GLenum target);
int CubeFaceIndex(GLenum cubeTarget);
bool IsTextureTarget(GLenum target);
GLenum ValidateTextureFormatType(GLenum format, GLenum type, GLint internalformat, GLint clientVersion);
GLenum ValidateTextureFormatType(GLenum format, GLenum type, GLint internalformat, GLenum target, GLint clientVersion);
GLsizei GetTypeSize(GLenum type);
GLenum GetBaseInternalFormat(GLint internalformat);
bool IsColorRenderable(GLint internalformat, GLint clientVersion);
bool IsDepthRenderable(GLint internalformat, GLint clientVersion);
......@@ -102,7 +101,6 @@ namespace es2sw
sw::MipmapType ConvertMipMapFilter(GLenum minFilter);
sw::FilterType ConvertTextureFilter(GLenum minFilter, GLenum magFilter, float maxAnisotropy);
bool ConvertPrimitiveType(GLenum primitiveType, GLsizei elementCount, GLenum elementType, sw::DrawType &swPrimitiveType, int &primitiveCount, int &verticesPerPrimitive);
sw::Format ConvertRenderbufferFormat(GLenum format);
}
namespace sw2es
......
......@@ -465,7 +465,7 @@ namespace sw
case FORMAT_X8R8G8B8:
if(writeRGBA)
{
Short4 c0 = RoundShort4(c.zyxw) | Short4(0x0000, 0x0000, 0x0000, 0xFFFFu);
Short4 c0 = RoundShort4(c.zyxw) | Short4(0x0000, 0x0000, 0x0000, 0x00FF);
*Pointer<Byte4>(element) = Byte4(PackUnsigned(c0, c0));
}
else
......@@ -480,7 +480,7 @@ namespace sw
case FORMAT_SRGB8_X8:
if(writeRGBA)
{
Short4 c0 = RoundShort4(c) | Short4(0x0000, 0x0000, 0x0000, 0xFFFFu);
Short4 c0 = RoundShort4(c) | Short4(0x0000, 0x0000, 0x0000, 0x00FF);
*Pointer<Byte4>(element) = Byte4(PackUnsigned(c0, c0));
}
else
......
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