[MPlayer-dev-eng] Direct3D OSD discussion

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Wed Nov 26 10:53:30 CET 2008


Hello,
On Wed, Nov 26, 2008 at 12:10:59AM +0000, Jim Hauxwell wrote:
> I was not aware of the reference code to do the osd blending, so I've
> taken a look at this and basically copied what it does.
> 
> I've attached a patch which follows the exact blend rules
> 
> ((dst * srca) >> 8) + src
> 
> it uses a constant color to pass the multiplication for src, so its actually
> 
> (1.0f * src) + (dst * srca) where srca is a float

Well, I have been using tmp[i] = -srca[i] for a very good reason,
because these are not the same, and has the same issue as your previous
approach.
For srca == 1, ((dst * srca) >> 8) will _always_ be 0, because
dst * srca  < 256 becomes 0 after an integer divide by 256.
Also, even mathematically, srca == 1 means a blend factor of 1 / 256,
whereas in OpenGL/Direct3D it is 1 / 255.
This of course means you can't implement _exactly_ the same algortihm
with 3D hardware, but I considered it important to get at least the
corner cases right, i.e.
MPlayer srca == 0 -> osd completely transparent
MPlayer srca == 1 -> osd completely opaque
MPlayer srca == 2 to == 255 -> progressively more transparent, exact
values do not really matter.
Which is why I chose to use -srca for the OpenGL alpha values: it is
fast to calculate and does not need a branch (though in your case the
branch may save some memory bandwidth - if that saves more than the
branch costs probably depends on the hardware).
And yes, I spent probably a few hours of thinking on how to implement
that horrid scheme, the EOSD stuff for ASS subtitles was much simpler in
that respect.
And thanks for the hint on alpha test, now that I have access to a
low-level integrated Intel card it might make sense to test if it helps
here (it made no difference I could measure with my GeForce3 back then,
though vo_gl only draws on the actual OSD areas, not the whole window).

> As a side effect you can change the color of the subtitles by changing
> the DWORD value in this line,
> 
> IDirect3DDevice9_SetRenderState(priv->d3d_device, D3DRS_BLENDFACTOR,
> 0xFFFFFFFF);
> 
> for red choose 0xFFFF0000, for example

Google tells me some Intel cards/drivers do not support
D3DRS_BLENDFACTOR, you could use D3DBLEND_ONE to avoid that.
If you want to be able to change texture colour you can probably do that
in a better supported way by changing the vertex colours (just assuming
that D3D works similarly to OpenGL here).

Greetings,
Reimar Döffinger



More information about the MPlayer-dev-eng mailing list