X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=jwxyz%2Fjwzgles.c;h=e0437e06eb530a323adf0e9157fbb5b55c31e32c;hb=c85f503f5793839a6be4c818332aca4a96927bb2;hp=912a4be31c770f237037c07ef6cc85dcfc95f89c;hpb=d6b0217f2417bd19187f0ebc389d6c5c2233b11c;p=xscreensaver diff --git a/jwxyz/jwzgles.c b/jwxyz/jwzgles.c index 912a4be3..e0437e06 100644 --- a/jwxyz/jwzgles.c +++ b/jwxyz/jwzgles.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 2012-2016 Jamie Zawinski +/* xscreensaver, Copyright (c) 2012-2018 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -181,6 +181,8 @@ #include "jwzglesI.h" +#include "pow2.h" + #define STRINGIFY(X) #X #undef countof @@ -324,7 +326,7 @@ typedef struct { } texgen_state; -typedef struct { /* global state */ +struct jwzgles_state { /* global state */ vert_set set; /* set being built */ @@ -342,7 +344,7 @@ typedef struct { /* global state */ /* Implementing glPushClientAttrib? Don't forget about these! */ draw_array varray, narray, carray, tarray; -} jwzgles_state; +}; static jwzgles_state *state = 0; @@ -618,10 +620,13 @@ make_room (const char *name, void **array, int span, int *count, int *size) void -jwzgles_reset (void) +jwzgles_free_state (void) { - if (! state) - state = (jwzgles_state *) calloc (1, sizeof (*state)); + /* Tricky: jwzgles_make_state doesn't require an active GLES context, but + jwzgles_free_state does. + */ + + LOG1("jwzgles_free_state %p", state); if (state->lists.lists) { @@ -636,12 +641,31 @@ jwzgles_reset (void) if (state->set.tex) free (state->set.tex); if (state->set.color) free (state->set.color); - memset (state, 0, sizeof(*state)); + free (state); + state = NULL; +} + + +jwzgles_state * +jwzgles_make_state (void) +{ + jwzgles_state *s = (jwzgles_state *) calloc (1, sizeof (*s)); + + LOG1("jwzgles_make_state %p", s); + + s->s.mode = s->t.mode = s->r.mode = s->q.mode = GL_EYE_LINEAR; + s->s.obj[0] = s->s.eye[0] = 1; /* s = 1 0 0 0 */ + s->t.obj[1] = s->t.eye[1] = 1; /* t = 0 1 0 0 */ - state->s.mode = state->t.mode = state->r.mode = state->q.mode = - GL_EYE_LINEAR; - state->s.obj[0] = state->s.eye[0] = 1; /* s = 1 0 0 0 */ - state->t.obj[1] = state->t.eye[1] = 1; /* t = 0 1 0 0 */ + return s; +} + + +void +jwzgles_make_current (jwzgles_state *s) +{ + LOG1("jwzgles_make_current %p", s); + state = s; } @@ -2952,15 +2976,6 @@ jwzgles_glGenTextures (GLuint n, GLuint *ret) } -/* return the next larger power of 2. */ -static int -to_pow2 (int value) -{ - int i = 1; - while (i < value) i <<= 1; - return i; -} - void jwzgles_glTexImage1D (GLenum target, GLint level, GLint internalFormat, @@ -3069,6 +3084,25 @@ jwzgles_glCopyTexImage2D (GLenum target, GLint level, GLenum internalformat, } +void +jwzgles_glCopyTexSubImage2D (GLenum target, GLint level, + GLint xoff, GLint yoff, + GLint x, GLint y, + GLsizei width, GLsizei height) +{ + Assert (!state->compiling_verts, + "glCopyTexSubImage2D not allowed inside glBegin"); + Assert (!state->compiling_list, /* technically legal, but stupid! */ + "glCopyTexSubImage2D not allowed inside glNewList"); + if (! state->replaying_list) + LOG9 ("direct %-12s %s %d %d %d %d %d %d %d", "glCopyTexSubImage2D", + mode_desc(target), level, xoff, yoff, x, y, width, height); + glCopyTexSubImage2D (target, level, /* the real one */ + xoff, yoff, x, y, width, height); + CHECK("glCopyTexSubImage2D"); +} + + /* OpenGLES doesn't have auto texture-generation at all! "Oh, just rewrite that code to use GPU shaders", they say. How fucking convenient. @@ -3289,8 +3323,8 @@ jwzgles_gluBuild2DMipmaps (GLenum target, Note that this required a corresponding hack in glTexParameterf(). */ - int w2 = to_pow2(width); - int h2 = to_pow2(height); + GLsizei w2 = (GLsizei)to_pow2(width); + GLsizei h2 = (GLsizei)to_pow2(height); void *d2 = (void *) data;