- Create unified RHIResourceView base interface with type-specific Initialize methods - Implement D3D12ResourceView with RTV/DSV/SRV/UAV/CBV support - Implement OpenGL ResourceView simulation layer using FBO, texture units, and UBO - Add OpenGLTextureUnitAllocator for managing texture unit bindings - Add OpenGLUniformBufferManager for UBO binding points - Add OpenGLFramebuffer for FBO management - Remove deprecated D3D12 view classes (RenderTargetView, DepthStencilView, etc.) - Fix ExecuteCommandLists type confusion bug by adding GetNativeHandle to RHICommandList - Fix test bug where Close() was called before ExecuteCommandLists - Update all integration tests to use new D3D12ResourceView class - All tests pass: 144 unit tests + 8 integration tests
89 lines
2.3 KiB
C++
89 lines
2.3 KiB
C++
#include "XCEngine/RHI/OpenGL/OpenGLTextureUnitAllocator.h"
|
|
#include "XCEngine/RHI/OpenGL/OpenGLTexture.h"
|
|
|
|
#include <glad/glad.h>
|
|
|
|
namespace XCEngine {
|
|
namespace RHI {
|
|
|
|
OpenGLTextureUnitAllocator::OpenGLTextureUnitAllocator()
|
|
: m_maxUnits(0) {
|
|
}
|
|
|
|
OpenGLTextureUnitAllocator::~OpenGLTextureUnitAllocator() {
|
|
Shutdown();
|
|
}
|
|
|
|
void OpenGLTextureUnitAllocator::Initialize(uint32_t maxUnits) {
|
|
m_maxUnits = maxUnits;
|
|
m_allocated.resize(maxUnits, false);
|
|
m_boundTextures.resize(maxUnits, nullptr);
|
|
}
|
|
|
|
void OpenGLTextureUnitAllocator::Shutdown() {
|
|
for (uint32_t i = 0; i < m_maxUnits; ++i) {
|
|
if (m_allocated[i]) {
|
|
Free(static_cast<int32_t>(i));
|
|
}
|
|
}
|
|
m_allocated.clear();
|
|
m_boundTextures.clear();
|
|
m_maxUnits = 0;
|
|
}
|
|
|
|
int32_t OpenGLTextureUnitAllocator::Allocate() {
|
|
for (uint32_t i = 0; i < m_maxUnits; ++i) {
|
|
if (!m_allocated[i]) {
|
|
m_allocated[i] = true;
|
|
return static_cast<int32_t>(i);
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
void OpenGLTextureUnitAllocator::Free(int32_t unit) {
|
|
if (unit < 0 || unit >= static_cast<int32_t>(m_maxUnits)) {
|
|
return;
|
|
}
|
|
UnbindTexture(unit);
|
|
m_allocated[unit] = false;
|
|
}
|
|
|
|
void OpenGLTextureUnitAllocator::BindTexture(int32_t unit, OpenGLTexture* texture) {
|
|
if (unit < 0 || unit >= static_cast<int32_t>(m_maxUnits)) {
|
|
return;
|
|
}
|
|
glActiveTexture(GL_TEXTURE0 + unit);
|
|
if (texture) {
|
|
glBindTexture(static_cast<GLenum>(texture->GetOpenGLType()), texture->GetID());
|
|
} else {
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
}
|
|
m_boundTextures[unit] = texture;
|
|
}
|
|
|
|
void OpenGLTextureUnitAllocator::UnbindTexture(int32_t unit) {
|
|
if (unit < 0 || unit >= static_cast<int32_t>(m_maxUnits)) {
|
|
return;
|
|
}
|
|
glActiveTexture(GL_TEXTURE0 + unit);
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
m_boundTextures[unit] = nullptr;
|
|
}
|
|
|
|
OpenGLTexture* OpenGLTextureUnitAllocator::GetBoundTexture(int32_t unit) const {
|
|
if (unit < 0 || unit >= static_cast<int32_t>(m_maxUnits)) {
|
|
return nullptr;
|
|
}
|
|
return m_boundTextures[unit];
|
|
}
|
|
|
|
bool OpenGLTextureUnitAllocator::IsAllocated(int32_t unit) const {
|
|
if (unit < 0 || unit >= static_cast<int32_t>(m_maxUnits)) {
|
|
return false;
|
|
}
|
|
return m_allocated[unit];
|
|
}
|
|
|
|
} // namespace RHI
|
|
} // namespace XCEngine
|