mirror of
https://github.com/love2d/love.git
synced 2026-08-12 08:30:56 +02:00
Cleaned up some internal love.graphics code.
--HG-- branch : minor
This commit is contained in:
@@ -142,23 +142,23 @@ love::image::ImageData *Canvas::newImageData(love::image::Image *module, int sli
|
||||
PixelFormat dataformat;
|
||||
switch (getPixelFormat())
|
||||
{
|
||||
case PIXELFORMAT_RGB10A2: // FIXME: Conversions aren't supported in GLES
|
||||
dataformat = PIXELFORMAT_RGBA16;
|
||||
break;
|
||||
case PIXELFORMAT_R16F:
|
||||
case PIXELFORMAT_RG16F:
|
||||
case PIXELFORMAT_RGBA16F:
|
||||
case PIXELFORMAT_RG11B10F: // FIXME: Conversions aren't supported in GLES
|
||||
dataformat = PIXELFORMAT_RGBA16F;
|
||||
break;
|
||||
case PIXELFORMAT_R32F:
|
||||
case PIXELFORMAT_RG32F:
|
||||
case PIXELFORMAT_RGBA32F:
|
||||
dataformat = PIXELFORMAT_RGBA32F;
|
||||
break;
|
||||
default:
|
||||
dataformat = PIXELFORMAT_RGBA8;
|
||||
break;
|
||||
case PIXELFORMAT_RGB10A2: // FIXME: Conversions aren't supported in GLES
|
||||
dataformat = PIXELFORMAT_RGBA16;
|
||||
break;
|
||||
case PIXELFORMAT_R16F:
|
||||
case PIXELFORMAT_RG16F:
|
||||
case PIXELFORMAT_RGBA16F:
|
||||
case PIXELFORMAT_RG11B10F: // FIXME: Conversions aren't supported in GLES
|
||||
dataformat = PIXELFORMAT_RGBA16F;
|
||||
break;
|
||||
case PIXELFORMAT_R32F:
|
||||
case PIXELFORMAT_RG32F:
|
||||
case PIXELFORMAT_RGBA32F:
|
||||
dataformat = PIXELFORMAT_RGBA32F;
|
||||
break;
|
||||
default:
|
||||
dataformat = PIXELFORMAT_RGBA8;
|
||||
break;
|
||||
}
|
||||
|
||||
return module->newImageData(r.w, r.h, dataformat);
|
||||
|
||||
@@ -117,6 +117,7 @@ Graphics::Graphics()
|
||||
, streamBufferState()
|
||||
, projectionMatrix()
|
||||
, canvasSwitchCount(0)
|
||||
, drawCalls(0)
|
||||
, drawCallsBatched(0)
|
||||
, capabilities()
|
||||
, cachedShaderStages()
|
||||
@@ -1459,8 +1460,9 @@ Graphics::Stats Graphics::getStats() const
|
||||
{
|
||||
Stats stats;
|
||||
|
||||
getAPIStats(stats.drawCalls, stats.shaderSwitches);
|
||||
getAPIStats(stats.shaderSwitches);
|
||||
|
||||
stats.drawCalls = drawCalls;
|
||||
if (streamBufferState.vertexCount > 0)
|
||||
stats.drawCalls++;
|
||||
|
||||
|
||||
@@ -908,7 +908,7 @@ protected:
|
||||
virtual void setCanvasInternal(const RenderTargets &rts, int w, int h, int pixelw, int pixelh, bool hasSRGBcanvas) = 0;
|
||||
|
||||
virtual void initCapabilities() = 0;
|
||||
virtual void getAPIStats(int &drawcalls, int &shaderswitches) const = 0;
|
||||
virtual void getAPIStats(int &shaderswitches) const = 0;
|
||||
|
||||
Canvas *getTemporaryCanvas(PixelFormat format, int w, int h, int samples);
|
||||
|
||||
@@ -946,6 +946,7 @@ protected:
|
||||
std::vector<TemporaryCanvas> temporaryCanvases;
|
||||
|
||||
int canvasSwitchCount;
|
||||
int drawCalls;
|
||||
int drawCallsBatched;
|
||||
|
||||
Capabilities capabilities;
|
||||
|
||||
@@ -323,7 +323,13 @@ void Graphics::draw(PrimitiveType primtype, int vertexstart, int vertexcount, in
|
||||
gl.bindTextureToUnit(texture, 0, false);
|
||||
|
||||
GLenum glprimitivetype = OpenGL::getGLPrimitiveType(primtype);
|
||||
gl.drawArrays(glprimitivetype, vertexstart, vertexcount, instancecount);
|
||||
|
||||
if (instancecount > 1)
|
||||
glDrawArraysInstanced(glprimitivetype, vertexstart, vertexcount, instancecount);
|
||||
else
|
||||
glDrawArrays(glprimitivetype, vertexstart, vertexcount);
|
||||
|
||||
++drawCalls;
|
||||
}
|
||||
|
||||
void Graphics::drawIndexed(PrimitiveType primtype, int indexcount, int instancecount, IndexDataType datatype, Resource *indexbuffer, size_t indexoffset, const vertex::Attributes &attribs, const vertex::Buffers &buffers, love::graphics::Texture *texture)
|
||||
@@ -337,7 +343,13 @@ void Graphics::drawIndexed(PrimitiveType primtype, int indexcount, int instancec
|
||||
GLenum gldatatype = OpenGL::getGLIndexDataType(datatype);
|
||||
|
||||
gl.bindBuffer(BUFFER_INDEX, indexbuffer->getHandle());
|
||||
gl.drawElements(glprimitivetype, indexcount, gldatatype, gloffset, instancecount);
|
||||
|
||||
if (instancecount > 1)
|
||||
glDrawElementsInstanced(glprimitivetype, indexcount, gldatatype, gloffset, instancecount);
|
||||
else
|
||||
glDrawElements(glprimitivetype, indexcount, gldatatype, gloffset);
|
||||
|
||||
++drawCalls;
|
||||
}
|
||||
|
||||
static void APIENTRY debugCB(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei /*len*/, const GLchar *msg, const GLvoid* /*usr*/)
|
||||
@@ -949,7 +961,7 @@ void Graphics::present(void *screenshotCallbackData)
|
||||
window->swapBuffers();
|
||||
|
||||
// Reset the per-frame stat counts.
|
||||
gl.stats.drawCalls = 0;
|
||||
drawCalls = 0;
|
||||
gl.stats.shaderSwitches = 0;
|
||||
canvasSwitchCount = 0;
|
||||
drawCallsBatched = 0;
|
||||
@@ -1260,9 +1272,8 @@ Graphics::RendererInfo Graphics::getRendererInfo() const
|
||||
return info;
|
||||
}
|
||||
|
||||
void Graphics::getAPIStats(int &drawcalls, int &shaderswitches) const
|
||||
void Graphics::getAPIStats(int &shaderswitches) const
|
||||
{
|
||||
drawcalls = gl.stats.drawCalls;
|
||||
shaderswitches = gl.stats.shaderSwitches;
|
||||
}
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@ private:
|
||||
love::graphics::StreamBuffer *newStreamBuffer(BufferType type, size_t size) override;
|
||||
void setCanvasInternal(const RenderTargets &rts, int w, int h, int pixelw, int pixelh, bool hasSRGBcanvas) override;
|
||||
void initCapabilities() override;
|
||||
void getAPIStats(int &drawcalls, int &shaderswitches) const override;
|
||||
void getAPIStats(int &shaderswitches) const override;
|
||||
|
||||
void endPass();
|
||||
void bindCachedFBO(const RenderTargets &targets);
|
||||
|
||||
@@ -627,26 +627,6 @@ void OpenGL::deleteBuffer(GLuint buffer)
|
||||
}
|
||||
}
|
||||
|
||||
void OpenGL::drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instancecount)
|
||||
{
|
||||
if (instancecount > 1)
|
||||
glDrawArraysInstanced(mode, first, count, instancecount);
|
||||
else
|
||||
glDrawArrays(mode, first, count);
|
||||
|
||||
++stats.drawCalls;
|
||||
}
|
||||
|
||||
void OpenGL::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount)
|
||||
{
|
||||
if (instancecount > 1)
|
||||
glDrawElementsInstanced(mode, count, type, indices, instancecount);
|
||||
else
|
||||
glDrawElements(mode, count, type, indices);
|
||||
|
||||
++stats.drawCalls;
|
||||
}
|
||||
|
||||
void OpenGL::setVertexAttributes(const vertex::Attributes &attributes, const vertex::Buffers &buffers)
|
||||
{
|
||||
uint32 enablediff = attributes.enablebits ^ state.enabledAttribArrays;
|
||||
|
||||
@@ -115,7 +115,6 @@ public:
|
||||
|
||||
struct Stats
|
||||
{
|
||||
int drawCalls;
|
||||
int shaderSwitches;
|
||||
} stats;
|
||||
|
||||
@@ -201,12 +200,8 @@ public:
|
||||
void deleteBuffer(GLuint buffer);
|
||||
|
||||
/**
|
||||
* glDrawArrays and glDrawElements which increment the draw-call counter by
|
||||
* themselves.
|
||||
* Set all vertex attribute state.
|
||||
**/
|
||||
void drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instancecount = 1);
|
||||
void drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount = 1);
|
||||
|
||||
void setVertexAttributes(const vertex::Attributes &attributes, const vertex::Buffers &buffers);
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user