@@ -92,10 +92,10 @@ static const char render_uniforms[] = R"(
9292// but we can't guarantee that highp is always supported in fragment shaders...
9393// We *really* don't want to use mediump for these in vertex shaders though.
9494#ifdef LOVE_SPLIT_UNIFORMS_PER_DRAW
95- uniform LOVE_HIGHP_OR_MEDIUMP vec4 love_UniformsPerDraw[12 ];
95+ uniform LOVE_HIGHP_OR_MEDIUMP vec4 love_UniformsPerDraw[13 ];
9696uniform LOVE_HIGHP_OR_MEDIUMP vec4 love_UniformsPerDraw2[1];
9797#else
98- uniform LOVE_HIGHP_OR_MEDIUMP vec4 love_UniformsPerDraw[13 ];
98+ uniform LOVE_HIGHP_OR_MEDIUMP vec4 love_UniformsPerDraw[14 ];
9999#endif
100100
101101// Older GLSL doesn't support preprocessor line continuations...
@@ -107,12 +107,15 @@ uniform LOVE_HIGHP_OR_MEDIUMP vec4 love_UniformsPerDraw[13];
107107
108108#define CurrentDPIScale (love_UniformsPerDraw[8].w)
109109#define ConstantPointSize (love_UniformsPerDraw[9].w)
110- #define ConstantColor (love_UniformsPerDraw[11])
110+
111+ #define love_ClipSpaceParams (love_UniformsPerDraw[11])
112+
113+ #define ConstantColor (love_UniformsPerDraw[12])
111114
112115#ifdef LOVE_SPLIT_UNIFORMS_PER_DRAW
113116#define love_ScreenSize (love_UniformsPerDraw2[0])
114117#else
115- #define love_ScreenSize (love_UniformsPerDraw[12 ])
118+ #define love_ScreenSize (love_UniformsPerDraw[13 ])
116119#endif
117120
118121// Alternate names
@@ -248,7 +251,13 @@ static const char vertex_header[] = R"(
248251#endif
249252)" ;
250253
251- static const char vertex_functions[] = R"( )" ;
254+ static const char vertex_functions[] = R"(
255+ vec4 love_clipSpaceTransform(vec4 clipPosition) {
256+ clipPosition.y *= love_ClipSpaceParams.x;
257+ clipPosition.z = (love_ClipSpaceParams.y * clipPosition.z + love_ClipSpaceParams.z * clipPosition.w) * love_ClipSpaceParams.w;
258+ return clipPosition;
259+ }
260+ )" ;
252261
253262static const char vertex_main[] = R"(
254263LOVE_IO_LOCATION(0) attribute vec4 VertexPosition;
@@ -264,6 +273,7 @@ void main() {
264273 VaryingTexCoord = VertexTexCoord;
265274 VaryingColor = gammaCorrectColor(VertexColor) * ConstantColor;
266275 love_Position = position(ClipSpaceFromLocal, VertexPosition);
276+ love_Position = love_clipSpaceTransform(love_Position);
267277}
268278)" ;
269279
@@ -272,6 +282,7 @@ void vertexmain();
272282
273283void main() {
274284 vertexmain();
285+ love_Position = love_clipSpaceTransform(love_Position);
275286}
276287)" ;
277288
@@ -588,7 +599,7 @@ static Shader::EntryPoint getComputeEntryPoint(const std::string &src, const std
588599
589600} // glsl
590601
591- static_assert (sizeof (Shader::BuiltinUniformData) == sizeof (float ) * 4 * 13 , " Update the array in wrap_GraphicsShader.lua if this changes." );
602+ static_assert (sizeof (Shader::BuiltinUniformData) == sizeof (float ) * 4 * 14 , " Update the array in wrap_GraphicsShader.lua if this changes." );
592603
593604love::Type Shader::type (" Shader" , &Object::type);
594605
@@ -793,6 +804,28 @@ bool Shader::isDefaultActive()
793804 return false ;
794805}
795806
807+ Vector4 Shader::computeClipSpaceParams (uint32 clipSpaceTransformFlags)
808+ {
809+ // See the love_clipSpaceTransform vertex shader function.
810+ Vector4 params (1 .0f , 1 .0f , 0 .0f , 1 .0f );
811+
812+ if (clipSpaceTransformFlags & CLIP_TRANSFORM_FLIP_Y )
813+ params.x = -1 .0f ;
814+
815+ if (clipSpaceTransformFlags & CLIP_TRANSFORM_Z_NEG1_1_TO_0_1 )
816+ {
817+ params.z = 1 .0f ;
818+ params.w = 0 .5f ;
819+ }
820+ else if (clipSpaceTransformFlags & CLIP_TRANSFORM_Z_0_1_TO_NEG1_1 )
821+ {
822+ params.y = 2 .0f ;
823+ params.z = -1 .0f ;
824+ }
825+
826+ return params;
827+ }
828+
796829const Shader::UniformInfo *Shader::getUniformInfo (const std::string &name) const
797830{
798831 const auto it = reflection.allUniforms .find (name);
0 commit comments