1076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian/*
2edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project** Copyright 2006, The Android Open Source Project
3edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project**
4076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian** Licensed under the Apache License, Version 2.0 (the "License");
5076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian** you may not use this file except in compliance with the License.
6076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian** You may obtain a copy of the License at
7edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project**
8076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian**     http://www.apache.org/licenses/LICENSE-2.0
9edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project**
10076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian** Unless required by applicable law or agreed to in writing, software
11076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian** distributed under the License is distributed on an "AS IS" BASIS,
12076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian** See the License for the specific language governing permissions and
14edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project** limitations under the License.
15edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project*/
16edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
17edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <stdlib.h>
18edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <stdio.h>
19edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
20edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include "context.h"
21edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include "fp.h"
22edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include "state.h"
23edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include "matrix.h"
24edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include "vertex.h"
25edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include "light.h"
26edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include "primitives.h"
27edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include "texture.h"
28edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include "BufferObjectManager.h"
29edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
30edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ----------------------------------------------------------------------------
31edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
32edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#define VC_CACHE_STATISTICS     0
33edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#define VC_CACHE_TYPE_NONE      0
34edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#define VC_CACHE_TYPE_INDEXED   1
35edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#define VC_CACHE_TYPE_LRU       2
36edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#define VC_CACHE_TYPE           VC_CACHE_TYPE_INDEXED
37edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
38edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#if VC_CACHE_STATISTICS
39edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <utils/Timers.h>
40edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#endif
41edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
42edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ----------------------------------------------------------------------------
43edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
44edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectnamespace android {
45edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
46edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void validate_arrays(ogles_context_t* c, GLenum mode);
47edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
48edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void compileElements__generic(ogles_context_t*,
49edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        vertex_t*, GLint, GLsizei);
50edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void compileElement__generic(ogles_context_t*,
51edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        vertex_t*, GLint);
52edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
53edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void drawPrimitivesPoints(ogles_context_t*, GLint, GLsizei);
54edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void drawPrimitivesLineStrip(ogles_context_t*, GLint, GLsizei);
55edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void drawPrimitivesLineLoop(ogles_context_t*, GLint, GLsizei);
56edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void drawPrimitivesLines(ogles_context_t*, GLint, GLsizei);
57edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void drawPrimitivesTriangleStrip(ogles_context_t*, GLint, GLsizei);
58edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void drawPrimitivesTriangleFan(ogles_context_t*, GLint, GLsizei);
59edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void drawPrimitivesTriangles(ogles_context_t*, GLint, GLsizei);
60edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
61edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void drawIndexedPrimitivesPoints(ogles_context_t*,
62edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        GLsizei, const GLvoid*);
63edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void drawIndexedPrimitivesLineStrip(ogles_context_t*,
64edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        GLsizei, const GLvoid*);
65edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void drawIndexedPrimitivesLineLoop(ogles_context_t*,
66edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        GLsizei, const GLvoid*);
67edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void drawIndexedPrimitivesLines(ogles_context_t*,
68edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        GLsizei, const GLvoid*);
69edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void drawIndexedPrimitivesTriangleStrip(ogles_context_t*,
70edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        GLsizei, const GLvoid*);
71edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void drawIndexedPrimitivesTriangleFan(ogles_context_t*,
72edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        GLsizei, const GLvoid*);
73edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void drawIndexedPrimitivesTriangles(ogles_context_t*,
74edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        GLsizei, const GLvoid*);
75edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
76edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ----------------------------------------------------------------------------
77edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
78edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projecttypedef void (*arrays_prims_fct_t)(ogles_context_t*, GLint, GLsizei);
79edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic const arrays_prims_fct_t drawArraysPrims[] = {
80edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    drawPrimitivesPoints,
81edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    drawPrimitivesLines,
82edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    drawPrimitivesLineLoop,
83edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    drawPrimitivesLineStrip,
84edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    drawPrimitivesTriangles,
85edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    drawPrimitivesTriangleStrip,
86edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    drawPrimitivesTriangleFan
87edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project};
88edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
89edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projecttypedef void (*elements_prims_fct_t)(ogles_context_t*, GLsizei, const GLvoid*);
90edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic const elements_prims_fct_t drawElementsPrims[] = {
91edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    drawIndexedPrimitivesPoints,
92edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    drawIndexedPrimitivesLines,
93edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    drawIndexedPrimitivesLineLoop,
94edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    drawIndexedPrimitivesLineStrip,
95edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    drawIndexedPrimitivesTriangles,
96edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    drawIndexedPrimitivesTriangleStrip,
97edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    drawIndexedPrimitivesTriangleFan
98edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project};
99edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
100edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ----------------------------------------------------------------------------
101edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#if 0
102edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#pragma mark -
103edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#endif
104edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
105edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectvoid ogles_init_array(ogles_context_t* c)
106edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
107edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    c->arrays.vertex.size = 4;
108edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    c->arrays.vertex.type = GL_FLOAT;
109edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    c->arrays.color.size = 4;
110edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    c->arrays.color.type = GL_FLOAT;
111edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    c->arrays.normal.size = 4;
112edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    c->arrays.normal.type = GL_FLOAT;
113edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    for (int i=0 ; i<GGL_TEXTURE_UNIT_COUNT ; i++) {
114edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        c->arrays.texture[i].size = 4;
115edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        c->arrays.texture[i].type = GL_FLOAT;
116edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
117edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    c->vc.init();
118edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
119edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (!c->vc.vBuffer) {
120edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        // this could have failed
121edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        ogles_error(c, GL_OUT_OF_MEMORY);
122edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
123edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
124edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
125edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectvoid ogles_uninit_array(ogles_context_t* c)
126edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
127edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    c->vc.uninit();
128edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
129edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
130edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ----------------------------------------------------------------------------
131edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#if 0
132edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#pragma mark -
133edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#pragma mark Array fetchers
134edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#endif
135edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
136edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void currentColor(ogles_context_t* c, GLfixed* v, const GLvoid*) {
137edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    memcpy(v, c->current.color.v, sizeof(vec4_t));
138edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
139edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void currentColor_clamp(ogles_context_t* c, GLfixed* v, const GLvoid*) {
140edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    memcpy(v, c->currentColorClamped.v, sizeof(vec4_t));
141edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
142edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void currentNormal(ogles_context_t* c, GLfixed* v, const GLvoid*) {
143edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    memcpy(v, c->currentNormal.v, sizeof(vec3_t));
144edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
145edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void currentTexCoord(ogles_context_t* c, GLfixed* v, const GLvoid*) {
146edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    memcpy(v, c->current.texture[c->arrays.tmu].v, sizeof(vec4_t));
147edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
148edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
149edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
150edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void fetchNop(ogles_context_t*, GLfixed*, const GLvoid*) {
151edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
152edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void fetch2b(ogles_context_t*, GLfixed* v, const GLbyte* p) {
153edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[0] = gglIntToFixed(p[0]);
154edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[1] = gglIntToFixed(p[1]);
155edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
156edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void fetch2s(ogles_context_t*, GLfixed* v, const GLshort* p) {
157edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[0] = gglIntToFixed(p[0]);
158edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[1] = gglIntToFixed(p[1]);
159edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
160edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void fetch2x(ogles_context_t*, GLfixed* v, const GLfixed* p) {
161edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    memcpy(v, p, 2*sizeof(GLfixed));
162edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
163edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void fetch2f(ogles_context_t*, GLfixed* v, const GLfloat* p) {
164edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[0] = gglFloatToFixed(p[0]);
165edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[1] = gglFloatToFixed(p[1]);
166edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
167edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void fetch3b(ogles_context_t*, GLfixed* v, const GLbyte* p) {
168edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[0] = gglIntToFixed(p[0]);
169edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[1] = gglIntToFixed(p[1]);
170edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[2] = gglIntToFixed(p[2]);
171edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
172edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void fetch3s(ogles_context_t*, GLfixed* v, const GLshort* p) {
173edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[0] = gglIntToFixed(p[0]);
174edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[1] = gglIntToFixed(p[1]);
175edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[2] = gglIntToFixed(p[2]);
176edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
177edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void fetch3x(ogles_context_t*, GLfixed* v, const GLfixed* p) {
178edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    memcpy(v, p, 3*sizeof(GLfixed));
179edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
180edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void fetch3f(ogles_context_t*, GLfixed* v, const GLfloat* p) {
181edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[0] = gglFloatToFixed(p[0]);
182edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[1] = gglFloatToFixed(p[1]);
183edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[2] = gglFloatToFixed(p[2]);
184edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
185edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void fetch4b(ogles_context_t*, GLfixed* v, const GLbyte* p) {
186edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[0] = gglIntToFixed(p[0]);
187edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[1] = gglIntToFixed(p[1]);
188edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[2] = gglIntToFixed(p[2]);
189edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[3] = gglIntToFixed(p[3]);
190edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
191edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void fetch4s(ogles_context_t*, GLfixed* v, const GLshort* p) {
192edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[0] = gglIntToFixed(p[0]);
193edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[1] = gglIntToFixed(p[1]);
194edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[2] = gglIntToFixed(p[2]);
195edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[3] = gglIntToFixed(p[3]);
196edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
197edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void fetch4x(ogles_context_t*, GLfixed* v, const GLfixed* p) {
198edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    memcpy(v, p, 4*sizeof(GLfixed));
199edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
200edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void fetch4f(ogles_context_t*, GLfixed* v, const GLfloat* p) {
201edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[0] = gglFloatToFixed(p[0]);
202edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[1] = gglFloatToFixed(p[1]);
203edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[2] = gglFloatToFixed(p[2]);
204edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[3] = gglFloatToFixed(p[3]);
205edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
206edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void fetchExpand4ub(ogles_context_t*, GLfixed* v, const GLubyte* p) {
207edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[0] = GGL_UB_TO_X(p[0]);
208edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[1] = GGL_UB_TO_X(p[1]);
209edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[2] = GGL_UB_TO_X(p[2]);
210edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[3] = GGL_UB_TO_X(p[3]);
211edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
212edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void fetchClamp4x(ogles_context_t*, GLfixed* v, const GLfixed* p) {
213edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[0] = gglClampx(p[0]);
214edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[1] = gglClampx(p[1]);
215edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[2] = gglClampx(p[2]);
216edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[3] = gglClampx(p[3]);
217edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
218edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void fetchClamp4f(ogles_context_t*, GLfixed* v, const GLfloat* p) {
219edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[0] = gglClampx(gglFloatToFixed(p[0]));
220edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[1] = gglClampx(gglFloatToFixed(p[1]));
221edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[2] = gglClampx(gglFloatToFixed(p[2]));
222edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[3] = gglClampx(gglFloatToFixed(p[3]));
223edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
224edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void fetchExpand3ub(ogles_context_t*, GLfixed* v, const GLubyte* p) {
225edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[0] = GGL_UB_TO_X(p[0]);
226edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[1] = GGL_UB_TO_X(p[1]);
227edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[2] = GGL_UB_TO_X(p[2]);
228edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[3] = 0x10000;
229edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
230edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void fetchClamp3x(ogles_context_t*, GLfixed* v, const GLfixed* p) {
231edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[0] = gglClampx(p[0]);
232edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[1] = gglClampx(p[1]);
233edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[2] = gglClampx(p[2]);
234edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[3] = 0x10000;
235edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
236edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void fetchClamp3f(ogles_context_t*, GLfixed* v, const GLfloat* p) {
237edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[0] = gglClampx(gglFloatToFixed(p[0]));
238edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[1] = gglClampx(gglFloatToFixed(p[1]));
239edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[2] = gglClampx(gglFloatToFixed(p[2]));
240edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[3] = 0x10000;
241edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
242edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void fetchExpand3b(ogles_context_t*, GLfixed* v, const GLbyte* p) {
243edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[0] = GGL_B_TO_X(p[0]);
244edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[1] = GGL_B_TO_X(p[1]);
245edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[2] = GGL_B_TO_X(p[2]);
246edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
247edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void fetchExpand3s(ogles_context_t*, GLfixed* v, const GLshort* p) {
248edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[0] = GGL_S_TO_X(p[0]);
249edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[1] = GGL_S_TO_X(p[1]);
250edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[2] = GGL_S_TO_X(p[2]);
251edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
252edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
253076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopiantypedef array_t::fetcher_t fn_t;
254edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
255edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic const fn_t color_fct[2][16] = { // size={3,4}, type={ub,f,x}
256edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    { 0, (fn_t)fetchExpand3ub, 0, 0, 0, 0,
257edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project         (fn_t)fetch3f, 0, 0, 0, 0, 0,
258edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project         (fn_t)fetch3x },
259edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    { 0, (fn_t)fetchExpand4ub, 0, 0, 0, 0,
260edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project         (fn_t)fetch4f, 0, 0, 0, 0, 0,
261edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project         (fn_t)fetch4x },
262edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project};
263edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic const fn_t color_clamp_fct[2][16] = { // size={3,4}, type={ub,f,x}
264edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    { 0, (fn_t)fetchExpand3ub, 0, 0, 0, 0,
265edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project         (fn_t)fetchClamp3f, 0, 0, 0, 0, 0,
266edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project         (fn_t)fetchClamp3x },
267edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    { 0, (fn_t)fetchExpand4ub, 0, 0, 0, 0,
268edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project         (fn_t)fetchClamp4f, 0, 0, 0, 0, 0,
269edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project         (fn_t)fetchClamp4x },
270edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project};
271edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic const fn_t normal_fct[1][16] = { // size={3}, type={b,s,f,x}
272edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    { (fn_t)fetchExpand3b, 0,
273edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project      (fn_t)fetchExpand3s, 0, 0, 0,
274edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project      (fn_t)fetch3f, 0, 0, 0, 0, 0,
275edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project      (fn_t)fetch3x },
276edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project};
277edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic const fn_t vertex_fct[3][16] = { // size={2,3,4}, type={b,s,f,x}
278edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    { (fn_t)fetch2b, 0,
279edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project      (fn_t)fetch2s, 0, 0, 0,
280edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project      (fn_t)fetch2f, 0, 0, 0, 0, 0,
281edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project      (fn_t)fetch3x },
282edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    { (fn_t)fetch3b, 0,
283edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project      (fn_t)fetch3s, 0, 0, 0,
284edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project      (fn_t)fetch3f, 0, 0, 0, 0, 0,
285edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project      (fn_t)fetch3x },
286edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    { (fn_t)fetch4b, 0,
287edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project      (fn_t)fetch4s, 0, 0, 0,
288edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project      (fn_t)fetch4f, 0, 0, 0, 0, 0,
289edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project      (fn_t)fetch4x }
290edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project};
291edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic const fn_t texture_fct[3][16] = { // size={2,3,4}, type={b,s,f,x}
292edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    { (fn_t)fetch2b, 0,
293edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project      (fn_t)fetch2s, 0, 0, 0,
294edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project      (fn_t)fetch2f, 0, 0, 0, 0, 0,
295edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project      (fn_t)fetch2x },
296edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    { (fn_t)fetch3b, 0,
297edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project      (fn_t)fetch3s, 0, 0, 0,
298edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project      (fn_t)fetch3f, 0, 0, 0, 0, 0,
299edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project      (fn_t)fetch3x },
300edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    { (fn_t)fetch4b, 0,
301edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project      (fn_t)fetch4s, 0, 0, 0,
302edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project      (fn_t)fetch4f, 0, 0, 0, 0, 0,
303edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project      (fn_t)fetch4x }
304edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project};
305edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
306edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ----------------------------------------------------------------------------
307edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#if 0
308edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#pragma mark -
309edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#pragma mark array_t
310edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#endif
311edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
312edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectvoid array_t::init(
313edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        GLint size, GLenum type, GLsizei stride,
314edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        const GLvoid *pointer, const buffer_t* bo, GLsizei count)
315edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
316edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (!stride) {
317edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        stride = size;
318edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        switch (type) {
319edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        case GL_SHORT:
320edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        case GL_UNSIGNED_SHORT:
321edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            stride *= 2;
322edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            break;
323edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        case GL_FLOAT:
324edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        case GL_FIXED:
325edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            stride *= 4;
326edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            break;
327edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        }
328edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
329edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    this->size = size;
330edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    this->type = type;
331edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    this->stride = stride;
332edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    this->pointer = pointer;
333edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    this->bo = bo;
334edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    this->bounds = count;
335edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
336edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
337076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopianinline void array_t::resolve()
338edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
339edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    physical_pointer = (bo) ? (bo->data + uintptr_t(pointer)) : pointer;
340edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
341edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
342edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ----------------------------------------------------------------------------
343edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#if 0
344edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#pragma mark -
345edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#pragma mark vertex_cache_t
346edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#endif
347edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
348edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectvoid vertex_cache_t::init()
349edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
350edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // make sure the size of vertex_t allows cache-line alignment
351edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    CTA<(sizeof(vertex_t) & 0x1F) == 0> assertAlignedSize;
352edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
353edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    const int align = 32;
354edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    const size_t s = VERTEX_BUFFER_SIZE + VERTEX_CACHE_SIZE;
355edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    const size_t size = s*sizeof(vertex_t) + align;
356edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    base = malloc(size);
357edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (base) {
358edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        memset(base, 0, size);
359edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        vBuffer = (vertex_t*)((size_t(base) + align - 1) & ~(align-1));
360edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        vCache = vBuffer + VERTEX_BUFFER_SIZE;
361edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        sequence = 0;
362edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
363edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
364edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
365edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectvoid vertex_cache_t::uninit()
366edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
367edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    free(base);
368edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    base = vBuffer = vCache = 0;
369edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
370edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
371edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectvoid vertex_cache_t::clear()
372edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
373edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#if VC_CACHE_STATISTICS
374edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    startTime = systemTime(SYSTEM_TIME_THREAD);
375edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    total = 0;
376edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    misses = 0;
377edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#endif
378edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
379edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#if VC_CACHE_TYPE == VC_CACHE_TYPE_LRU
380edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    vertex_t* v = vBuffer;
381edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    size_t count = VERTEX_BUFFER_SIZE + VERTEX_CACHE_SIZE;
382edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    do {
383edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        v->mru = 0;
384edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        v++;
385edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    } while (--count);
386edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#endif
387edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
388edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    sequence += INDEX_SEQ;
389edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (sequence >= 0x80000000LU) {
390edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        sequence = INDEX_SEQ;
391edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        vertex_t* v = vBuffer;
392edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        size_t count = VERTEX_BUFFER_SIZE + VERTEX_CACHE_SIZE;
393edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        do {
394edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            v->index = 0;
395edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            v++;
396edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        } while (--count);
397edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
398edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
399edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
40092dc3fc52cf097bd105460cf377779bdcf146d62Mark Salyzyn#if VC_CACHE_STATISTICS
401edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectvoid vertex_cache_t::dump_stats(GLenum mode)
402edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
403edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    nsecs_t time = systemTime(SYSTEM_TIME_THREAD) - startTime;
404edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    uint32_t hits = total - misses;
405edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    uint32_t prim_count;
406edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    switch (mode) {
407edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    case GL_POINTS:             prim_count = total;         break;
408edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    case GL_LINE_STRIP:         prim_count = total - 1;     break;
409edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    case GL_LINE_LOOP:          prim_count = total - 1;     break;
410edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    case GL_LINES:              prim_count = total / 2;     break;
411edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    case GL_TRIANGLE_STRIP:     prim_count = total - 2;     break;
412edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    case GL_TRIANGLE_FAN:       prim_count = total - 2;     break;
413edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    case GL_TRIANGLES:          prim_count = total / 3;     break;
414edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    default:    return;
415edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
416edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    printf( "total=%5u, hits=%5u, miss=%5u, hitrate=%3u%%,"
417edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            " prims=%5u, time=%6u us, prims/s=%d, v/t=%f\n",
418edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            total, hits, misses, (hits*100)/total,
419edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            prim_count, int(ns2us(time)), int(prim_count*float(seconds(1))/time),
420edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            float(misses) / prim_count);
421edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
42292dc3fc52cf097bd105460cf377779bdcf146d62Mark Salyzyn#else
42392dc3fc52cf097bd105460cf377779bdcf146d62Mark Salyzynvoid vertex_cache_t::dump_stats(GLenum /*mode*/)
42492dc3fc52cf097bd105460cf377779bdcf146d62Mark Salyzyn{
42592dc3fc52cf097bd105460cf377779bdcf146d62Mark Salyzyn}
42692dc3fc52cf097bd105460cf377779bdcf146d62Mark Salyzyn#endif
427edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
428edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ----------------------------------------------------------------------------
429edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#if 0
430edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#pragma mark -
431edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#endif
432edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
433edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic __attribute__((noinline))
434edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectvoid enableDisableClientState(ogles_context_t* c, GLenum array, bool enable)
435edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
436edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    const int tmu = c->arrays.activeTexture;
437edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    array_t* a;
438edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    switch (array) {
439edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    case GL_COLOR_ARRAY:            a = &c->arrays.color;           break;
440edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    case GL_NORMAL_ARRAY:           a = &c->arrays.normal;          break;
441edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    case GL_TEXTURE_COORD_ARRAY:    a = &c->arrays.texture[tmu];    break;
442edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    case GL_VERTEX_ARRAY:           a = &c->arrays.vertex;          break;
443edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    default:
444edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        ogles_error(c, GL_INVALID_ENUM);
445edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        return;
446edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
447edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    a->enable = enable ? GL_TRUE : GL_FALSE;
448edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
449edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
450edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ----------------------------------------------------------------------------
451edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#if 0
452edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#pragma mark -
453edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#pragma mark Vertex Cache
454edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#endif
455edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
456edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic __attribute__((noinline))
457edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectvertex_t* cache_vertex(ogles_context_t* c, vertex_t* v, uint32_t index)
458edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
459edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    #if VC_CACHE_STATISTICS
460edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        c->vc.misses++;
461edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    #endif
462edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (ggl_unlikely(v->locked)) {
463edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        // we're just looking for an entry in the cache that is not locked.
464edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        // and we know that there cannot be more than 2 locked entries
465edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        // because a triangle needs at most 3 vertices.
466edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        // We never use the first and second entries because they might be in
467edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        // use by the striper or faner. Any other entry will do as long as
468edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        // it's not locked.
469edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        // We compute directly the index of a "free" entry from the locked
470edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        // state of v[2] and v[3].
471edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        v = c->vc.vBuffer + 2;
472076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian        v += v[0].locked | (v[1].locked<<1);
473edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
474edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // note: compileElement clears v->flags
475edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    c->arrays.compileElement(c, v, index);
476edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v->locked = 1;
477edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    return v;
478edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
479edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
480edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic __attribute__((noinline))
481edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectvertex_t* fetch_vertex(ogles_context_t* c, size_t index)
482edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
483edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    index |= c->vc.sequence;
484edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
485edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#if VC_CACHE_TYPE == VC_CACHE_TYPE_INDEXED
486edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
487076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    vertex_t* const v = c->vc.vCache +
488edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            (index & (vertex_cache_t::VERTEX_CACHE_SIZE-1));
489edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
490edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (ggl_likely(v->index == index)) {
491edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        v->locked = 1;
492edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        return v;
493edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
494edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    return cache_vertex(c, v, index);
495edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
496edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#elif VC_CACHE_TYPE == VC_CACHE_TYPE_LRU
497edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
498076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    vertex_t* v = c->vc.vCache +
499edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            (index & ((vertex_cache_t::VERTEX_CACHE_SIZE-1)>>1))*2;
500edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
501edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // always record LRU in v[0]
502edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (ggl_likely(v[0].index == index)) {
503edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        v[0].locked = 1;
504edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        v[0].mru = 0;
505edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        return &v[0];
506edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
507edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
508edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (ggl_likely(v[1].index == index)) {
509edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        v[1].locked = 1;
510edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        v[0].mru = 1;
511edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        return &v[1];
512edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
513edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
514edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    const int lru = 1 - v[0].mru;
515edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v[0].mru = lru;
516edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    return cache_vertex(c, &v[lru], index);
517edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
518edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#elif VC_CACHE_TYPE == VC_CACHE_TYPE_NONE
519edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
520edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // just for debugging...
521edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    vertex_t* v = c->vc.vBuffer + 2;
522edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    return cache_vertex(c, v, index);
523edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
524edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#endif
525edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
526edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
527edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ----------------------------------------------------------------------------
528edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#if 0
529edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#pragma mark -
530edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#pragma mark Primitive Assembly
531edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#endif
532edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
533edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectvoid drawPrimitivesPoints(ogles_context_t* c, GLint first, GLsizei count)
534edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
535edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (ggl_unlikely(count < 1))
536edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        return;
537edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
538edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // vertex cache size must be multiple of 1
539076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    const GLsizei vcs =
540edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            (vertex_cache_t::VERTEX_BUFFER_SIZE +
541edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project             vertex_cache_t::VERTEX_CACHE_SIZE);
542edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    do {
543edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        vertex_t* v = c->vc.vBuffer;
544076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian        GLsizei num = count > vcs ? vcs : count;
545edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        c->arrays.cull = vertex_t::CLIP_ALL;
546edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        c->arrays.compileElements(c, v, first, num);
547edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        first += num;
548edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        count -= num;
549edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        if (!c->arrays.cull) {
550edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            // quick/trivial reject of the whole batch
551edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            do {
552edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                const uint32_t cc = v[0].flags;
553edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                if (ggl_likely(!(cc & vertex_t::CLIP_ALL)))
554edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                    c->prims.renderPoint(c, v);
555edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                v++;
556edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                num--;
557edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            } while (num);
558edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        }
559edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    } while (count);
560edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
561edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
562edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ----------------------------------------------------------------------------
563edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
564edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectvoid drawPrimitivesLineStrip(ogles_context_t* c, GLint first, GLsizei count)
565edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
566edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (ggl_unlikely(count < 2))
567edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        return;
568edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
569edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    vertex_t *v, *v0, *v1;
570edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    c->arrays.cull = vertex_t::CLIP_ALL;
571edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    c->arrays.compileElement(c, c->vc.vBuffer, first);
572edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    first += 1;
573edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    count -= 1;
574edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
575edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // vertex cache size must be multiple of 1
576076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    const GLsizei vcs =
577edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        (vertex_cache_t::VERTEX_BUFFER_SIZE +
578edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project         vertex_cache_t::VERTEX_CACHE_SIZE - 1);
579edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    do {
580076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian        v0 = c->vc.vBuffer + 0;
581edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        v  = c->vc.vBuffer + 1;
582076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian        GLsizei num = count > vcs ? vcs : count;
583edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        c->arrays.compileElements(c, v, first, num);
584edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        first += num;
585edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        count -= num;
586edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        if (!c->arrays.cull) {
587edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            // quick/trivial reject of the whole batch
588edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            do {
589edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                v1 = v++;
590edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                const uint32_t cc = v0->flags & v1->flags;
591edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                if (ggl_likely(!(cc & vertex_t::CLIP_ALL)))
592edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                    c->prims.renderLine(c, v0, v1);
593edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                v0 = v1;
594edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                num--;
595edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            } while (num);
596edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        }
597edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        // copy back the last processed vertex
598edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        c->vc.vBuffer[0] = *v0;
599edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        c->arrays.cull = v0->flags & vertex_t::CLIP_ALL;
600edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    } while (count);
601edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
602edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
603edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectvoid drawPrimitivesLineLoop(ogles_context_t* c, GLint first, GLsizei count)
604edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
605edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (ggl_unlikely(count < 2))
606edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        return;
607edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    drawPrimitivesLineStrip(c, first, count);
608edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (ggl_likely(count >= 3)) {
609076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian        vertex_t* v0 = c->vc.vBuffer;
610edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        vertex_t* v1 = c->vc.vBuffer + 1;
611edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        c->arrays.compileElement(c, v1, first);
612edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        const uint32_t cc = v0->flags & v1->flags;
613edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        if (ggl_likely(!(cc & vertex_t::CLIP_ALL)))
614edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            c->prims.renderLine(c, v0, v1);
615edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
616edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
617edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
618edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectvoid drawPrimitivesLines(ogles_context_t* c, GLint first, GLsizei count)
619edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
620edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (ggl_unlikely(count < 2))
621edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        return;
622edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
623edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // vertex cache size must be multiple of 2
624076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    const GLsizei vcs =
625edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        ((vertex_cache_t::VERTEX_BUFFER_SIZE +
626edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        vertex_cache_t::VERTEX_CACHE_SIZE) / 2) * 2;
627edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    do {
628edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        vertex_t* v = c->vc.vBuffer;
629076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian        GLsizei num = count > vcs ? vcs : count;
630edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        c->arrays.cull = vertex_t::CLIP_ALL;
631edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        c->arrays.compileElements(c, v, first, num);
632edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        first += num;
633edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        count -= num;
634edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        if (!c->arrays.cull) {
635edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            // quick/trivial reject of the whole batch
636edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            num -= 2;
637edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            do {
638edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                const uint32_t cc = v[0].flags & v[1].flags;
639edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                if (ggl_likely(!(cc & vertex_t::CLIP_ALL)))
640edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                    c->prims.renderLine(c, v, v+1);
641edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                v += 2;
642edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                num -= 2;
643edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            } while (num >= 0);
644edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        }
645edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    } while (count >= 2);
646edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
647edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
648edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ----------------------------------------------------------------------------
649edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
650edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void drawPrimitivesTriangleFanOrStrip(ogles_context_t* c,
651edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        GLint first, GLsizei count, int winding)
652edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
653edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // winding == 2 : fan
654edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // winding == 1 : strip
655edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
656edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (ggl_unlikely(count < 3))
657edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        return;
658edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
659edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    vertex_t *v, *v0, *v1, *v2;
660edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    c->arrays.cull = vertex_t::CLIP_ALL;
661edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    c->arrays.compileElements(c, c->vc.vBuffer, first, 2);
662edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    first += 2;
663edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    count -= 2;
664edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
665edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // vertex cache size must be multiple of 2. This is extremely important
666edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // because it allows us to preserve the same winding when the whole
667edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // batch is culled. We also need 2 extra vertices in the array, because
668edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // we always keep the two first ones.
669076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    const GLsizei vcs =
670edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        ((vertex_cache_t::VERTEX_BUFFER_SIZE +
671edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project          vertex_cache_t::VERTEX_CACHE_SIZE - 2) / 2) * 2;
672edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    do {
673076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian        v0 = c->vc.vBuffer + 0;
674076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian        v1 = c->vc.vBuffer + 1;
675edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        v  = c->vc.vBuffer + 2;
676076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian        GLsizei num = count > vcs ? vcs : count;
677edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        c->arrays.compileElements(c, v, first, num);
678edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        first += num;
679edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        count -= num;
680edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        if (!c->arrays.cull) {
681edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            // quick/trivial reject of the whole batch
682edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            do {
683edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                v2 = v++;
684edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                const uint32_t cc = v0->flags & v1->flags & v2->flags;
685edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                if (ggl_likely(!(cc & vertex_t::CLIP_ALL)))
686edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                    c->prims.renderTriangle(c, v0, v1, v2);
687edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                swap(((winding^=1) ? v1 : v0), v2);
688edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                num--;
689edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            } while (num);
690edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        }
691edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        if (count) {
692e3586182ec7a5942b758610fe9d084a82486307eMathias Agopian            v0 = c->vc.vBuffer + 2 + vcs - 2;
693e3586182ec7a5942b758610fe9d084a82486307eMathias Agopian            v1 = c->vc.vBuffer + 2 + vcs - 1;
694edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            if ((winding&2) == 0) {
695edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                // for strips copy back the two last compiled vertices
696edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                c->vc.vBuffer[0] = *v0;
697edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            }
698edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            c->vc.vBuffer[1] = *v1;
699edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            c->arrays.cull = v0->flags & v1->flags & vertex_t::CLIP_ALL;
700edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        }
701edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    } while (count > 0);
702edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
703edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
704076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopianvoid drawPrimitivesTriangleStrip(ogles_context_t* c,
705edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        GLint first, GLsizei count) {
706edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    drawPrimitivesTriangleFanOrStrip(c, first, count, 1);
707edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
708edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
709edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectvoid drawPrimitivesTriangleFan(ogles_context_t* c,
710edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        GLint first, GLsizei count) {
711edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    drawPrimitivesTriangleFanOrStrip(c, first, count, 2);
712edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
713edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
714edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectvoid drawPrimitivesTriangles(ogles_context_t* c, GLint first, GLsizei count)
715edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
716edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (ggl_unlikely(count < 3))
717edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        return;
718edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
719edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // vertex cache size must be multiple of 3
720076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    const GLsizei vcs =
721edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        ((vertex_cache_t::VERTEX_BUFFER_SIZE +
722edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        vertex_cache_t::VERTEX_CACHE_SIZE) / 3) * 3;
723edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    do {
724edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        vertex_t* v = c->vc.vBuffer;
725076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian        GLsizei num = count > vcs ? vcs : count;
726edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        c->arrays.cull = vertex_t::CLIP_ALL;
727edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        c->arrays.compileElements(c, v, first, num);
728edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        first += num;
729edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        count -= num;
730edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        if (!c->arrays.cull) {
731edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            // quick/trivial reject of the whole batch
732edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            num -= 3;
733edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            do {
734edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                const uint32_t cc = v[0].flags & v[1].flags & v[2].flags;
735edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                if (ggl_likely(!(cc & vertex_t::CLIP_ALL)))
736edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                    c->prims.renderTriangle(c, v, v+1, v+2);
737edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                v += 3;
738edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                num -= 3;
739edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            } while (num >= 0);
740edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        }
741edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    } while (count >= 3);
742edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
743edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
744edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ----------------------------------------------------------------------------
745edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#if 0
746edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#pragma mark -
747edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#endif
748edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
749edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// this looks goofy, but gcc does a great job with this...
750edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic inline unsigned int read_index(int type, const GLvoid*& p) {
751edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    unsigned int r;
752edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (type) {
753edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        r = *(const GLubyte*)p;
754edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        p = (const GLubyte*)p + 1;
755edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    } else {
756edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        r = *(const GLushort*)p;
757edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        p = (const GLushort*)p + 1;
758edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
759edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    return r;
760edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
761edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
762edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ----------------------------------------------------------------------------
763edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
764edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectvoid drawIndexedPrimitivesPoints(ogles_context_t* c,
765edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        GLsizei count, const GLvoid *indices)
766edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
767edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (ggl_unlikely(count < 1))
768edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        return;
769edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    const int type = (c->arrays.indicesType == GL_UNSIGNED_BYTE);
770edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    do {
771edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        vertex_t * v = fetch_vertex(c, read_index(type, indices));
772edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        if (ggl_likely(!(v->flags & vertex_t::CLIP_ALL)))
773edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            c->prims.renderPoint(c, v);
774edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        v->locked = 0;
775edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        count--;
776edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    } while(count);
777edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
778edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
779edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ----------------------------------------------------------------------------
780edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
781edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectvoid drawIndexedPrimitivesLineStrip(ogles_context_t* c,
782edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        GLsizei count, const GLvoid *indices)
783edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
784edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (ggl_unlikely(count < 2))
785edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        return;
786076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
787edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    vertex_t * const v = c->vc.vBuffer;
788edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    vertex_t* v0 = v;
789edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    vertex_t* v1;
790076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
791edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    const int type = (c->arrays.indicesType == GL_UNSIGNED_BYTE);
792edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    c->arrays.compileElement(c, v0, read_index(type, indices));
793edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    count -= 1;
794edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    do {
795edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        v1 = fetch_vertex(c, read_index(type, indices));
796edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        const uint32_t cc = v0->flags & v1->flags;
797edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        if (ggl_likely(!(cc & vertex_t::CLIP_ALL)))
798edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            c->prims.renderLine(c, v0, v1);
799edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        v0->locked = 0;
800edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        v0 = v1;
801edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        count--;
802edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    } while (count);
803edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v1->locked = 0;
804edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
805edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
806edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectvoid drawIndexedPrimitivesLineLoop(ogles_context_t* c,
807edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        GLsizei count, const GLvoid *indices)
808edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
809edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (ggl_unlikely(count <= 2)) {
810edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        drawIndexedPrimitivesLines(c, count, indices);
811edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        return;
812edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
813076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
814edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    vertex_t * const v = c->vc.vBuffer;
815edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    vertex_t* v0 = v;
816edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    vertex_t* v1;
817076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
818edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    const int type = (c->arrays.indicesType == GL_UNSIGNED_BYTE);
819edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    c->arrays.compileElement(c, v0, read_index(type, indices));
820edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    count -= 1;
821edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    do {
822edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        v1 = fetch_vertex(c, read_index(type, indices));
823edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        const uint32_t cc = v0->flags & v1->flags;
824edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        if (ggl_likely(!(cc & vertex_t::CLIP_ALL)))
825edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            c->prims.renderLine(c, v0, v1);
826edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        v0->locked = 0;
827edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        v0 = v1;
828edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        count--;
829edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    } while (count);
830edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v1->locked = 0;
831edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
832076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    v1 = c->vc.vBuffer;
833edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    const uint32_t cc = v0->flags & v1->flags;
834edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (ggl_likely(!(cc & vertex_t::CLIP_ALL)))
835edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        c->prims.renderLine(c, v0, v1);
836edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
837edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
838edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectvoid drawIndexedPrimitivesLines(ogles_context_t* c,
839edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        GLsizei count, const GLvoid *indices)
840edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
841edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (ggl_unlikely(count < 2))
842edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        return;
843edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
844edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    count -= 2;
845edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    const int type = (c->arrays.indicesType == GL_UNSIGNED_BYTE);
846edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    do {
847edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        vertex_t* const v0 = fetch_vertex(c, read_index(type, indices));
848edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        vertex_t* const v1 = fetch_vertex(c, read_index(type, indices));
849edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        const uint32_t cc = v0->flags & v1->flags;
850edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        if (ggl_likely(!(cc & vertex_t::CLIP_ALL)))
851edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            c->prims.renderLine(c, v0, v1);
852edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        v0->locked = 0;
853edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        v1->locked = 0;
854edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        count -= 2;
855edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    } while (count >= 0);
856edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
857edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
858edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ----------------------------------------------------------------------------
859edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
860edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void drawIndexedPrimitivesTriangleFanOrStrip(ogles_context_t* c,
861edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        GLsizei count, const GLvoid *indices, int winding)
862edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
863edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // winding == 2 : fan
864edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // winding == 1 : strip
865edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
866edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (ggl_unlikely(count < 3))
867edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        return;
868076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
869edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    vertex_t * const v = c->vc.vBuffer;
870edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    vertex_t* v0 = v;
871edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    vertex_t* v1 = v+1;
872edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    vertex_t* v2;
873edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
874edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    const int type = (c->arrays.indicesType == GL_UNSIGNED_BYTE);
875edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    c->arrays.compileElement(c, v0, read_index(type, indices));
876edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    c->arrays.compileElement(c, v1, read_index(type, indices));
877edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    count -= 2;
878edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
879edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // note: GCC 4.1.1 here makes a prety interesting optimization
880edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // where it duplicates the loop below based on c->arrays.indicesType
881edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
882edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    do {
883edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        v2 = fetch_vertex(c, read_index(type, indices));
884edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        const uint32_t cc = v0->flags & v1->flags & v2->flags;
885edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        if (ggl_likely(!(cc & vertex_t::CLIP_ALL)))
886edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            c->prims.renderTriangle(c, v0, v1, v2);
887edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        vertex_t* & consumed = ((winding^=1) ? v1 : v0);
888edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        consumed->locked = 0;
889edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        consumed = v2;
890edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        count--;
891edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    } while (count);
892edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v0->locked = v1->locked = 0;
893edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v2->locked = 0;
894edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
895edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
896edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectvoid drawIndexedPrimitivesTriangleStrip(ogles_context_t* c,
897edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        GLsizei count, const GLvoid *indices) {
898edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    drawIndexedPrimitivesTriangleFanOrStrip(c, count, indices, 1);
899edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
900edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
901edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectvoid drawIndexedPrimitivesTriangleFan(ogles_context_t* c,
902edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        GLsizei count, const GLvoid *indices) {
903edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    drawIndexedPrimitivesTriangleFanOrStrip(c, count, indices, 2);
904edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
905edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
906edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectvoid drawIndexedPrimitivesTriangles(ogles_context_t* c,
907edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        GLsizei count, const GLvoid *indices)
908edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
909edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (ggl_unlikely(count < 3))
910edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        return;
911edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
912edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    count -= 3;
913edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (ggl_likely(c->arrays.indicesType == GL_UNSIGNED_SHORT)) {
914edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        // This case is probably our most common case...
915edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        uint16_t const * p = (uint16_t const *)indices;
916edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        do {
917edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            vertex_t* const v0 = fetch_vertex(c, *p++);
918edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            vertex_t* const v1 = fetch_vertex(c, *p++);
919edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            vertex_t* const v2 = fetch_vertex(c, *p++);
920edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            const uint32_t cc = v0->flags & v1->flags & v2->flags;
921edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            if (ggl_likely(!(cc & vertex_t::CLIP_ALL)))
922edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                c->prims.renderTriangle(c, v0, v1, v2);
923edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            v0->locked = 0;
924edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            v1->locked = 0;
925edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            v2->locked = 0;
926edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            count -= 3;
927edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        } while (count >= 0);
928edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    } else {
929edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        uint8_t const * p = (uint8_t const *)indices;
930edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        do {
931edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            vertex_t* const v0 = fetch_vertex(c, *p++);
932edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            vertex_t* const v1 = fetch_vertex(c, *p++);
933edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            vertex_t* const v2 = fetch_vertex(c, *p++);
934edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            const uint32_t cc = v0->flags & v1->flags & v2->flags;
935edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            if (ggl_likely(!(cc & vertex_t::CLIP_ALL)))
936edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                c->prims.renderTriangle(c, v0, v1, v2);
937edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            v0->locked = 0;
938edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            v1->locked = 0;
939edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            v2->locked = 0;
940edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            count -= 3;
941edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        } while (count >= 0);
942edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
943edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
944edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
945edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ----------------------------------------------------------------------------
946edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#if 0
947edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#pragma mark -
948edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#pragma mark Array compilers
949edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#endif
950edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
951edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectvoid compileElement__generic(ogles_context_t* c,
952edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        vertex_t* v, GLint first)
953edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
954edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v->flags = 0;
955edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    v->index = first;
956edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    first &= vertex_cache_t::INDEX_MASK;
957edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    const GLubyte* vp = c->arrays.vertex.element(first);
95869ca17a12444ef619952b783ddaac121a0d438e5Mathias Agopian    v->obj.z = 0;
95969ca17a12444ef619952b783ddaac121a0d438e5Mathias Agopian    v->obj.w = 0x10000;
960edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    c->arrays.vertex.fetch(c, v->obj.v, vp);
961edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    c->arrays.mvp_transform(&c->transforms.mvp, &v->clip, &v->obj);
962edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    c->arrays.perspective(c, v);
963edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
964edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
965edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectvoid compileElements__generic(ogles_context_t* c,
966edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        vertex_t* v, GLint first, GLsizei count)
967edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
968edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    const GLubyte* vp = c->arrays.vertex.element(
969edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            first & vertex_cache_t::INDEX_MASK);
970edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    const size_t stride = c->arrays.vertex.stride;
971edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    transform_t const* const mvp = &c->transforms.mvp;
972edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    do {
973edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        v->flags = 0;
974edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        v->index = first++;
97569ca17a12444ef619952b783ddaac121a0d438e5Mathias Agopian        v->obj.z = 0;
97669ca17a12444ef619952b783ddaac121a0d438e5Mathias Agopian        v->obj.w = 0x10000;
977edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        c->arrays.vertex.fetch(c, v->obj.v, vp);
978edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        c->arrays.mvp_transform(mvp, &v->clip, &v->obj);
979edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        c->arrays.perspective(c, v);
980edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        vp += stride;
981edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        v++;
982edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    } while (--count);
983edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
984edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
985edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project/*
986edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectvoid compileElements__3x_full(ogles_context_t* c,
987edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        vertex_t* v, GLint first, GLsizei count)
988edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
989edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    const GLfixed* vp = (const GLfixed*)c->arrays.vertex.element(first);
990edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    const size_t stride = c->arrays.vertex.stride / 4;
991edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project//    const GLfixed* const& m = c->transforms.mvp.matrix.m;
992076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
993edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    GLfixed m[16];
994edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    memcpy(&m, c->transforms.mvp.matrix.m, sizeof(m));
995076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
996edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    do {
997edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        const GLfixed rx = vp[0];
998edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        const GLfixed ry = vp[1];
999edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        const GLfixed rz = vp[2];
1000edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        vp += stride;
1001edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        v->index = first++;
1002076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian        v->clip.x = mla3a(rx, m[ 0], ry, m[ 4], rz, m[ 8], m[12]);
1003edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        v->clip.y = mla3a(rx, m[ 1], ry, m[ 5], rz, m[ 9], m[13]);
1004edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        v->clip.z = mla3a(rx, m[ 2], ry, m[ 6], rz, m[10], m[14]);
1005edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        v->clip.w = mla3a(rx, m[ 3], ry, m[ 7], rz, m[11], m[15]);
1006edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
1007edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        const GLfixed w = v->clip.w;
1008edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        uint32_t clip = 0;
1009edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        if (v->clip.x < -w)   clip |= vertex_t::CLIP_L;
1010edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        if (v->clip.x >  w)   clip |= vertex_t::CLIP_R;
1011edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        if (v->clip.y < -w)   clip |= vertex_t::CLIP_B;
1012edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        if (v->clip.y >  w)   clip |= vertex_t::CLIP_T;
1013edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        if (v->clip.z < -w)   clip |= vertex_t::CLIP_N;
1014edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        if (v->clip.z >  w)   clip |= vertex_t::CLIP_F;
1015edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        v->flags = clip;
1016edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        c->arrays.cull &= clip;
1017edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
1018edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        //c->arrays.perspective(c, v);
1019edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        v++;
1020edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    } while (--count);
1021edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
1022edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project*/
1023edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
1024edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ----------------------------------------------------------------------------
1025edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#if 0
1026edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#pragma mark -
1027edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#pragma mark clippers
1028edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#endif
1029edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
1030076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopianstatic void clipVec4(vec4_t& nv,
1031edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        GLfixed t, const vec4_t& s, const vec4_t& p)
1032edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
1033edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    for (int i=0; i<4 ; i++)
1034edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        nv.v[i] = gglMulAddx(t, s.v[i] - p.v[i], p.v[i], 28);
1035edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
1036edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
1037edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void clipVertex(ogles_context_t* c, vertex_t* nv,
1038edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        GLfixed t, const vertex_t* s, const vertex_t* p)
1039edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
1040edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    clipVec4(nv->clip, t, s->clip, p->clip);
1041edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    nv->fog = gglMulAddx(t, s->fog - p->fog, p->fog, 28);
1042edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    ogles_vertex_project(c, nv);
1043edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    nv->flags |=  vertex_t::LIT | vertex_t::EYE | vertex_t::TT;
1044edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    nv->flags &= ~vertex_t::CLIP_ALL;
1045edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
1046edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
1047edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void clipVertexC(ogles_context_t* c, vertex_t* nv,
1048edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        GLfixed t, const vertex_t* s, const vertex_t* p)
1049edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
1050edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    clipVec4(nv->color, t, s->color, p->color);
1051edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    clipVertex(c, nv, t, s, p);
1052edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
1053edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
1054edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void clipVertexT(ogles_context_t* c, vertex_t* nv,
1055edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        GLfixed t, const vertex_t* s, const vertex_t* p)
1056edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
1057edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    for (int i=0 ; i<GGL_TEXTURE_UNIT_COUNT ; i++) {
1058edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        if (c->rasterizer.state.texture[i].enable)
1059edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            clipVec4(nv->texture[i], t, s->texture[i], p->texture[i]);
1060edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
1061edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    clipVertex(c, nv, t, s, p);
1062edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
1063edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
1064edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void clipVertexAll(ogles_context_t* c, vertex_t* nv,
1065edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        GLfixed t, const vertex_t* s, const vertex_t* p)
1066edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
1067edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    clipVec4(nv->color, t, s->color, p->color);
1068edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    clipVertexT(c, nv, t, s, p);
1069edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
1070edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
1071edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectstatic void clipEye(ogles_context_t* c, vertex_t* nv,
1072edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        GLfixed t, const vertex_t* s, const vertex_t* p)
1073edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
1074edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    nv->clear();
1075edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    c->arrays.clipVertex(c, nv, t, p, s);
1076edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    clipVec4(nv->eye, t, s->eye, p->eye);
1077edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
1078edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
1079edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ----------------------------------------------------------------------------
1080edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#if 0
1081edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#pragma mark -
1082edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#endif
1083edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
1084edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectvoid validate_arrays(ogles_context_t* c, GLenum mode)
1085edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
1086edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    uint32_t enables = c->rasterizer.state.enables;
1087edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
1088edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // Perspective correction is not need if Ortho transform, but
1089edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // the user can still provide the w coordinate manually, so we can't
1090edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // automatically turn it off (in fact we could when the 4th coordinate
1091edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // is not spcified in the vertex array).
1092edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // W interpolation is never needed for points.
1093076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    GLboolean perspective =
1094edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        c->perspective && mode!=GL_POINTS && (enables & GGL_ENABLE_TMUS);
1095edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    c->rasterizer.procs.enableDisable(c, GGL_W_LERP, perspective);
1096076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
1097edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // set anti-aliasing
1098edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    GLboolean smooth = GL_FALSE;
1099edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    switch (mode) {
1100edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    case GL_POINTS:
1101edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        smooth = c->point.smooth;
1102edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        break;
1103edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    case GL_LINES:
1104edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    case GL_LINE_LOOP:
1105edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    case GL_LINE_STRIP:
1106edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        smooth = c->line.smooth;
1107edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        break;
1108edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
1109edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (((enables & GGL_ENABLE_AA)?1:0) != smooth)
1110edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        c->rasterizer.procs.enableDisable(c, GGL_AA, smooth);
1111edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
1112edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // set the shade model for this primitive
1113edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    c->rasterizer.procs.shadeModel(c,
1114edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            (mode == GL_POINTS) ? GL_FLAT : c->lighting.shadeModel);
1115edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
1116edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // compute all the matrices we'll need...
1117edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    uint32_t want =
1118edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            transform_state_t::MVP |
1119edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            transform_state_t::VIEWPORT;
1120edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (c->lighting.enable) { // needs normal transforms and eye coords
1121edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        want |= transform_state_t::MVUI;
1122edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        want |= transform_state_t::MODELVIEW;
1123edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
1124edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (enables & GGL_ENABLE_TMUS) { // needs texture transforms
1125edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        want |= transform_state_t::TEXTURE;
1126edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
1127076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian    if (c->clipPlanes.enable || (enables & GGL_ENABLE_FOG)) {
1128edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        want |= transform_state_t::MODELVIEW; // needs eye coords
1129edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
1130edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    ogles_validate_transform(c, want);
1131edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
1132edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // textures...
1133edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (enables & GGL_ENABLE_TMUS)
1134edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        ogles_validate_texture(c);
1135edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
1136edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // vertex compilers
1137edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    c->arrays.compileElement = compileElement__generic;
1138edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    c->arrays.compileElements = compileElements__generic;
1139edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
1140edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // vertex transform
1141edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    c->arrays.mvp_transform =
1142edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        c->transforms.mvp.pointv[c->arrays.vertex.size - 2];
1143edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
1144edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    c->arrays.mv_transform =
1145edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        c->transforms.modelview.transform.pointv[c->arrays.vertex.size - 2];
1146076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
1147edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    /*
1148edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project     * ***********************************************************************
1149edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project     *  pick fetchers
1150edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project     * ***********************************************************************
1151edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project     */
1152076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
1153edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    array_machine_t& am = c->arrays;
1154edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    am.vertex.fetch = fetchNop;
1155edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    am.normal.fetch = currentNormal;
1156edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    am.color.fetch = currentColor;
1157076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian
1158edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (am.vertex.enable) {
1159edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        am.vertex.resolve();
1160edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        if (am.vertex.bo || am.vertex.pointer) {
1161edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            am.vertex.fetch = vertex_fct[am.vertex.size-2][am.vertex.type & 0xF];
1162edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        }
1163edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
1164edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
1165edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (am.normal.enable) {
1166edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        am.normal.resolve();
1167edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        if (am.normal.bo || am.normal.pointer) {
1168edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            am.normal.fetch = normal_fct[am.normal.size-3][am.normal.type & 0xF];
1169edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        }
1170edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
1171edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
1172edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (am.color.enable) {
1173edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        am.color.resolve();
1174edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        if (c->lighting.enable) {
1175edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            if (am.color.bo || am.color.pointer) {
1176edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                am.color.fetch = color_fct[am.color.size-3][am.color.type & 0xF];
1177edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            }
1178edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        } else {
1179edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            if (am.color.bo || am.color.pointer) {
1180edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                am.color.fetch = color_clamp_fct[am.color.size-3][am.color.type & 0xF];
1181edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            }
1182edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        }
1183edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
1184edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
1185edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    int activeTmuCount = 0;
1186edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    for (int i=0 ; i<GGL_TEXTURE_UNIT_COUNT ; i++) {
1187edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        am.texture[i].fetch = currentTexCoord;
1188edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        if (c->rasterizer.state.texture[i].enable) {
1189edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
1190edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            // texture fetchers...
1191edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            if (am.texture[i].enable) {
1192edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                am.texture[i].resolve();
1193edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                if (am.texture[i].bo || am.texture[i].pointer) {
1194edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                    am.texture[i].fetch = texture_fct[am.texture[i].size-2][am.texture[i].type & 0xF];
1195edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                }
1196edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            }
1197edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
1198edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            // texture transform...
1199edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            const int index = c->arrays.texture[i].size - 2;
1200edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            c->arrays.tex_transform[i] =
1201edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                c->transforms.texture[i].transform.pointv[index];
1202edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
1203edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            am.tmu = i;
1204edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project            activeTmuCount++;
1205edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        }
1206edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
1207edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
1208edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // pick the vertex-clipper
1209edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    uint32_t clipper = 0;
1210edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // we must reload 'enables' here
1211edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    enables = c->rasterizer.state.enables;
1212edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (enables & GGL_ENABLE_SMOOTH)
1213edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        clipper |= 1;   // we need to interpolate colors
1214edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (enables & GGL_ENABLE_TMUS)
1215edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        clipper |= 2;   // we need to interpolate textures
1216edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    switch (clipper) {
1217edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    case 0: c->arrays.clipVertex = clipVertex;      break;
1218edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    case 1: c->arrays.clipVertex = clipVertexC;     break;
1219edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    case 2: c->arrays.clipVertex = clipVertexT;     break;
1220edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    case 3: c->arrays.clipVertex = clipVertexAll;   break;
1221edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
1222edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    c->arrays.clipEye = clipEye;
1223edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
1224edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // pick the primitive rasterizer
1225edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    ogles_validate_primitives(c);
1226edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}
1227edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
1228edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ----------------------------------------------------------------------------
1229edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}; // namespace android
1230edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ----------------------------------------------------------------------------
1231edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
1232edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectusing namespace android;
1233edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
1234edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#if 0
1235edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#pragma mark -
1236edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#pragma mark array API
1237edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#endif
1238edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
1239edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectvoid glVertexPointer(
1240edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)
1241edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
1242edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    ogles_context_t* c = ogles_context_t::get();
1243edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    if (size<2 || size>4 || stride<0) {
1244edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        ogles_error(c, GL_INVALID_VALUE);
1245edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        return;
1246edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    }
1247edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    switch (type) {
1248edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    case GL_BYTE:
1249edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    case GL_SHORT:
1250edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    case GL_FIXED:
1251edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    case GL_FLOAT:
1252edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        break;
1253edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    default:
1254edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project        ogles_error(c, GL_INVALID_ENUM);
1255