Vertex shaders can write to gl_PointSize (fixes #1603).

If a shader uses gl_PointSize then it can only be used when drawing points. If a shader doesn't use gl_PointSize then it can't be used when drawing points.

Added 'ConstantPointSize' and 'CurrentDPIScale' built-in shader uniforms.

ConstantPointSize is in DPI-scaled points, whereas gl_PointSize is in pixels, so to get the correct default behaviour a shader needs to do gl_PointSize = ConstantPointSize * CurrentDPIScale
This commit is contained in:
Alex Szpakowski
2021-01-23 13:47:12 -04:00
parent deff795908
commit 694d448e83
13 changed files with 83 additions and 87 deletions
+4 -2
View File
@@ -304,6 +304,9 @@ bool Graphics::setMode(int width, int height, int pixelwidth, int pixelheight, b
glEnable(GL_TEXTURE_2D);
}
if (!GLAD_ES_VERSION_2_0)
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
gl.setTextureUnit(0);
// Set pixel row alignment - code that calls glTexSubImage and glReadPixels
@@ -1444,10 +1447,9 @@ void Graphics::setBlendState(const BlendState &blend)
void Graphics::setPointSize(float size)
{
if (batchedDrawState.primitiveMode == PRIMITIVE_POINTS)
if (size != states.back().pointSize)
flushBatchedDraws();
gl.setPointSize(size * getCurrentDPIScale());
states.back().pointSize = size;
}
-13
View File
@@ -943,19 +943,6 @@ void OpenGL::setScissor(const Rect &v, bool rtActive)
state.scissor = v;
}
void OpenGL::setPointSize(float size)
{
if (GLAD_VERSION_1_0)
glPointSize(size);
state.pointSize = size;
}
float OpenGL::getPointSize() const
{
return state.pointSize;
}
void OpenGL::setEnableState(EnableState enablestate, bool enable)
{
GLenum glstate = GL_NONE;
-6
View File
@@ -270,12 +270,6 @@ public:
**/
void setScissor(const Rect &v, bool rtActive);
/**
* Sets the global point size.
**/
void setPointSize(float size);
float getPointSize() const;
/**
* State-tracked version of glEnable.
**/
+6 -18
View File
@@ -48,7 +48,6 @@ Shader::Shader(love::graphics::ShaderStage *vertex, love::graphics::ShaderStage
, builtinUniforms()
, builtinUniformInfo()
, builtinAttributes()
, lastPointSize(0.0f)
{
// load shader source and create program object
loadVolatile();
@@ -430,8 +429,6 @@ bool Shader::loadVolatile()
{
OpenGL::TempDebugGroup debuggroup("Shader load");
lastPointSize = -1.0f;
// zero out active texture list
textureUnits.clear();
textureUnits.push_back(TextureUnit());
@@ -971,26 +968,11 @@ void Shader::setVideoTextures(love::graphics::Texture *ytexture, love::graphics:
}
}
void Shader::updatePointSize(float size)
{
if (size == lastPointSize || current != this)
return;
GLint location = builtinUniforms[BUILTIN_POINT_SIZE];
if (location >= 0)
glUniform1f(location, size);
lastPointSize = size;
}
void Shader::updateBuiltinUniforms(love::graphics::Graphics *gfx, int viewportW, int viewportH)
{
if (current != this)
return;
if (GLAD_ES_VERSION_2_0)
updatePointSize(gl.getPointSize());
BuiltinUniformData data;
data.transformMatrix = gfx->getTransform();
@@ -1010,6 +992,12 @@ void Shader::updateBuiltinUniforms(love::graphics::Graphics *gfx, int viewportW,
}
}
// Store DPI scale in an unused component of another vector.
data.normalMatrix[0].w = (float) gfx->getCurrentDPIScale();
// Same with point size.
data.normalMatrix[1].w = gfx->getPointSize();
data.screenSizeParams.x = viewportW;
data.screenSizeParams.y = viewportH;
-7
View File
@@ -43,10 +43,6 @@ class Shader final : public love::graphics::Shader, public Volatile
{
public:
/**
* Creates a new Shader using a list of source codes.
* Source must contain either vertex or pixel shader code, or both.
**/
Shader(love::graphics::ShaderStage *vertex, love::graphics::ShaderStage *pixel);
virtual ~Shader();
@@ -67,7 +63,6 @@ public:
ptrdiff_t getHandle() const override;
void setVideoTextures(love::graphics::Texture *ytexture, love::graphics::Texture *cbtexture, love::graphics::Texture *crtexture) override;
void updatePointSize(float size);
void updateBuiltinUniforms(love::graphics::Graphics *gfx, int viewportW, int viewportH);
private:
@@ -128,8 +123,6 @@ private:
std::vector<std::pair<const UniformInfo *, int>> pendingUniformUpdates;
float lastPointSize;
}; // Shader
} // opengl