Skip to main content
GameDev.net gamedev.net
🔒 Locked

Pointer to video ram

Started by Foot Soldier Nov 20, 2004 at 2:04 AM 3 replies 1.2k views
Original Post
Foot Soldier
Foot Soldier
Hello, I am making a custom graphic filetype for 2D sprites, and everything is working great, but I think it would be awsome if I could load the image into video ram instead of system ram. I am using standard C way of loading a file, nothing special, so how do you create a pointer to video RAM? P.S. I am using SDL
Sure is a big 'ol world.
Stephen R
Stephen R
You'll need to make the sdl surface with the SDL_HWSURFACE flag in the SDL_CreateRGBSurface function. You can then lock the surface and memcpy your pixel data to the surface. When you unlock it your pixel data will be stored in VRAM.
MaulingMonkey
MaulingMonkey
Quote:
Original post by stro
You'll need to make the sdl surface with the SDL_HWSURFACE flag in the SDL_CreateRGBSurface function. You can then lock the surface and memcpy your pixel data to the surface. When you unlock it your pixel data will be stored in VRAM.


Assuming, of course, that SDL actually gives you a hardware surface (SDL_HWSURFACE is a request, not a mandate).

Also note that on many systems sending to (or worse, reading data from) the video card can be slow. Although you should be able to blit two surfaces together faster using the SDL functions, if you tried to say, create a 3rd surface from the two, made of the two images blended together, using your own for loop - that would be SLOWER than using just plain 'ole software surfaces.


Most likely, you're optimizing prematurely (and premature optimization is the root of all evil). If your program is having framerate issues then it might be worth looking into - but most likely other bits of your code will be to blame.

In fact, you should use a profiler before even touching this area, to double check that in fact improving this area of your code would make the program faster.
Foot Soldier
Foot Soldier
Mauling, you are absolutely right. It is running perfectly fast, but I assumed down the line it might slow things down.

I can see how it would be foolish and dangerous to do this, so i will hold back. Thanks for the help you guys.

P.S. I know I am necroposting, but I have been on vacation.
Sure is a big 'ol world.
MaulingMonkey
MaulingMonkey
Quote:
Original post by Foot Soldier
Mauling, you are absolutely right. It is running perfectly fast, but I assumed down the line it might slow things down.

I can see how it would be foolish and dangerous to do this, so i will hold back. Thanks for the help you guys.


It's a reoccuring belief. I wouldn't call it dangerous, nor even foolish - you simply linked what you know with common sense (otherwise known as using your brain ;) ). It's just that the bandwidth of the graphics pipe isn't something one normally thinks of.

Quote:
P.S. I know I am necroposting, but I have been on vacation.


It happens. :-).

Topic Locked

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

Sign in to reply to this topic.