summaryrefslogtreecommitdiff
path: root/Runtime/Graphics
diff options
context:
space:
mode:
Diffstat (limited to 'Runtime/Graphics')
-rw-r--r--Runtime/Graphics/GfxDevice.cpp28
-rw-r--r--Runtime/Graphics/GfxDevice.h2
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();