ref: 6a213254b9ed856592b4a024508ffdc80cceb534
parent: b93651d8cd0877cd77b09d5b2001f4f5a2e020e7
author: David <gek@katherine>
date: Sun Feb 21 18:41:08 EST 2021
Feature update
--- a/README.md
+++ b/README.md
@@ -89,7 +89,9 @@
* Added glDrawArrays
-* Added Buffers
+* Added Buffers (For memory management purposes)
+
+* Added glTexImage1D (... it just resizes it to 2D, but it works!)
* Added glPixelSize (TODO is to implement distance scaling)
--- a/SDL_Examples/texture.c
+++ b/SDL_Examples/texture.c
@@ -32,6 +32,8 @@
#endif
GLuint tex = 0;
+GLuint do1D = 0;
+GLint Row1D = 30;
GLfloat texture_mult = 1.0;
GLuint loadRGBTexture(unsigned char* buf, unsigned int w, unsigned int h) {
GLuint t = 0;
@@ -51,7 +53,10 @@
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexImage2D(GL_TEXTURE_2D, 0, 3, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, buf);
+ if(!do1D)
+ glTexImage2D(GL_TEXTURE_2D, 0, 3, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, buf);
+ else
+ glTexImage1D(GL_TEXTURE_1D, 0, 3, w, 0, GL_RGB, GL_UNSIGNED_BYTE, buf + Row1D * w * 3);
return t;
}
@@ -129,6 +134,10 @@
fps = strtoull(argv[i], 0, 10);
if (!strcmp(larg, "-texscale"))
texture_mult = atof(argv[i]);
+ if (!strcmp(larg, "-1D")){
+ do1D = 1;
+ Row1D = atoi(argv[i]);
+ }
larg = argv[i];
}
}
--- a/include/GL/gl.h
+++ b/include/GL/gl.h
@@ -881,6 +881,10 @@
void glTexImage2D( GLint target, GLint level, GLint components,
GLint width, GLint height, GLint border,
GLint format, GLint type, void *pixels);
+
+void glTexImage1D( GLint target, GLint level, GLint components,
+ GLint width, GLint border,
+ GLint format, GLint type, void *pixels);
void glCopyTexImage2D( GLenum target,
GLint level,
GLenum internalformat,
@@ -890,8 +894,9 @@
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);
+
GLboolean glAreTexturesResident( GLsizei n,
const GLuint * textures,
GLboolean * residences);
--- a/include/zfeatures.h
+++ b/include/zfeatures.h
@@ -8,8 +8,8 @@
#define TGL_FEATURE_ERROR_CHECK 1
//Strict out-of-memory checking. All OpenGL function calls are invalidated (ALL OF THEM) if a GL_OUT_OF_MEMORY error occurs.
//The checks slow down the renderer so it is not recommended , but
-//it's part of the GL spec and it was relatively easy to add so I added it.
-#define TGL_FEATURE_STRICT_OOM_CHECKS 0
+//it's in the GL spec that this should occur.
+#define TGL_FEATURE_STRICT_OOM_CHECKS 1
//Use Fast Inverse Square Root. Toggleable because it's actually slower on some systems, i've heard.
#define TGL_FEATURE_FISR 1
//Clientside Arrays
--- a/src/api.c
+++ b/src/api.c
@@ -518,6 +518,21 @@
gl_add_op(p);
}
+void glTexImage1D(GLint target, GLint level, GLint components, GLint width, GLint border, GLint format, GLint type, void* pixels) {
+ GLParam p[10];
+#include "error_check_no_context.h"
+ p[0].op = OP_TexImage1D;
+ p[1].i = target;
+ p[2].i = level;
+ p[3].i = components;
+ p[4].i = width;
+ p[5].i = border;
+ p[6].i = format;
+ p[7].i = type;
+ p[8].p = pixels;
+ gl_add_op(p);
+}
+
void glBindTexture(GLint target, GLint texture) {
GLParam p[3];
#include "error_check_no_context.h"
@@ -529,35 +544,36 @@
}
void glTexEnvi(GLint target, GLint pname, GLint param) {
- GLParam p[8];
+// GLParam p[8];
#include "error_check_no_context.h"
- p[0].op = OP_TexEnv;
- p[1].i = target;
- p[2].i = pname;
- p[3].i = param;
- p[4].f = 0;
- p[5].f = 0;
- p[6].f = 0;
- p[7].f = 0;
+// p[0].op = OP_TexEnv;
+// p[1].i = target;
+// p[2].i = pname;
+// p[3].i = param;
+// p[4].f = 0;
+// p[5].f = 0;
+// p[6].f = 0;
+// p[7].f = 0;
- gl_add_op(p);
+// gl_add_op(p);
}
void glTexParameteri(GLint target, GLint pname, GLint param) {
- GLParam p[8];
+// GLParam p[8];
#include "error_check_no_context.h"
- p[0].op = OP_TexParameter;
- p[1].i = target;
- p[2].i = pname;
- p[3].i = param;
- p[4].f = 0;
- p[5].f = 0;
- p[6].f = 0;
- p[7].f = 0;
+// p[0].op = OP_TexParameter;
+// p[1].i = target;
+// p[2].i = pname;
+// p[3].i = param;
+// p[4].f = 0;
+// p[5].f = 0;
+// p[6].f = 0;
+// p[7].f = 0;
- gl_add_op(p);
+// gl_add_op(p);
}
+/*
void glPixelStorei(GLint pname, GLint param) {
GLParam p[3];
#include "error_check_no_context.h"
@@ -567,7 +583,7 @@
gl_add_op(p);
}
-
+*/
/* selection */
void glInitNames(void) {
@@ -629,13 +645,8 @@
}
void glHint(GLint target, GLint mode) {
- GLParam p[3];
#include "error_check_no_context.h"
- p[0].op = OP_Hint;
- p[1].i = target;
- p[2].i = mode;
-
- gl_add_op(p);
+
}
/* Non standard functions */
--- a/src/arrays.c
+++ b/src/arrays.c
@@ -78,7 +78,7 @@
void glGenBuffers( GLsizei n,
GLuint * buffers)
-{
+{GLContext* c = gl_get_context();
#include "error_check.h"
if(n > MAX_BUFFERS) goto error;
@@ -105,7 +105,7 @@
}
void glDeleteBuffers( GLsizei n,
const GLuint * buffers)
-{
+{GLContext* c = gl_get_context();
#include "error_check.h"
for(GLint i = 0; i < n; i++) free_buffer(buffers[i]);
}
@@ -275,7 +275,7 @@
#define ERROR_FLAG GL_OUT_OF_MEMORY
#include "error_check.h"
#else
- gl_fatal_error("GL_OUT_OF_MEMORY")
+ gl_fatal_error("GL_OUT_OF_MEMORY");
#endif
}
memcpy(buf->data, data, size);
@@ -421,7 +421,7 @@
#define ERROR_FLAG GL_INVALID_ENUM
#include "error_check.h"
#else
- assert(type == GL_FLOAT); Everything is fine!
+ if(type != GL_FLOAT) return;
#endif
p[0].op = OP_VertexPointer;
p[1].i = size;
--- a/src/misc.c
+++ b/src/misc.c
@@ -175,14 +175,6 @@
}
}
-void glopHint(GLContext* c, GLParam* p) {
-#if 0
- GLint target=p[1].i;
- GLint mode=p[2].i;
-
- /* do nothing */
-#endif
-}
void glopPolygonOffset(GLContext* c, GLParam* p) {
c->offset_factor = p[1].f;
--- a/src/opinfo.h
+++ b/src/opinfo.h
@@ -39,11 +39,12 @@
ADD_OP(LoadName, 1, "%d")
ADD_OP(TexImage2D, 9, "%d %d %d %d %d %d %d %d %d")
+ADD_OP(TexImage1D, 8, "%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")
-ADD_OP(PixelStore, 2, "%C %C")
+//ADD_OP(TexEnv, 7, "%C %C %C %f %f %f %f")
+//ADD_OP(TexParameter, 7, "%C %C %C %f %f %f %f")
+//ADD_OP(PixelStore, 2, "%C %C")
ADD_OP(ShadeModel, 1, "%C")
ADD_OP(CullFace, 1, "%C")
@@ -51,7 +52,7 @@
ADD_OP(PolygonMode, 2, "%C %C")
ADD_OP(CallList, 1, "%d")
-ADD_OP(Hint, 2, "%C %C")
+//ADD_OP(Hint, 2, "%C %C")
/* special opcodes */
ADD_OP(EndList, 0, "")
--- a/src/select.c
+++ b/src/select.c
@@ -40,7 +40,7 @@
#define RETVAL 0
#include "error_check.h"
#else
- if(c->select_buffer == NULL)return;
+ if(c->select_buffer == NULL)return 0;
#endif
c->render_mode = GL_SELECT;
c->select_ptr = c->select_buffer;
--- a/src/texture.c
+++ b/src/texture.c
@@ -21,11 +21,13 @@
GLContext* c = gl_get_context();
#define RETVAL GL_FALSE
#include "error_check.h"
+GLboolean retval = GL_TRUE;
for(GLint i = 0; i < n; i++)
if(find_texture(c, textures[i]))
- residences[i] = GL_TRUE;
+ {residences[i] = GL_TRUE;}
else
- residences[i] = GL_FALSE;
+ {residences[i] = GL_FALSE;retval = GL_FALSE;}
+ return retval;
}
GLboolean glIsTexture( GLuint texture){
GLContext* c = gl_get_context();
@@ -202,6 +204,85 @@
//TODO
}
+void glopTexImage1D(GLContext* c, GLParam* p){
+ GLint target = p[1].i;
+ GLint level = p[2].i;
+ GLint components = p[3].i;
+ GLint width = p[4].i;
+ //GLint height = p[5].i;
+ GLint height = 1;
+ GLint border = p[5].i;
+ GLint format = p[6].i;
+ GLint type = p[7].i;
+ void* pixels = p[8].p;
+ GLImage* im;
+ GLubyte* pixels1;
+ GLint do_free;
+
+ {
+#if TGL_FEATURE_ERROR_CHECK == 1
+ if (!(target == GL_TEXTURE_1D && level == 0 && components == 3 && border == 0 && format == GL_RGB && type == GL_UNSIGNED_BYTE))
+#define ERROR_FLAG GL_INVALID_ENUM
+#include "error_check.h"
+
+#else
+ if (!(target == GL_TEXTURE_1D && level == 0 && components == 3 && border == 0 && format == GL_RGB && type == GL_UNSIGNED_BYTE))
+ gl_fatal_error("glTexImage2D: combination of parameters not handled!!");
+#endif
+ }
+ 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 ! */
+ //TODO: Make this more efficient.
+ gl_resizeImageNoInterpolate(pixels1, TGL_FEATURE_TEXTURE_DIM, TGL_FEATURE_TEXTURE_DIM, pixels, width, height);
+ do_free = 1;
+ width = TGL_FEATURE_TEXTURE_DIM;
+ height = TGL_FEATURE_TEXTURE_DIM; //TODO: make this more efficient.
+ } else {
+ pixels1 = pixels;
+ }
+
+
+ im = &c->current_texture->images[level];
+ im->xsize = width;
+ im->ysize = height;
+ if (im->pixmap != NULL) gl_free(im->pixmap);
+#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);
+ }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 == 16
+ im->pixmap = gl_malloc(width * height * 2);
+ if (im->pixmap) {
+ gl_convertRGB_to_5R6G5B(im->pixmap, pixels1, width, height);
+ }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
+ }
+
+#else
+#error TODO
+#endif
+ if (do_free)
+ gl_free(pixels1);
+
+
+
+
+
+}
void glopTexImage2D(GLContext* c, GLParam* p) {
GLint target = p[1].i;
GLint level = p[2].i;
@@ -278,6 +359,7 @@
}
/* TODO: not all tests are done */
+/*
void glopTexEnv(GLContext* c, GLParam* p) {
GLint target = p[1].i;
GLint pname = p[2].i;
@@ -302,16 +384,19 @@
if (param != GL_DECAL)
goto error;
}
-
+*/
/* TODO: not all tests are done */
+/*
void glopTexParameter(GLContext* c, GLParam* p) {
GLint target = p[1].i;
GLint pname = p[2].i;
GLint param = p[3].i;
- if (target != GL_TEXTURE_2D) {
+ if (target != GL_TEXTURE_2D &&
+ target != GL_TEXTURE_1D) {
error:
- gl_fatal_error("glTexParameter: unsupported option");
+ tgl_warning("glTexParameter: unsupported option");
+ return;
}
switch (pname) {
@@ -322,8 +407,9 @@
break;
}
}
-
-//TODO: implement this.
+*/
+//TODO: implement pixel packing?
+/*
void glopPixelStore(GLContext* c, GLParam* p) {
GLint pname = p[1].i;
GLint param = p[2].i;
@@ -332,3 +418,4 @@
gl_fatal_error("glPixelStore: unsupported option");
}
}
+*/