• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Xeeynamo

[GDI/DDraw7/D3D9] Dynamic palette support?

10 posts in this topic

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.
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
[quote name='Retsu90' timestamp='1328363582' post='4909512']
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
[/quote]

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!
2

Share this post


Link to post
Share on other sites
[quote name='Adam_42' timestamp='1328365074' post='4909519']
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.
[/quote]
Mmh, the shaders are completely news for me, I think that it's time to learn them :P

[quote name='mhagain' timestamp='1328378164' post='4909596']
Look at the "Texture Palettes" entry in your DirectX SDK - I believe this might be what you want.
[/quote]
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.

[quote name='kauna' timestamp='1328382528' post='4909614']
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!
[/quote]
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?
0

Share this post


Link to post
Share on other sites
[quote name='Retsu90' timestamp='1328448339' post='4909808']
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?
[/quote]

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!
0

Share this post


Link to post
Share on other sites
[quote name='Retsu90' timestamp='1328448339' post='4909808']
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.
[/quote]
It's not in the samples, it's in the help file. You also need to look at SetCurrentTexturePalette and SetPaletteEntries.
0

Share this post


Link to post
Share on other sites
[quote name='mhagain' timestamp='1328453351' post='4909822']
[quote name='Retsu90' timestamp='1328448339' post='4909808']
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.
[/quote]
It's not in the samples, it's in the help file. You also need to look at SetCurrentTexturePalette and SetPaletteEntries.
[/quote]That only works if the graphics card supported palletised textures, which no current cards do.
0

Share this post


Link to post
Share on other sites
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 :)
0

Share this post


Link to post
Share on other sites
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)?
0

Share this post


Link to post
Share on other sites
[quote name='Evil Steve' timestamp='1328810961' post='4911389']
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)?
[/quote]
Yes, I'm using D3DXCreateTextureFromFile
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0