![]() |
Load Surfaces To Video/System Memory Based on GFX Card - Printable Version +- Mirage Source (https://mirage-engine.uk/forums) +-- Forum: Mirage Source (Nostalgia) (https://mirage-engine.uk/forums/forumdisplay.php?fid=61) +--- Forum: Archive (2006-2011) (https://mirage-engine.uk/forums/forumdisplay.php?fid=18) +---- Forum: Resources (https://mirage-engine.uk/forums/forumdisplay.php?fid=49) +---- Thread: Load Surfaces To Video/System Memory Based on GFX Card (/showthread.php?tid=2040) |
Load Surfaces To Video/System Memory Based on GFX Card - JokeofWeek - 29-08-2008 Alright, so every now and then I'll go through posts and see a post that says something along the lines of : "The best option would be to get the specs of the graphic card, and load surfaces based on that, since video memory is faster." So one day, I finally decided to look into and, and found out that this is actually really easy to accomplish xD. What this does is, depending on a few values, decides on a certain amount of video memory the client can use for surfaces. This won't be full on Copy & Paste, you're going to have to work a little! This is all client side, no worries ![]() Add this variable to modGlobals as a Public Variable. This is the variable that will hold the video memory left for the program to use. Code: ' Video Memory And add these constants. These constants are set by you, and are the constants which will be used as the maximum amount of memory for the program to use and the minimum required for the surfaces to be set for video memory : Code: ' Video Memory Modifier I personally find these good values for the following reason : a ) 64MB is plenty of memory for all your surfaces. b ) If the users card has 64mb or less, it's probably (by today's standards) a low end computer, so only use 16MB of video memory for this program. c ) If the user has a 16mb video card, the program should definitely not be using video memory xD Now in sub InitDirectDraw, add this at the top : Code: Dim DDSCaps As DDSCAPS2 'DirectDraw capabilities structure DDSCAPS2 is a special structure provided with the DX7 .dll which holds the graphic card's capabilities. This is the key to finding the video memory ![]() Now, in between where you Set the Cooperative Level of DD (challenging :wink: ) and where you initialize the DDSD_Primary flags ( hint : With DDSD_Primary), add the following code : Code: ' Set Video Memory Allowed To Be Used Now first, this gets the free video memory and converts it to megabytes, and then based on the value it got, checks with the MAX_USAGE and the MIN_USAGE constants to see how much video memory it should use. Now that the video memory variable is set, we have to use it someplace don't we! This is how we'll load a surface using it. First, in your sub InitDDSurf, add the variable : Code: Dim FileSize As Integer and add the following line after the check to see if the file exists : Code: FileSize = FileLen(tempFileName) / 1024 / 1024 FileLen is a built-in vb6 function which gives the length of a file in bytes. So we convert it to megabytes for simplification ![]() Code: If VRAM >= FileSize Then Now what this does is checks to make sure there is enough video memory left to allocate to the file, and then if there is, sets it to use video memory (DDSCAPS_VIDEOMEMORY) instead of system memory (DDSCAPS_SYSTEMMEMORY) and if so, it takes away the amount of megabytes used by the file from the variable VRAM for the next surface. And there you go ![]() ![]() Re: Load Surfaces To Video/System Memory Based on GFX Card - GIAKEN - 29-08-2008 Little typo: Code: FileSize = FileLen(FilePath) / 1024 / 1204 Re: Load Surfaces To Video/System Memory Based on GFX Card - JokeofWeek - 29-08-2008 GIAKEN Wrote:Little typo: Ah, thanks for that ![]() ![]() Re: Load Surfaces To Video/System Memory Based on GFX Card - JokeofWeek - 06-09-2008 Edited tutorial on September 6th 2008 : -Modified it to work with MSE 3.50 (current version) -Fixed a typo which would cause a RTE |