mirror of
https://github.com/love2d/love.git
synced 2026-08-15 15:51:12 +02:00
Merge default into minor
--HG-- branch : minor
This commit is contained in:
@@ -111,11 +111,20 @@ int w_getSource(lua_State *L)
|
||||
|
||||
int w_mount(lua_State *L)
|
||||
{
|
||||
const char *archive = luaL_checkstring(L, 1);
|
||||
std::string archive;
|
||||
|
||||
if (luax_istype(L, 1, FILESYSTEM_DROPPED_FILE_ID))
|
||||
{
|
||||
DroppedFile *file = luax_totype<DroppedFile>(L, 1, FILESYSTEM_DROPPED_FILE_ID);
|
||||
archive = file->getFilename();
|
||||
}
|
||||
else
|
||||
archive = luax_checkstring(L, 1);
|
||||
|
||||
const char *mountpoint = luaL_checkstring(L, 2);
|
||||
bool append = luax_optboolean(L, 3, false);
|
||||
|
||||
luax_pushboolean(L, instance()->mount(archive, mountpoint, append));
|
||||
luax_pushboolean(L, instance()->mount(archive.c_str(), mountpoint, append));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "common/math.h"
|
||||
#include "common/Matrix.h"
|
||||
#include "graphics/Graphics.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <sstream>
|
||||
@@ -112,12 +113,36 @@ Font::TextureSize Font::getNextTextureSize() const
|
||||
return size;
|
||||
}
|
||||
|
||||
GLenum Font::getTextureFormat(FontType fontType, GLenum *internalformat) const
|
||||
{
|
||||
GLenum format = fontType == FONT_TRUETYPE ? GL_LUMINANCE_ALPHA : GL_RGBA;
|
||||
GLenum iformat = fontType == FONT_TRUETYPE ? GL_LUMINANCE8_ALPHA8 : GL_RGBA8;
|
||||
|
||||
if (format == GL_RGBA && isGammaCorrect())
|
||||
{
|
||||
// In ES2, the internalformat and format params of TexImage must match.
|
||||
// ES3 doesn't allow "GL_SRGB_ALPHA" as the internal format. But it also
|
||||
// requires GL_LUMINANCE_ALPHA rather than GL_LUMINANCE8_ALPHA8 as the
|
||||
// internal format, for LA.
|
||||
if (GLAD_ES_VERSION_2_0 && !GLAD_ES_VERSION_3_0)
|
||||
format = iformat = GL_SRGB_ALPHA;
|
||||
else
|
||||
iformat = GL_SRGB8_ALPHA8;
|
||||
}
|
||||
else if (GLAD_ES_VERSION_2_0)
|
||||
iformat = format;
|
||||
|
||||
if (internalformat != nullptr)
|
||||
*internalformat = iformat;
|
||||
|
||||
return format;
|
||||
}
|
||||
|
||||
void Font::createTexture()
|
||||
{
|
||||
OpenGL::TempDebugGroup debuggroup("Font create texture");
|
||||
|
||||
GLenum format = type == FONT_TRUETYPE ? GL_LUMINANCE_ALPHA : GL_RGBA;
|
||||
size_t bpp = format == GL_LUMINANCE_ALPHA ? 2 : 4;
|
||||
size_t bpp = type == FONT_TRUETYPE ? 2 : 4;
|
||||
|
||||
size_t prevmemsize = textureMemorySize;
|
||||
if (prevmemsize > 0)
|
||||
@@ -151,13 +176,8 @@ void Font::createTexture()
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
GLenum internalformat = type == FONT_TRUETYPE ? GL_LUMINANCE8_ALPHA8 : GL_RGBA8;
|
||||
|
||||
// In GLES2, the internalformat and format params of TexImage have to match.
|
||||
// There is still no GL_LUMINANCE8_ALPHA8 in GLES3, so we have to use
|
||||
// GL_LUMINANCE_ALPHA even on ES3.
|
||||
if (GLAD_ES_VERSION_2_0)
|
||||
internalformat = format;
|
||||
GLenum internalformat = GL_RGBA;
|
||||
GLenum format = getTextureFormat(type, &internalformat);
|
||||
|
||||
// Initialize the texture with transparent black.
|
||||
std::vector<GLubyte> emptydata(size.width * size.height * bpp, 0);
|
||||
@@ -268,14 +288,12 @@ const Font::Glyph &Font::addGlyph(uint32 glyph)
|
||||
// don't waste space for empty glyphs. also fixes a divide by zero bug with ATI drivers
|
||||
if (w > 0 && h > 0)
|
||||
{
|
||||
const GLuint t = textures.back();
|
||||
GLenum format = getTextureFormat(type);
|
||||
g.texture = textures.back();
|
||||
|
||||
gl.bindTexture(t);
|
||||
gl.bindTexture(g.texture);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, textureX, textureY, w, h,
|
||||
(type == FONT_TRUETYPE ? GL_LUMINANCE_ALPHA : GL_RGBA),
|
||||
GL_UNSIGNED_BYTE, gd->getData());
|
||||
|
||||
g.texture = t;
|
||||
format, GL_UNSIGNED_BYTE, gd->getData());
|
||||
|
||||
double tX = (double) textureX, tY = (double) textureY;
|
||||
double tWidth = (double) textureWidth, tHeight = (double) textureHeight;
|
||||
|
||||
@@ -222,6 +222,7 @@ private:
|
||||
};
|
||||
|
||||
TextureSize getNextTextureSize() const;
|
||||
GLenum getTextureFormat(FontType fontType, GLenum *internalformat = nullptr) const;
|
||||
void createTexture();
|
||||
love::font::GlyphData *getRasterizerGlyphData(uint32 glyph);
|
||||
const Glyph &addGlyph(uint32 glyph);
|
||||
|
||||
@@ -317,18 +317,20 @@ bool Graphics::setMode(int width, int height)
|
||||
pixelSizeStack.reserve(5);
|
||||
pixelSizeStack.push_back(1);
|
||||
|
||||
int gammacorrect = isGammaCorrect() ? 1 : 0;
|
||||
|
||||
// We always need a default shader.
|
||||
if (!Shader::defaultShader)
|
||||
{
|
||||
Renderer renderer = GLAD_ES_VERSION_2_0 ? RENDERER_OPENGLES : RENDERER_OPENGL;
|
||||
Shader::defaultShader = newShader(Shader::defaultCode[renderer]);
|
||||
Shader::defaultShader = newShader(Shader::defaultCode[renderer][gammacorrect]);
|
||||
}
|
||||
|
||||
// and a default video shader.
|
||||
if (!Shader::defaultVideoShader)
|
||||
{
|
||||
Renderer renderer = GLAD_ES_VERSION_2_0 ? RENDERER_OPENGLES : RENDERER_OPENGL;
|
||||
Shader::defaultVideoShader = newShader(Shader::defaultVideoCode[renderer]);
|
||||
Shader::defaultVideoShader = newShader(Shader::defaultVideoCode[renderer][gammacorrect]);
|
||||
}
|
||||
|
||||
// A shader should always be active, but the default shader shouldn't be
|
||||
|
||||
@@ -221,8 +221,8 @@ void Image::loadDefaultTexture()
|
||||
setFilter(filter);
|
||||
|
||||
// A nice friendly checkerboard to signify invalid textures...
|
||||
GLubyte px[] = {0xFF,0xFF,0xFF,0xFF, 0xFF,0xC0,0xC0,0xFF,
|
||||
0xFF,0xC0,0xC0,0xFF, 0xFF,0xFF,0xFF,0xFF};
|
||||
GLubyte px[] = {0xFF,0xFF,0xFF,0xFF, 0xFF,0xA0,0xA0,0xFF,
|
||||
0xFF,0xA0,0xA0,0xFF, 0xFF,0xFF,0xFF,0xFF};
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, px);
|
||||
}
|
||||
|
||||
@@ -66,8 +66,8 @@ Shader *Shader::current = nullptr;
|
||||
Shader *Shader::defaultShader = nullptr;
|
||||
Shader *Shader::defaultVideoShader = nullptr;
|
||||
|
||||
Shader::ShaderSource Shader::defaultCode[Graphics::RENDERER_MAX_ENUM];
|
||||
Shader::ShaderSource Shader::defaultVideoCode[Graphics::RENDERER_MAX_ENUM];
|
||||
Shader::ShaderSource Shader::defaultCode[Graphics::RENDERER_MAX_ENUM][2];
|
||||
Shader::ShaderSource Shader::defaultVideoCode[Graphics::RENDERER_MAX_ENUM][2];
|
||||
|
||||
std::vector<int> Shader::textureCounters;
|
||||
|
||||
@@ -250,9 +250,10 @@ bool Shader::loadVolatile()
|
||||
|
||||
std::vector<GLuint> shaderids;
|
||||
|
||||
const ShaderSource *defaults = &defaultCode[Graphics::RENDERER_OPENGL];
|
||||
bool gammacorrect = graphics::isGammaCorrect();
|
||||
const ShaderSource *defaults = &defaultCode[Graphics::RENDERER_OPENGL][gammacorrect ? 1 : 0];
|
||||
if (GLAD_ES_VERSION_2_0)
|
||||
defaults = &defaultCode[Graphics::RENDERER_OPENGLES];
|
||||
defaults = &defaultCode[Graphics::RENDERER_OPENGLES][gammacorrect ? 1 : 0];
|
||||
|
||||
// The shader program must have both vertex and pixel shader stages.
|
||||
const std::string &vertexcode = shaderSource.vertex.empty() ? defaults->vertex : shaderSource.vertex;
|
||||
|
||||
@@ -95,8 +95,8 @@ public:
|
||||
static Shader *defaultVideoShader;
|
||||
|
||||
// Default shader code (a shader is always required internally.)
|
||||
static ShaderSource defaultCode[Graphics::RENDERER_MAX_ENUM];
|
||||
static ShaderSource defaultVideoCode[Graphics::RENDERER_MAX_ENUM];
|
||||
static ShaderSource defaultCode[Graphics::RENDERER_MAX_ENUM][2];
|
||||
static ShaderSource defaultVideoCode[Graphics::RENDERER_MAX_ENUM][2];
|
||||
|
||||
/**
|
||||
* Creates a new Shader using a list of source codes.
|
||||
|
||||
@@ -1346,41 +1346,34 @@ int w_getShader(lua_State *L)
|
||||
int w_setDefaultShaderCode(lua_State *L)
|
||||
{
|
||||
luaL_checktype(L, 1, LUA_TTABLE);
|
||||
luaL_checktype(L, 2, LUA_TTABLE);
|
||||
|
||||
lua_getfield(L, 1, "opengl");
|
||||
lua_rawgeti(L, -1, 1);
|
||||
lua_rawgeti(L, -2, 2);
|
||||
lua_rawgeti(L, -3, 3);
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
for (int renderer = 0; renderer < Graphics::RENDERER_MAX_ENUM; renderer++)
|
||||
{
|
||||
const char *lang = renderer == Graphics::RENDERER_OPENGLES ? "glsles" : "glsl";
|
||||
|
||||
Shader::ShaderSource openglcode;
|
||||
openglcode.vertex = luax_checkstring(L, -3);
|
||||
openglcode.pixel = luax_checkstring(L, -2);
|
||||
lua_getfield(L, i + 1, lang);
|
||||
|
||||
Shader::ShaderSource openglVideocode;
|
||||
openglVideocode.vertex = luax_checkstring(L, -3);
|
||||
openglVideocode.pixel = luax_checkstring(L, -1);
|
||||
lua_getfield(L, -1, "vertex");
|
||||
lua_getfield(L, -2, "pixel");
|
||||
lua_getfield(L, -3, "videopixel");
|
||||
|
||||
lua_pop(L, 4);
|
||||
Shader::ShaderSource code;
|
||||
code.vertex = luax_checkstring(L, -3);
|
||||
code.pixel = luax_checkstring(L, -2);
|
||||
|
||||
lua_getfield(L, 1, "opengles");
|
||||
lua_rawgeti(L, -1, 1);
|
||||
lua_rawgeti(L, -2, 2);
|
||||
lua_rawgeti(L, -3, 3);
|
||||
Shader::ShaderSource videocode;
|
||||
videocode.vertex = luax_checkstring(L, -3);
|
||||
videocode.pixel = luax_checkstring(L, -1);
|
||||
|
||||
Shader::ShaderSource openglescode;
|
||||
openglescode.vertex = luax_checkstring(L, -3);
|
||||
openglescode.pixel = luax_checkstring(L, -2);
|
||||
lua_pop(L, 4);
|
||||
|
||||
Shader::ShaderSource openglesVideocode;
|
||||
openglesVideocode.vertex = luax_checkstring(L, -3);
|
||||
openglesVideocode.pixel = luax_checkstring(L, -1);
|
||||
|
||||
lua_pop(L, 4);
|
||||
|
||||
Shader::defaultCode[Graphics::RENDERER_OPENGL] = openglcode;
|
||||
Shader::defaultCode[Graphics::RENDERER_OPENGLES] = openglescode;
|
||||
Shader::defaultVideoCode[Graphics::RENDERER_OPENGL] = openglVideocode;
|
||||
Shader::defaultVideoCode[Graphics::RENDERER_OPENGLES] = openglesVideocode;
|
||||
Shader::defaultCode[renderer][i] = code;
|
||||
Shader::defaultVideoCode[renderer][i] = videocode;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ misrepresented as being the original software.
|
||||
--]]
|
||||
|
||||
local table_concat = table.concat
|
||||
local ipairs = ipairs
|
||||
|
||||
-- SHADERS
|
||||
|
||||
@@ -139,6 +140,8 @@ varying vec4 VaryingColor;
|
||||
uniform mediump float love_PointSize;
|
||||
#endif]],
|
||||
|
||||
FUNCTIONS = "",
|
||||
|
||||
FOOTER = [[
|
||||
void main() {
|
||||
VaryingTexCoord = VertexTexCoord;
|
||||
@@ -210,33 +213,21 @@ void main() {
|
||||
}]],
|
||||
}
|
||||
|
||||
local function createVertexCode(vertexcode, lang)
|
||||
local vertexcodes = {
|
||||
local function createShaderStageCode(stage, code, lang, gammacorrect, multicanvas)
|
||||
stage = stage:upper()
|
||||
local lines = {
|
||||
lang == "glsles" and GLSL.VERSION_ES or GLSL.VERSION,
|
||||
GLSL.SYNTAX,
|
||||
love.graphics.isGammaCorrect() and "#define LOVE_GAMMA_CORRECT 1" or "",
|
||||
GLSL.VERTEX.HEADER, GLSL.UNIFORMS,
|
||||
gammacorrect and "#define LOVE_GAMMA_CORRECT 1" or "",
|
||||
GLSL[stage].HEADER,
|
||||
GLSL.UNIFORMS,
|
||||
GLSL.FUNCTIONS,
|
||||
GLSL[stage].FUNCTIONS,
|
||||
lang == "glsles" and "#line 1" or "#line 0",
|
||||
vertexcode,
|
||||
GLSL.VERTEX.FOOTER,
|
||||
code,
|
||||
multicanvas and GLSL[stage].FOOTER_MULTI_CANVAS or GLSL[stage].FOOTER,
|
||||
}
|
||||
return table_concat(vertexcodes, "\n")
|
||||
end
|
||||
|
||||
local function createPixelCode(pixelcode, is_multicanvas, lang)
|
||||
local pixelcodes = {
|
||||
lang == "glsles" and GLSL.VERSION_ES or GLSL.VERSION,
|
||||
GLSL.SYNTAX,
|
||||
love.graphics.isGammaCorrect() and "#define LOVE_GAMMA_CORRECT 1" or "",
|
||||
GLSL.PIXEL.HEADER, GLSL.UNIFORMS,
|
||||
GLSL.FUNCTIONS,
|
||||
GLSL.PIXEL.FUNCTIONS,
|
||||
lang == "glsles" and "#line 1" or "#line 0",
|
||||
pixelcode,
|
||||
is_multicanvas and GLSL.PIXEL.FOOTER_MULTI_CANVAS or GLSL.PIXEL.FOOTER,
|
||||
}
|
||||
return table_concat(pixelcodes, "\n")
|
||||
return table_concat(lines, "\n")
|
||||
end
|
||||
|
||||
local function isVertexCode(code)
|
||||
@@ -258,11 +249,6 @@ function love.graphics._shaderCodeToGLSL(arg1, arg2)
|
||||
local vertexcode, pixelcode
|
||||
local is_multicanvas = false -- whether pixel code has "effects" function instead of "effect"
|
||||
|
||||
local lang = "glsl"
|
||||
if (love.graphics.getRendererInfo()) == "OpenGL ES" then
|
||||
lang = "glsles"
|
||||
end
|
||||
|
||||
if arg1 then
|
||||
if isVertexCode(arg1) then
|
||||
vertexcode = arg1 -- first arg contains vertex shader code
|
||||
@@ -287,11 +273,18 @@ function love.graphics._shaderCodeToGLSL(arg1, arg2)
|
||||
end
|
||||
end
|
||||
|
||||
local lang = "glsl"
|
||||
if love.graphics.getRendererInfo() == "OpenGL ES" then
|
||||
lang = "glsles"
|
||||
end
|
||||
|
||||
local gammacorrect = love.graphics.isGammaCorrect()
|
||||
|
||||
if vertexcode then
|
||||
vertexcode = createVertexCode(vertexcode, lang)
|
||||
vertexcode = createShaderStageCode("VERTEX", vertexcode, lang, gammacorrect)
|
||||
end
|
||||
if pixelcode then
|
||||
pixelcode = createPixelCode(pixelcode, is_multicanvas, lang)
|
||||
pixelcode = createShaderStageCode("PIXEL", pixelcode, lang, gammacorrect, is_multicanvas)
|
||||
end
|
||||
|
||||
return vertexcode, pixelcode
|
||||
@@ -339,20 +332,21 @@ vec4 effect(mediump vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) {
|
||||
}]],
|
||||
}
|
||||
|
||||
local defaults = {
|
||||
opengl = {
|
||||
createVertexCode(defaultcode.vertex, "glsl"),
|
||||
createPixelCode(defaultcode.pixel, false, "glsl"),
|
||||
createPixelCode(defaultcode.videopixel, false, "glsl"),
|
||||
},
|
||||
opengles = {
|
||||
createVertexCode(defaultcode.vertex, "glsles"),
|
||||
createPixelCode(defaultcode.pixel, false, "glsles"),
|
||||
createPixelCode(defaultcode.videopixel, false, "glsles"),
|
||||
},
|
||||
}
|
||||
local defaults = {}
|
||||
local defaults_gammacorrect = {}
|
||||
|
||||
love.graphics._setDefaultShaderCode(defaults)
|
||||
for _, lang in ipairs{"glsl", "glsles"} do
|
||||
for _, gammacorrect in ipairs{false, true} do
|
||||
local t = gammacorrect and defaults_gammacorrect or defaults
|
||||
t[lang] = {
|
||||
vertex = createShaderStageCode("VERTEX", defaultcode.vertex, lang, gammacorrect),
|
||||
pixel = createShaderStageCode("PIXEL", defaultcode.pixel, lang, gammacorrect, false),
|
||||
videopixel = createShaderStageCode("PIXEL", defaultcode.videopixel, lang, gammacorrect, false),
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
love.graphics._setDefaultShaderCode(defaults, defaults_gammacorrect)
|
||||
|
||||
function love.graphics.newVideo(file, loadaudio)
|
||||
local video = love.graphics._newVideo(file)
|
||||
|
||||
@@ -151,12 +151,12 @@ bool VideoStream::readPacket(bool mustSucceed)
|
||||
|
||||
while (ogg_stream_packetout(&stream, &packet) != 1)
|
||||
{
|
||||
// We need to read another page, but there is none, we're at the end
|
||||
if (ogg_page_eos(&page) && !mustSucceed)
|
||||
return eos = true;
|
||||
|
||||
do
|
||||
{
|
||||
// We need to read another page, but there is none, we're at the end
|
||||
if (ogg_page_eos(&page) && !mustSucceed)
|
||||
return eos = true;
|
||||
|
||||
readPage();
|
||||
} while (ogg_page_serialno(&page) != videoSerial);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user