From 0cfd86d0f4128296d322293658335c5422501897 Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 31 Dec 2018 13:11:33 +0100 Subject: [PATCH] glgsg: warn if Cg shader uses float4 vtx_normal See #495; Cg's glslv profile does not handle a float4 vtx_normal well and causes garbage to be in the w coordinate. --- panda/src/glstuff/glCgShaderContext_src.cxx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/panda/src/glstuff/glCgShaderContext_src.cxx b/panda/src/glstuff/glCgShaderContext_src.cxx index 649208fb47..6e7fc565cc 100644 --- a/panda/src/glstuff/glCgShaderContext_src.cxx +++ b/panda/src/glstuff/glCgShaderContext_src.cxx @@ -157,6 +157,16 @@ CLP(CgShaderContext)(CLP(GraphicsStateGuardian) *glgsg, Shader *s) : ShaderConte break; case 2: // gl_Normal loc = CA_normal; + if (cgGetParameterColumns(p) == 4) { + // Don't declare vtx_normal with 4 coordinates; it results in it + // reading the w coordinate from random memory. + GLCAT.error() + << "Cg varying " << cgGetParameterName(p); + if (cgGetParameterSemantic(p)) { + GLCAT.error(false) << " : " << cgGetParameterSemantic(p); + } + GLCAT.error(false) << " should be declared as float4, not float3!\n"; + } break; case 3: // gl_Color loc = CA_color;