Using latest love-android branch (e263d91d136d)

This commit is contained in:
fysx
2014-04-04 11:37:36 +02:00
parent 8acfb8d91a
commit e96eef4435
87 changed files with 1070 additions and 397 deletions
@@ -134,6 +134,7 @@ StringMap<Graphics::BlendMode, Graphics::BLEND_MAX_ENUM>::Entry Graphics::blendM
{ "subtractive", Graphics::BLEND_SUBTRACTIVE },
{ "multiplicative", Graphics::BLEND_MULTIPLICATIVE },
{ "premultiplied", Graphics::BLEND_PREMULTIPLIED },
{ "screen", Graphics::BLEND_SCREEN },
{ "replace", Graphics::BLEND_REPLACE },
};
+1
View File
@@ -57,6 +57,7 @@ public:
BLEND_SUBTRACTIVE,
BLEND_MULTIPLICATIVE,
BLEND_PREMULTIPLIED,
BLEND_SCREEN,
BLEND_REPLACE,
BLEND_MAX_ENUM
};
+47 -12
View File
@@ -55,10 +55,11 @@ struct FramebufferStrategy
/**
* @param[in] width Width of the stencil buffer
* @param[in] height Height of the stencil buffer
* @param[in] samples Number of samples to use
* @param[out] stencil Name for stencil buffer
* @return Whether the stencil buffer was successfully created
**/
virtual bool createStencil(int, int, GLuint &)
virtual bool createStencil(int, int, int, GLuint &)
{
return false;
}
@@ -121,13 +122,17 @@ struct FramebufferStrategyCore : public FramebufferStrategy
return status;
}
virtual bool createStencil(int width, int height, GLuint &stencil)
virtual bool createStencil(int width, int height, int samples, GLuint &stencil)
{
// create stencil buffer
glDeleteRenderbuffers(1, &stencil);
glGenRenderbuffers(1, &stencil);
glBindRenderbuffer(GL_RENDERBUFFER, stencil);
glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, width, height);
if (samples > 1)
glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, GL_STENCIL_INDEX8, width, height);
else
glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, width, height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
GL_RENDERBUFFER, stencil);
@@ -217,13 +222,17 @@ struct FramebufferStrategyCore : public FramebufferStrategy
struct FramebufferStrategyCorePacked : public FramebufferStrategyCore
{
virtual bool createStencil(int width, int height, GLuint &stencil)
virtual bool createStencil(int width, int height, int samples, GLuint &stencil)
{
// create combined depth/stencil buffer
glDeleteRenderbuffers(1, &stencil);
glGenRenderbuffers(1, &stencil);
glBindRenderbuffer(GL_RENDERBUFFER, stencil);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_STENCIL, width, height);
if (samples > 1)
glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, GL_DEPTH_STENCIL, width, height);
else
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_STENCIL, width, height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
GL_RENDERBUFFER, stencil);
@@ -257,14 +266,24 @@ struct FramebufferStrategyPackedEXT : public FramebufferStrategy
return status;
}
virtual bool createStencil(int width, int height, GLuint &stencil)
virtual bool createStencil(int width, int height, int samples, GLuint &stencil)
{
// create combined depth/stencil buffer
glDeleteRenderbuffersEXT(1, &stencil);
glGenRenderbuffersEXT(1, &stencil);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, stencil);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_STENCIL_EXT,
width, height);
if (samples > 1)
{
glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, samples,
GL_DEPTH_STENCIL, width, height);
}
else
{
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_STENCIL_EXT,
width, height);
}
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT,
GL_RENDERBUFFER_EXT, stencil);
@@ -356,14 +375,24 @@ struct FramebufferStrategyPackedEXT : public FramebufferStrategy
struct FramebufferStrategyEXT : public FramebufferStrategyPackedEXT
{
virtual bool createStencil(int width, int height, GLuint &stencil)
virtual bool createStencil(int width, int height, int samples, GLuint &stencil)
{
// create stencil buffer
glDeleteRenderbuffersEXT(1, &stencil);
glGenRenderbuffersEXT(1, &stencil);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, stencil);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_STENCIL_INDEX,
width, height);
if (samples > 1)
{
glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, samples,
GL_STENCIL_INDEX, width, height);
}
else
{
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_STENCIL_INDEX,
width, height);
}
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT,
GL_RENDERBUFFER_EXT, stencil);
@@ -589,6 +618,9 @@ bool Canvas::loadVolatile()
return false;
clear(Color(0, 0, 0, 0));
fsaa_dirty = (fsaa_buffer != 0);
return true;
}
@@ -865,6 +897,9 @@ void Canvas::clear(Color c)
if (current != this)
strategy->bindFBO(previous);
if (fsaa_buffer != 0)
fsaa_dirty = true;
}
bool Canvas::checkCreateStencil()
@@ -876,7 +911,7 @@ bool Canvas::checkCreateStencil()
if (current != this)
strategy->bindFBO(fbo);
bool success = strategy->createStencil(width, height, depth_stencil);
bool success = strategy->createStencil(width, height, fsaa_samples, depth_stencil);
if (current && current != this)
strategy->bindFBO(current->fbo);
+1 -1
View File
@@ -175,7 +175,7 @@ private:
return texture < other.texture;
else
return startvertex < other.startvertex;
};
}
};
bool initializeTexture(GLenum format);
@@ -52,6 +52,7 @@ Graphics::Graphics()
, width(0)
, height(0)
, created(false)
, activeStencil(false)
, savedState()
{
currentWindow = love::window::sdl::Window::createSingleton();
@@ -266,17 +267,19 @@ bool Graphics::setMode(int width, int height, bool &sRGB)
void Graphics::unSetMode()
{
if (!isCreated())
return;
// Window re-creation may destroy the GL context, so we must save the state.
if (isCreated())
{
savedState = saveState();
savedState = saveState();
// Unload all volatile objects. These must be reloaded after the display
// mode change.
Volatile::unloadAll();
// Unload all volatile objects. These must be reloaded after the display
// mode change.
Volatile::unloadAll();
gl.deInitContext();
}
gl.deInitContext();
created = false;
}
static void APIENTRY debugCB(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei /*len*/, const GLchar *msg, const GLvoid* /*usr*/)
@@ -439,6 +442,8 @@ void Graphics::defineStencil()
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS, 1, 1);
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
activeStencil = true;
}
void Graphics::useStencil(bool invert)
@@ -450,8 +455,12 @@ void Graphics::useStencil(bool invert)
void Graphics::discardStencil()
{
if (!activeStencil)
return;
setColorMask(colorMask[0], colorMask[1], colorMask[2], colorMask[3]);
glDisable(GL_STENCIL_TEST);
activeStencil = false;
}
Image *Graphics::newImage(love::image::ImageData *data, Texture::Format format)
@@ -691,6 +700,10 @@ void Graphics::setBlendMode(Graphics::BlendMode mode)
state.srcRGB = state.srcA = GL_SRC_ALPHA;
state.dstRGB = state.dstA = GL_ONE;
break;
case BLEND_SCREEN:
state.srcRGB = state.srcA = GL_ONE;
state.dstRGB = state.dstA = GL_ONE_MINUS_SRC_COLOR;
break;
case BLEND_REPLACE:
default:
state.srcRGB = state.srcA = GL_ONE;
@@ -718,6 +731,8 @@ Graphics::BlendMode Graphics::getBlendMode() const
return BLEND_MULTIPLICATIVE;
else if (state.srcRGB == GL_ONE && state.dstRGB == GL_ONE_MINUS_SRC_ALPHA)
return BLEND_PREMULTIPLIED;
else if (state.srcRGB == GL_ONE && state.dstRGB == GL_ONE_MINUS_SRC_COLOR)
return BLEND_SCREEN;
else if (state.srcRGB == GL_ONE && state.dstRGB == GL_ZERO)
return BLEND_REPLACE;
}
@@ -481,6 +481,8 @@ private:
int height;
bool created;
bool activeStencil;
DisplayState savedState;
}; // Graphics
+102 -22
View File
@@ -38,6 +38,7 @@ Mesh::Mesh(const std::vector<Vertex> &verts, Mesh::DrawMode mode)
, vertex_count(0)
, ibo(nullptr)
, element_count(0)
, element_data_type(getGLDataTypeFromMax(verts.size()))
, instance_count(1)
, draw_mode(mode)
, range_min(-1)
@@ -53,6 +54,7 @@ Mesh::Mesh(int vertexcount, Mesh::DrawMode mode)
, vertex_count(0)
, ibo(nullptr)
, element_count(0)
, element_data_type(getGLDataTypeFromMax(vertexcount))
, draw_mode(mode)
, range_min(-1)
, range_max(-1)
@@ -151,15 +153,42 @@ size_t Mesh::getVertexCount() const
return vertex_count;
}
/**
* Copies index data from a vector to a mapped index buffer.
**/
template <typename T>
static void copyToIndexBuffer(const std::vector<uint32> &indices, VertexBuffer::Mapper &buffermap, size_t maxval)
{
T *elems = (T *) buffermap.get();
for (size_t i = 0; i < indices.size(); i++)
{
if (indices[i] >= maxval)
throw love::Exception("Invalid vertex map value: %d", indices[i] + 1);
elems[i] = (T) indices[i];
}
}
void Mesh::setVertexMap(const std::vector<uint32> &map)
{
for (size_t i = 0; i < map.size(); i++)
{
if (map[i] >= vertex_count)
throw love::Exception("Invalid vertex map value: %d", map[i] + 1);
}
GLenum datatype = getGLDataTypeFromMax(vertex_count);
size_t size = sizeof(uint32) * map.size();
// Calculate the size in bytes of the index buffer data.
size_t size = map.size();
switch (datatype)
{
case GL_UNSIGNED_BYTE:
size *= sizeof(uint8);
break;
case GL_UNSIGNED_SHORT:
size *= sizeof(uint16);
break;
case GL_UNSIGNED_INT:
default:
size *= sizeof(uint32);
break;
}
if (ibo && size > ibo->getSize())
{
@@ -175,27 +204,68 @@ void Mesh::setVertexMap(const std::vector<uint32> &map)
element_count = map.size();
if (ibo && element_count > 0)
{
VertexBuffer::Bind ibo_bind(*ibo);
VertexBuffer::Mapper ibo_map(*ibo);
if (!ibo || element_count == 0)
return;
// Fill the buffer.
memcpy(ibo_map.get(), &map[0], size);
VertexBuffer::Bind ibo_bind(*ibo);
VertexBuffer::Mapper ibo_map(*ibo);
// Fill the buffer with the index values from the vector.
switch (datatype)
{
case GL_UNSIGNED_BYTE:
copyToIndexBuffer<uint8>(map, ibo_map, vertex_count);
break;
case GL_UNSIGNED_SHORT:
copyToIndexBuffer<uint16>(map, ibo_map, vertex_count);
break;
case GL_UNSIGNED_INT:
default:
copyToIndexBuffer<uint32>(map, ibo_map, vertex_count);
break;
}
element_data_type = datatype;
}
const uint32 *Mesh::getVertexMap() const
/**
* Copies index data from a mapped buffer to a vector.
**/
template <typename T>
static void copyFromIndexBuffer(void *buffer, std::vector<uint32> &indices, size_t maxval)
{
if (ibo && element_count > 0)
T *elems = (T *) buffer;
for (size_t i = 0; i < maxval; i++)
indices.push_back((uint32) elems[i]);
}
void Mesh::getVertexMap(std::vector<uint32> &map) const
{
if (!ibo || element_count == 0)
return;
map.clear();
map.reserve(element_count);
VertexBuffer::Bind ibo_bind(*ibo);
// We unmap the buffer in Mesh::draw and Mesh::setVertexMap.
void *buffer = ibo->map();
// Fill the vector from the buffer.
switch (element_data_type)
{
VertexBuffer::Bind ibo_bind(*ibo);
// We unmap the buffer in Mesh::draw and Mesh::setVertexMap.
return (uint32 *) ibo->map();
case GL_UNSIGNED_BYTE:
copyFromIndexBuffer<uint8>(buffer, map, vertex_count);
break;
case GL_UNSIGNED_SHORT:
copyFromIndexBuffer<uint16>(buffer, map, vertex_count);
break;
case GL_UNSIGNED_INT:
default:
copyFromIndexBuffer<uint32>(buffer, map, vertex_count);
break;
}
return nullptr;
}
size_t Mesh::getVertexMapCount() const
@@ -335,7 +405,7 @@ void Mesh::draw(float x, float y, float angle, float sx, float sy, float ox, flo
min = std::min(std::max(range_min, 0), max);
const void *indices = ibo->getPointer(min * sizeof(uint32));
GLenum type = GL_UNSIGNED_INT;
GLenum type = element_data_type;
if (instance_count > 1)
gl.drawElementsInstanced(mode, max - min + 1, type, indices, instance_count);
@@ -375,7 +445,7 @@ void Mesh::draw(float x, float y, float angle, float sx, float sy, float ox, flo
texture->postdraw();
}
GLenum Mesh::getGLDrawMode(Mesh::DrawMode mode) const
GLenum Mesh::getGLDrawMode(DrawMode mode) const
{
switch (mode)
{
@@ -394,6 +464,16 @@ GLenum Mesh::getGLDrawMode(Mesh::DrawMode mode) const
return GL_TRIANGLES;
}
GLenum Mesh::getGLDataTypeFromMax(size_t maxvalue) const
{
if (maxvalue > LOVE_UINT16_MAX)
return GL_UNSIGNED_INT;
else if (maxvalue > LOVE_UINT8_MAX)
return GL_UNSIGNED_SHORT;
else
return GL_UNSIGNED_BYTE;
}
bool Mesh::getConstant(const char *in, Mesh::DrawMode &out)
{
return drawModes.find(in, out);
+5 -4
View File
@@ -109,11 +109,10 @@ public:
void setVertexMap(const std::vector<uint32> &map);
/**
* Gets a pointer to the vertex map array. The pointer is only valid until
* the next function call in the graphics module.
* May return null if the vertex map is empty.
* Fills the uint32 vector passed into the method with the previously set
* vertex map (index buffer) values.
**/
const uint32 *getVertexMap() const;
void getVertexMap(std::vector<uint32> &map) const;
/**
* Gets the total number of elements in the vertex map array.
@@ -171,6 +170,7 @@ public:
private:
GLenum getGLDrawMode(DrawMode mode) const;
GLenum getGLDataTypeFromMax(size_t maxvalue) const;
// Vertex buffer.
VertexBuffer *vbo;
@@ -179,6 +179,7 @@ private:
// Element (vertex index) buffer, for the vertex map.
VertexBuffer *ibo;
size_t element_count;
GLenum element_data_type;
int instance_count;
@@ -66,7 +66,7 @@ public:
INSERT_MODE_TOP,
INSERT_MODE_BOTTOM,
INSERT_MODE_RANDOM,
INSERT_MODE_MAX_ENUM,
INSERT_MODE_MAX_ENUM
};
/**
@@ -494,8 +494,8 @@ int w_newMesh(lua_State *L)
v.x = (float) luaL_checknumber(L, -8);
v.y = (float) luaL_checknumber(L, -7);
v.s = (float) luaL_checknumber(L, -6);
v.t = (float) luaL_checknumber(L, -5);
v.s = (float) luaL_optnumber(L, -6, 0.0);
v.t = (float) luaL_optnumber(L, -5, 0.0);
v.r = (unsigned char) luaL_optinteger(L, -4, 255);
v.g = (unsigned char) luaL_optinteger(L, -3, 255);
@@ -53,8 +53,8 @@ int w_Mesh_setVertex(lua_State *L)
v.x = luaL_checknumber(L, -8);
v.y = luaL_checknumber(L, -7);
v.s = luaL_checknumber(L, -6);
v.t = luaL_checknumber(L, -5);
v.s = luaL_optnumber(L, -6, 0.0);
v.t = luaL_optnumber(L, -5, 0.0);
v.r = luaL_optinteger(L, -4, 255);
v.g = luaL_optinteger(L, -3, 255);
v.b = luaL_optinteger(L, -2, 255);
@@ -66,8 +66,8 @@ int w_Mesh_setVertex(lua_State *L)
{
v.x = luaL_checknumber(L, 3);
v.y = luaL_checknumber(L, 4);
v.s = luaL_checknumber(L, 5);
v.t = luaL_checknumber(L, 6);
v.s = luaL_optnumber(L, 5, 0.0);
v.t = luaL_optnumber(L, 6, 0.0);
v.r = luaL_optinteger(L, 7, 255);
v.g = luaL_optinteger(L, 8, 255);
v.b = luaL_optinteger(L, 9, 255);
@@ -122,8 +122,8 @@ int w_Mesh_setVertices(lua_State *L)
v.x = (float) luaL_checknumber(L, -8);
v.y = (float) luaL_checknumber(L, -7);
v.s = (float) luaL_checknumber(L, -6);
v.t = (float) luaL_checknumber(L, -5);
v.s = (float) luaL_optnumber(L, -6, 0.0);
v.t = (float) luaL_optnumber(L, -5, 0.0);
v.r = (unsigned char) luaL_optinteger(L, -4, 255);
v.g = (unsigned char) luaL_optinteger(L, -3, 255);
@@ -220,14 +220,15 @@ int w_Mesh_setVertexMap(lua_State *L)
int w_Mesh_getVertexMap(lua_State *L)
{
Mesh *t = luax_checkmesh(L, 1);
const uint32 *vertex_map = 0;
EXCEPT_GUARD(vertex_map = t->getVertexMap();)
size_t elements = t->getVertexMapCount();
std::vector<uint32> vertex_map;
EXCEPT_GUARD(t->getVertexMap(vertex_map);)
lua_createtable(L, elements, 0);
size_t element_count = vertex_map.size();
for (size_t i = 0; i < elements; i++)
lua_createtable(L, element_count, 0);
for (size_t i = 0; i < element_count; i++)
{
lua_pushinteger(L, lua_Integer(vertex_map[i]) + 1);
lua_rawseti(L, -2, i + 1);
@@ -370,8 +371,12 @@ static const luaL_Reg functions[] =
{ "getVertexCount", w_Mesh_getVertexCount },
{ "setVertexMap", w_Mesh_setVertexMap },
{ "getVertexMap", w_Mesh_getVertexMap },
{ "setInstanceCount", w_Mesh_setInstanceCount },
{ "getInstanceCount", w_Mesh_getInstanceCount },
// Disabled for now, since implementation is incomplete and might change
// if/when VertexBuffers / custom vertex attributes are added.
// { "setInstanceCount", w_Mesh_setInstanceCount },
// { "getInstanceCount", w_Mesh_getInstanceCount },
{ "setTexture", w_Mesh_setTexture },
{ "getTexture", w_Mesh_getTexture },
{ "setDrawMode", w_Mesh_setDrawMode },