Support for PVRTC?

Monkey Targets Forums/iOS/Support for PVRTC?

anawiki(Posted 2011) [#1]
Hi
Is it possible to use PVRTC textures in Monkey on iOS? I read that they sasve memory and gain performance, and because we're using few fullscreen 1024x768 backgrounds it could be worth to use that format.

Any experience?

cheers
Roman


xzess(Posted 2011) [#2]
very propably this is possible, but i guess this isn't really important for many people as other features are much more needed.

And i guess this isn't just a quick addition

You could try to write it yourself to learn from if you have time.

Here is an example for loading dds (you have to wrap SOIL as your needs)

//Native Code
//http://www.lonesock.net/soil.html

void PlotDDSFile(char* _pcFileName)
{
    int iWidth    = 0;
    int iHeight   = 0;
    int iChannels = 0;    
    int iR = 0;
    int iG = 0;
    int iB = 0;
    unsigned char* pucImage = SOIL_load_image(_pcFileName, &iHeight, &iWidth,
            &iChannels, SOIL_LOAD_AUTO);

    if (pucImage == NULL) { return; }

   
    char acBuffer[200];
    for (int y = 0; y < iHeight; ++y)
    {
        for (int x = 0; x < iWidth; ++x)
        {
             iR = pucImage[(y * iWidth * iChannels) + (x * iChannels)];
             iG = pucImage[(y * iWidth * iChannels) + (x * iChannels) + 1];
             iB = pucImage[(y * iWidth * iChannels) + (x * iChannels) + 2];
             SetColor((float)iR/255, (float)iG/255, (float)iB/255, 1.0f);
             WritePixel(x, y);
        }
    }
    SetColor(1.0f, 1.0f, 1.0f, 1.0f);
}


You have to write a WritePixel/SetPixel Function

Here is a example by a german member of the site monkeycoder.de called Suco-X

Hopefully he don't smash my head to much for spreading his code ^^

Class CPixmap
   Field _canvas:HTMLCanvasElement
   Field _rc:CanvasRenderingContext2D
   Field _pixel:ImageData
   
      
   Method New(canvas:HTMLCanvasElement)
      _canvas = canvas
      _rc = CanvasRenderingContext2D(canvas.getContext("2d"))
   End
   
   
   Method Width:Float()
      If Not _pixel Return
      
      Return _pixel.width
   End 
   
   
   Method Height:Float()
      If Not _pixel Return 
      
      Return _pixel.height
   End 
   
   Method GetPixel:Int[](x:Int, y:Int)
      Local index:Int, color:Int[4]
      
      If Not _pixel Return 
      
      x = Min(x, _pixel.width)
      y = Min(y, _pixel.height)
      
      
      index = (y*4)*Width+(x*4)
      
      color[0] = _pixel.data[index]
      color[1] = _pixel.data[index+1]
      color[2] = _pixel.data[index+2]
      color[3] = _pixel.data[index+3]
      
      Return color
   End 

   
   Method SetPixel(x:Int, y:Int, r:Int, g:Int, b:Int, a:Int)
      Local index:Int 
   
      If Not _pixel Return 
      
      index = (y*4)*Width+(x*4)

      _pixel.data[index]   = r
      _pixel.data[index+1] = g
      _pixel.data[index+2] = b
      _pixel.data[index+3] = a
   End 
   
   Method Create(w:Int, h:Int)
      If Not _rc Return 

      _pixel = _rc.createImageData(w,h)
   End
   
   
   Method Grab(x:Int, y:Int, w:Int, h:Int)
      If Not _rc 
         Print "Rendering Context doesn`s exists"
         Return
      End
       
      _pixel = _rc.getImageData(x,y,w,h)
   End 
   
   
   
   Method Draw(x:Float, y:Float)
      If Not _pixel Return 
      
      _rc.putImageData(_pixel,x,y)
   End
   
   

End