~compiz-team/compiz/compiz.packaging.gles

« back to all changes in this revision

Viewing changes to plugins/animation/src/grid.cpp

  • Committer: Sam Spilsbury
  • Date: 2012-07-11 01:34:55 UTC
  • mfrom: (3273.1.2 compiz.packaging.gles)
  • Revision ID: sam.spilsbury@canonical.com-20120711013455-489y3e43oldfe395
[ Sam Spilsbury ]
Update patches for GLES2 support

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 * Hexagon tessellator added by : Mike Slegeir
20
20
 * E-mail                       : mikeslegeir@mail.utexas.edu>
21
21
 *
 
22
 * Ported to GLES by : Travis Watkins
 
23
 *                     (C) 2011 Linaro Limited
 
24
 * E-mail            : travis.watkins@linaro.org
 
25
 *
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
36
40
 
37
41
#include "private.h"
38
42
 
 
43
// use the old structure then copy the data we want out of it
 
44
class GridGeometry
 
45
{
 
46
    public:
 
47
 
 
48
        GridGeometry () :
 
49
            vertices (NULL),
 
50
            vertexSize (0),
 
51
            vertexStride (0),
 
52
            vCount (0),
 
53
            texUnits (0),
 
54
            texCoordSize (0)
 
55
        {
 
56
        }
 
57
 
 
58
    public:
 
59
 
 
60
        GLfloat  *vertices;
 
61
        int      vertexSize;
 
62
        int      vertexStride;
 
63
        int      vCount;
 
64
        int      texUnits;
 
65
        int      texCoordSize;
 
66
};
 
67
 
 
68
 
39
69
// =====================  Effect: Dodge  =========================
40
70
 
41
71
GridAnim::GridModel::GridObject::GridObject () :
217
247
                       unsigned int                maxGridWidth,
218
248
                       unsigned int                maxGridHeight)
219
249
{
 
250
    GridGeometry geometry;
220
251
    unsigned int nMatrix = matrix.size ();
221
 
    int nVertices, nIndices;
222
 
    GLushort *i;
 
252
    int nVertices;
223
253
    GLfloat *v;
224
254
    int x1, y1, x2, y2;
225
255
    float winContentsY, winContentsHeight;
234
264
    if (region.isEmpty ()) // nothing to do
235
265
        return;
236
266
 
237
 
    GLWindow::Geometry &geometry = GLWindow::get (mWindow)->geometry ();
238
 
 
239
267
    for (unsigned int it = 0; it < nMatrix; it++)
240
268
    {
241
269
        if (matrix[it].xy != 0.0f || matrix[it].yx != 0.0f)
263
291
    winContentsHeight = oheight - outExtents.top - outExtents.bottom;
264
292
 
265
293
    geometry.texUnits = (int)nMatrix;
266
 
 
267
 
    if (geometry.vCount == 0)
268
 
    {
269
 
        // reset
270
 
        geometry.indexCount = 0;
271
 
        geometry.texCoordSize = 4;
272
 
    }
 
294
    geometry.vertices = NULL;
 
295
    geometry.vCount = 0;
 
296
    geometry.texCoordSize = 4;
273
297
    geometry.vertexStride = 3 + geometry.texUnits * geometry.texCoordSize;
 
298
 
274
299
    vSize = geometry.vertexStride;
275
 
 
276
300
    nVertices = geometry.vCount;
277
 
    nIndices = geometry.indexCount;
278
 
 
279
301
    v = geometry.vertices + (nVertices * vSize);
280
 
    i = geometry.indices + nIndices;
281
302
 
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;
317
338
 
318
 
        // Allocate 4 indices for each quad
319
 
        int newIndexSize = nIndices + ((nVertX - 1) * (nVertY - 1) * 4);
320
 
 
321
 
        if (newIndexSize > geometry.indexSize)
322
 
        {
323
 
            if (!geometry.moreIndices (newIndexSize))
324
 
                return;
325
 
 
326
 
            i = geometry.indices + nIndices;
327
 
        }
328
 
        // Assign quad vertices to indices
329
 
        for (int jy = 0; jy < nVertY - 1; jy++)
330
 
        {
331
 
            for (int jx = 0; jx < nVertX - 1; jx++)
332
 
            {
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;
337
 
 
338
 
                nIndices += 4;
339
 
            }
340
 
        }
341
 
 
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)
346
343
        {
347
 
            if (!geometry.moreVertices (newVertexSize))
 
344
            if (geometry.vertices == NULL)
 
345
                geometry.vertices = (GLfloat *)
 
346
                                      malloc (sizeof (GLfloat) * newVertexSize);
 
347
            else
 
348
                geometry.vertices = (GLfloat *)
 
349
                  realloc (geometry.vertices, sizeof (GLfloat) * newVertexSize);
 
350
 
 
351
            if (!geometry.vertices)
348
352
                return;
349
353
 
 
354
            geometry.vertexSize = newVertexSize;
350
355
            v = geometry.vertices + (nVertices * vSize);
351
356
        }
352
357
 
588
593
            }
589
594
        }
590
595
    }
 
596
 
591
597
    geometry.vCount = nVertices;
592
 
    geometry.indexCount = nIndices;
593
 
}
594
 
 
595
 
void
596
 
GridAnim::drawGeometry ()
597
 
{
598
 
    GLWindow::Geometry &geometry = GLWindow::get (mWindow)->geometry ();
599
 
 
600
 
    int     texUnit = geometry.texUnits;
601
 
    int     currentTexUnit = 0;
602
 
    int     stride = geometry.vertexStride;
603
 
    GLfloat *vertices = geometry.vertices + (stride - 3);
604
 
 
605
 
    stride *= (int) sizeof (GLfloat);
606
 
 
607
 
    glVertexPointer (3, GL_FLOAT, stride, vertices);
608
 
 
609
 
    while (texUnit--)
610
 
    {
611
 
        if (texUnit != currentTexUnit)
612
 
        {
613
 
            (*GL::clientActiveTexture) ((GLenum)(GL_TEXTURE0_ARB + texUnit));
614
 
            glEnableClientState (GL_TEXTURE_COORD_ARRAY);
615
 
            currentTexUnit = texUnit;
616
 
        }
617
 
        vertices -= geometry.texCoordSize;
618
 
        glTexCoordPointer (geometry.texCoordSize,
619
 
                           GL_FLOAT, stride, vertices);
620
 
    }
621
 
 
622
 
    glDrawElements (GL_QUADS, geometry.indexCount,
623
 
                    GL_UNSIGNED_SHORT, geometry.indices);
624
 
 
625
 
    // disable all texture coordinate arrays except 0
626
 
    texUnit = geometry.texUnits;
627
 
    if (texUnit > 1)
628
 
    {
629
 
        while (--texUnit)
630
 
        {
631
 
            (*GL::clientActiveTexture) ((GLenum)(GL_TEXTURE0_ARB + texUnit));
632
 
            glDisableClientState (GL_TEXTURE_COORD_ARRAY);
633
 
        }
634
 
 
635
 
        (*GL::clientActiveTexture) (GL_TEXTURE0_ARB);
636
 
    }
637
598
}
638
599
 
639
600
GridTransformAnim::GridTransformAnim (CompWindow *w,