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

Windows header compatibility problem (LogLevel ERROR) #98

Open
Katharsas opened this issue Oct 9, 2024 · 6 comments
Open

Windows header compatibility problem (LogLevel ERROR) #98

Katharsas opened this issue Oct 9, 2024 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@Katharsas
Copy link

Hi,

i am currently trying to migrate from ZenLib to ZenKit, but i have some problems with the headers. My renderer is DirectX only. It is also a bit chaotic with header includes (m basically including d3d headers everywhere so i can quickly implement things), like this:

#include <dxgi1_4.h>
#include <dxgi1_2.h>

#include <d3d11_1.h>
#include <d3d11.h>
#include <d3dx11.h>

#include <d3dx10.h>

(Yes im using both modern DX as well as old DX SDK, but problem is the same when only using modern DX.)

However, d3d headers include some windows headers like wingdi.h. This cannot be changed without fully removing d3d headers. They depend on constants/macros in wingdi.h so i cannot use NOGDI preprocessor flag.

wingdi.h has the following line:
#define ERROR 0

This conflicts with ZenKit's logging in Logger.h:

namespace zenkit {
	enum class LogLevel : std::uint8_t {
		ERROR = 0,

So basically this is my fault for not having very clean separation between asset loading and direct3d code. However maybe you would be willing to change the ERROR value (g3log for example uses FATAL) so ZenKit can be used easily with windows-heavy code?

If not i can understand that.

@lmichaelis
Copy link
Member

Hej there, and thanks for reporting this! I'd be happy to accommodate your needs, however I can't simply change the enum member name without breaking existing code.

I'd propose the following alternative: I can add a special CMake option or preprocessor directive to enable a new Windows compatibility mode (e.g. ZK_ENABLE_WINCOMPAT) that you can activate whenever you need it. When it's enabled, it would change all conflicting code to an alternative version which works fine.

Are there any other incompatibilities you have noticed?

Lmk if this works for you :)

@lmichaelis lmichaelis self-assigned this Oct 9, 2024
@lmichaelis lmichaelis added the bug Something isn't working label Oct 9, 2024
@Katharsas
Copy link
Author

That would probably work. But i did just manage to remove my d3d header files from loader code, so maybe this is not necessary after all.

My code now runs successfully with ZenKit header file included but i have yet to actually write some ZenKit code. Ill get back to you if i find anything else.

@Katharsas
Copy link
Author

Katharsas commented Oct 9, 2024

Btw. i had a little bit of trouble with setting up CMake:

A)
I had trouble due to having both ZenLib and ZenKit in my project at the same time, which resulted in libsquash population conflicting somehow, which i fixed by adding ZenKit CMakefile before ZenLib and removing libsquish section from ZenLib CMake.

B)
ZenKit threw compilation error for me:

Error	C1083	Cannot open include file: 'glm/mat3x3.hpp': No such file or directory
C:\Users\Jan\Repositories\Renderer\ZenRen2\out\build\Ninja-x86-Debug\ZenRen2
C:\Users\Jan\Repositories\Renderer\ZenRen2\lib\ZenKit\include\phoenix\buffer.hh	7		

I fixed this by just adding this to my own CMake:
target_include_directories(${PROJECT_NAME} PUBLIC "lib/ZenKit/vendor/glm")

@lmichaelis
Copy link
Member

lmichaelis commented Oct 12, 2024

Hm as for A), that's a side product of the way libsquish is bundled with ZenKit and ZenLib. Ideally, I'd use find_package for it, but that's a lot of work, so I haven't figured that one out yet.

To solve B) I'd need the CMake configure output (i.e. the output produced by CMake before building) from a fresh cache (i.e. clear the CMake cache, then reconfigure). Generally it should work just find with both git clone --recursive and non-recursive clones (e.g. git submodule add). If you're using submodules you could try to get ZenKit's submodules but going in its directory and running git submodule init.

@Katharsas
Copy link
Author

B) I already cloned all submodules for ZenKit but that did not help fix the error.

@Katharsas
Copy link
Author

Regarding windows.h, it did not manage to separate my code strictly into d3d and loader, and doing so is not possible with my current architecture i think. However, for now this workaround seems to do the trick:

#undef ERROR
#include <zenkit/...>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants