-/* xscreensaver, Copyright (c) 2012-2015 Jamie Zawinski <jwz@jwz.org>
+/* xscreensaver, Copyright (c) 2012-2018 Jamie Zawinski <jwz@jwz.org>
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
#include "jwzglesI.h"
+#include "pow2.h"
+
#define STRINGIFY(X) #X
#undef countof
} texgen_state;
-typedef struct { /* global state */
+struct jwzgles_state { /* global state */
vert_set set; /* set being built */
/* Implementing glPushClientAttrib? Don't forget about these! */
draw_array varray, narray, carray, tarray;
-} jwzgles_state;
+};
static jwzgles_state *state = 0;
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)
{
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;
}
}
-/* 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,
}
+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.
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;
*o++ = (istride == 4 ? *i : 0xFF); /* A */
}
}
- // width = w2;
- // height = h2;
+ /* width = w2; */
+ /* height = h2; */
internalFormat = GL_RGBA;
format = GL_RGBA;
}