Jump to content

  • Log In with Google      Sign In   
  • Create Account

[GDI/DDraw7/D3D9] Dynamic palette support?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 Retsu90   Members   -  Reputation: 208

Like
0Likes
Like

Posted 04 February 2012 - 07:53 AM

Hi!
I'm trying to do a porting of a 2D game from SNES/Genesis era on Windows. This game is tile-based in 16x16 images, 8 bit per pixel and a palette large 256 entries with 16 bit of depth. I develop already a level editor using GDI and I'm able to render an entire level with dynamic palette and dynamic tiles in 1680x1050 in 24 frame per second (i think that it's a good result) using various DC in 4bpp and 8bpp. After developed level editor, I started to create the real game, so I started to learn DirectDraw. With it I had a lot of problems like the surfaces in 4bpp that can be created but can't be blitted on backbuffer; after a lot of tries and combinations I was able to create a surface in 8bpp palettized and render the entire level like GDI at 26 fps but with the 90% of use of GPU (!!!) without to be able to flip/mirror the tiles. After this fail I decided to learn Direct3D. With it I'm able to set a good viewport for X0 Y0 at top-left and X640 Y480 at bottom-right and draw squares with textures using integer coordinates like GDI and DirectDraw, but not to create surfaces or textures palettized. I tried CheckDeviceType and I discovered also that my graphic card doesn't support 16bpp surfaces in fullscreen mode and now I don't know how to proceed without to use a lot of memory and without to have bad performances.
The summary of my situation is this:
I can use GDI, it can create any DC in 2bpp, 4bpp, 8bpp all paletized, 16 and 32bpp, stretch support, flip/mirroring but trasparence blit without flipping and all this via software rendering with a good use of CPU.
I can use DirectDraw, it can create surfaces in 8bpp palettized, 16 and 32bpp, stretch support and full transparence support, but no flip/mirroring and with intense use of CPU and GPU using FastBlt
I can use Direct3D, but it cannot create surfaces different from 32bpp and lacks of palette support, stretch and flip/mirroring with projection, no support for transparent textures and with intense use of CPU and a good use of GPU using DrawPrimitives with strip triangles.
Seems that new technologies lacks a lot of features and to reach my intention the easy way is to use GDI. It's possible that if an image uses less than 256 colors I'm forced to convert it in X8R8G8B8 without palette support? I studied also some consoles and also PSP and PS2 uses 8BPP textures with dynamic palettes, so I don't understand these limits from DirectX. Also with Direct3D9 to render 1200 squares (strip triangles with 4 vertices) uses 70% of a single CPU core, so really I don't understand how some games can render a lot of graphics without lags or how some porting or emulators uses dynamic palettes.
Maybe I miss some key information to go to the right way to realize this porting. I'll wait someone that can clear my ideas here.

Sponsor:

#2 Adam_42   Crossbones+   -  Reputation: 2618

Like
0Likes
Like

Posted 04 February 2012 - 08:17 AM

You can emulate palettes in D3D - you just need a 256x1 texture to hold the palette, store the textures using say D3DFMT_A8 and use the pixel shader to combine the two.

#3 mhagain   Crossbones+   -  Reputation: 8278

Like
0Likes
Like

Posted 04 February 2012 - 11:56 AM

Look at the "Texture Palettes" entry in your DirectX SDK - I believe this might be what you want.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#4 kauna   Crossbones+   -  Reputation: 2852

Like
2Likes
Like

Posted 04 February 2012 - 01:08 PM

Also with Direct3D9 to render 1200 squares (strip triangles with 4 vertices) uses 70% of a single CPU core, so really I don't understand how some games can render a lot of graphics without lags


There are lots of different ways of drawing things on the screen. Some are faster and some are slower. Some ways are just horribly slow and use huge amount of CPU usage.

Basically, rendering 1200 squares is a rather trivial task for any GPU. Of course there are factors such as the pixel coverage of each square and blending states (alpha blending for example) and the shader complexity. Those things put stress on the GPU.

To be CPU bound (low FPS and high CPU usage) means that your CPU is working too hard. My guess would be that you are submitting 1200 separate draw calls for your tiles. This is an absolute "no no" if you wish to have better performance.

There are lots of ways to improve your situation. Basically what you need to do is less draw calls. Draw multiple tiles sharing the same texture or material attributes with single draw call. You may use dynamic vertex buffers with all the tile data, or different forms of geometry instancing. Less draw calls is less work for the CPU.

Best regards!

#5 Retsu90   Members   -  Reputation: 208

Like
0Likes
Like

Posted 05 February 2012 - 07:25 AM

You can emulate palettes in D3D - you just need a 256x1 texture to hold the palette, store the textures using say D3DFMT_A8 and use the pixel shader to combine the two.

Mmh, the shaders are completely news for me, I think that it's time to learn them :P

Look at the "Texture Palettes" entry in your DirectX SDK - I believe this might be what you want.

I haven't any sample with that name, I'm using DXSDK7a and DSDK9 June 2010. However I did other tests like create DDS or textures in photoshop with 8bpp palettized, and they won't be loaded on my D3D app, so seems that I have no chance to uses palettes in classic way.

My guess would be that you are submitting 1200 separate draw calls for your tiles. This is an absolute "no no" if you wish to have better performance.

There are lots of ways to improve your situation. Basically what you need to do is less draw calls. Draw multiple tiles sharing the same texture or material attributes with single draw call. You may use dynamic vertex buffers with all the tile data, or different forms of geometry instancing. Less draw calls is less work for the CPU.

Best regards!

Yeah, I call DrawPrimitives for every tile. So you recommend me to use dynamic vertex buffer? I need to study them, I have few days experience of D3D. My main idea was to create a big texture where all the tiles are stored and to have a square that will be rendered with different tu and tv edited in runtime that select the correct tile but I don't know how to do that... Maybe I need to use Vertex shaders?

#6 kauna   Crossbones+   -  Reputation: 2852

Like
0Likes
Like

Posted 05 February 2012 - 07:54 AM

Yeah, I call DrawPrimitives for every tile. So you recommend me to use dynamic vertex buffer? I need to study them, I have few days experience of D3D. My main idea was to create a big texture where all the tiles are stored and to have a square that will be rendered with different tu and tv edited in runtime that select the correct tile but I don't know how to do that... Maybe I need to use Vertex shaders?


Well, if you able to present the data in a static fashion, you don't need dynamic vertex buffers.

Having all textures inside a big texture (ie. having a texture atlas) helps to batch the draw calls, but it may also be a bit more difficult to edit the tile textures. Your choice.

I think that you can draw your tiles without vertex/pixel shader (especially since you have just started). For example, if you used a dynamic vertex buffer, for each tile material, you could fill the buffer with the tile position and texture coordinates of each visible tile and the draw the contents of the buffer. So, you'd have one draw call per material instead of per tile. Of course, if you used a texture atlas, you'd just provide different texture coordinates (based on the tile location in the atlas) and you could draw all tiles with a single draw call.




Best regards!

#7 mhagain   Crossbones+   -  Reputation: 8278

Like
0Likes
Like

Posted 05 February 2012 - 08:49 AM

I haven't any sample with that name, I'm using DXSDK7a and DSDK9 June 2010. However I did other tests like create DDS or textures in photoshop with 8bpp palettized, and they won't be loaded on my D3D app, so seems that I have no chance to uses palettes in classic way.

It's not in the samples, it's in the help file. You also need to look at SetCurrentTexturePalette and SetPaletteEntries.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#8 Evil Steve   Members   -  Reputation: 1987

Like
0Likes
Like

Posted 06 February 2012 - 10:14 AM


I haven't any sample with that name, I'm using DXSDK7a and DSDK9 June 2010. However I did other tests like create DDS or textures in photoshop with 8bpp palettized, and they won't be loaded on my D3D app, so seems that I have no chance to uses palettes in classic way.

It's not in the samples, it's in the help file. You also need to look at SetCurrentTexturePalette and SetPaletteEntries.

That only works if the graphics card supported palletised textures, which no current cards do.

Steve Macpherson
Systems Programmer

Rockstar North


#9 Retsu90   Members   -  Reputation: 208

Like
0Likes
Like

Posted 09 February 2012 - 05:15 AM

Okay, I found a good and easy solution! I'm using TGA palettized textures, I'm able to load them and also change the palette :)

#10 Evil Steve   Members   -  Reputation: 1987

Like
0Likes
Like

Posted 09 February 2012 - 12:09 PM

Out of interest, how are you loading them? D3DXCreateTextureFromFile? Surely D3D will still be trying to create a D3DFMT_P8 format texture or similar behind the scenes (Which is very poorly supported)?

Steve Macpherson
Systems Programmer

Rockstar North


#11 Retsu90   Members   -  Reputation: 208

Like
0Likes
Like

Posted 09 February 2012 - 02:05 PM

Out of interest, how are you loading them? D3DXCreateTextureFromFile? Surely D3D will still be trying to create a D3DFMT_P8 format texture or similar behind the scenes (Which is very poorly supported)?

Yes, I'm using D3DXCreateTextureFromFile




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS