🔒 Locked
Fullscreen interpolation
Advertisement
Original Post
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
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
It is as I thought, OpenGL does linear with hardware. That''s why software is slow...
-----------------------------
Final Frontier Trader
The code is following
I''m using SDL and CAN use hardware via Open GL but choose not to.
-----------------------------
Final Frontier Trader
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
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
Mark
Cornutopia Games
http://www.cornutopia.net
Bytten Independent Games Magazine
http://www.bytten.com
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)
-----------------------------
Final Frontier Trader
[edited by - biovenger on February 26, 2003 5:27:40 AM]
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]
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.
Also, inlining that inerpolate function could help tremendously...
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.
__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
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.
Advertisement