mirror of
https://github.com/love2d/love.git
synced 2026-08-15 15:51:12 +02:00
Merge in default, update changelog
--HG-- branch : minor
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2012 LOVE Development Team
|
||||
* Copyright (c) 2006-2013 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
@@ -19,7 +19,7 @@
|
||||
**/
|
||||
|
||||
#include "wrap_Graphics.h"
|
||||
#include "GLee.h"
|
||||
#include "OpenGL.h"
|
||||
#include "graphics/DrawQable.h"
|
||||
#include "image/ImageData.h"
|
||||
#include "font/Rasterizer.h"
|
||||
@@ -491,29 +491,50 @@ int w_newCanvas(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newPixelEffect(lua_State *L)
|
||||
int w_newShader(lua_State *L)
|
||||
{
|
||||
if (!PixelEffect::isSupported())
|
||||
return luaL_error(L, "Sorry, your graphics card does not support pixel effects.");
|
||||
if (!Shader::isSupported())
|
||||
return luaL_error(L, "Sorry, your graphics card does not support shaders.");
|
||||
|
||||
try
|
||||
{
|
||||
luaL_checkstring(L, 1);
|
||||
// clamp stack to 2 elements
|
||||
lua_settop(L, 2);
|
||||
|
||||
luax_getfunction(L, "graphics", "_effectCodeToGLSL");
|
||||
lua_pushvalue(L, 1);
|
||||
lua_pcall(L, 1, 1, 0);
|
||||
|
||||
const char *code = lua_tostring(L, -1);
|
||||
PixelEffect *effect = instance->newPixelEffect(code);
|
||||
luax_newtype(L, "PixelEffect", GRAPHICS_PIXELEFFECT_T, (void *)effect);
|
||||
// push vertcode and fragcode strings to the top of the stack so they become arguments for the function
|
||||
lua_pushvalue(L, 1);
|
||||
lua_pushvalue(L, 2);
|
||||
|
||||
// call effectCodeToGLSL, returned values will be at the top of the stack
|
||||
lua_pcall(L, 2, 2, 0);
|
||||
|
||||
Shader::ShaderSources sources;
|
||||
|
||||
// vertex shader code
|
||||
if (lua_isstring(L, -2))
|
||||
{
|
||||
std::string vertcode(luaL_checkstring(L, -2));
|
||||
sources[Shader::TYPE_VERTEX] = vertcode;
|
||||
}
|
||||
|
||||
// fragment shader code
|
||||
if (lua_isstring(L, -1))
|
||||
{
|
||||
std::string fragcode(luaL_checkstring(L, -1));
|
||||
sources[Shader::TYPE_FRAGMENT] = fragcode;
|
||||
}
|
||||
|
||||
Shader *shader = instance->newShader(sources);
|
||||
luax_newtype(L, "Shader", GRAPHICS_SHADER_T, (void *)shader);
|
||||
}
|
||||
catch(const love::Exception &e)
|
||||
{
|
||||
// memory is freed in Graphics::newPixelEffect
|
||||
// memory is freed in Graphics::newShader
|
||||
luax_getfunction(L, "graphics", "_transformGLSLErrorMessages");
|
||||
lua_pushstring(L, e.what());
|
||||
lua_pcall(L, 1,1, 0);
|
||||
lua_pcall(L, 1, 1, 0);
|
||||
const char *err = lua_tostring(L, -1);
|
||||
return luaL_error(L, "%s", err);
|
||||
}
|
||||
@@ -679,13 +700,19 @@ int w_setDefaultImageFilter(lua_State *L)
|
||||
|
||||
int w_getBlendMode(lua_State *L)
|
||||
{
|
||||
Graphics::BlendMode mode = instance->getBlendMode();
|
||||
const char *str;
|
||||
if (!Graphics::getConstant(mode, str))
|
||||
return luaL_error(L, "Invalid blend mode: %s", str);
|
||||
|
||||
lua_pushstring(L, str);
|
||||
return 1;
|
||||
try
|
||||
{
|
||||
Graphics::BlendMode mode = instance->getBlendMode();
|
||||
const char *str;
|
||||
if (!Graphics::getConstant(mode, str))
|
||||
return luaL_error(L, "Unknown blend mode");
|
||||
lua_pushstring(L, str);
|
||||
return 1;
|
||||
}
|
||||
catch (love::Exception &e)
|
||||
{
|
||||
return luaL_error(L, "%s", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
int w_getColorMode(lua_State *L)
|
||||
@@ -693,8 +720,7 @@ int w_getColorMode(lua_State *L)
|
||||
Graphics::ColorMode mode = instance->getColorMode();
|
||||
const char *str;
|
||||
if (!Graphics::getConstant(mode, str))
|
||||
return luaL_error(L, "Invalid color mode: %s", str);
|
||||
|
||||
return luaL_error(L, "Unknown color mode");
|
||||
lua_pushstring(L, str);
|
||||
return 1;
|
||||
}
|
||||
@@ -704,8 +730,10 @@ int w_getDefaultImageFilter(lua_State *L)
|
||||
const Image::Filter &f = instance->getDefaultImageFilter();
|
||||
const char *minstr;
|
||||
const char *magstr;
|
||||
Image::getConstant(f.min, minstr);
|
||||
Image::getConstant(f.mag, magstr);
|
||||
if (!Image::getConstant(f.min, minstr))
|
||||
return luaL_error(L, "Unknown filter mode for argument #1");
|
||||
if (!Image::getConstant(f.mag, magstr))
|
||||
return luaL_error(L, "Unknown filter mode for argument #2");
|
||||
lua_pushstring(L, minstr);
|
||||
lua_pushstring(L, magstr);
|
||||
return 2;
|
||||
@@ -756,7 +784,8 @@ int w_getLineStyle(lua_State *L)
|
||||
{
|
||||
Graphics::LineStyle style = instance->getLineStyle();
|
||||
const char *str;
|
||||
Graphics::getConstant(style, str);
|
||||
if (!Graphics::getConstant(style, str))
|
||||
return luaL_error(L, "Unknown line style");
|
||||
lua_pushstring(L, str);
|
||||
return 1;
|
||||
}
|
||||
@@ -805,7 +834,11 @@ int w_getPointSize(lua_State *L)
|
||||
|
||||
int w_getPointStyle(lua_State *L)
|
||||
{
|
||||
lua_pushinteger(L, instance->getPointStyle());
|
||||
Graphics::PointStyle style = instance->getPointStyle();
|
||||
const char *str;
|
||||
if (!Graphics::getConstant(style, str))
|
||||
return luaL_error(L, "Unknown point style");
|
||||
lua_pushstring(L, str);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -856,26 +889,26 @@ int w_getCanvas(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_setPixelEffect(lua_State *L)
|
||||
int w_setShader(lua_State *L)
|
||||
{
|
||||
if (lua_isnoneornil(L,1))
|
||||
{
|
||||
PixelEffect::detach();
|
||||
Shader::detach();
|
||||
return 0;
|
||||
}
|
||||
|
||||
PixelEffect *effect = luax_checkpixeleffect(L, 1);
|
||||
effect->attach();
|
||||
Shader *shader = luax_checkshader(L, 1);
|
||||
shader->attach();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_getPixelEffect(lua_State *L)
|
||||
int w_getShader(lua_State *L)
|
||||
{
|
||||
PixelEffect *effect = PixelEffect::current;
|
||||
if (effect)
|
||||
Shader *shader = Shader::current;
|
||||
if (shader)
|
||||
{
|
||||
effect->retain();
|
||||
luax_newtype(L, "PixelEffect", GRAPHICS_PIXELEFFECT_T, (void *) effect);
|
||||
shader->retain();
|
||||
luax_newtype(L, "Shader", GRAPHICS_SHADER_T, (void *) shader);
|
||||
}
|
||||
else
|
||||
lua_pushnil(L);
|
||||
@@ -892,7 +925,10 @@ int w_isSupported(lua_State *L)
|
||||
{
|
||||
const char *str = luaL_checkstring(L, i);
|
||||
if (!Graphics::getConstant(str, support))
|
||||
{
|
||||
supported = false;
|
||||
break;
|
||||
}
|
||||
switch (support)
|
||||
{
|
||||
case Graphics::SUPPORT_CANVAS:
|
||||
@@ -903,8 +939,8 @@ int w_isSupported(lua_State *L)
|
||||
if (!Canvas::isHdrSupported())
|
||||
supported = false;
|
||||
break;
|
||||
case Graphics::SUPPORT_PIXELEFFECT:
|
||||
if (!PixelEffect::isSupported())
|
||||
case Graphics::SUPPORT_SHADER:
|
||||
if (!Shader::isSupported())
|
||||
supported = false;
|
||||
break;
|
||||
case Graphics::SUPPORT_NPOT:
|
||||
@@ -990,20 +1026,6 @@ int w_drawq(lua_State *L)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_drawTest(lua_State *L)
|
||||
{
|
||||
Image *image = luax_checktype<Image>(L, 1, "Image", GRAPHICS_IMAGE_T);
|
||||
float x = (float)luaL_optnumber(L, 2, 0.0f);
|
||||
float y = (float)luaL_optnumber(L, 3, 0.0f);
|
||||
float angle = (float)luaL_optnumber(L, 4, 0.0f);
|
||||
float sx = (float)luaL_optnumber(L, 5, 1.0f);
|
||||
float sy = (float)luaL_optnumber(L, 6, sx);
|
||||
float ox = (float)luaL_optnumber(L, 7, 0);
|
||||
float oy = (float)luaL_optnumber(L, 8, 0);
|
||||
instance->drawTest(image, x, y, angle, sx, sy, ox, oy);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_print(lua_State *L)
|
||||
{
|
||||
const char *str = luaL_checkstring(L, 1);
|
||||
@@ -1323,7 +1345,7 @@ static const luaL_Reg functions[] =
|
||||
{ "newSpriteBatch", w_newSpriteBatch },
|
||||
{ "newParticleSystem", w_newParticleSystem },
|
||||
{ "newCanvas", w_newCanvas },
|
||||
{ "newPixelEffect", w_newPixelEffect },
|
||||
{ "newShader", w_newShader },
|
||||
|
||||
{ "setColor", w_setColor },
|
||||
{ "getColor", w_getColor },
|
||||
@@ -1354,14 +1376,13 @@ static const luaL_Reg functions[] =
|
||||
{ "setCanvas", w_setCanvas },
|
||||
{ "getCanvas", w_getCanvas },
|
||||
|
||||
{ "setPixelEffect", w_setPixelEffect },
|
||||
{ "getPixelEffect", w_getPixelEffect },
|
||||
{ "setShader", w_setShader },
|
||||
{ "getShader", w_getShader },
|
||||
|
||||
{ "isSupported", w_isSupported },
|
||||
|
||||
{ "draw", w_draw },
|
||||
{ "drawq", w_drawq },
|
||||
{ "drawTest", w_drawTest },
|
||||
|
||||
{ "print", w_print },
|
||||
{ "printf", w_printf },
|
||||
@@ -1416,7 +1437,7 @@ static const lua_CFunction types[] =
|
||||
luaopen_spritebatch,
|
||||
luaopen_particlesystem,
|
||||
luaopen_canvas,
|
||||
luaopen_pixeleffect,
|
||||
luaopen_shader,
|
||||
0
|
||||
};
|
||||
|
||||
@@ -1428,7 +1449,7 @@ extern "C" int luaopen_love_graphics(lua_State *L)
|
||||
{
|
||||
instance = new Graphics();
|
||||
}
|
||||
catch(Exception &e)
|
||||
catch (love::Exception &e)
|
||||
{
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user