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
+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;