summaryrefslogtreecommitdiff
path: root/Runtime/GfxDevice/opengles20/GpuProgramsGLES20_UniformCache.h
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2019-08-14 22:50:43 +0800
committerchai <chaifix@163.com>2019-08-14 22:50:43 +0800
commit15740faf9fe9fe4be08965098bbf2947e096aeeb (patch)
treea730ec236656cc8cab5b13f088adfaed6bb218fb /Runtime/GfxDevice/opengles20/GpuProgramsGLES20_UniformCache.h
+Unity Runtime codeHEADmaster
Diffstat (limited to 'Runtime/GfxDevice/opengles20/GpuProgramsGLES20_UniformCache.h')
-rw-r--r--Runtime/GfxDevice/opengles20/GpuProgramsGLES20_UniformCache.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/Runtime/GfxDevice/opengles20/GpuProgramsGLES20_UniformCache.h b/Runtime/GfxDevice/opengles20/GpuProgramsGLES20_UniformCache.h
new file mode 100644
index 0000000..6f01fc4
--- /dev/null
+++ b/Runtime/GfxDevice/opengles20/GpuProgramsGLES20_UniformCache.h
@@ -0,0 +1,51 @@
+#pragma once
+
+#if !GFX_SUPPORTS_OPENGLES20
+#error "Should not include GpuProgramsGLES20 on this platform"
+#endif
+
+#include "Runtime/Utilities/LogAssert.h"
+#include "Runtime/GfxDevice/GfxDeviceTypes.h"
+#include <string.h>
+
+class GpuProgramParameters;
+
+struct
+UniformCacheGLES20
+{
+ // for gles we must set values per-uniform (not per-registers like in dx)
+ // so there is no real need for dirty tracking.
+ // TODO: do unified impl with dirty tracking if/when we do "everything is an array" in gles
+ float* uniform;
+ unsigned count;
+
+ UniformCacheGLES20() : uniform(0), count(0) {}
+
+ // we will pre-alloc memory. Fog params are handled differently (not added to gpu params).
+ // TODO: make it more general, int* perhaps, or some struct
+ void Create(const GpuProgramParameters* params, int fogParamsIndex, int fogColorIndex);
+ void Destroy();
+
+ // returns true if you need to update for real
+ bool UpdateUniform(int index, const float* val, unsigned floatCount);
+};
+
+void CachedUniform1(UniformCacheGLES20* cache, ShaderParamType type, int index, const float* val);
+void CachedUniform2(UniformCacheGLES20* cache, ShaderParamType type, int index, const float* val);
+void CachedUniform3(UniformCacheGLES20* cache, ShaderParamType type, int index, const float* val);
+void CachedUniform4(UniformCacheGLES20* cache, ShaderParamType type, int index, const float* val);
+
+
+inline bool UniformCacheGLES20::UpdateUniform(int index, const float* val, unsigned floatCount)
+{
+ Assert(index < count);
+ const unsigned mem_sz = floatCount*sizeof(float);
+
+ float* target = uniform + 4*index;
+ if(::memcmp(target, val, mem_sz))
+ {
+ ::memcpy(target, val, mem_sz);
+ return true;
+ }
+ return false;
+}