Error if a non-2D/affine matrix is used with auto-batched draws, since they perform CPU-side matrix transforms on 2-component vectors.

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2017-04-23 00:12:57 -03:00
parent 7161d600b7
commit 70b32c47ce
13 changed files with 79 additions and 26 deletions
+7 -7
View File
@@ -62,10 +62,10 @@ Canvas::Canvas(const Settings &settings)
if (readable && isPixelFormatDepthStencil(format) && settings.msaa > 1)
throw love::Exception("Readable depth/stencil Canvases with MSAA are not currently supported.");
if ((!readable || settings.msaa > 1) && settings.mipmaps != MIPMAP_NONE)
if ((!readable || settings.msaa > 1) && settings.mipmaps != MIPMAPS_NONE)
throw love::Exception("Non-readable and MSAA textures cannot have mipmaps.");
mipmapCount = settings.mipmaps == MIPMAP_NONE ? 1 : getMipmapCount(pixelWidth, pixelHeight);
mipmapCount = settings.mipmaps == MIPMAPS_NONE ? 1 : getMipmapCount(pixelWidth, pixelHeight);
canvasCount++;
}
@@ -111,14 +111,14 @@ bool Canvas::getConstant(MipmapMode in, const char *&out)
return mipmapModes.find(in, out);
}
StringMap<Canvas::MipmapMode, Canvas::MIPMAP_MAX_ENUM>::Entry Canvas::mipmapEntries[] =
StringMap<Canvas::MipmapMode, Canvas::MIPMAPS_MAX_ENUM>::Entry Canvas::mipmapEntries[] =
{
{ "none", MIPMAP_NONE },
{ "manual", MIPMAP_MANUAL },
{ "auto", MIPMAP_AUTO },
{ "none", MIPMAPS_NONE },
{ "manual", MIPMAPS_MANUAL },
{ "auto", MIPMAPS_AUTO },
};
StringMap<Canvas::MipmapMode, Canvas::MIPMAP_MAX_ENUM> Canvas::mipmapModes(Canvas::mipmapEntries, sizeof(Canvas::mipmapEntries));
StringMap<Canvas::MipmapMode, Canvas::MIPMAPS_MAX_ENUM> Canvas::mipmapModes(Canvas::mipmapEntries, sizeof(Canvas::mipmapEntries));
} // graphics
} // love
+7 -7
View File
@@ -41,10 +41,10 @@ public:
enum MipmapMode
{
MIPMAP_NONE,
MIPMAP_MANUAL,
MIPMAP_AUTO,
MIPMAP_MAX_ENUM
MIPMAPS_NONE,
MIPMAPS_MANUAL,
MIPMAPS_AUTO,
MIPMAPS_MAX_ENUM
};
struct Settings
@@ -52,7 +52,7 @@ public:
int width = 1;
int height = 1;
int layers = 1; // depth for 3D textures
MipmapMode mipmaps = MIPMAP_NONE;
MipmapMode mipmaps = MIPMAPS_NONE;
PixelFormat format = PIXELFORMAT_NORMAL;
TextureType type = TEXTURE_2D;
float pixeldensity = 1.0f;
@@ -86,8 +86,8 @@ protected:
private:
static StringMap<MipmapMode, MIPMAP_MAX_ENUM>::Entry mipmapEntries[];
static StringMap<MipmapMode, MIPMAP_MAX_ENUM> mipmapModes;
static StringMap<MipmapMode, MIPMAPS_MAX_ENUM>::Entry mipmapEntries[];
static StringMap<MipmapMode, MIPMAPS_MAX_ENUM> mipmapModes;
}; // Canvas
+10
View File
@@ -593,6 +593,16 @@ Graphics::StreamVertexData Graphics::requestStreamDraw(const StreamDrawRequest &
if (state.vertexCount == 0 && Shader::current != nullptr && req.texture != nullptr)
Shader::current->checkMainTexture(req.texture);
if (!getTransform().isAffine2DTransform())
{
for (CommonFormat fmt : req.formats)
{
int components = getFormatPositionComponents(fmt);
if (components > 0 && components < 3)
throw love::Exception("Obly affine 2D transforms are supported with auto-batched draws.");
}
}
bool shouldflush = false;
bool shouldresize = false;
+1 -1
View File
@@ -523,7 +523,7 @@ love::image::ImageData *Canvas::newImageData(love::image::Image *module, int sli
void Canvas::generateMipmaps()
{
if (getMipmapCount() == 1 || getMipmapMode() == MIPMAP_NONE)
if (getMipmapCount() == 1 || getMipmapMode() == MIPMAPS_NONE)
throw love::Exception("generateMipmaps can only be called on a Canvas which was created with mipmaps enabled.");
gl.bindTextureToUnit(this, 0, false);
+2 -2
View File
@@ -713,12 +713,12 @@ void Graphics::endPass()
for (const auto &rt : rts.colors)
{
if (rt.canvas->getMipmapMode() == Canvas::MIPMAP_AUTO && rt.mipmap == 0)
if (rt.canvas->getMipmapMode() == Canvas::MIPMAPS_AUTO && rt.mipmap == 0)
rt.canvas->generateMipmaps();
}
int dsmipmap = rts.depthStencil.mipmap;
if (depthstencil != nullptr && depthstencil->getMipmapMode() == Canvas::MIPMAP_AUTO && dsmipmap == 0)
if (depthstencil != nullptr && depthstencil->getMipmapMode() == Canvas::MIPMAPS_AUTO && dsmipmap == 0)
depthstencil->generateMipmaps();
}
+17
View File
@@ -79,6 +79,23 @@ uint32 getFormatFlags(CommonFormat format)
}
}
int getFormatPositionComponents(CommonFormat format)
{
switch (format)
{
case CommonFormat::NONE:
case CommonFormat::RGBAub:
return 0;
case CommonFormat::XYf:
case CommonFormat::XYf_STf:
case CommonFormat::XYf_STPf:
case CommonFormat::XYf_STf_RGBAub:
case CommonFormat::XYf_STus_RGBAub:
case CommonFormat::XYf_STPf_RGBAub:
return 2;
}
}
size_t getIndexDataSize(IndexDataType type)
{
switch (type)
+5
View File
@@ -137,8 +137,13 @@ struct XYf_STPf_RGBAub
};
size_t getFormatStride(CommonFormat format);
uint32 getFormatFlags(CommonFormat format);
int getFormatPositionComponents(CommonFormat format);
size_t getIndexDataSize(IndexDataType type);
IndexDataType getIndexDataTypeFromMax(size_t maxvalue);
int getIndexCount(TriangleIndexMode mode, int vertexCount);
+3 -3
View File
@@ -2519,7 +2519,7 @@ int w_push(lua_State *L)
if (luax_istype(L, 2, math::Transform::type))
{
math::Transform *t = luax_totype<math::Transform>(L, 2);
instance()->applyTransform(t);
luax_catchexcept(L, [&]() { instance()->applyTransform(t); });
}
return 0;
@@ -2571,14 +2571,14 @@ int w_origin(lua_State * /*L*/)
int w_applyTransform(lua_State *L)
{
math::Transform *t = math::luax_checktransform(L, 1);
instance()->applyTransform(t);
luax_catchexcept(L, [&]() { instance()->applyTransform(t); });
return 0;
}
int w_replaceTransform(lua_State *L)
{
math::Transform *t = math::luax_checktransform(L, 1);
instance()->replaceTransform(t);
luax_catchexcept(L, [&]() { instance()->replaceTransform(t); });
return 0;
}
+2 -2
View File
@@ -204,7 +204,7 @@ GLSL.VERTEX = {
#endif]],
FUNCTIONS = [[
void updatePointSize() {
void setPointSize() {
#ifdef GL_ES
gl_PointSize = love_PointSize;
#endif
@@ -224,7 +224,7 @@ vec4 position(mat4 transform_proj, vec4 vertpos);
void main() {
VaryingTexCoord = VertexTexCoord;
VaryingColor = gammaCorrectColor(VertexColor) * ConstantColor;
updatePointSize();
setPointSize();
love_Position = position(TransformProjectionMatrix, VertexPosition);
}]],
}
+8
View File
@@ -57,6 +57,13 @@ int w_Transform_apply(lua_State *L)
return 1;
}
int w_Transform_isAffine2DTransform(lua_State *L)
{
Transform *t = luax_checktransform(L, 1);
luax_pushboolean(L, t->getMatrix().isAffine2DTransform());
return 1;
}
int w_Transform_translate(lua_State *L)
{
Transform *t = luax_checktransform(L, 1);
@@ -284,6 +291,7 @@ static const luaL_Reg functions[] =
{ "clone", w_Transform_clone },
{ "inverse", w_Transform_inverse },
{ "apply", w_Transform_apply },
{ "isAffine2DTransform", w_Transform_isAffine2DTransform },
{ "translate", w_Transform_translate },
{ "rotate", w_Transform_rotate },
{ "scale", w_Transform_scale },