阅读Vulken源码,学习C++高级用法(对于初学者是高级~)
/**
* 这段代码是 C++ 语言的一个类的构造函数实现。这个类名为VulkanRendererImpl,
* 构造函数接收一个NativeWindow *类型的参数window。在构造函数中,通过初始化列表对成员变量
vulkanContext进行初始化,
* 接着从vulkanContext中获取各种队列家族索引、物理设备、图形设备、队列等信息,并记录窗口帧缓冲区的宽度
和高度。
* 最后调用initialize函数进行初始化操作,并输出日志信息表示VulkanRenderer_Impl已初始化。
* @param window
*/
VulkanRendererImpl::VulkanRendererImpl(NativeWindow *window) : vulkanContext(window)
{
queueFamilyIndices = vulkanContext.getQueueFamilyIndices();
physicalDevice = vulkanContext.getPhysicalDevice();
graphicsDevice = vulkanContext.getDevice();
device = vulkanContext.getDevice();
graphicsQueue = vulkanContext.getGraphicsQueue();
presentQueue = vulkanContext.getPresentQueue();
computeQueue = vulkanContext.getComputeQueue();
graphicsCommandPool = vulkanContext.getGraphicsCommandPool();
computeCommandPool = vulkanContext.getComputeCommandPool();
std::tie(windowFrameBufferWidth, windowFrameBufferHeight) =
vulkanContext.getWindowFrameBufferSize();
// LOGI("Window width %{public}d, height %{public}d.", windowFrameBufferWidth,
windowFrameBufferHeight);
initialize();
// LOGI("VulkanRenderer_Impl initialized.");
}
class VulkanRendererImpl {
public:
explicit VulkanRendererImpl(OHNativeWindow *window);
void resize(int width, int height);
void requestDraw(float deltatime);
void cleanUp();
void setCamera(const glm::mat4 &view, const glm::vec3 campos);
int getDebugViewIndex() const { return debugViewIndex; }
void changeDebugViewIndex(int targetView)
{
debugViewIndex = targetView % 5;
recreateSwapChain();
}
private:
VulkanContext vulkanContext;
/**
* 这行代码可能是在使用一个名为 “VulkanUtil” 的工具类或结构体,并传入一个名为 “vulkanContext” 的
参数进行初始化。其中 “utility” 可能是这个工具类的一个实例。
* 具体的含义取决于代码的上下文环境。但仅从这行代码来看,可以确定是在创建一个与 Vulkan 相关的工具对
象,并将 “vulkanContext” 作为其构造函数的参数。
*/
VulkanUtil utility{vulkanContext};
}
class VulkanContext {
public:
VulkanContext(OHNativeWindow *window);
~VulkanContext();
}