In the function distSigned
I am assuming that l.p != vec2(0)
. If this isn't the case, it could break the entire shader with a hard to find bug. Is there is any way of verifying this, and throwing a runtime-error if the parameters are invalid? This would make debugging a lot easier. I know GLSL doesn't have a throw
like Java, but maybe theres some kind of hack?
struct parallel {
vec2 p;
vec2 d;
};
struct pt {vec2 v;};
float distSigned(pt p, parallel l) {
vec2 l2o = fromOrigo(l);
float d = length(l2o);
return dot(p.v, l2o/d) - d;
}
Edit: I had a look at the GLSL specification and found this:
"Compile-time errors must be returned for lexically or grammatically incorrect shaders. Other errors are reported at compile time or link time as indicated."
I guess this means GLSL doesn't have runtime errors? If so, maybe its possible for me to implement exceptions on my own? Is there some kind of design pattern for this?
Error Pixel Implementation, Webgl2:
//:ES2_AA2_MAC_DEB: My debug macro, true if positive.
//: pix_err: PIXel ERRor ( Stores Hex Error Code )
//: pix_fra: PIXel FRAgment ( fragment color )
#if( ES2_AA2_MAC_DEB > 0 ) //:///////////////////////////://
//:ASSIGN_TO_ZERO_AT_TOP_OF_FUNCTION!!!!!!!!!!!!!!!!!!!!
uint pix_err =( 0x00000000 );
#endif //:///////////////////////////////////////////////://
//: ...Later when you want to error check....
#if( ES2_AA2_MAC_DEB > 0 ) //:///////////////////////////://
if( Ax1-Ax0+uint(1) != ES2_zoo_wid ||
Ay1-Ay0+uint(1) != ES2_zoo_hig ){
//: The first error encountered puts program ://
//: into invalid state, so we want to make sure ://
//: we never override the first error tripped. ://
//: So always guard with comparison to ://
//: 0x00000000 before setting to the error color.://
if( uint(0x00000000) == pix_err ){
pix_err=( uint(0xFF9000FF) );
};;
};;
#endif //:///////////////////////////////////////////////://
... Do more code.......................................
... DONT TRY TO EXIT EARLY if error is tripped ........
... that will just turn your code into spaghetti ......
#if( ES2_AA2_MAC_DEB > 0 ) //://////////////////////////://
if( uint(0x000000) != pix_err ){
#define F_F uint(0xFF)" //://////////////////////://
pix_fra=( vec4( //://///////////////////////////://
float( ( pix_err >> 24 ) & F_F ) / 255.0
,float( ( pix_err >> 16 ) & F_F ) / 255.0
,float( ( pix_err >> 8 ) & F_F ) / 255.0
,float( ( pix_err >> 0 ) & F_F ) / 255.0
));; //://///////////////////////////////////////://
#undef F_F //://////////////////////////////////://
};;
#endif //:///////////////////////////////////////////////://
//: Now in debug mode, you can color sample the pixel ://
//: and type in the hex code to find the exact error. ://
//: Might not be helpful for minor edge cases, but ://
//: should be very helpful for gross mistakes in ://
//: your programming logic. ://
return( pix_fra );