| Mirage Source http://miragesource.net/forums/ |
|
| Load Surfaces To Video/System Memory Based on GFX Card http://miragesource.net/forums/viewtopic.php?f=210&t=4217 |
Page 1 of 1 |
| Author: | JokeofWeek [ Fri Aug 29, 2008 3:25 am ] |
| Post subject: | Load Surfaces To Video/System Memory Based on GFX Card |
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 Public VRAM As Integer 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 Public Const MAX_USAGE As Byte = 64 Public Const MIN_USAGE As Byte = 16 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 Code: ' Set Video Memory Allowed To Be Used VRAM = Val(DD.GetFreeMem(DDSCaps)) / 1024 / 1024 If VRAM < MAX_USAGE And VRAM > MIN_USAGE Then VRAM = MIN_USAGE ' IF IN BETWEEN MAX AND MIN, MID LEVEL GFX CARD, SET TO MIN USAGE If VRAM > MAX_USAGE Then VRAM = MAX_USAGE ' IF HIGH LEVEL GFX CARD, SET TO MAX USAGE If VRAM < MIN_USAGE Then VRAM = 0 ' IF LOW LEVEL GFX CARD, SET TO NO USAGE [/code] 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 SurfDesc.lFlags = DDSD_CAPS SurfDesc.DDSCaps.lCaps = DDSCAPS_OFFSCREENPLAIN Or DDSCAPS_VIDEOMEMORY VRAM = VRAM - FileSize Else SurfDesc.lFlags = DDSD_CAPS SurfDesc.DDSCaps.lCaps = DDSCAPS_OFFSCREENPLAIN Or DDSCAPS_SYSTEMMEMORY End If 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 |
|
| Author: | GIAKEN [ Fri Aug 29, 2008 3:37 am ] |
| Post subject: | Re: Load Surfaces To Video/System Memory Based on GFX Card |
Little typo: Code: FileSize = FileLen(FilePath) / 1024 / 1204
|
|
| Author: | JokeofWeek [ Fri Aug 29, 2008 3:52 am ] |
| Post subject: | Re: Load Surfaces To Video/System Memory Based on GFX Card |
GIAKEN wrote: Little typo: Code: FileSize = FileLen(FilePath) / 1024 / 1204 Ah, thanks for that |
|
| Author: | JokeofWeek [ Sat Sep 06, 2008 5:28 am ] |
| Post subject: | Re: Load Surfaces To Video/System Memory Based on GFX Card |
Edited tutorial on September 6th 2008 : -Modified it to work with MSE 3.50 (current version) -Fixed a typo which would cause a RTE |
|
| Page 1 of 1 | All times are UTC |
| Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |
|