forked from jsgf/pspgl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
glDrawSplineArrays.c
85 lines (65 loc) · 1.79 KB
/
glDrawSplineArrays.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <malloc.h>
#include "pspgl_internal.h"
#include "pspgl_buffers.h"
#include "pspgl_dlist.h"
void glDrawSplineArraysPSP(GLenum mode, GLuint u, GLuint v,
GLenum u_flags, GLenum v_flags,
GLint first)
{
struct pspgl_context *c = pspgl_curctx;
struct vertex_format vfmt, *vfmtp;
struct pspgl_buffer *vbuf;
unsigned vbuf_offset;
const void *buf;
unsigned prim;
unsigned count;
GLenum error;
error = GL_INVALID_ENUM;
if (u_flags < GL_PATCH_INNER_INNER_PSP || u_flags > GL_PATCH_OUTER_OUTER_PSP ||
v_flags < GL_PATCH_INNER_INNER_PSP || v_flags > GL_PATCH_OUTER_OUTER_PSP)
goto out_error;
switch(mode) {
case GL_TRIANGLES: prim = 0; break;
case GL_LINES: prim = 1; break;
case GL_POINTS: prim = 2; break;
default:
goto out_error;
}
sendCommandi(CMD_PATCH_PRIM, prim);
count = u * v;
vbuf = NULL;
vbuf_offset = 0;
vfmtp = &vfmt;
if (__pspgl_cache_arrays()) {
/* FAST: draw from locked array */
struct locked_arrays *l = &c->vertex_array.locked;
vbuf = l->cached_array;
vbuf_offset = l->cached_array_offset;
vfmtp = &l->vfmt;
first -= l->cached_first;
vbuf->refcount++;
}
error = GL_OUT_OF_MEMORY;
if (unlikely(vbuf == NULL)) {
/* SLOW: convert us some arrays */
__pspgl_ge_vertex_fmt(c, &vfmt);
if (vfmt.hwformat == 0)
return;
vbuf = __pspgl_varray_convert(&vfmt, first, count);
if (vbuf == NULL)
goto out_error;
}
buf = vbuf->base + vbuf_offset;
buf += first * vfmtp->vertex_size;
u_flags &= 3;
v_flags &= 3;
__pspgl_context_render_setup(c, vfmtp->hwformat, buf, NULL);
__pspgl_context_writereg_uncached(c, CMD_SPLINE,
(v_flags << 18) | (u_flags << 16) | (v << 8) | u);
__pspgl_context_pin_buffers(c);
__pspgl_dlist_pin_buffer(vbuf, BF_PINNED_RD);
__pspgl_buffer_free(vbuf);
return;
out_error:
GLERROR(error);
}