Skip to main content
gamedev.net
🔒 Locked

Fullscreen interpolation

Started by biovenger Feb 23, 2003 at 5:29 AM 10 replies 550+ views
Original Post
biovenger
biovenger
I have just a small question. The latest addition to the engine I am coding is an ability to use full-screen interpolation. It is the fastest interpolation; Linear. The thing is, it is horridly slow, so my question is how to speed it up. Can it be done through hardware or is there another way to make it smooth? An example of fullscreen interpolation is the SNES emulator ZSNES. Can it be done fullscreen without any noticable loss in speed? ----------------------------- Final Frontier Trader
-----------------------------Final Frontier Trader
sphinx23
sphinx23
use OpenGL and GL_LINEAR for Linear filtering.
(SNES does this)
biovenger
biovenger
My engine uses only SDL and I don''t want to mix in any extra libraries.

It is as I thought, OpenGL does linear with hardware. That''s why software is slow...

-----------------------------
Final Frontier Trader
-----------------------------Final Frontier Trader
biovenger
biovenger
The code is following


  
void Linear_Interpolate(Uint8 a, Uint8 b, float x)
{
return (a + b) * x;
}

void Interpolate()
{
int amount = WIDTH * HEIGHT;

// ...get rgbvalues and interpolate with Linear_Interpolate();


screen->DrawPixel(x, y, color);
}


I''m using SDL and CAN use hardware via Open GL but choose not to.




-----------------------------
Final Frontier Trader
-----------------------------Final Frontier Trader
Cornutopia
Cornutopia
If getting/setting a pixel locks then unlocks the video memory each time it will be slow. For speed alone the best option would be to store the source/dest images in sepearate arrays I think and read/write array slots, only when the whole scene is changed blit the full picture.

Mark
Cornutopia Games
http://www.cornutopia.net
Bytten Independent Games Magazine
http://www.bytten.com
Merle
Merle
MarkSheeky: "If getting/setting a pixel locks then unlocks the video memory each time it will be slow."

Yes -- plus drawing directly to the screen, rather than a second buffer, will result in a less than optimal looking game. Do some searches on "double buffering".
biovenger
biovenger
My display surface is double-buffered. I always draw on a back buffer and my problem isn't hacked animations, but slow movement.

The surface doesn't need to be locked since it isn't a screen surface.

[EDIT]

Here is the exact sourcecode of the interpolation function. (Note that the lock and unlock methods are there for security only, since the surface shouldn't need to be locked)


  
void Interpolation()
{
// calc len

int len = WIDTH * HEIGHT;

// colors

static Uint32 first, last;

static Uint8 r, g, b, r2, g2, b2;

// pixel ptr

Uint32 *ptr = (Uint32 *)screen->surface->pixels;
SDL_PixelFormat *frm = screen->surface->format;

// lock

screen->Lock();

// start the interpolation loop

for(int i = 1; i < len; i++)
{
// get first pixel colors

SDL_GetRGB(ptr[i - 1], frm, &r, &g, &b);

// get second pixel colors

SDL_GetRGB(ptr[i + 1], frm, &r2, &g2, &b2);

// interpolate and draw

ptr[i] = SDL_MapRGB(frm, Uint8(Math_LinearInterpolate(r, r2, 0.5)),
Uint8(Math_LinearInterpolate(g, g2, 0.5)),
Uint8(Math_LinearInterpolate(b, b2, 0.5)));
}

// unlock

screen->Unlock();
}


-----------------------------
Final Frontier Trader

[edited by - biovenger on February 26, 2003 5:27:40 AM]
-----------------------------Final Frontier Trader
EEROOKIE
EEROOKIE
Are you sure that the linear interpolation is taking the time? Replace your LI function with a function that simply returns a floating point value and see if your timing changes. I expect that the timing issues you have are a result of calling to SDL_GetRGB and SDL_MapRGB for each pixel.
Ready4Dis
Ready4Dis
Also, inlining that inerpolate function could help tremendously...


  
__forceinline Uint8 Linear_Interpolate(Uint8 &a, Uint8 &b, float &x)
{
return (a + b) * x;
}


Btw, I changed the return type from void -> Uint8, otherwise you can''t return a value . I also pass by refrence, so no extra memory is being used, and no copying of the variables needs to be done.
biovenger
biovenger
The Math_LinearInterpolate is an inline function. I will check replacing the SDL_GetRGB with direct access to the pixels and checking where the red, green and blue values are.

-----------------------------
Final Frontier Trader
-----------------------------Final Frontier Trader

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.