Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Request] Hook for post frame render #12

Open
WizzardMaker opened this issue Apr 13, 2021 · 5 comments
Open

[Request] Hook for post frame render #12

WizzardMaker opened this issue Apr 13, 2021 · 5 comments

Comments

@WizzardMaker
Copy link
Collaborator

There is already a FrameListener which gets called before a frame gets drawn to the HWND - what would be the best way to get a hook for right after the IDirectDraw7 surface drew its content to the HWND?

@nyfrk
Copy link
Owner

nyfrk commented Apr 14, 2021

What would be the use case for this? Drawing directly onto the hwnd surface would probably result in noticeable flickering. Or do you need something to capture the rendering output?

@WizzardMaker
Copy link
Collaborator Author

I am using Direct2D as a rendering backend for the HD Patch. I am currently drawing everything onto a buffer surface and then transferring that onto the IDirectDraw Surface by locking it and then AlphaBlending my buffer. That operation is very slow due to different pixel formats (the surface given to FrameProc is RGB565) and not using the GPU (because the DD surface is software rendered)

@nyfrk
Copy link
Owner

nyfrk commented Apr 14, 2021

Are you sure that the IDirectDraw Surface obtained through S4FrameProc is a RGB565 surface? IIRC it is already a RGB24 surface and the game renders all its intermediate RGB565 surfaces to the final RGB24 surface. The hook is set where all the intermediate surfaces have been blitted.

AlphaBlending is slow without hardware support and the History Edition does not seem to initialize anything with hardware support. I think Directx7 does not have hardware support for alpha blending anyways - at least it was never implemented by Microsoft (?).

You could also try to use the GDI functions. But I doubt that they will be faster. We could also try the Gdi+ functions. Microsoft has an article for the problem you face and a solution using Gdi+. But I am sure that Gdi+ does not come with hardware support either. GDI may come with hardware support. But I am not sure if it gets real hardware support on modern devices that run Windows 10.

Would it be possible to use color keying instead? That should be faster.

Another trick could be to use Direct3D. The ddraw.dll of the History Edition is just a compatibility wrapper to d3d9.dll. So it may be possible to exploit that. However this will probably make your plugin incompatible with the Gold Edition.

@WizzardMaker
Copy link
Collaborator Author

Are you sure that the IDirectDraw Surface obtained through S4FrameProc is a RGB565 surface? IIRC it is already a RGB24 surface and the game renders all its intermediate RGB565 surfaces to the final RGB24 surface. The hook is set where all the intermediate surfaces have been blitted.

Sadly not
image

The IDirectDrawSurface7 from the FrameProc is only 16bit

Would it be possible to use color keying instead? That should be faster.

Color key is not possible as I'm dependent on 8Bit Alpha for my main surface (shadows, etc.)

@nyfrk
Copy link
Owner

nyfrk commented Apr 27, 2021

We could try to use GetDC or GetWindowDC to get the DC of the window and then draw onto that using BitBlt. If Windows is configured to run in 24 bit color mode then this should be a RGB24 DC.

Other than that I am out of ideas. Maybe we could suppress the rendering entirely and just create a new window with a new Direct3D Render Chain. This way you could draw all your stuff with true hardware support. We would have to forward all Window Messages to the original window procedure. I am not sure how feasible this is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants