Commit f97641c1 by Lingfeng Yang Committed by Commit Bot

GLES1: Texture parameters

Note: minimum buffer size is now checked for texture parameters in GLES2. - Mipmap generation hint - Crop rect - Update test expectations BUG=angleproject:2306 Change-Id: Ib459b8191111732a1326b44f2226b72ca297325a Reviewed-on: https://chromium-review.googlesource.com/1111575Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Lingfeng Yang <lfy@google.com>
parent dcb6e927
......@@ -960,6 +960,9 @@ Error Texture::setImage(const Context *context,
InitState initState = DetermineInitState(context, pixels);
mState.setImageDesc(target, level, ImageDesc(size, Format(internalFormat, type), initState));
ANGLE_TRY(handleMipmapGenerationHint(context, level));
signalDirty(context, initState);
return NoError();
......@@ -980,7 +983,11 @@ Error Texture::setSubImage(const Context *context,
ImageIndex index = ImageIndex::MakeFromTarget(target, level);
return mTexture->setSubImage(context, index, area, format, type, unpackState, pixels);
ANGLE_TRY(mTexture->setSubImage(context, index, area, format, type, unpackState, pixels));
ANGLE_TRY(handleMipmapGenerationHint(context, level));
return NoError();
}
Error Texture::setCompressedImage(const Context *context,
......@@ -1060,6 +1067,8 @@ Error Texture::copyImage(const Context *context,
ImageDesc(Extents(sourceArea.width, sourceArea.height, 1),
Format(internalFormatInfo), InitState::Initialized));
ANGLE_TRY(handleMipmapGenerationHint(context, level));
// We need to initialize this texture only if the source attachment is not initialized.
signalDirty(context, InitState::Initialized);
......@@ -1083,7 +1092,10 @@ Error Texture::copySubImage(const Context *context,
ImageIndex index = ImageIndex::MakeFromTarget(target, level);
return mTexture->copySubImage(context, index, destOffset, sourceArea, source);
ANGLE_TRY(mTexture->copySubImage(context, index, destOffset, sourceArea, source));
ANGLE_TRY(handleMipmapGenerationHint(context, level));
return NoError();
}
Error Texture::copyTexture(const Context *context,
......@@ -1640,4 +1652,15 @@ Error Texture::ensureSubImageInitialized(const Context *context,
return NoError();
}
Error Texture::handleMipmapGenerationHint(const Context *context, int level)
{
if (getGenerateMipmapHint() == GL_TRUE && level == 0)
{
ANGLE_TRY(generateMipmap(context));
}
return NoError();
}
} // namespace gl
......@@ -119,8 +119,8 @@ struct TextureState final : private angle::NonCopyable
const ImageDesc &getBaseLevelDesc() const;
// GLES1 emulation: For GL_OES_draw_texture
void setCrop(const gl::Rectangle& rect);
const gl::Rectangle& getCrop() const;
void setCrop(const gl::Rectangle &rect);
const gl::Rectangle &getCrop() const;
// GLES1 emulation: Auto-mipmap generation is a texparameter
void setGenerateMipmapHint(GLenum hint);
......@@ -381,8 +381,8 @@ class Texture final : public egl::ImageSibling, public LabeledObject
bool getAttachmentFixedSampleLocations(const ImageIndex &imageIndex) const;
// GLES1 emulation
void setCrop(const gl::Rectangle& rect);
const gl::Rectangle& getCrop() const;
void setCrop(const gl::Rectangle &rect);
const gl::Rectangle &getCrop() const;
void setGenerateMipmapHint(GLenum generate);
GLenum getGenerateMipmapHint() const;
......@@ -455,6 +455,8 @@ class Texture final : public egl::ImageSibling, public LabeledObject
size_t level,
const gl::Box &area);
Error handleMipmapGenerationHint(const Context *context, int level);
TextureState mState;
DirtyBits mDirtyBits;
rx::TextureImpl *mTexture;
......
......@@ -88,6 +88,8 @@ template GLfloat CastFromGLintStateValue<GLfloat, GLenum>(GLenum pname, GLenum v
template GLint CastFromGLintStateValue<GLint, GLenum>(GLenum pname, GLenum value);
template GLint64 CastFromGLintStateValue<GLint64, GLenum>(GLenum pname, GLenum value);
template GLuint CastFromGLintStateValue<GLuint, GLenum>(GLenum pname, GLenum value);
template GLfloat CastFromGLintStateValue<GLfloat, GLint>(GLenum pname, GLint value);
template GLint CastFromGLintStateValue<GLint, GLint>(GLenum pname, GLint value);
template GLfloat CastFromGLintStateValue<GLfloat, bool>(GLenum pname, bool value);
template GLuint CastFromGLintStateValue<GLuint, bool>(GLenum pname, bool value);
template GLint CastFromGLintStateValue<GLint, bool>(GLenum pname, bool value);
......
......@@ -188,6 +188,18 @@ void QueryTexParameterBase(const Texture *texture, GLenum pname, ParamType *para
*params =
CastFromGLintStateValue<ParamType>(pname, texture->getDepthStencilTextureMode());
break;
case GL_TEXTURE_CROP_RECT_OES:
{
const gl::Rectangle &crop = texture->getCrop();
params[0] = CastFromGLintStateValue<ParamType>(pname, crop.x);
params[1] = CastFromGLintStateValue<ParamType>(pname, crop.y);
params[2] = CastFromGLintStateValue<ParamType>(pname, crop.width);
params[3] = CastFromGLintStateValue<ParamType>(pname, crop.height);
break;
}
case GL_GENERATE_MIPMAP:
*params = CastFromGLintStateValue<ParamType>(pname, texture->getGenerateMipmapHint());
break;
default:
UNREACHABLE();
break;
......@@ -261,6 +273,15 @@ void SetTexParameterBase(Context *context, Texture *texture, GLenum pname, const
case GL_TEXTURE_SRGB_DECODE_EXT:
texture->setSRGBDecode(ConvertToGLenum(pname, params[0]));
break;
case GL_TEXTURE_CROP_RECT_OES:
texture->setCrop(gl::Rectangle(CastQueryValueTo<GLint>(pname, params[0]),
CastQueryValueTo<GLint>(pname, params[1]),
CastQueryValueTo<GLint>(pname, params[2]),
CastQueryValueTo<GLint>(pname, params[3])));
break;
case GL_GENERATE_MIPMAP:
texture->setGenerateMipmapHint(ConvertToGLenum(params[0]));
break;
default:
UNREACHABLE();
break;
......@@ -2510,6 +2531,39 @@ void GetPointSize(GLES1State *state, GLfloat *sizeOut)
*sizeOut = params.pointSize;
}
unsigned int GetTexParameterCount(GLenum pname)
{
switch (pname)
{
case GL_TEXTURE_CROP_RECT_OES:
return 4;
case GL_TEXTURE_MAG_FILTER:
case GL_TEXTURE_MIN_FILTER:
case GL_TEXTURE_WRAP_S:
case GL_TEXTURE_WRAP_T:
case GL_TEXTURE_USAGE_ANGLE:
case GL_TEXTURE_MAX_ANISOTROPY_EXT:
case GL_TEXTURE_IMMUTABLE_FORMAT:
case GL_TEXTURE_WRAP_R:
case GL_TEXTURE_IMMUTABLE_LEVELS:
case GL_TEXTURE_SWIZZLE_R:
case GL_TEXTURE_SWIZZLE_G:
case GL_TEXTURE_SWIZZLE_B:
case GL_TEXTURE_SWIZZLE_A:
case GL_TEXTURE_BASE_LEVEL:
case GL_TEXTURE_MAX_LEVEL:
case GL_TEXTURE_MIN_LOD:
case GL_TEXTURE_MAX_LOD:
case GL_TEXTURE_COMPARE_MODE:
case GL_TEXTURE_COMPARE_FUNC:
case GL_TEXTURE_SRGB_DECODE_EXT:
case GL_DEPTH_STENCIL_TEXTURE_MODE:
return 1;
default:
return 0;
}
}
} // namespace gl
namespace egl
......
......@@ -205,6 +205,8 @@ void GetPointParameter(const GLES1State *state, PointParameter pname, GLfloat *p
void SetPointSize(GLES1State *state, GLfloat size);
void GetPointSize(GLES1State *state, GLfloat *sizeOut);
unsigned int GetTexParameterCount(GLenum pname);
} // namespace gl
namespace egl
......
......@@ -22,6 +22,7 @@
#include "libANGLE/angletypes.h"
#include "libANGLE/formatutils.h"
#include "libANGLE/queryconversions.h"
#include "libANGLE/queryutils.h"
#include "libANGLE/validationES2.h"
#include "libANGLE/validationES3.h"
......@@ -522,6 +523,24 @@ bool IsCompatibleDrawModeWithGeometryShader(PrimitiveMode drawMode,
}
}
// GLES1 texture parameters are a small subset of the others
bool IsValidGLES1TextureParameter(GLenum pname)
{
switch (pname)
{
case GL_TEXTURE_MAG_FILTER:
case GL_TEXTURE_MIN_FILTER:
case GL_TEXTURE_WRAP_S:
case GL_TEXTURE_WRAP_T:
case GL_TEXTURE_WRAP_R:
case GL_GENERATE_MIPMAP:
case GL_TEXTURE_CROP_RECT_OES:
return true;
default:
return false;
}
}
} // anonymous namespace
void SetRobustLengthParam(GLsizei *length, GLsizei value)
......@@ -5435,6 +5454,12 @@ bool ValidateGetTexParameterBase(Context *context,
return false;
}
if (context->getClientMajorVersion() == 1 && !IsValidGLES1TextureParameter(pname))
{
ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported);
return false;
}
switch (pname)
{
case GL_TEXTURE_MAG_FILTER:
......@@ -5501,6 +5526,16 @@ bool ValidateGetTexParameterBase(Context *context,
}
break;
case GL_GENERATE_MIPMAP:
case GL_TEXTURE_CROP_RECT_OES:
// TODO(lfy@google.com): Restrict to GL_OES_draw_texture
// after GL_OES_draw_texture functionality implemented
if (context->getClientMajorVersion() > 1)
{
ANGLE_VALIDATION_ERR(context, InvalidEnum(), GLES1Only);
return false;
}
break;
default:
ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported);
return false;
......@@ -5508,7 +5543,7 @@ bool ValidateGetTexParameterBase(Context *context,
if (length)
{
*length = 1;
*length = GetTexParameterCount(pname);
}
return true;
}
......@@ -5865,13 +5900,19 @@ bool ValidateTexParameterBase(Context *context,
return false;
}
const GLsizei minBufSize = 1;
const GLsizei minBufSize = GetTexParameterCount(pname);
if (bufSize >= 0 && bufSize < minBufSize)
{
ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize);
return false;
}
if (context->getClientMajorVersion() == 1 && !IsValidGLES1TextureParameter(pname))
{
ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported);
return false;
}
switch (pname)
{
case GL_TEXTURE_WRAP_R:
......@@ -5899,6 +5940,14 @@ bool ValidateTexParameterBase(Context *context,
}
break;
case GL_GENERATE_MIPMAP:
case GL_TEXTURE_CROP_RECT_OES:
if (context->getClientMajorVersion() > 1)
{
ANGLE_VALIDATION_ERR(context, InvalidEnum(), GLES1Only);
return false;
}
break;
default:
break;
}
......@@ -6083,6 +6132,14 @@ bool ValidateTexParameterBase(Context *context,
}
break;
case GL_GENERATE_MIPMAP:
case GL_TEXTURE_CROP_RECT_OES:
if (context->getClientMajorVersion() > 1)
{
ANGLE_VALIDATION_ERR(context, InvalidEnum(), GLES1Only);
return false;
}
break;
default:
ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported);
return false;
......
......@@ -840,7 +840,13 @@ bool ValidateGetTexEnvxv(Context *context,
bool ValidateGetTexParameterxv(Context *context, TextureType target, GLenum pname, GLfixed *params)
{
UNIMPLEMENTED();
ANGLE_VALIDATE_IS_GLES1(context);
if (!ValidateGetTexParameterBase(context, target, pname, nullptr))
{
return false;
}
return true;
}
......@@ -1248,8 +1254,9 @@ bool ValidateTexEnvxv(Context *context,
bool ValidateTexParameterx(Context *context, TextureType target, GLenum pname, GLfixed param)
{
UNIMPLEMENTED();
return true;
ANGLE_VALIDATE_IS_GLES1(context);
GLfloat paramf = FixedToFloat(param);
return ValidateTexParameterBase(context, target, pname, 1, &paramf);
}
bool ValidateTexParameterxv(Context *context,
......@@ -1257,8 +1264,13 @@ bool ValidateTexParameterxv(Context *context,
GLenum pname,
const GLfixed *params)
{
UNIMPLEMENTED();
return true;
ANGLE_VALIDATE_IS_GLES1(context);
GLfloat paramsf[4] = {};
for (unsigned int i = 0; i < GetTexParameterCount(pname); i++)
{
paramsf[i] = FixedToFloat(params[i]);
}
return ValidateTexParameterBase(context, target, pname, -1, paramsf);
}
bool ValidateTranslatef(Context *context, GLfloat x, GLfloat y, GLfloat z)
......
......@@ -6261,7 +6261,7 @@ bool ValidateReadPixels(Context *context,
bool ValidateTexParameterf(Context *context, TextureType target, GLenum pname, GLfloat param)
{
return ValidateTexParameterBase(context, target, pname, -1, &param);
return ValidateTexParameterBase(context, target, pname, 1, &param);
}
bool ValidateTexParameterfv(Context *context,
......@@ -6274,7 +6274,7 @@ bool ValidateTexParameterfv(Context *context,
bool ValidateTexParameteri(Context *context, TextureType target, GLenum pname, GLint param)
{
return ValidateTexParameterBase(context, target, pname, -1, &param);
return ValidateTexParameterBase(context, target, pname, 1, &param);
}
bool ValidateTexParameteriv(Context *context, TextureType target, GLenum pname, const GLint *params)
......
......@@ -67,6 +67,7 @@
'<(angle_path)/src/tests/gl_tests/gles1/PointParameterTest.cpp',
'<(angle_path)/src/tests/gl_tests/gles1/ShadeModelTest.cpp',
'<(angle_path)/src/tests/gl_tests/gles1/TextureEnvTest.cpp',
'<(angle_path)/src/tests/gl_tests/gles1/TextureParameterTest.cpp',
'<(angle_path)/src/tests/gl_tests/gles1/TextureTargetEnableTest.cpp',
'<(angle_path)/src/tests/gl_tests/gles1/VertexPointerTest.cpp',
'<(angle_path)/src/tests/gl_tests/GLSLTest.cpp',
......
//
// Copyright 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// TextureParameterTest.cpp: Tests GLES1-specific usage of glTexParameter.
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"
#include "random_utils.h"
#include <stdint.h>
using namespace angle;
class TextureParameterTest : public ANGLETest
{
protected:
TextureParameterTest()
{
setWindowWidth(32);
setWindowHeight(32);
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
setConfigDepthBits(24);
}
};
// Initial state check
TEST_P(TextureParameterTest, InitialState)
{
GLint params[4] = {};
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, params);
EXPECT_GL_NO_ERROR();
EXPECT_EQ(GL_NEAREST_MIPMAP_LINEAR, params[0]);
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, params);
EXPECT_GL_NO_ERROR();
EXPECT_EQ(GL_LINEAR, params[0]);
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, params);
EXPECT_GL_NO_ERROR();
EXPECT_EQ(GL_REPEAT, params[0]);
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, params);
EXPECT_GL_NO_ERROR();
EXPECT_EQ(GL_REPEAT, params[0]);
glGetTexParameteriv(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, params);
EXPECT_GL_NO_ERROR();
EXPECT_GL_FALSE(params[0]);
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, params);
EXPECT_GL_NO_ERROR();
EXPECT_EQ(0, params[0]);
EXPECT_EQ(0, params[1]);
EXPECT_EQ(0, params[2]);
EXPECT_EQ(0, params[3]);
}
// Negative test: invalid enum / operation
TEST_P(TextureParameterTest, NegativeEnum)
{
// Invalid target (not supported)
glGetTexParameteriv(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, nullptr);
EXPECT_GL_ERROR(GL_INVALID_ENUM);
// Invalid parameter name
glGetTexParameteriv(GL_TEXTURE_2D, 0, nullptr);
EXPECT_GL_ERROR(GL_INVALID_ENUM);
// Not enough buffer
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, 3);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
// Not supported in GLES1
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
EXPECT_GL_ERROR(GL_INVALID_ENUM);
}
// Checks that GLES1-specific texture parameters can be set.
TEST_P(TextureParameterTest, Set)
{
GLint params[4] = {};
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
EXPECT_GL_NO_ERROR();
glGetTexParameteriv(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, params);
EXPECT_GL_NO_ERROR();
EXPECT_GL_TRUE(params[0]);
GLint cropRect[4] = {10, 20, 30, 40};
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, cropRect);
EXPECT_GL_NO_ERROR();
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, params);
EXPECT_GL_NO_ERROR();
for (int i = 0; i < 4; i++)
{
EXPECT_EQ(cropRect[i], params[i]);
}
}
ANGLE_INSTANTIATE_TEST(TextureParameterTest, ES1_D3D11(), ES1_OPENGL(), ES1_OPENGLES());
......@@ -269,7 +269,6 @@ TEST_P(GLES1ConformanceTest, LogicOp)
TEST_P(GLES1ConformanceTest, Mip)
{
ANGLE_SKIP_TEST_IF(true);
ASSERT_NE(CONFORMANCE_TEST_ERROR, MipExec());
}
......@@ -281,13 +280,11 @@ TEST_P(GLES1ConformanceTest, MipLevels)
TEST_P(GLES1ConformanceTest, MipLin)
{
ANGLE_SKIP_TEST_IF(true);
ASSERT_NE(CONFORMANCE_TEST_ERROR, MipLinExec());
}
TEST_P(GLES1ConformanceTest, MipSelect)
{
ANGLE_SKIP_TEST_IF(true);
ASSERT_NE(CONFORMANCE_TEST_ERROR, MipSelectExec());
}
......
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