~amaranth/compiz-core/gles

« back to all changes in this revision

Viewing changes to plugins/opengl/src/texture.cpp

  • Committer: Travis Watkins
  • Date: 2011-08-10 16:56:45 UTC
  • mfrom: (2778.1.37)
  • Revision ID: travis.watkins@linaro.org-20110810165645-y5tmvfyex36bukbo
merge in gles git branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
#include <privatetexture.h>
39
39
#include "privates.h"
40
40
 
 
41
#ifdef USE_GLES
 
42
std::map<Damage, EglTexture*> boundPixmapTex;
 
43
#else
41
44
std::map<Damage, TfpTexture*> boundPixmapTex;
 
45
#endif
42
46
 
43
47
static GLTexture::Matrix _identity_matrix = {
44
48
    1.0f, 0.0f,
166
170
GLTexture::enable (GLTexture::Filter filter)
167
171
{
168
172
    GLScreen *gs = GLScreen::get (screen);
 
173
#ifndef USE_GLES
169
174
    glEnable (priv->target);
 
175
#endif
170
176
    glBindTexture (priv->target, priv->name);
171
177
 
172
178
    if (filter == Fast)
229
235
    {
230
236
        if (priv->initial)
231
237
        {
232
 
            (*GL::generateMipmap) (priv->target);
 
238
            GL::generateMipmap (priv->target);
233
239
            priv->initial = false;
234
240
        }
235
241
    }
239
245
GLTexture::disable ()
240
246
{
241
247
    glBindTexture (priv->target, 0);
 
248
#ifndef USE_GLES
242
249
    glDisable (priv->target);
 
250
#endif
243
251
}
244
252
 
245
253
void
303
311
    GLenum            target;
304
312
    bool              mipmap;
305
313
 
 
314
    #ifdef USE_GLES
 
315
    target = GL_TEXTURE_2D;
 
316
    matrix.xx = 1.0f / width;
 
317
    matrix.yy = 1.0f / height;
 
318
    matrix.y0 = 0.0f;
 
319
    mipmap = true;
 
320
    #else
306
321
 
307
322
    if (GL::textureNonPowerOfTwo ||
308
323
        (POWER_OF_TWO (width) && POWER_OF_TWO (height)))
321
336
        matrix.y0 = 0.0f;
322
337
        mipmap = false;
323
338
    }
 
339
    #endif
324
340
 
325
341
    t->setData (target, matrix, mipmap);
326
342
    t->setGeometry (0, 0, width, height);
327
343
 
328
344
    glBindTexture (target, t->name ());
329
345
 
 
346
    #ifdef USE_GLES
 
347
//    internalFormat = GL_BGRA;
 
348
    internalFormat = GL_BGRA;
 
349
    #else
 
350
    internalFormat = GL_RGBA;
 
351
    #endif
 
352
 
 
353
    #ifndef USE_GLES
330
354
    opt = GLScreen::get (screen)->getOption ("texture_compression");
331
355
    if (opt->value ().b () && GL::textureCompression)
332
356
        internalFormat = GL_COMPRESSED_RGBA_ARB;
333
 
    else
334
 
        internalFormat =  GL_RGBA;
 
357
    #endif
335
358
 
336
359
    glTexImage2D (target, 0, internalFormat, width, height, 0,
337
360
                  format, type, image);
416
439
    return GLTexture::List ();
417
440
}
418
441
 
 
442
#ifdef USE_GLES
 
443
EglTexture::EglTexture () :
 
444
    damaged (true),
 
445
    damage (None),
 
446
    updateMipMap (true)
 
447
{
 
448
}
 
449
 
 
450
EglTexture::~EglTexture ()
 
451
{
 
452
    GLuint temp = name ();
 
453
    glBindTexture (target (), name ());
 
454
 
 
455
    glDeleteTextures (1, &temp);
 
456
 
 
457
    glBindTexture (target (), 0);
 
458
 
 
459
    boundPixmapTex.erase (damage);
 
460
    XDamageDestroy (screen->dpy (), damage);
 
461
}
 
462
 
 
463
GLTexture::List
 
464
EglTexture::bindPixmapToTexture (Pixmap pixmap,
 
465
                                 int    width,
 
466
                                 int    height,
 
467
                                 int    depth)
 
468
{
 
469
    if ((int) width > GL::maxTextureSize || (int) height > GL::maxTextureSize ||
 
470
        !GL::textureFromPixmap)
 
471
        return GLTexture::List ();
 
472
 
 
473
    GLTexture::List   rv (1);
 
474
    EglTexture        *tex = NULL;
 
475
    EGLImageKHR       eglImage = NULL;
 
476
    GLTexture::Matrix matrix = _identity_matrix;
 
477
 
 
478
    const EGLint img_attribs[] = {
 
479
        EGL_IMAGE_PRESERVED_KHR, EGL_TRUE,
 
480
        EGL_NONE
 
481
    };
 
482
 
 
483
    eglImage = GL::createImage (eglGetDisplay (screen->dpy ()),
 
484
                                EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR,
 
485
                                (EGLClientBuffer)pixmap, img_attribs);
 
486
 
 
487
    if (eglImage == EGL_NO_IMAGE_KHR)
 
488
    {
 
489
        compLogMessage ("core", CompLogLevelWarn,
 
490
                        "eglCreateImageKHR failed");
 
491
 
 
492
        return GLTexture::List ();
 
493
    }
 
494
 
 
495
    matrix.xx = 1.0f / width;
 
496
    matrix.yy = 1.0f / height;
 
497
    matrix.y0 = 0.0f;
 
498
 
 
499
    tex = new EglTexture ();
 
500
    tex->setData (GL_TEXTURE_2D, matrix, true);
 
501
    tex->setGeometry (0, 0, width, height);
 
502
 
 
503
    rv[0] = tex;
 
504
 
 
505
    glBindTexture (GL_TEXTURE_2D, tex->name ());
 
506
 
 
507
    GL::eglImageTargetTexture (GL_TEXTURE_2D, (GLeglImageOES)eglImage);
 
508
    GL::destroyImage (eglGetDisplay (screen->dpy ()), eglImage);
 
509
 
 
510
    tex->setFilter (GL_NEAREST);
 
511
    tex->setWrap (GL_CLAMP_TO_EDGE);
 
512
 
 
513
    glBindTexture (GL_TEXTURE_2D, 0);
 
514
 
 
515
    tex->damage = XDamageCreate (screen->dpy (), pixmap,
 
516
                                 XDamageReportRawRectangles);
 
517
    boundPixmapTex[tex->damage] = tex;
 
518
 
 
519
    return rv;
 
520
}
 
521
 
 
522
void
 
523
EglTexture::enable (GLTexture::Filter filter)
 
524
{
 
525
    glBindTexture (target (), name ());
 
526
    GLTexture::enable (filter);
 
527
    
 
528
    if (damaged)
 
529
        updateMipMap = true;
 
530
 
 
531
    if (this->filter () == GL_LINEAR_MIPMAP_LINEAR && updateMipMap)
 
532
    {
 
533
        GL::generateMipmap (target ());
 
534
        updateMipMap = false;
 
535
    }
 
536
    damaged = false;
 
537
}
 
538
#else
 
539
 
419
540
TfpTexture::TfpTexture () :
420
541
    pixmap (0),
421
542
    damaged (true),
614
735
    }
615
736
    damaged = false;
616
737
}
 
738
#endif
 
739