File: GLUniformCache.h

package info (click to toggle)
jazz2-native 3.5.0-2
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 16,912 kB
  • sloc: cpp: 172,557; xml: 113; python: 36; makefile: 5; sh: 2
file content (66 lines) | stat: -rw-r--r-- 1,650 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#pragma once

#ifndef DOXYGEN_GENERATING_OUTPUT
#define NCINE_INCLUDE_OPENGL
#include "../../CommonHeaders.h"
#endif

#include "../../../Main.h"

namespace nCine
{
	class GLUniform;

	/// Caches a uniform value and then updates it in the shader
	class GLUniformCache
	{
	public:
		GLUniformCache();
		explicit GLUniformCache(const GLUniform* uniform);

		inline const GLUniform* GetUniform() const {
			return uniform_;
		}
		inline const GLubyte* GetDataPointer() const {
			return dataPointer_;
		}
		inline void SetDataPointer(GLubyte* dataPointer) {
			dataPointer_ = dataPointer;
		}

		const GLfloat* GetFloatVector() const;
		GLfloat GetFloatValue(std::uint32_t index) const;
		const GLint* GetIntVector() const;
		GLint GetIntValue(std::uint32_t index) const;

		bool SetFloatVector(const GLfloat* vec);
		bool SetFloatValue(GLfloat v0);
		bool SetFloatValue(GLfloat v0, GLfloat v1);
		bool SetFloatValue(GLfloat v0, GLfloat v1, GLfloat v2);
		bool SetFloatValue(GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
		bool SetIntVector(const GLint* vec);
		bool SetIntValue(GLint v0);
		bool SetIntValue(GLint v0, GLint v1);
		bool SetIntValue(GLint v0, GLint v1, GLint v2);
		bool SetIntValue(GLint v0, GLint v1, GLint v2, GLint v3);

		inline bool IsDirty() const {
			return isDirty_;
		}
		inline void SetDirty(bool isDirty) {
			isDirty_ = isDirty;
		}
		bool CommitValue();

	private:
		const GLUniform* uniform_;
		GLubyte* dataPointer_;
		/// A flag to signal if the uniform needs to be committed
		bool isDirty_;

		bool CheckFloat() const;
		bool CheckInt() const;
		bool CheckComponents(std::uint32_t requiredComponents) const;
	};

}