eglutilsvg.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #ifdef USE_OPENVG
  2. #include <VG/openvg.h>
  3. #endif
  4. #include <QDebug>
  5. #include <QString>
  6. #include <QImage>
  7. #include "eglutilsvg.h"
  8. #include <stdio.h>
  9. EGLUtilsVG::EGLUtilsVG() : EglUtils()
  10. {
  11. }
  12. EGLUtilsVG::~EGLUtilsVG()
  13. {
  14. }
  15. void EGLUtilsVG::clear(float r, float g, float b)
  16. {
  17. VGfloat color[4] = { r, g, b, 1.0f };
  18. vgSetfv(VG_CLEAR_COLOR, 4, color);
  19. vgClear(0, 0, 1024, 1024);
  20. }
  21. int EGLUtilsVG::loadTexture(const char *fn)
  22. {
  23. char testr[256];
  24. sprintf(testr, ":/%s", fn );
  25. QString filename = QString( testr );
  26. QImage image = QImage( filename );
  27. int w=image.width();
  28. int h=image.height();
  29. qDebug() << filename << "w:" << w << "h:" << h;
  30. VGImage texture = vgCreateImage(VG_sARGB_8888, w, h, VG_IMAGE_QUALITY_BETTER);
  31. qDebug("vgCreateImage handle %x", texture);
  32. if(texture==VG_INVALID_HANDLE)
  33. {
  34. VGErrorCode err = vgGetError();
  35. qDebug("loadVGImage '%s' error 0x%x", fn, err);
  36. }
  37. vgImageSubData(texture, (QRgb*)image.bits(), w*4, VG_sARGB_8888, 0, 0, w, h);
  38. return texture;
  39. }
  40. void EGLUtilsVG::releaseTexture(int textureHandle)
  41. {
  42. if(textureHandle) vgDestroyImage(textureHandle);
  43. }