|
|

楼主 |
发表于 2006-9-28 14:34:00
|
显示全部楼层
Re:哪里可以卖我的文章?
这个是介绍,中文的正在写。
我想还是放在GamaSutra或者GameDev.net吧,能挣稿费的希望比较渺茫。
When developing casual games, a problem we often face is to create a pure 2D render base without 3D acceleration and create the exact same effect. But this is never an easy task if you think it seriously. The culprit this time is combination explosion. Let me explain it to you.
We've been familiar with the concept of bitblt, color-keyed or with alpha blending. But really, they are just two kinds of pixel blending methods. It's easy to enumerate more methods such as additive, subtractive, color fill, color-keyed color fill, alpha blending with color mask, red channel only, bitblt with pixel format conversion. And this isn't over. As for pixel format, we have R5G5B5, R5G6B6, X8R8G8B8 and B8G8R8. Finally, for sampling methods, we have versions with/without stretching and rotating. So if you are going to make a full functional 2D render base compatible with the 3D version, we will have to write a hell of functions:
The number of functions = number of blending methods * number of sampling methods * number of pixel formats
The recipe to this problem is policy based design, as suggested in the book Modern C++ Design: Generic Programming and Design Patterns Applied by Scott Meyers. I'm going to offer a c++ file with the length of only several hundreds of lines. But it's functional complete and its efficiency can compete the handcrafted code without ASM optimization. (Template specialization allows you to add as much optimization as you want at a later stage. I'll show you some examples.) The biggest winning point of this design is that it allows you to extend the code base to support new blending methods or new pixel formats with only several tens of lines of code!
Solving the Hell of Combination
-- A 2D render base using policy based design
Table of Contents
2D? Why bother?
The difficulty of making a 2D render base
Brutal force solution
A suggested solution using policy based design
What’s policy based design?
Pixel Policy
Surface
Raster operation policy
Combine the policies
Optimize with templete specialization
Stretching and rotating
Pixel Format Conversion
More raster operations
Benchmark
After thoughts -- Things to think before slamming it into your engine
Error Checking
Design it fast before coding it fast
Using high level optimization (Dirty region) before using ASM |
|