19
19
* Hexagon tessellator added by : Mike Slegeir
20
20
* E-mail : mikeslegeir@mail.utexas.edu>
22
* Ported to GLES by : Travis Watkins
23
* (C) 2011 Linaro Limited
24
* E-mail : travis.watkins@linaro.org
22
26
* This program is free software; you can redistribute it and/or
23
27
* modify it under the terms of the GNU General Public License
24
28
* as published by the Free Software Foundation; either version 2
217
247
unsigned int maxGridWidth,
218
248
unsigned int maxGridHeight)
250
GridGeometry geometry;
220
251
unsigned int nMatrix = matrix.size ();
221
int nVertices, nIndices;
224
254
int x1, y1, x2, y2;
225
255
float winContentsY, winContentsHeight;
234
264
if (region.isEmpty ()) // nothing to do
237
GLWindow::Geometry &geometry = GLWindow::get (mWindow)->geometry ();
239
267
for (unsigned int it = 0; it < nMatrix; it++)
241
269
if (matrix[it].xy != 0.0f || matrix[it].yx != 0.0f)
263
291
winContentsHeight = oheight - outExtents.top - outExtents.bottom;
265
293
geometry.texUnits = (int)nMatrix;
267
if (geometry.vCount == 0)
270
geometry.indexCount = 0;
271
geometry.texCoordSize = 4;
294
geometry.vertices = NULL;
296
geometry.texCoordSize = 4;
273
297
geometry.vertexStride = 3 + geometry.texUnits * geometry.texCoordSize;
274
299
vSize = geometry.vertexStride;
276
300
nVertices = geometry.vCount;
277
nIndices = geometry.indexCount;
279
301
v = geometry.vertices + (nVertices * vSize);
280
i = geometry.indices + nIndices;
282
303
// For each clip passed to this function
283
304
foreach (const CompRect &pClip, region.rects ())
315
336
nVertX = ceil ((x2 - x1) / gridW) + 2;
316
337
nVertY = (gridH ? ceil ((y2 - y1) / gridH) : 0) + 2;
318
// Allocate 4 indices for each quad
319
int newIndexSize = nIndices + ((nVertX - 1) * (nVertY - 1) * 4);
321
if (newIndexSize > geometry.indexSize)
323
if (!geometry.moreIndices (newIndexSize))
326
i = geometry.indices + nIndices;
328
// Assign quad vertices to indices
329
for (int jy = 0; jy < nVertY - 1; jy++)
331
for (int jx = 0; jx < nVertX - 1; jx++)
333
*i++ = nVertices + nVertX * (2 * jy + 1) + jx;
334
*i++ = nVertices + nVertX * (2 * jy + 1) + jx + 1;
335
*i++ = nVertices + nVertX * 2 * jy + jx + 1;
336
*i++ = nVertices + nVertX * 2 * jy + jx;
342
339
// Allocate vertices
343
340
int newVertexSize =
344
341
(nVertices + nVertX * (2 * nVertY - 2)) * vSize;
345
if (newVertexSize > geometry.vertexSize)
342
if (newVertexSize > geometry.vertexSize || geometry.vertices == NULL)
347
if (!geometry.moreVertices (newVertexSize))
344
if (geometry.vertices == NULL)
345
geometry.vertices = (GLfloat *)
346
malloc (sizeof (GLfloat) * newVertexSize);
348
geometry.vertices = (GLfloat *)
349
realloc (geometry.vertices, sizeof (GLfloat) * newVertexSize);
351
if (!geometry.vertices)
354
geometry.vertexSize = newVertexSize;
350
355
v = geometry.vertices + (nVertices * vSize);
591
597
geometry.vCount = nVertices;
592
geometry.indexCount = nIndices;
596
GridAnim::drawGeometry ()
598
GLWindow::Geometry &geometry = GLWindow::get (mWindow)->geometry ();
600
int texUnit = geometry.texUnits;
601
int currentTexUnit = 0;
602
int stride = geometry.vertexStride;
603
GLfloat *vertices = geometry.vertices + (stride - 3);
605
stride *= (int) sizeof (GLfloat);
607
glVertexPointer (3, GL_FLOAT, stride, vertices);
611
if (texUnit != currentTexUnit)
613
(*GL::clientActiveTexture) ((GLenum)(GL_TEXTURE0_ARB + texUnit));
614
glEnableClientState (GL_TEXTURE_COORD_ARRAY);
615
currentTexUnit = texUnit;
617
vertices -= geometry.texCoordSize;
618
glTexCoordPointer (geometry.texCoordSize,
619
GL_FLOAT, stride, vertices);
622
glDrawElements (GL_QUADS, geometry.indexCount,
623
GL_UNSIGNED_SHORT, geometry.indices);
625
// disable all texture coordinate arrays except 0
626
texUnit = geometry.texUnits;
631
(*GL::clientActiveTexture) ((GLenum)(GL_TEXTURE0_ARB + texUnit));
632
glDisableClientState (GL_TEXTURE_COORD_ARRAY);
635
(*GL::clientActiveTexture) (GL_TEXTURE0_ARB);
639
600
GridTransformAnim::GridTransformAnim (CompWindow *w,