ref: 968148ad548285cf8e63e97a4ee13d3054e7e407
parent: c429386086c69185f833a5a554d3797bf78227ff
author: David <gek@katherine>
date: Tue Feb 16 23:38:33 EST 2021
BLENDING SUPPORT IMPLEMENTED
--- a/README.md
+++ b/README.md
@@ -60,6 +60,8 @@
* Added support for glDepthMask and glDisable(GL_DEPTH_TEST) as per-GL-spec
+* ADDED BLENDING SUPPORT!
+
* Fixed a myriad of bugs and... weirdnesses
@@ -74,8 +76,6 @@
* The only supported texture size and format is RGB 256x256
-* Blending is in development.
-
* A lot of prototypes are missing.
* glPolygonOffset doesn't change anything about how rendering occurs. It does nothing, at the moment.
@@ -114,6 +114,8 @@
glClose();
```
+
+Note that while you... *can* invoke ZB_Resize to resize the framebuffer, you really shouldn't. It isn't tested.
### WHAT ARE THE MINIMUM REQUIREMENTS OF THIS LIBRARY?
--- a/include/zbuffer.h
+++ b/include/zbuffer.h
@@ -93,47 +93,49 @@
#if TGL_FEATURE_BLEND == 1
#define TGL_NO_BLEND_FUNC(source, dest){dest = source;}
#define TGL_NO_BLEND_FUNC_RGB(rr, gg, bb, dest){dest = RGB_TO_PIXEL(rr,gg,bb);}
-#define TGL_CLAMPI(imp,min,max) ( (imp<min)?min:((imp>max)?max:imp) )
+//SORCERY to achieve 32 bit signed integer clamping
+//#define TGL_IGTZ(imp) ((imp>>31) == 0)
+//#define TGL_ILT(imp) ((imp & 0x10000) != 0x10000)
+//#define TGL_INLT(imp) ((imp & 0x10000) == 0x10000)
+//#define TGL_CLAMPI(imp) ( TGL_IGTZ(imp)*( TGL_ILT(imp) * imp + !TGL_INLT(imp) * 65535) )
+#define TGL_CLAMPI(imp) ( (imp<0)?0:((imp>65535)?65535:imp) )
-#if TGL_FEATURE_EXPENSIVE_BLEND == 1
#define TGL_BLEND_SWITCH_CASE(sr,sg,sb,dr,dg,db,dest) \
switch(zb->blendeq){ \
case GL_FUNC_ADD: \
default: \
- dest = RGB_TO_PIXEL(sr+dr, sg+dg, sb+db); \
+ sr+=dr;sg+=dg;sb+=db; \
+ sr = TGL_CLAMPI(sr); \
+ sg = TGL_CLAMPI(sg); \
+ sb = TGL_CLAMPI(sb); \
+ dest = RGB_TO_PIXEL(sr,sg,sb); \
break; \
case GL_FUNC_SUBTRACT: \
sr-=dr;sg-=dg;sb-=db; \
- dest = RGB_TO_PIXEL(sr * (sr),sg,sb); \
+ sr = TGL_CLAMPI(sr); \
+ sg = TGL_CLAMPI(sg); \
+ sb = TGL_CLAMPI(sb); \
+ dest = RGB_TO_PIXEL(sr,sg,sb); \
break; \
case GL_FUNC_REVERSE_SUBTRACT: \
sr=dr-sr;sg=dg-sg;sb=db-sb; \
- sr = TGL_CLAMPI(sr, 0, 65280); \
- sg = TGL_CLAMPI(sg, 0, 65280); \
- sb = TGL_CLAMPI(sb, 0, 65280); \
+ sr = TGL_CLAMPI(sr); \
+ sg = TGL_CLAMPI(sg); \
+ sb = TGL_CLAMPI(sb); \
dest = RGB_TO_PIXEL(sr,sg,sb); \
break; \
\
}
-#else
-#define TGL_BLEND_SWITCH_CASE(sr,sg,sb,dr,dg,db,dest) \
- /*switch(zb->blendeq){*/ \
- /* case GL_FUNC_ADD: */ \
- /* default: */ \
- \
- dest = RGB_TO_PIXEL(sr+dr, sg+dg, sb+db); \
- /* break; */ \
- \
- /*} */
-#endif
+
+
#define TGL_BLEND_FUNC(source, dest){ \
if(zb->enable_blend != 1){ \
TGL_NO_BLEND_FUNC(source,dest) \
} else { \
GLuint sr, sg, sb, dr, dg, db; \
- { GLuint t = source; \
+ { GLuint t = source; \
sr = GET_REDDER(t); sg = GET_GREENER(t); sb = GET_BLUEER(t); \
t = dest; \
dr = GET_REDDER(t); dg = GET_GREENER(t); db = GET_BLUEER(t);} \
--- a/include/zfeatures.h
+++ b/include/zfeatures.h
@@ -10,8 +10,7 @@
//NOTE: Polygon Offset does nothing at the moment.
#define TGL_FEATURE_POLYGON_OFFSET 0
#define TGL_FEATURE_POLYGON_STIPPLE 0
-#define TGL_FEATURE_BLEND 0
-#define TGL_FEATURE_EXPENSIVE_BLEND 1
+#define TGL_FEATURE_BLEND 1
//A stipple pattern is 128 bytes in size.
#define TGL_POLYGON_STIPPLE_BYTES 128
//A stipple pattern is 2^5 (32) bits wide.