PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Dynamic texture mapping on E2DSurface

Hi,

I would like to texture map a dynamic texture (which is basically an array of raw pixels that changes every frame like a live video) on to the E2DSurface and draw it on the background, but I don't see a functionality that takes raw pixels (e.g. unsigned char * pixels).

I see PutPixel function, but this function only puts one by one, and it'll be very slow. Is there an easy way in EDGELIB that I can pass raw pixels to a texture (like glTexImage2D) and draw the texture on the background (like glDrawTexOES)?

Thanks
Hi Ohanoda,

A fast way to transfer memory quickly is to lock the surface and access its memory directly. Use the following code:

Code:

E2DSURFACEINFO info;
unsigned char *memptr = surface.Lock(&info);
if (memptr)
{
//copy your data here
surface.Unlock();
}


It's important to check the alignment of the memory through the xpitch/ypitch members of the info structure.

In most cases the memory is aligned from left to right (x-axis) and top to bottom (y-axis). In these cases you can use a memcopy call which is very fast. In some cases the alignment is different (when the device orientation is changed and rare devices with odd memory layouts). Then you need to set each pixel by 'walking through' the memory using 2 for loops.

Here is a sample (it assumes a 32-bit surface):

Code:

long xc, yc;
memptr += info.bufferoffset;
if (info.xpitch == info.bitwidth / 8) //memory is aligned correctly
{
for (yc = 0; yc < info.height; yc++)
ClassEMemory::Copy(&memptr[yc * info.ypitch], &your_source[yc * yourypitch], info.width * info.bitwidth / 8);
}
else //Memory has different alignment
{
unsigned long *memptr32 = (unsigned long *)memptr;
unsigned long *your_source32 = (unsigned long *)your_source;
for (yc = 0; yc < info.height; yc++)
for (xc = 0; xc < info.width; xc++)
memptr32[yc * info.ypitch / 4 + xc * info.xpitch / 4] = your_source32[yc * yourypitch + xc * yourxpitch];
}
Thank you very much!! That works :P