mirror of
https://github.com/love2d/love.git
synced 2026-08-17 11:00:31 +02:00
Array textures can be easily drawn without a shader (resolves issue #1111).
Added love.graphics.drawLayer(texture, layerindex, …). ‘texture’ must be an array texture. Added SpriteBatch:add/setLayer. Added Quad:get/setLayer. This applies to array textures that are drawn without specifying an explicit layer index in the draw call. Added love.graphics.newQuad variants which have layer arguments. --HG-- branch : minor
This commit is contained in:
@@ -140,7 +140,7 @@ Canvas::Canvas(const Settings &settings)
|
||||
|
||||
this->format = getSizedFormat(settings.format);
|
||||
|
||||
initVertices();
|
||||
initQuad();
|
||||
loadVolatile();
|
||||
|
||||
if (status != GL_FRAMEBUFFER_COMPLETE)
|
||||
|
||||
@@ -268,25 +268,19 @@ bool Graphics::setMode(int width, int height, int pixelwidth, int pixelheight, b
|
||||
restoreState(states.back());
|
||||
|
||||
int gammacorrect = isGammaCorrect() ? 1 : 0;
|
||||
Shader::Language target = getShaderLanguageTarget();
|
||||
|
||||
// We always need a default shader.
|
||||
if (!Shader::defaultShader)
|
||||
for (int i = 0; i < Shader::STANDARD_MAX_ENUM; i++)
|
||||
{
|
||||
Shader::Language target = getShaderLanguageTarget();
|
||||
Shader::defaultShader = newShader(defaultShaderCode[target][gammacorrect]);
|
||||
}
|
||||
|
||||
// and a default video shader.
|
||||
if (!Shader::defaultVideoShader)
|
||||
{
|
||||
Shader::Language target = getShaderLanguageTarget();
|
||||
Shader::defaultVideoShader = newShader(defaultVideoShaderCode[target][gammacorrect]);
|
||||
if (!Shader::standardShaders[i])
|
||||
Shader::standardShaders[i] = newShader(defaultShaderCode[i][target][gammacorrect]);
|
||||
}
|
||||
|
||||
// A shader should always be active, but the default shader shouldn't be
|
||||
// returned by getShader(), so we don't do setShader(defaultShader).
|
||||
if (!Shader::current)
|
||||
Shader::defaultShader->attach();
|
||||
Shader::standardShaders[Shader::STANDARD_DEFAULT]->attach();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -343,8 +337,21 @@ void Graphics::flushStreamDraws()
|
||||
if (sbstate.vertexCount == 0 && sbstate.indexCount == 0)
|
||||
return;
|
||||
|
||||
if (Shader::current && sbstate.texture.get())
|
||||
Shader::current->checkMainTextureType(sbstate.texture->getTextureType());
|
||||
love::graphics::Shader *prevdefaultshader = nullptr;
|
||||
|
||||
if (sbstate.texture.get())
|
||||
{
|
||||
TextureType textype = sbstate.texture->getTextureType();
|
||||
|
||||
if (textype == TEXTURE_2D_ARRAY && Shader::isDefaultActive())
|
||||
{
|
||||
prevdefaultshader = Shader::current;
|
||||
Shader::standardShaders[Shader::STANDARD_ARRAY]->attach();
|
||||
}
|
||||
|
||||
if (Shader::current)
|
||||
Shader::current->checkMainTextureType(textype);
|
||||
}
|
||||
|
||||
OpenGL::TempDebugGroup debuggroup("Stream vertices flush and draw");
|
||||
|
||||
@@ -425,6 +432,9 @@ void Graphics::flushStreamDraws()
|
||||
|
||||
streamBufferState.vertexCount = 0;
|
||||
streamBufferState.indexCount = 0;
|
||||
|
||||
if (prevdefaultshader != nullptr)
|
||||
prevdefaultshader->attach();
|
||||
}
|
||||
|
||||
static void APIENTRY debugCB(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei /*len*/, const GLchar *msg, const GLvoid* /*usr*/)
|
||||
|
||||
@@ -92,8 +92,8 @@ void Image::init(PixelFormat fmt, int w, int h, const Settings &settings)
|
||||
if (getMipmapCount() > 1)
|
||||
filter.mipmap = defaultMipmapFilter;
|
||||
|
||||
initQuad();
|
||||
loadVolatile();
|
||||
initVertices();
|
||||
}
|
||||
|
||||
void Image::generateMipmaps()
|
||||
|
||||
@@ -650,6 +650,10 @@ void OpenGL::setVertexPointers(vertex::CommonFormat format, size_t stride, size_
|
||||
glVertexAttribPointer(ATTRIB_POS, 2, GL_FLOAT, GL_FALSE, stride, BUFFER_OFFSET(offset + offsetof(XYf_STf, x)));
|
||||
glVertexAttribPointer(ATTRIB_TEXCOORD, 2, GL_FLOAT, GL_FALSE, stride, BUFFER_OFFSET(offset + offsetof(XYf_STf, s)));
|
||||
break;
|
||||
case CommonFormat::XYf_STPf:
|
||||
glVertexAttribPointer(ATTRIB_POS, 2, GL_FLOAT, GL_FALSE, stride, BUFFER_OFFSET(offset + offsetof(XYf_STPf, x)));
|
||||
glVertexAttribPointer(ATTRIB_TEXCOORD, 3, GL_FLOAT, GL_FALSE, stride, BUFFER_OFFSET(offset + offsetof(XYf_STPf, s)));
|
||||
break;
|
||||
case CommonFormat::XYf_STf_RGBAub:
|
||||
glVertexAttribPointer(ATTRIB_POS, 2, GL_FLOAT, GL_FALSE, stride, BUFFER_OFFSET(offset + offsetof(XYf_STf_RGBAub, x)));
|
||||
glVertexAttribPointer(ATTRIB_TEXCOORD, 2, GL_FLOAT, GL_FALSE, stride, BUFFER_OFFSET(offset + offsetof(XYf_STf_RGBAub, s)));
|
||||
@@ -660,6 +664,11 @@ void OpenGL::setVertexPointers(vertex::CommonFormat format, size_t stride, size_
|
||||
glVertexAttribPointer(ATTRIB_TEXCOORD, 2, GL_UNSIGNED_SHORT, GL_TRUE, stride, BUFFER_OFFSET(offset + offsetof(XYf_STus_RGBAub, s)));
|
||||
glVertexAttribPointer(ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, stride, BUFFER_OFFSET(offset + offsetof(XYf_STus_RGBAub, color.r)));
|
||||
break;
|
||||
case CommonFormat::XYf_STPf_RGBAub:
|
||||
glVertexAttribPointer(ATTRIB_POS, 2, GL_FLOAT, GL_FALSE, stride, BUFFER_OFFSET(offset + offsetof(XYf_STPf_RGBAub, x)));
|
||||
glVertexAttribPointer(ATTRIB_TEXCOORD, 3, GL_FLOAT, GL_FALSE, stride, BUFFER_OFFSET(offset + offsetof(XYf_STPf_RGBAub, s)));
|
||||
glVertexAttribPointer(ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, stride, BUFFER_OFFSET(offset + offsetof(XYf_STPf_RGBAub, color.r)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,8 +60,21 @@ void SpriteBatch::draw(Graphics *gfx, const Matrix4 &m)
|
||||
|
||||
gfx->flushStreamDraws();
|
||||
|
||||
if (Shader::current && texture.get())
|
||||
Shader::current->checkMainTextureType(texture->getTextureType());
|
||||
Shader *prevdefaultshader = nullptr;
|
||||
|
||||
if (texture.get())
|
||||
{
|
||||
TextureType textype = texture->getTextureType();
|
||||
|
||||
if (textype == TEXTURE_2D_ARRAY && Shader::isDefaultActive())
|
||||
{
|
||||
prevdefaultshader = Shader::current;
|
||||
Shader::standardShaders[Shader::STANDARD_ARRAY]->attach();
|
||||
}
|
||||
|
||||
if (Shader::current)
|
||||
Shader::current->checkMainTextureType(texture->getTextureType());
|
||||
}
|
||||
|
||||
OpenGL::TempDebugGroup debuggroup("SpriteBatch draw");
|
||||
|
||||
@@ -72,13 +85,19 @@ void SpriteBatch::draw(Graphics *gfx, const Matrix4 &m)
|
||||
// Make sure the VBO isn't mapped when we draw (sends data to GPU if needed.)
|
||||
array_buf->unmap();
|
||||
|
||||
CommonFormat format = CommonFormat::XYf_STf_RGBAub;
|
||||
if (color == nullptr)
|
||||
format = CommonFormat::XYf_STf;
|
||||
CommonFormat format = vertex_format;
|
||||
|
||||
if (!color_active)
|
||||
{
|
||||
if (format == CommonFormat::XYf_STPf_RGBAub)
|
||||
format = CommonFormat::XYf_STPf;
|
||||
else
|
||||
format = CommonFormat::XYf_STf;
|
||||
}
|
||||
|
||||
uint32 enabledattribs = getFormatFlags(format);
|
||||
|
||||
gl.setVertexPointers(format, array_buf, getFormatStride(CommonFormat::XYf_STf_RGBAub), 0);
|
||||
gl.setVertexPointers(format, array_buf, format_stride, 0);
|
||||
|
||||
for (const auto &it : attached_attributes)
|
||||
{
|
||||
@@ -116,6 +135,9 @@ void SpriteBatch::draw(Graphics *gfx, const Matrix4 &m)
|
||||
|
||||
gl.drawElements(GL_TRIANGLES, (GLsizei) quad_indices.getIndexCount(count), gltype, indices);
|
||||
}
|
||||
|
||||
if (prevdefaultshader != nullptr)
|
||||
prevdefaultshader->attach();
|
||||
}
|
||||
|
||||
} // opengl
|
||||
|
||||
Reference in New Issue
Block a user