Skip to content
This repository has been archived by the owner on Nov 5, 2022. It is now read-only.

include: Add support for C compilation #14

Merged
merged 1 commit into from Apr 19, 2022
Merged

include: Add support for C compilation #14

merged 1 commit into from Apr 19, 2022

Conversation

flibitijibibo
Copy link
Contributor

@flibitijibibo flibitijibibo commented Mar 11, 2022

This fixes building FNA3D with dxvk-native.

As a reminder, the FNA3D build:

git clone --recursive https://github.com/FNA-XNA/FNA3D
git clone https://github.com/Joshua-Ashton/dxvk-native
mkdir FNA3D/flibitBuild
cd FNA3D/flibitBuild
cmake .. -DBUILD_DXVK_NATIVE=ON
make

Test program (throw this in flibitBuild):

/* cc clear.c -I../include `sdl2-config --cflags --libs` libFNA3D.so */

#include <SDL.h>
#include <FNA3D.h>

int main(int argc, char **argv)
{
	SDL_Window *window;
	FNA3D_Device *device;
	FNA3D_PresentationParameters params;
	FNA3D_Vec4 color;
	SDL_Event evt;
	SDL_bool run = SDL_TRUE;

	SDL_Init(SDL_INIT_VIDEO);
	window = SDL_CreateWindow(
		"FNA3D dxvk-native Test",
		SDL_WINDOWPOS_CENTERED,
		SDL_WINDOWPOS_CENTERED,
		640,
		480,
		SDL_WINDOW_SHOWN | FNA3D_PrepareWindowAttributes()
	);
	params.backBufferWidth = 640;
	params.backBufferHeight = 480;
	params.backBufferFormat = FNA3D_SURFACEFORMAT_COLOR;
	params.multiSampleCount = 0;
	params.deviceWindowHandle = window;
	params.isFullScreen = 0;
	params.depthStencilFormat = FNA3D_DEPTHFORMAT_NONE;
	params.presentationInterval = FNA3D_PRESENTINTERVAL_DEFAULT;
	params.displayOrientation = FNA3D_DISPLAYORIENTATION_DEFAULT;
	params.renderTargetUsage = FNA3D_RENDERTARGETUSAGE_DISCARDCONTENTS;
	device = FNA3D_CreateDevice(&params, 0);
	color.x = 100 / 255.0f;
	color.y = 149 / 255.0f;
	color.z = 237 / 255.0f;
	color.w = 1.0f;

	while (run)
	{
		while (SDL_PollEvent(&evt) > 0)
		{
			if (evt.type == SDL_QUIT)
			{
				run = SDL_FALSE;
			}
		}

		FNA3D_Clear(
			device,
			FNA3D_CLEAROPTIONS_TARGET,
			&color,
			1.0f,
			0
		);
		FNA3D_SwapBuffers(device, NULL, NULL, window);
	}

	FNA3D_DestroyDevice(device);
	SDL_DestroyWindow(window);
	SDL_Quit();
	return 0;
}

Patch Notes:

  • THE WARNINGS, OH GOD THE WARNINGS oh it's just -Wpedantic
  • A good amount of this can be guarded with __cplusplus, but not quite all... it might be better to replicate exactly how the official headers do things.
  • I mostly improvised some of the interface-y bits from how I remember it working but there's no way it isn't wrong.

Fixes #4

@flibitijibibo
Copy link
Contributor Author

Fixed the dxvk build, this is "ready" to review.

@flibitijibibo flibitijibibo changed the title [WIP] include: Add support for C compilation include: Add support for C compilation Mar 12, 2022
@flibitijibibo
Copy link
Contributor Author

Figured out the last of the Win32 quirks, this is now actually ready for review.

include/native/windows/windows_base.h Outdated Show resolved Hide resolved
include/native/windows/windows_base.h Outdated Show resolved Hide resolved
@flibitijibibo
Copy link
Contributor Author

Pushed with both fixes applied! A notable change is that FAILED/SUCCEEDED needed to wrap (hr) for complete safety.

@Joshua-Ashton Joshua-Ashton merged commit f41a8f5 into Joshua-Ashton:master Apr 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[include] C Compiler Support
2 participants