Path: blob/master/servers/rendering/rendering_context_driver.h
10277 views
/**************************************************************************/1/* rendering_context_driver.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "servers/display_server.h"3334class RenderingDeviceDriver;3536class RenderingContextDriver {37public:38typedef uint64_t SurfaceID;3940private:41HashMap<DisplayServer::WindowID, SurfaceID> window_surface_map;4243public:44SurfaceID surface_get_from_window(DisplayServer::WindowID p_window) const;45Error window_create(DisplayServer::WindowID p_window, const void *p_platform_data);46void window_set_size(DisplayServer::WindowID p_window, uint32_t p_width, uint32_t p_height);47void window_set_vsync_mode(DisplayServer::WindowID p_window, DisplayServer::VSyncMode p_vsync_mode);48DisplayServer::VSyncMode window_get_vsync_mode(DisplayServer::WindowID p_window) const;49void window_destroy(DisplayServer::WindowID p_window);5051public:52// Not an enum as these values are matched against values returned by53// the various drivers, which report them in uint32_t. Casting to an54// enum value is dangerous in this case as we don't actually know what55// range the driver is reporting a value in.56struct Vendor {57constexpr static uint32_t VENDOR_UNKNOWN = 0x0;58constexpr static uint32_t VENDOR_AMD = 0x1002;59constexpr static uint32_t VENDOR_IMGTEC = 0x1010;60constexpr static uint32_t VENDOR_APPLE = 0x106B;61constexpr static uint32_t VENDOR_NVIDIA = 0x10DE;62constexpr static uint32_t VENDOR_ARM = 0x13B5;63constexpr static uint32_t VENDOR_MICROSOFT = 0x1414;64constexpr static uint32_t VENDOR_QUALCOMM = 0x5143;65constexpr static uint32_t VENDOR_INTEL = 0x8086;66};6768enum DeviceType {69DEVICE_TYPE_OTHER = 0x0,70DEVICE_TYPE_INTEGRATED_GPU = 0x1,71DEVICE_TYPE_DISCRETE_GPU = 0x2,72DEVICE_TYPE_VIRTUAL_GPU = 0x3,73DEVICE_TYPE_CPU = 0x4,74DEVICE_TYPE_MAX = 0x575};7677struct Workarounds {78bool avoid_compute_after_draw = false;79};8081struct Device {82String name = "Unknown";83uint32_t vendor = Vendor::VENDOR_UNKNOWN;84DeviceType type = DEVICE_TYPE_OTHER;85Workarounds workarounds;86};8788virtual ~RenderingContextDriver();89virtual Error initialize() = 0;90virtual const Device &device_get(uint32_t p_device_index) const = 0;91virtual uint32_t device_get_count() const = 0;92virtual bool device_supports_present(uint32_t p_device_index, SurfaceID p_surface) const = 0;93virtual RenderingDeviceDriver *driver_create() = 0;94virtual void driver_free(RenderingDeviceDriver *p_driver) = 0;95virtual SurfaceID surface_create(const void *p_platform_data) = 0;96virtual void surface_set_size(SurfaceID p_surface, uint32_t p_width, uint32_t p_height) = 0;97virtual void surface_set_vsync_mode(SurfaceID p_surface, DisplayServer::VSyncMode p_vsync_mode) = 0;98virtual DisplayServer::VSyncMode surface_get_vsync_mode(SurfaceID p_surface) const = 0;99virtual uint32_t surface_get_width(SurfaceID p_surface) const = 0;100virtual uint32_t surface_get_height(SurfaceID p_surface) const = 0;101virtual void surface_set_needs_resize(SurfaceID p_surface, bool p_needs_resize) = 0;102virtual bool surface_get_needs_resize(SurfaceID p_surface) const = 0;103virtual void surface_destroy(SurfaceID p_surface) = 0;104virtual bool is_debug_utils_enabled() const = 0;105106String get_driver_and_device_memory_report() const;107108virtual const char *get_tracked_object_name(uint32_t p_type_index) const;109virtual uint64_t get_tracked_object_type_count() const;110111virtual uint64_t get_driver_total_memory() const;112virtual uint64_t get_driver_allocation_count() const;113virtual uint64_t get_driver_memory_by_object_type(uint32_t p_type) const;114virtual uint64_t get_driver_allocs_by_object_type(uint32_t p_type) const;115116virtual uint64_t get_device_total_memory() const;117virtual uint64_t get_device_allocation_count() const;118virtual uint64_t get_device_memory_by_object_type(uint32_t p_type) const;119virtual uint64_t get_device_allocs_by_object_type(uint32_t p_type) const;120};121122123