ref: dc133d6431539124dcb3e99f9c98f43600775cc2
parent: 63ec41d0a6f4ed434f0ff3f2d68cdd008b45eb34
author: David <gek@katherine>
date: Wed Mar 10 07:32:12 EST 2021
Automatic commit.
--- a/README.md
+++ b/README.md
@@ -1,8 +1,10 @@
# TinyGL- New and Improved
A major overhaul of Fabrice Bellard's TinyGL (still compiling with -std=c99) to be
-more useful as a software rasterizer.
+more useful as a software rasterizer.'
+Now with limited multithreading support
+
## Tightly tweaked and tuned for performance
The library has been tightly tuned using valgrind, perf stat, and other tools.
@@ -54,6 +56,7 @@
+
Without Polygon Stipple:
![GIF Video of demo](capture.gif)
@@ -151,7 +154,9 @@
* Fixed all the memory leaks.
+* added Openmp multithreading and glPostProcess()
+
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
@@ -278,6 +283,22 @@
* A memory allocator of some sort with some equivalents or replacements for malloc, calloc, and free.
There is no FILE* usage, or I/O outside of 'msghandling.c' so if you want to remove all stdio dependency, just stub out the calls there.
+
+
+### Multithreading support
+
+OpenMP is used on supported platforms to multithread certain operations.
+These are the operations that are accelerated:
+
+* glDrawPixels
+
+* glPostProcess
+
+Compile the library with -fopenmp to see them in action!
+
+You do not need a multithreaded processor to use TinyGL!
+
+### Performance Recommendations
```
it is recommended that for best performance you keep TinyGL on a separate thread from SDL, and to guard TinyGL's buffer with a mutex.
--- a/SDL_Examples/texture.c
+++ b/SDL_Examples/texture.c
@@ -25,6 +25,7 @@
#include "include/stb_image.h"
#include <SDL/SDL.h>
int noSDL = 0;
+int doPostProcess = 0;
#include <math.h>
#ifndef M_PI
@@ -60,6 +61,16 @@
return t;
}
+GLuint postProcessingStep(GLint x, GLint y, GLuint pixel, GLushort z){
+#if TGL_FEATURE_RENDER_BITS == 32
+//32 bit pixel
+ return pixel & 0x8F8F8F; //Half color mode.
+#else
+//16 bit mode
+ return 63<<5; //Solid green
+#endif
+}
+
void draw() {
glClearColor(0.0, 0.0, 0.0, 0.0);
glEnable(GL_TEXTURE_2D);
@@ -84,8 +95,11 @@
glTexCoord2f(1 * texture_mult, -1 * texture_mult);
glVertex3f(1, 1, 0.5);
glEnd();
+ if(doPostProcess) glPostProcess(postProcessingStep); //do a post processing step on the rendered geometry.
}
+
+
void initScene() {
static GLfloat pos[4] = {5.0, 5.0, 10.0, 0.0};
@@ -124,9 +138,11 @@
int winSizeY = 480;
unsigned int fps = 0;
char needsRGBAFix = 0;
- if (argc > 2) {
+ if (argc > 1) {
char* larg = argv[1];
for (int i = 0; i < argc; i++) {
+ if (!strcmp(argv[i], "-pp"))
+ doPostProcess = 1;
if (!strcmp(larg, "-w"))
winSizeX = atoi(argv[i]);
if (!strcmp(larg, "-h"))
--- a/include/GL/gl.h
+++ b/include/GL/gl.h
@@ -978,8 +978,13 @@
void glRasterPos4fv(GLfloat* v);
void glDrawPixels(GLsizei width, GLsizei height, GLenum format, GLenum type, void* data);
void glPixelZoom(GLfloat x, GLfloat y);
+
+/* PostProcessing pass implementation */
+void glPostProcess(GLuint (*postprocess)(GLint x, GLint y, GLuint pixel, GLushort z));
/* not implemented, just added to compile */
/*
+
+
inline void glLineWidth(GLfloat) {}
inline void glDepthFunc(GLint) {}
--- a/src/Makefile
+++ b/src/Makefile
@@ -4,7 +4,7 @@
misc.o clear.o light.o clip.o select.o get.o \
zbuffer.o zline.o ztriangle.o \
zmath.o image_util.o msghandling.o \
- arrays.o specbuf.o memory.o ztext.o zraster.o accum.o
+ arrays.o specbuf.o memory.o ztext.o zraster.o accum.o zpostprocess.o
INCLUDES = -I./include
--- /dev/null
+++ b/src/zpostprocess.c
@@ -1,0 +1,11 @@
+#include "../include/GL/gl.h"
+#include "../include/zbuffer.h"
+#include "zgl.h"
+
+void glPostProcess(GLuint (*postprocess)(GLint x, GLint y, GLuint pixel, GLushort z)){
+ GLContext* c = gl_get_context();
+#pragma omp parallel for collapse(2)
+ for(GLint j = 0; j < c->zb->ysize; j++)
+ for(GLint i = 0; i < c->zb->xsize; i++)
+ c->zb->pbuf[i+j*(c->zb->xsize)] = postprocess(i,j,c->zb->pbuf[i+j*(c->zb->xsize)],c->zb->zbuf[i+j*(c->zb->xsize)]);
+}