set(MODULE_NAME graphics)

message(STATUS "Checking dependencies for module: " ${MODULE_NAME})

set(platform_LIB_INCLUDES "")
set(platform_INCLUDE_DIRS "")
set(platform_HEADERS "")
set(platform_LIBS "")

list(APPEND graphics_LIB_INCLUDES 
    DrawingContext.cpp
    DrawingSurface.cpp
    RasterPainter.cpp
    PainterFactory.cpp
    ${platform_LIB_INCLUDES}
)
    
list(APPEND graphics_HEADERS 
    ${platform_HEADERS}
    RasterPainter.h
	DrawingContext.h
    PainterFactory.h
	AbstractPainter.h
	DrawingSurface.h
    )
	
if(UNIX)
	set(OpenGL_GL_PREFERENCE "GLVND")
	find_package(OpenGL QUIET)
	if (OpenGL_FOUND)
		list(APPEND platform_LIBS OpenGL::GL OpenGL::GLU)
		list(APPEND graphics_LIB_INCLUDES 
				opengl/OpenGlPainter.cpp
				opengl/OpenGlTextPainter.cpp
				opengl/OpenGlMeshPainter.cpp
				opengl/OpenGlFontTexture.cpp
				opengl/OpenGlShaderProgram.cpp
				)
		list(APPEND ${MODULE_NAME} 
			opengl/OpenGlPainter.h
			opengl/OpenGlTextPainter.h
			opengl/OpenGlMeshPainter.h
			opengl/OpenGlFontTexture.h
			opengl/OpenGlShaderProgram.h)
		list(APPEND DEFINES "HAS_OPENGL") 
	else()
		message(STATUS "OpenGL not found - skipping support")
	endif()
else()
		list(APPEND graphics_LIB_INCLUDES 
				directx/DirectXInterface.cpp
				directx/DirectX2dInterface.cpp
				directx/DirectXMesh.cpp
				directx/DirectXPainter.cpp
				directx/DirectX2dPainter.cpp
				directx/DirectXTextPainter.cpp
				directx/DirectXMeshPainter.cpp
				directx/DirectXShaderProgram.cpp
				)
		list(APPEND graphics_HEADERS
				directx/DirectXInterface.h	
				directx/DirectX2dInterface.h
				directx/DirectXMesh.h
				directx/DirectXPainter.h
				directx/DirectX2dPainter.h
				directx/DirectXTextPainter.h
				directx/DirectXMeshPainter.h
				directx/DirectXShaderProgram.h
		)

		find_package(DirectX-Headers REQUIRED) 
		list(APPEND platform_LIBS D3D12.lib D3DCompiler.lib DXGI.lib Dwrite.lib D2d1.lib D3D11.lib Microsoft::DirectX-Headers) 
endif()

add_library(${MODULE_NAME} SHARED 
    ${graphics_LIB_INCLUDES} 
    ${graphics_HEADERS})
    
target_include_directories(${MODULE_NAME} PUBLIC
                          ${platform_INCLUDE_DIRS}
                          ${CMAKE_CURRENT_SOURCE_DIR}
                          ${CMAKE_CURRENT_SOURCE_DIR}/opengl
						  ${CMAKE_CURRENT_SOURCE_DIR}/directx
                          )
                          
target_compile_definitions(${MODULE_NAME} PRIVATE ${DEFINES})
target_link_libraries(${MODULE_NAME} PUBLIC geometry mesh fonts image visual_elements ${platform_LIBS})

set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER src/rendering)
set_target_properties( ${MODULE_NAME} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON ) 