ref: f136e0b18cb02e06ac18aeb52cc8df00947a97f5
parent: 5a4e2a659d7f460b962909e49b524d8292c96728
author: David <gek@katherine>
date: Fri Feb 19 16:31:17 EST 2021
Any power of 2 texture size
--- a/README.md
+++ b/README.md
@@ -55,9 +55,11 @@
* Disabled 8, 15, and 24 bit rendering modes. 16 and 32 are the only supported rendering modes (Coincidentally, they are also the fastest)
+* Allowed the fixed texture size to be changed at compile time. It must be a power of 2, but that is the only limitation.
+
* Removed the entire GLX/NanoGLX part of the library. Not portable and mostly useless.
-* Implemented new functions and some of GL 1.1's prototypes including polygon stipple.
+* Implemented new functions and some more of GL 1.1's prototypes including polygon stipple.
* Triangles can now be lit and textured at the same time!
@@ -75,13 +77,15 @@
* Added glGetString() for GL_VENDOR, GL_RENDERER, GL_VERSION, and GL_LICENSE
-* Added comprehensive glGetError() functionality
+* Added comprehensive, usable glGetError() functionality for debugging.
* Fixed a myriad of bugs and... weirdnesses
* Tuned the triangle rasterizer to near-perfection.
+* Tuned the transformations to absolute perfection
+
Note that this Softrast **is not GL 1.1 compliant** and does not constitute a complete GL implementation.
You *will* have to tweak your code to work with this library. That said, once you have, it will run anywhere that you can get
@@ -99,11 +103,13 @@
* There is no stencil buffer.
+* Blending can't use alpha values. the rasterizer has no concept of alpha.
+
* There is no mipmapping, antialiasing, or any form of texture filtering.
-* The only wrap mode is wrapping. You cannot change it.
+* No edge clamping. S and T are wrapped.
-* Lit triangles will use the current material properties, even if they are textures. If the diffuse color is black, then your
+* Lit triangles will use the current material properties, even if they are textured. If the diffuse color is black, then your
textured triangles will appear black.
* Lit textured triangles are smoothly shaded, irrespective of glShadeModel (Untextured triangles do not have this bug)
--- a/include/zbuffer.h
+++ b/include/zbuffer.h
@@ -16,11 +16,11 @@
//a "1" in bit FRAC_BITS+1 (starting at zero) = 1.
#define ZB_POINT_S_MIN ( (1<<ZB_POINT_S_FRAC_BITS) )
-#define ZB_POINT_S_MAX ( (1<<(1+TGL_FEATURE_TEXTURE_POW2+ZB_POINT_S_FRAC_BITS))-(1<<ZB_POINT_S_FRAC_BITS) )
+#define ZB_POINT_S_MAX ( (1<<(1+TGL_FEATURE_TEXTURE_POW2+ZB_POINT_S_FRAC_BITS))-ZB_POINT_S_MIN )
#define ZB_POINT_T_MIN ( (1<<ZB_POINT_T_FRAC_BITS) )
-#define ZB_POINT_T_MAX ( (1<<(1+TGL_FEATURE_TEXTURE_POW2+ZB_POINT_T_FRAC_BITS))-(1<<ZB_POINT_T_FRAC_BITS) )
-#define ZB_POINT_S_VALUE (ZB_POINT_S_FRAC_BITS + TGL_FEATURE_TEXTURE_POW2_HALF)
-#define ZB_POINT_T_VALUE (ZB_POINT_T_FRAC_BITS - TGL_FEATURE_TEXTURE_POW2_HALF)
+#define ZB_POINT_T_MAX ( (1<<(1+TGL_FEATURE_TEXTURE_POW2+ZB_POINT_T_FRAC_BITS))-ZB_POINT_T_MIN )
+#define ZB_POINT_S_VALUE (ZB_POINT_S_FRAC_BITS + 4)
+#define ZB_POINT_T_VALUE (ZB_POINT_T_FRAC_BITS - 4)
#define ZB_S_MASK ((TGL_FEATURE_TEXTURE_DIM-1)<<(ZB_POINT_S_FRAC_BITS+1))
#define ZB_T_MASK ((TGL_FEATURE_TEXTURE_DIM-1)<<(ZB_POINT_T_FRAC_BITS+1))
//PSZSH is 5 at 32 bit, or 4 at 16 bit.
--- a/include/zfeatures.h
+++ b/include/zfeatures.h
@@ -1,6 +1,7 @@
#ifndef _tgl_features_h_
#define _tgl_features_h_
-
+//This include is for debugging, you can safely remove it if it's enabled
+//#include <stdio.h>
/* It is possible to enable/disable (compile time) features in this
header file. */
@@ -25,14 +26,14 @@
#define TGL_FEATURE_POLYGON_STIPPLE 0
//Enable GL_BLEND functionality
#define TGL_FEATURE_BLEND 1
-//The width of textures as a power of 2. Must be divisible by 2.
+//The width of textures as a power of 2. The default is 8, or 256x256 textures.
#define TGL_FEATURE_TEXTURE_POW2 8
#define TGL_FEATURE_TEXTURE_DIM (1<<TGL_FEATURE_TEXTURE_POW2)
-#define TGL_FEATURE_TEXTURE_POW2_HALF (TGL_FEATURE_TEXTURE_POW2>>1)
+//#define TGL_FEATURE_TEXTURE_POW2_HALF (TGL_FEATURE_TEXTURE_POW2>>1)
-#if TGL_FEATURE_TEXTURE_POW2%2 != 0
-#error "bad TGL_FEATURE_TEXTURE_POW2"
-#endif
+//#if TGL_FEATURE_TEXTURE_POW2%2 != 0
+//#error "bad TGL_FEATURE_TEXTURE_POW2"
+//#endif
//A stipple pattern is 128 bytes in size.
#define TGL_POLYGON_STIPPLE_BYTES 128
--- a/src/get.c
+++ b/src/get.c
@@ -127,7 +127,6 @@
"TGL_FEATURE_OPTIMIZED_TEXTURE_ACCESS "
#endif
"TGL_FEATURE_TEXTURE_POW2=" xstr(TGL_FEATURE_TEXTURE_POW2) " "
-"TGL_FEATURE_TEXTURE_DIM=" xstr(xstr(TGL_FEATURE_TEXTURE_DIM)) " "
#if TGL_FEATURE_LIT_TEXTURES == 1
"TGL_FEATURE_LIT_TEXTURES "
#endif
--- a/src/texture.c
+++ b/src/texture.c
@@ -143,9 +143,8 @@
if(!(target == GL_TEXTURE_2D && target > 0))
#define ERROR_FLAG GL_INVALID_ENUM
#include "error_check.h"
-
#else
- //assert(target == GL_TEXTURE_2D && target > 0);
+ assert(target == GL_TEXTURE_2D && target > 0);
#endif
t = find_texture(c, texture);
if (t == NULL) {
@@ -193,6 +192,7 @@
if (width != TGL_FEATURE_TEXTURE_DIM || height != TGL_FEATURE_TEXTURE_DIM) {
pixels1 = gl_malloc(TGL_FEATURE_TEXTURE_DIM * TGL_FEATURE_TEXTURE_DIM * 3);
/* no GLinterpolation is done here to respect the original image aliasing ! */
+ //printf("\nYes this is being called.");
gl_resizeImageNoInterpolate(pixels1, TGL_FEATURE_TEXTURE_DIM, TGL_FEATURE_TEXTURE_DIM, pixels, width, height);
do_free = 1;
width = TGL_FEATURE_TEXTURE_DIM;
@@ -206,19 +206,7 @@
im->ysize = height;
if (im->pixmap != NULL)
gl_free(im->pixmap);
-#if TGL_FEATURE_RENDER_BITS == 24
- im->pixmap = gl_malloc(width * height * 3);
- if (im->pixmap) {
- memcpy(im->pixmap, pixels1, width * height * 3);
- } else {
-#if TGL_FEATURE_ERROR_CHECK == 1
-#define ERROR_FLAG GL_OUT_OF_MEMORY
-#include "error_check.h"
-#else
- gl_fatal_error("GL_OUT_OF_MEMORY");
-#endif
- }
-#elif TGL_FEATURE_RENDER_BITS == 32
+#if TGL_FEATURE_RENDER_BITS == 32
im->pixmap = gl_malloc(width * height * 4);
if (im->pixmap) {
gl_convertRGB_to_8A8R8G8B(im->pixmap, pixels1, width, height);
--- a/src/ztriangle.c
+++ b/src/ztriangle.c
@@ -480,7 +480,6 @@
register GLuint zz =z >> ZB_POINT_Z_FRAC_BITS; \
c = TEXTURE_SAMPLE(texture, s, t); \
if (ZCMP(zz, pz[_a], _a, c)) { \
- /*pp[_a] = RGB_MIX_FUNC(or1, og1, ob1, c);*/ \
TGL_BLEND_FUNC(RGB_MIX_FUNC(or1, og1, ob1, c), (pp[_a])); \
if(zbdw) pz[_a] = zz; \
} \