diff options
author | chai <chaifix@163.com> | 2021-11-04 14:48:07 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-11-04 14:48:07 +0800 |
commit | ae2c6b26c2453cfb84153c39861a1bcd02479a85 (patch) | |
tree | 259457dcd09db3c256ff613c4483e67495d29fec /Runtime/Graphics | |
parent | d7c051cecf0db9056e94d5e80146aa0b066e606b (diff) |
-textureUnitBucket
Diffstat (limited to 'Runtime/Graphics')
-rw-r--r-- | Runtime/Graphics/GfxDevice.cpp | 28 | ||||
-rw-r--r-- | Runtime/Graphics/GfxDevice.h | 2 |
2 files changed, 13 insertions, 17 deletions
diff --git a/Runtime/Graphics/GfxDevice.cpp b/Runtime/Graphics/GfxDevice.cpp index e172756..f83a9b4 100644 --- a/Runtime/Graphics/GfxDevice.cpp +++ b/Runtime/Graphics/GfxDevice.cpp @@ -3,9 +3,19 @@ #include "Runtime/Math/Math.h" static bool deviceInited = false; +// +//static const std::vector<byte> s_AvailableTextureUnitPreset = {0,1,2,3,4,5,6,7}; // 最多支持8个贴图 +//static std::vector<byte> s_TextureUnitBucket = s_AvailableTextureUnitPreset; -static const std::vector<byte> s_AvailableTextureUnitPreset = {0,1,2,3,4,5,6,7}; // 最多支持8个贴图 -static std::vector<byte> s_TextureUnitBucket = s_AvailableTextureUnitPreset; +static const int kMaxAvailableTextureUnitCount = 8; // 最多支持8个贴图 +static int s_CurAvailableTextureUnit = 0; + +static int ClaimTextureUnit() +{ + int unit = s_CurAvailableTextureUnit; + s_CurAvailableTextureUnit = (s_CurAvailableTextureUnit + 1) % kMaxAvailableTextureUnitCount; + return unit; +} GfxDevice g_GfxDevice; @@ -129,14 +139,7 @@ void GfxDevice::SetUniformMat4(const char* name, Matrix44 mat4) void GfxDevice::SetUniformTexture(const char* name, Texture* texture) { - if (s_TextureUnitBucket.size() == 0) - { - log_error("No available texture unit. Too many textures or forget invoke ResetUniformsState()"); - return; - } - - int texUnit = s_TextureUnitBucket.back(); - s_TextureUnitBucket.pop_back(); + int texUnit = ClaimTextureUnit(); glActiveTexture(GL_TEXTURE0 + texUnit);
glBindTexture(GL_TEXTURE_2D, texture->GetGpuID());
@@ -144,11 +147,6 @@ void GfxDevice::SetUniformTexture(const char* name, Texture* texture) glUniform1i(loc, texUnit); } -void GfxDevice::ResetUniformsState() -{ - s_TextureUnitBucket = s_AvailableTextureUnitPreset; -} - void GfxDevice::BeginFrame() { m_IsInsideFrame = true; diff --git a/Runtime/Graphics/GfxDevice.h b/Runtime/Graphics/GfxDevice.h index f00a58f..dccde4b 100644 --- a/Runtime/Graphics/GfxDevice.h +++ b/Runtime/Graphics/GfxDevice.h @@ -70,8 +70,6 @@ public: void SetUniformMat4(const char* name, Matrix44 mat4); void SetUniformTexture(const char* name, Texture* texture); - void ResetUniformsState(); - void BeginFrame(); void EndFrame(); void PresentFrame(); |