Index

zydeco / fractal

Experiment in graphics programming, C++, OpenGL, simulation techniques.

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
1008 Dec 2023 15:215a717feFractal renderer update for articleJosh Stockin1640G

Blob @ zydeco / src / render / gl / GLUniformUploader.cpp

text/plain3944 bytesdownload raw
1#include "ZydecoCommon.hpp"
2#include "GLUniformUploader.hpp"
3
4
5static Logger LOGGER("GLUniformUploader");
6
7
8void GLUniformUploader::UploadUniforms(uint64_t program_id)
9{
10 for (std::pair<std::string, glUniform> uniform : m_uniforms)
11 {
12 int location = glGetUniformLocation(program_id, uniform.first.c_str());
13 if (location == -1)
14 {
15 LOGGER.Log(Logger::WARNING, "UploadUniforms(): {} not found", uniform.first);
16 continue;
17 }
18
19 if (uniform.second.type == glUniformType::FLOAT)
20 {
21 switch (uniform.second.quantity)
22 {
23 case 1: glProgramUniform1f(program_id, location, *(float*)(uniform.second.data[0])); break;
24 case 2: glProgramUniform2f(program_id, location, *(float*)(uniform.second.data[0]), *(float*)(uniform.second.data[1])); break;
25 case 3: glProgramUniform3f(program_id, location, *(float*)(uniform.second.data[0]), *(float*)(uniform.second.data[1]), *(float*)(uniform.second.data[2])); break;
26 case 4: glProgramUniform4f(program_id, location, *(float*)(uniform.second.data[0]), *(float*)(uniform.second.data[1]), *(float*)(uniform.second.data[2]), *(float*)(uniform.second.data[3])); break;
27 }
28 }
29 else if (uniform.second.type == glUniformType::DOUBLE)
30 {
31 switch (uniform.second.quantity)
32 {
33 case 1: glProgramUniform1d(program_id, location, *(double*)(uniform.second.data[0])); break;
34 case 2: glProgramUniform2d(program_id, location, *(double*)(uniform.second.data[0]), *(double*)(uniform.second.data[1])); break;
35 case 3: glProgramUniform3d(program_id, location, *(double*)(uniform.second.data[0]), *(double*)(uniform.second.data[1]), *(double*)(uniform.second.data[2])); break;
36 case 4: glProgramUniform4d(program_id, location, *(double*)(uniform.second.data[0]), *(double*)(uniform.second.data[1]), *(double*)(uniform.second.data[2]), *(double*)(uniform.second.data[3])); break;
37 }
38 }
39 else if (uniform.second.type == glUniformType::INT)
40 {
41 switch (uniform.second.quantity)
42 {
43 case 1: glProgramUniform1i(program_id, location, *(int*)(uniform.second.data[0])); break;
44 case 2: glProgramUniform2i(program_id, location, *(int*)(uniform.second.data[0]), *(int*)(uniform.second.data[1])); break;
45 case 3: glProgramUniform3i(program_id, location, *(int*)(uniform.second.data[0]), *(int*)(uniform.second.data[1]), *(int*)(uniform.second.data[2])); break;
46 case 4: glProgramUniform4i(program_id, location, *(int*)(uniform.second.data[0]), *(int*)(uniform.second.data[1]), *(int*)(uniform.second.data[2]), *(int*)(uniform.second.data[3])); break;
47 }
48 }
49 else if (uniform.second.type == glUniformType::UINT)
50 {
51 switch (uniform.second.quantity)
52 {
53 case 1: glProgramUniform1ui(program_id, location, *(unsigned int*)(uniform.second.data[0])); break;
54 case 2: glProgramUniform2ui(program_id, location, *(unsigned int*)(uniform.second.data[0]), *(unsigned int*)(uniform.second.data[1])); break;
55 case 3: glProgramUniform3ui(program_id, location, *(unsigned int*)(uniform.second.data[0]), *(unsigned int*)(uniform.second.data[1]), *(unsigned int*)(uniform.second.data[2])); break;
56 case 4: glProgramUniform4ui(program_id, location, *(unsigned int*)(uniform.second.data[0]), *(unsigned int*)(uniform.second.data[1]), *(unsigned int*)(uniform.second.data[2]), *(unsigned int*)(uniform.second.data[3])); break;
57 }
58 }
59 else if (uniform.second.type == glUniformType::MAT4)
60 {
61 glProgramUniformMatrix4fv(program_id, location, uniform.second.quantity, false, (float*)(uniform.second.data[0]) );
62 }
63 }
64}
65