mirror of
https://github.com/love2d/love.git
synced 2026-08-17 11:00:31 +02:00
Merge branch '12.0-development' into metal
This commit is contained in:
@@ -123,7 +123,7 @@ CompareMode getReversedCompareMode(CompareMode mode)
|
||||
}
|
||||
}
|
||||
|
||||
static StringMap<BlendMode, BLEND_MAX_ENUM>::Entry blendModeEntries[] =
|
||||
STRINGMAP_BEGIN(BlendMode, BLEND_MAX_ENUM, blendMode)
|
||||
{
|
||||
{ "alpha", BLEND_ALPHA },
|
||||
{ "add", BLEND_ADD },
|
||||
@@ -135,19 +135,17 @@ static StringMap<BlendMode, BLEND_MAX_ENUM>::Entry blendModeEntries[] =
|
||||
{ "replace", BLEND_REPLACE },
|
||||
{ "none", BLEND_NONE },
|
||||
{ "custom", BLEND_CUSTOM },
|
||||
};
|
||||
}
|
||||
STRINGMAP_END(BlendMode, BLEND_MAX_ENUM, blendMode)
|
||||
|
||||
static StringMap<BlendMode, BLEND_MAX_ENUM> blendModes(blendModeEntries, sizeof(blendModeEntries));
|
||||
|
||||
static StringMap<BlendAlpha, BLENDALPHA_MAX_ENUM>::Entry blendAlphaEntries[] =
|
||||
STRINGMAP_BEGIN(BlendAlpha, BLENDALPHA_MAX_ENUM, blendAlpha)
|
||||
{
|
||||
{ "alphamultiply", BLENDALPHA_MULTIPLY },
|
||||
{ "premultiplied", BLENDALPHA_PREMULTIPLIED },
|
||||
};
|
||||
}
|
||||
STRINGMAP_END(BlendAlpha, BLENDALPHA_MAX_ENUM, blendAlpha)
|
||||
|
||||
static StringMap<BlendAlpha, BLENDALPHA_MAX_ENUM> blendAlphaModes(blendAlphaEntries, sizeof(blendAlphaEntries));
|
||||
|
||||
static StringMap<BlendFactor, BLENDFACTOR_MAX_ENUM>::Entry blendFactorEntries[] =
|
||||
STRINGMAP_BEGIN(BlendFactor, BLENDFACTOR_MAX_ENUM, blendFactor)
|
||||
{
|
||||
{ "zero", BLENDFACTOR_ZERO },
|
||||
{ "one", BLENDFACTOR_ONE },
|
||||
@@ -160,22 +158,20 @@ static StringMap<BlendFactor, BLENDFACTOR_MAX_ENUM>::Entry blendFactorEntries[]
|
||||
{ "dstalpha", BLENDFACTOR_DST_ALPHA },
|
||||
{ "oneminusdstalpha", BLENDFACTOR_ONE_MINUS_DST_ALPHA },
|
||||
{ "srcalphasaturated", BLENDFACTOR_SRC_ALPHA_SATURATED },
|
||||
};
|
||||
}
|
||||
STRINGMAP_END(BlendFactor, BLENDFACTOR_MAX_ENUM, blendFactor)
|
||||
|
||||
static StringMap<BlendFactor, BLENDFACTOR_MAX_ENUM> blendFactors(blendFactorEntries, sizeof(blendFactorEntries));
|
||||
|
||||
static StringMap<BlendOperation, BLENDOP_MAX_ENUM>::Entry blendOperationEntries[] =
|
||||
STRINGMAP_BEGIN(BlendOperation, BLENDOP_MAX_ENUM, blendOperation)
|
||||
{
|
||||
{ "add", BLENDOP_ADD },
|
||||
{ "subtract", BLENDOP_SUBTRACT },
|
||||
{ "reversesubtract", BLENDOP_REVERSE_SUBTRACT },
|
||||
{ "min", BLENDOP_MIN },
|
||||
{ "max", BLENDOP_MAX },
|
||||
};
|
||||
}
|
||||
STRINGMAP_END(BlendOperation, BLENDOP_MAX_ENUM, blendOperation)
|
||||
|
||||
static StringMap<BlendOperation, BLENDOP_MAX_ENUM> blendOperations(blendOperationEntries, sizeof(blendOperationEntries));
|
||||
|
||||
static StringMap<StencilAction, STENCIL_MAX_ENUM>::Entry stencilActionEntries[] =
|
||||
STRINGMAP_BEGIN(StencilAction, STENCIL_MAX_ENUM, stencilAction)
|
||||
{
|
||||
{ "keep", STENCIL_KEEP },
|
||||
{ "zero", STENCIL_ZERO },
|
||||
@@ -185,11 +181,10 @@ static StringMap<StencilAction, STENCIL_MAX_ENUM>::Entry stencilActionEntries[]
|
||||
{ "incrementwrap", STENCIL_INCREMENT_WRAP },
|
||||
{ "decrementwrap", STENCIL_DECREMENT_WRAP },
|
||||
{ "invert", STENCIL_INVERT },
|
||||
};
|
||||
}
|
||||
STRINGMAP_END(StencilAction, STENCIL_MAX_ENUM, stencilAction)
|
||||
|
||||
static StringMap<StencilAction, STENCIL_MAX_ENUM> stencilActions(stencilActionEntries, sizeof(stencilActionEntries));
|
||||
|
||||
static StringMap<CompareMode, COMPARE_MAX_ENUM>::Entry compareModeEntries[] =
|
||||
STRINGMAP_BEGIN(CompareMode, COMPARE_MAX_ENUM, compareMode)
|
||||
{
|
||||
{ "less", COMPARE_LESS },
|
||||
{ "lequal", COMPARE_LEQUAL },
|
||||
@@ -199,99 +194,8 @@ static StringMap<CompareMode, COMPARE_MAX_ENUM>::Entry compareModeEntries[] =
|
||||
{ "notequal", COMPARE_NOTEQUAL },
|
||||
{ "always", COMPARE_ALWAYS },
|
||||
{ "never", COMPARE_NEVER },
|
||||
};
|
||||
|
||||
static StringMap<CompareMode, COMPARE_MAX_ENUM> compareModes(compareModeEntries, sizeof(compareModeEntries));
|
||||
|
||||
bool getConstant(const char *in, BlendMode &out)
|
||||
{
|
||||
return blendModes.find(in, out);
|
||||
}
|
||||
|
||||
bool getConstant(BlendMode in, const char *&out)
|
||||
{
|
||||
return blendModes.find(in, out);
|
||||
}
|
||||
|
||||
std::vector<std::string> getConstants(BlendMode)
|
||||
{
|
||||
return blendModes.getNames();
|
||||
}
|
||||
|
||||
bool getConstant(const char *in, BlendAlpha &out)
|
||||
{
|
||||
return blendAlphaModes.find(in, out);
|
||||
}
|
||||
|
||||
bool getConstant(BlendAlpha in, const char *&out)
|
||||
{
|
||||
return blendAlphaModes.find(in, out);
|
||||
}
|
||||
|
||||
std::vector<std::string> getConstants(BlendAlpha)
|
||||
{
|
||||
return blendAlphaModes.getNames();
|
||||
}
|
||||
|
||||
bool getConstant(const char *in, BlendFactor &out)
|
||||
{
|
||||
return blendFactors.find(in, out);
|
||||
}
|
||||
|
||||
bool getConstant(BlendFactor in, const char *&out)
|
||||
{
|
||||
return blendFactors.find(in, out);
|
||||
}
|
||||
|
||||
std::vector<std::string> getConstants(BlendFactor)
|
||||
{
|
||||
return blendFactors.getNames();
|
||||
}
|
||||
|
||||
bool getConstant(const char *in, BlendOperation &out)
|
||||
{
|
||||
return blendOperations.find(in, out);
|
||||
}
|
||||
|
||||
bool getConstant(BlendOperation in, const char *&out)
|
||||
{
|
||||
return blendOperations.find(in, out);
|
||||
}
|
||||
|
||||
std::vector<std::string> getConstants(BlendOperation)
|
||||
{
|
||||
return blendOperations.getNames();
|
||||
}
|
||||
|
||||
bool getConstant(const char *in, StencilAction &out)
|
||||
{
|
||||
return stencilActions.find(in, out);
|
||||
}
|
||||
|
||||
bool getConstant(StencilAction in, const char *&out)
|
||||
{
|
||||
return stencilActions.find(in, out);
|
||||
}
|
||||
|
||||
std::vector<std::string> getConstants(StencilAction)
|
||||
{
|
||||
return stencilActions.getNames();
|
||||
}
|
||||
|
||||
bool getConstant(const char *in, CompareMode &out)
|
||||
{
|
||||
return compareModes.find(in, out);
|
||||
}
|
||||
|
||||
bool getConstant(CompareMode in, const char *&out)
|
||||
{
|
||||
return compareModes.find(in, out);
|
||||
}
|
||||
|
||||
std::vector<std::string> getConstants(CompareMode)
|
||||
{
|
||||
return compareModes.getNames();
|
||||
}
|
||||
STRINGMAP_END(CompareMode, COMPARE_MAX_ENUM, compareMode)
|
||||
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#include "common/int.h"
|
||||
#include "common/math.h"
|
||||
#include "common/StringMap.h"
|
||||
#include "vertex.h"
|
||||
|
||||
#include <vector>
|
||||
@@ -203,29 +204,12 @@ bool isAlphaMultiplyBlendSupported(BlendMode mode);
|
||||
**/
|
||||
CompareMode getReversedCompareMode(CompareMode mode);
|
||||
|
||||
bool getConstant(const char *in, BlendMode &out);
|
||||
bool getConstant(BlendMode in, const char *&out);
|
||||
std::vector<std::string> getConstants(BlendMode);
|
||||
|
||||
bool getConstant(const char *in, BlendAlpha &out);
|
||||
bool getConstant(BlendAlpha in, const char *&out);
|
||||
std::vector<std::string> getConstants(BlendAlpha);
|
||||
|
||||
bool getConstant(const char *in, BlendFactor &out);
|
||||
bool getConstant(BlendFactor in, const char *&out);
|
||||
std::vector<std::string> getConstants(BlendFactor);
|
||||
|
||||
bool getConstant(const char *in, BlendOperation &out);
|
||||
bool getConstant(BlendOperation in, const char *&out);
|
||||
std::vector<std::string> getConstants(BlendOperation);
|
||||
|
||||
bool getConstant(const char *in, StencilAction &out);
|
||||
bool getConstant(StencilAction in, const char *&out);
|
||||
std::vector<std::string> getConstants(StencilAction);
|
||||
|
||||
bool getConstant(const char *in, CompareMode &out);
|
||||
bool getConstant(CompareMode in, const char *&out);
|
||||
std::vector<std::string> getConstants(CompareMode);
|
||||
STRINGMAP_DECLARE(BlendMode);
|
||||
STRINGMAP_DECLARE(BlendAlpha);
|
||||
STRINGMAP_DECLARE(BlendFactor);
|
||||
STRINGMAP_DECLARE(BlendOperation);
|
||||
STRINGMAP_DECLARE(StencilAction);
|
||||
STRINGMAP_DECLARE(CompareMode);
|
||||
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
@@ -309,75 +309,6 @@ static int w_Buffer_setArrayData(lua_State *L)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int w_Buffer_setElement(lua_State *L)
|
||||
{
|
||||
Buffer *t = luax_checkbuffer(L, 1);
|
||||
|
||||
size_t index = (size_t) (luaL_checkinteger(L, 2) - 1);
|
||||
if (index >= t->getArrayLength())
|
||||
return luaL_error(L, "Invalid Buffer element index: %d", (int) index + 1);
|
||||
|
||||
size_t stride = t->getArrayStride();
|
||||
size_t offset = index * stride;
|
||||
char *data = (char *) t->map() + offset;
|
||||
const auto &members = t->getDataMembers();
|
||||
|
||||
bool istable = lua_istable(L, 3);
|
||||
int idx = istable ? 1 : 3;
|
||||
|
||||
if (istable)
|
||||
{
|
||||
for (const Buffer::DataMember &member : members)
|
||||
{
|
||||
int components = member.info.components;
|
||||
|
||||
for (int i = idx; i < idx + components; i++)
|
||||
lua_rawgeti(L, 3, i);
|
||||
|
||||
luax_writebufferdata(L, -components, member.decl.format, data + member.offset);
|
||||
|
||||
idx += components;
|
||||
lua_pop(L, components);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (const Buffer::DataMember &member : members)
|
||||
{
|
||||
luax_writebufferdata(L, idx, member.decl.format, data + member.offset);
|
||||
idx += member.info.components;
|
||||
}
|
||||
}
|
||||
|
||||
t->setMappedRangeModified(offset, stride);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int w_Buffer_getElement(lua_State *L)
|
||||
{
|
||||
Buffer *t = luax_checkbuffer(L, 1);
|
||||
if ((t->getMapFlags() & Buffer::MAP_READ) == 0)
|
||||
return luaL_error(L, "Buffer:getElement requires the buffer to be created with the 'cpureadable' setting set to true.");
|
||||
|
||||
size_t index = (size_t) (luaL_checkinteger(L, 2) - 1);
|
||||
if (index >= t->getArrayLength())
|
||||
return luaL_error(L, "Invalid Buffer element index: %d", (int) index + 1);
|
||||
|
||||
size_t offset = index * t->getArrayStride();
|
||||
const char *data = (const char *) t->map() + offset;
|
||||
const auto &members = t->getDataMembers();
|
||||
|
||||
int n = 0;
|
||||
|
||||
for (const Buffer::DataMember &member : members)
|
||||
{
|
||||
luax_readbufferdata(L, member.decl.format, data + member.offset);
|
||||
n += member.info.components;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
static int w_Buffer_getElementCount(lua_State *L)
|
||||
{
|
||||
Buffer *t = luax_checkbuffer(L, 1);
|
||||
@@ -443,25 +374,15 @@ static int w_Buffer_isBufferType(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int w_Buffer_isCPUReadable(lua_State *L)
|
||||
{
|
||||
Buffer *t = luax_checkbuffer(L, 1);
|
||||
luax_pushboolean(L, (t->getMapFlags() & Buffer::MAP_READ) != 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg w_Buffer_functions[] =
|
||||
{
|
||||
{ "flush", w_Buffer_flush },
|
||||
{ "setArrayData", w_Buffer_setArrayData },
|
||||
{ "setElement", w_Buffer_setElement },
|
||||
{ "getElement", w_Buffer_getElement },
|
||||
{ "getElementCount", w_Buffer_getElementCount },
|
||||
{ "getElementStride", w_Buffer_getElementStride },
|
||||
{ "getSize", w_Buffer_getSize },
|
||||
{ "getFormat", w_Buffer_getFormat },
|
||||
{ "isBufferType", w_Buffer_isBufferType },
|
||||
{ "isCPUReadable", w_Buffer_isCPUReadable },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
@@ -1146,7 +1146,7 @@ int w_newVolumeTexture(lua_State *L)
|
||||
|
||||
for (int slice = 0; slice < slicelen; slice++)
|
||||
{
|
||||
lua_rawgeti(L, -1, mip + 1);
|
||||
lua_rawgeti(L, -1, slice + 1);
|
||||
|
||||
auto data = getImageData(L, -1, true, slice == 0 && mip == 0 ? autodpiscale : nullptr);
|
||||
if (data.first.get())
|
||||
@@ -1508,11 +1508,6 @@ static void luax_optbuffersettings(lua_State *L, int idx, Buffer::Settings &sett
|
||||
lua_getfield(L, idx, "usage");
|
||||
settings.usage = luax_optbufferusage(L, -1, settings.usage);
|
||||
lua_pop(L, 1);
|
||||
|
||||
if (luax_boolflag(L, idx, "cpureadable", settings.mapFlags & Buffer::MAP_READ))
|
||||
settings.mapFlags = (Buffer::MapFlags)(settings.mapFlags | Buffer::MAP_READ);
|
||||
else
|
||||
settings.mapFlags = (Buffer::MapFlags)(settings.mapFlags & (~Buffer::MAP_READ));
|
||||
}
|
||||
|
||||
static void luax_checkbufferformat(lua_State *L, int idx, std::vector<Buffer::DataDeclaration> &format)
|
||||
|
||||
Reference in New Issue
Block a user