ref: b93651d8cd0877cd77b09d5b2001f4f5a2e020e7
parent: fba8d05c264d1939b42fa8487425492744f59f74
author: David <gek@katherine>
date: Sun Feb 21 16:30:10 EST 2021
Bug fixing and compiling improvements
--- a/include/GL/gl.h
+++ b/include/GL/gl.h
@@ -772,6 +772,13 @@
void glEnd(void);
void glDrawBuffer(GLenum mode);
void glReadBuffer(GLenum mode);
+void glReadPixels( GLint x,
+ GLint y,
+ GLsizei width,
+ GLsizei height,
+ GLenum format,
+ GLenum type,
+ void * data);
void glDrawArrays( GLenum mode,
GLint first,
GLsizei count);
@@ -874,6 +881,14 @@
void glTexImage2D( GLint target, GLint level, GLint components,
GLint width, GLint height, GLint border,
GLint format, GLint type, void *pixels);
+void glCopyTexImage2D( GLenum target,
+ GLint level,
+ GLenum internalformat,
+ GLint x,
+ GLint y,
+ GLsizei width,
+ GLsizei height,
+ GLint border);
void glTexEnvi(GLint target,GLint pname,GLint param);
void glTexParameteri(GLint target,GLint pname,GLint param);
void glPixelStorei(GLint pname,GLint param);
--- a/src/api.c
+++ b/src/api.c
@@ -108,6 +108,7 @@
void glEdgeFlag(GLint flag) {
GLParam p[2];
+#define NEED_CONTEXT
#include "error_check_no_context.h"
#if TGL_FEATURE_ERROR_CHECK == 1
if(flag != GL_TRUE && flag != GL_FALSE)
@@ -124,6 +125,7 @@
void glShadeModel(GLint mode) {
GLParam p[2];
+#define NEED_CONTEXT
#include "error_check_no_context.h"
#if TGL_FEATURE_ERROR_CHECK == 1
if(mode != GL_FLAT && mode != GL_SMOOTH)
@@ -130,7 +132,7 @@
#define ERROR_FLAG GL_INVALID_ENUM
#include "error_check.h"
#else
-// assert(mode == GL_FLAT || mode == GL_SMOOTH);
+ if(mode != GL_FLAT && mode != GL_SMOOTH) return;
//Assume that they know what they're doing.
#endif
p[0].op = OP_ShadeModel;
@@ -141,6 +143,7 @@
void glCullFace(GLint mode) {
GLParam p[2];
+#define NEED_CONTEXT
#include "error_check_no_context.h"
#if TGL_FEATURE_ERROR_CHECK == 1
if(!(mode == GL_BACK || mode == GL_FRONT || mode == GL_FRONT_AND_BACK))
@@ -158,6 +161,7 @@
void glFrontFace(GLint mode) {
GLParam p[2];
+#define NEED_CONTEXT
#include "error_check_no_context.h"
#if TGL_FEATURE_ERROR_CHECK == 1
if(!(mode == GL_CCW || mode == GL_CW))
@@ -176,6 +180,7 @@
void glPolygonMode(GLint face, GLint mode) {
GLParam p[3];
+#define NEED_CONTEXT
#include "error_check_no_context.h"
#if TGL_FEATURE_ERROR_CHECK == 1
if(!( (face == GL_BACK || face == GL_FRONT || face == GL_FRONT_AND_BACK)&&
@@ -361,6 +366,7 @@
void glMaterialfv(GLint mode, GLint type, GLfloat* v) {
GLParam p[7];
GLint i, n;
+#define NEED_CONTEXT
#include "error_check_no_context.h"
#if TGL_FEATURE_ERROR_CHECK == 1
if(!(mode == GL_FRONT || mode == GL_BACK || mode == GL_FRONT_AND_BACK))
--- a/src/arrays.c
+++ b/src/arrays.c
@@ -414,6 +414,7 @@
void glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid* pointer) {
GLParam p[4];
+#define NEED_CONTEXT
#include "error_check_no_context.h"
#if TGL_FEATURE_ERROR_CHECK == 1
if(type != GL_FLOAT)
@@ -437,6 +438,7 @@
void glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid* pointer) {
GLParam p[4];
+#define NEED_CONTEXT
#include "error_check_no_context.h"
#if TGL_FEATURE_ERROR_CHECK == 1
if(type != GL_FLOAT)
@@ -459,6 +461,7 @@
void glNormalPointer(GLenum type, GLsizei stride, const GLvoid* pointer) {
GLParam p[3];
+#define NEED_CONTEXT
#include "error_check_no_context.h"
#if TGL_FEATURE_ERROR_CHECK == 1
if(type != GL_FLOAT)
@@ -481,6 +484,7 @@
void glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid* pointer) {
GLParam p[4];
+#define NEED_CONTEXT
#include "error_check_no_context.h"
#if TGL_FEATURE_ERROR_CHECK == 1
if(type != GL_FLOAT)
--- a/src/error_check_no_context.h
+++ b/src/error_check_no_context.h
@@ -3,13 +3,17 @@
#endif
#if TGL_FEATURE_ERROR_CHECK == 1
- GLContext* c = gl_get_context();
+
//#error should never execute
#if TGL_FEATURE_STRICT_OOM_CHECKS == 1
+ GLContext* c = gl_get_context();
if(c->error_flag == GL_OUT_OF_MEMORY)
return RETVAL;
+#elif defined(NEED_CONTEXT)
+ GLContext* c = gl_get_context();
#endif
#endif
#undef RETVAL
+#undef NEED_CONTEXT
--- a/src/misc.c
+++ b/src/misc.c
@@ -233,6 +233,37 @@
c->readbuffer = mode;
}
+//Only ever reads pixels from the depth buffer
+void glReadPixels( GLint x,
+ GLint y,
+ GLsizei width,
+ GLsizei height,
+ GLenum format,
+ GLenum type,
+ void * data){
+ GLContext* c = gl_get_context();
+ #include "error_check.h"
+ if(c->readbuffer != GL_FRONT ||
+ (format != GL_RGBA && format != GL_RGB && format != GL_DEPTH_COMPONENT) ||
+#if TGL_FEATURE_RENDER_BITS == 32
+ (type != GL_UNSIGNED_INT && type != GL_UNSIGNED_INT_8_8_8_8)
+#elif TGL_FEATURE_RENDER_BITS == 16
+ (type != GL_UNSIGNED_SHORT && type != GL_UNSIGNED_SHORT_5_6_5)
+#else
+#error "Unsupported TGL_FEATURE_RENDER_BITS"
+#endif
+
+ ){
+#if TGL_FEATURE_ERROR_CHECK
+#define ERROR_FLAG GL_INVALID_OPERATION
+#include "error_check.h"
+#else
+ return;
+#endif
+ }
+
+}
+
void glFinish(){
return;
}
--- a/src/opinfo.h
+++ b/src/opinfo.h
@@ -38,7 +38,8 @@
ADD_OP(PopName, 0, "")
ADD_OP(LoadName, 1, "%d")
-ADD_OP(TexImage2D, 9, "%d %d %d %d %d %d %d %d %d")
+ADD_OP(TexImage2D, 9, "%d %d %d %d %d %d %d %d %d")
+ADD_OP(CopyTexImage2D, 8, "%d %d %d %d %d %d %d %d")
ADD_OP(BindTexture, 2, "%C %d")
ADD_OP(TexEnv, 7, "%C %C %C %f %f %f %f")
ADD_OP(TexParameter, 7, "%C %C %C %f %f %f %f")
--- a/src/texture.c
+++ b/src/texture.c
@@ -182,6 +182,26 @@
c->current_texture = t;
}
+//TODO: Write this, then
+//Write something to test this. This function is useful for doing render targets in TinyGL
+//- not that you couldn't do that
+//already by manually copying pixels around. But, this is a nifty utility, eh?
+void glCopyTexImage2D( GLenum target,
+ GLint level,
+ GLenum internalformat,
+ GLint x,
+ GLint y,
+ GLsizei width,
+ GLsizei height,
+ GLint border){
+ GLContext* c = gl_get_context();
+#include "error_check.h"
+ //TODO
+}
+void glopCopyTexImage2D(GLContext* c, GLParam* p){
+ //TODO
+}
+
void glopTexImage2D(GLContext* c, GLParam* p) {
GLint target = p[1].i;
GLint level = p[2].i;
@@ -224,8 +244,7 @@
im = &c->current_texture->images[level];
im->xsize = width;
im->ysize = height;
- if (im->pixmap != NULL)
- gl_free(im->pixmap);
+ if (im->pixmap != NULL) gl_free(im->pixmap);
#if TGL_FEATURE_RENDER_BITS == 32
im->pixmap = gl_malloc(width * height * 4);
if (im->pixmap) {
--- a/src/ztext.c
+++ b/src/ztext.c
@@ -9,6 +9,7 @@
void glTextSize(GLTEXTSIZE mode) {
+#define NEED_CONTEXT
#include "error_check_no_context.h"
#if TGL_FEATURE_ERROR_CHECK == 1
if(mode < 1 || GL_MAX_TEXT_SIZE < mode)