mirror of
https://github.com/allemangD/toddcox-visualize.git
synced 2025-11-10 12:02:47 -05:00
use program pipelines instead
This commit is contained in:
@@ -3,3 +3,4 @@ target_link_libraries(memo PRIVATE tc vis-util)
|
|||||||
|
|
||||||
add_executable(geom geomtest.cpp)
|
add_executable(geom geomtest.cpp)
|
||||||
target_link_libraries(geom PRIVATE tc vis-util)
|
target_link_libraries(geom PRIVATE tc vis-util)
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,3 @@
|
|||||||
add_executable(vis src/main.cpp)
|
|
||||||
target_include_directories(vis PRIVATE include)
|
|
||||||
target_link_libraries(vis PRIVATE tc glad glm glfw)
|
|
||||||
|
|
||||||
add_custom_target(shaders ALL DEPENDS shader_output)
|
add_custom_target(shaders ALL DEPENDS shader_output)
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT shader_output
|
OUTPUT shader_output
|
||||||
@@ -9,7 +5,10 @@ add_custom_command(
|
|||||||
COMMENT "copied shaders"
|
COMMENT "copied shaders"
|
||||||
)
|
)
|
||||||
|
|
||||||
add_dependencies(vis shaders)
|
|
||||||
|
|
||||||
add_library(vis-util INTERFACE)
|
add_library(vis-util INTERFACE)
|
||||||
target_include_directories(vis-util INTERFACE include)
|
target_include_directories(vis-util INTERFACE include)
|
||||||
|
|
||||||
|
add_executable(vis src/main.cpp)
|
||||||
|
target_include_directories(vis PRIVATE include)
|
||||||
|
target_link_libraries(vis PRIVATE tc glad glm glfw)
|
||||||
|
add_dependencies(vis shaders)
|
||||||
|
|||||||
@@ -29,6 +29,26 @@ public:
|
|||||||
explicit program_error(const char *string) : gl_error(string) {}
|
explicit program_error(const char *string) : gl_error(string) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<class T, GLenum prop>
|
||||||
|
T utilGetShader(GLuint shader) {
|
||||||
|
GLint res;
|
||||||
|
glGetShaderiv(shader, prop, &res);
|
||||||
|
return static_cast<T>(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define getShaderInfoLogLength utilGetShader<size_t, GL_INFO_LOG_LENGTH>
|
||||||
|
#define getShaderCompileStatus utilGetShader<size_t, GL_COMPILE_STATUS>
|
||||||
|
|
||||||
|
template<class T, GLenum prop>
|
||||||
|
T utilGetProgram(GLuint program) {
|
||||||
|
GLint res;
|
||||||
|
glGetProgramiv(program, prop, &res);
|
||||||
|
return static_cast<T>(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define getProgramInfoLogLength utilGetProgram<size_t, GL_INFO_LOG_LENGTH>
|
||||||
|
#define getProgramLinkStatus utilGetProgram<size_t, GL_LINK_STATUS>
|
||||||
|
|
||||||
void utilShaderSource(GLuint shader, const std::vector<std::string> &sources) {
|
void utilShaderSource(GLuint shader, const std::vector<std::string> &sources) {
|
||||||
char const *ptrs[sources.size()];
|
char const *ptrs[sources.size()];
|
||||||
for (size_t i = 0; i < sources.size(); ++i) {
|
for (size_t i = 0; i < sources.size(); ++i) {
|
||||||
@@ -37,17 +57,15 @@ void utilShaderSource(GLuint shader, const std::vector<std::string> &sources) {
|
|||||||
glShaderSource(shader, sources.size(), ptrs, nullptr);
|
glShaderSource(shader, sources.size(), ptrs, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string utilShaderInfoLog(GLuint shader) {
|
std::string getShaderInfoLog(GLuint shader) {
|
||||||
int len;
|
int len = getShaderInfoLogLength(shader);
|
||||||
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &len);
|
|
||||||
char buffer[len];
|
char buffer[len];
|
||||||
glGetShaderInfoLog(shader, len, nullptr, buffer);
|
glGetShaderInfoLog(shader, len, nullptr, buffer);
|
||||||
return std::string(buffer);
|
return std::string(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string utilProgramInfoLog(GLuint program) {
|
std::string getProgramInfoLog(GLuint program) {
|
||||||
int len;
|
int len = getProgramInfoLogLength(program);
|
||||||
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &len);
|
|
||||||
char buffer[len];
|
char buffer[len];
|
||||||
glGetProgramInfoLog(program, len, nullptr, buffer);
|
glGetProgramInfoLog(program, len, nullptr, buffer);
|
||||||
return std::string(buffer);
|
return std::string(buffer);
|
||||||
@@ -86,11 +104,9 @@ GLuint utilCompileFiles(const GLenum type, const std::vector<std::string> &files
|
|||||||
utilShaderSource(shader, sources);
|
utilShaderSource(shader, sources);
|
||||||
glCompileShader(shader);
|
glCompileShader(shader);
|
||||||
|
|
||||||
int success;
|
if (getShaderCompileStatus(shader)) return shader;
|
||||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
|
|
||||||
if (success) return shader;
|
|
||||||
|
|
||||||
throw shader_error(utilShaderInfoLog(shader));
|
throw shader_error(getShaderInfoLog(shader));
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint utilLinkProgram(const std::vector<GLuint> &shaders) {
|
GLuint utilLinkProgram(const std::vector<GLuint> &shaders) {
|
||||||
@@ -100,9 +116,26 @@ GLuint utilLinkProgram(const std::vector<GLuint> &shaders) {
|
|||||||
}
|
}
|
||||||
glLinkProgram(program);
|
glLinkProgram(program);
|
||||||
|
|
||||||
int success;
|
if (getProgramLinkStatus(program)) return program;
|
||||||
glGetProgramiv(program, GL_LINK_STATUS, &success);
|
|
||||||
if (success)return program;
|
|
||||||
|
|
||||||
throw program_error(utilProgramInfoLog(program));
|
throw program_error(getProgramInfoLog(program));
|
||||||
|
}
|
||||||
|
|
||||||
|
GLuint utilCreateShaderProgram(GLenum type, const std::vector<std::string> &src) {
|
||||||
|
std::vector<const char *> c_str(src.size());
|
||||||
|
std::transform(src.begin(), src.end(), c_str.begin(), [](auto &str) {
|
||||||
|
return str.c_str();
|
||||||
|
});
|
||||||
|
|
||||||
|
GLuint program = glCreateShaderProgramv(type, src.size(), &c_str[0]);
|
||||||
|
|
||||||
|
if (getProgramLinkStatus(program)) return program;
|
||||||
|
|
||||||
|
throw program_error(getProgramInfoLog(program));
|
||||||
|
}
|
||||||
|
|
||||||
|
GLuint utilCreateShaderProgramFile(GLenum type, const std::vector<std::string> &files) {
|
||||||
|
std::vector<std::string> sources(files.size());
|
||||||
|
std::transform(files.begin(), files.end(), sources.begin(), utilReadFile);
|
||||||
|
return utilCreateShaderProgram(type, sources);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
#version 430
|
#version 430
|
||||||
|
|
||||||
|
out gl_PerVertex {
|
||||||
|
vec4 gl_Position;
|
||||||
|
};
|
||||||
|
|
||||||
layout(location=0) uniform mat4 proj;
|
layout(location=0) uniform mat4 proj;
|
||||||
layout(location=1) uniform mat4 view;
|
layout(location=1) uniform mat4 view;
|
||||||
|
|
||||||
@@ -8,8 +12,6 @@ layout(location=0) in vec4 pos;
|
|||||||
out vec4 vpos;
|
out vec4 vpos;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
int i = gl_VertexID;
|
|
||||||
vpos = view * pos;
|
vpos = view * pos;
|
||||||
gl_Position = proj * vec4(vpos.xyz / (1), 1);
|
gl_Position = proj * vec4(vpos.xyz / (1), 1);
|
||||||
gl_PointSize = 5;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,13 +18,6 @@ __attribute__((unused)) __declspec(dllexport) int NvOptimusEnablement = 0x000000
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
float floatmod(float x, float m) {
|
|
||||||
if (x < 0) {
|
|
||||||
x += (float)((int)((-x)/m) + 1)*m;
|
|
||||||
}
|
|
||||||
return x - ((float)((int)(x / m)))*m;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
//region init window
|
//region init window
|
||||||
if (!glfwInit()) {
|
if (!glfwInit()) {
|
||||||
@@ -50,24 +43,17 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
std::cout << utilInfo();
|
std::cout << utilInfo();
|
||||||
|
|
||||||
GLuint pgm;
|
GLuint pipe;
|
||||||
|
glCreateProgramPipelines(1, &pipe);
|
||||||
|
|
||||||
|
GLuint vs, fs;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// GLuint vs = utilCompileFiles(GL_VERTEX_SHADER, {"shaders/ortho.vs.glsl"});
|
vs = utilCreateShaderProgramFile(GL_VERTEX_SHADER, {"shaders/ortho.vs.glsl"});
|
||||||
// GLuint vs = utilCompileFiles(GL_VERTEX_SHADER, {"shaders/stereo.vs.glsl"});
|
fs = utilCreateShaderProgramFile(GL_FRAGMENT_SHADER, {"shaders/one-color.fs.glsl"});
|
||||||
// GLuint fs = utilCompileFiles(GL_FRAGMENT_SHADER, {"shaders/one-color.fs.glsl"});
|
|
||||||
// GLuint fs = utilCompileFiles(GL_FRAGMENT_SHADER, {"shaders/w-axis-hue.fs.glsl"});
|
|
||||||
|
|
||||||
// pgm = utilLinkProgram({vs, fs});
|
glUseProgramStages(pipe, GL_VERTEX_SHADER_BIT, vs);
|
||||||
|
glUseProgramStages(pipe, GL_FRAGMENT_SHADER_BIT, fs);
|
||||||
pgm = utilLinkProgram({
|
|
||||||
utilCompileFiles(GL_VERTEX_SHADER, {"shaders/stereo-proper.vs.glsl"}),
|
|
||||||
// utilCompileFiles(GL_VERTEX_SHADER, {"shaders/ortho.vs.glsl"}),
|
|
||||||
// utilCompileFiles(GL_VERTEX_SHADER, {"shaders/stereo.vs.glsl"}),
|
|
||||||
// utilCompileFiles(GL_GEOMETRY_SHADER, {"shaders/stereo-proper.gm.glsl"}),
|
|
||||||
utilCompileFiles(GL_FRAGMENT_SHADER, {"shaders/one-color.fs.glsl"}),
|
|
||||||
// utilCompileFiles(GL_FRAGMENT_SHADER, {"shaders/w-axis-hue.fs.glsl"})
|
|
||||||
});
|
|
||||||
} catch (const gl_error &e) {
|
} catch (const gl_error &e) {
|
||||||
std::cerr << e.what() << std::endl;
|
std::cerr << e.what() << std::endl;
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
@@ -75,16 +61,12 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto group = tc::group::H(3);
|
auto group = tc::group::H(3);
|
||||||
// auto group = tc::group::B(5);
|
|
||||||
// auto group = tc::group::A(5);
|
|
||||||
GeomGen gg(group);
|
GeomGen gg(group);
|
||||||
auto res = gg.solve();
|
auto res = gg.solve();
|
||||||
auto mirrors = mirror(group);
|
auto mirrors = mirror(group);
|
||||||
|
|
||||||
auto corners = plane_intersections(mirrors);
|
auto corners = plane_intersections(mirrors);
|
||||||
// auto start = barycentric(corners, {.75f, .75f, .75f, .75f});
|
|
||||||
auto start = barycentric(corners, {1.00f, 0.1f, 0.01f, 0.005f});
|
auto start = barycentric(corners, {1.00f, 0.1f, 0.01f, 0.005f});
|
||||||
// auto start = barycentric(corners, {1, 1, 0.05, 1});
|
|
||||||
auto points = res.path.walk<glm::vec4, glm::vec4>(start, mirrors, reflect);
|
auto points = res.path.walk<glm::vec4, glm::vec4>(start, mirrors, reflect);
|
||||||
|
|
||||||
GLuint vbo;
|
GLuint vbo;
|
||||||
@@ -128,11 +110,11 @@ int main(int argc, char *argv[]) {
|
|||||||
float _ts[numts];
|
float _ts[numts];
|
||||||
float _ts_temp[numts];
|
float _ts_temp[numts];
|
||||||
for (int i = 0; i < numts; ++i) {
|
for (int i = 0; i < numts; ++i) {
|
||||||
_ts[i] = ((float)i - (numts/2.f))*0.1f;
|
_ts[i] = ((float) i - (numts / 2.f)) * 0.1f;
|
||||||
}
|
}
|
||||||
float* ts = _ts;
|
float *ts = _ts;
|
||||||
float* ts_temp = _ts_temp;
|
float *ts_temp = _ts_temp;
|
||||||
float* swap_t;
|
float *swap_t;
|
||||||
float alpha = 0.0001;
|
float alpha = 0.0001;
|
||||||
float beta = 0.0002;
|
float beta = 0.0002;
|
||||||
|
|
||||||
@@ -143,7 +125,7 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
glUseProgram(pgm);
|
glBindProgramPipeline(pipe);
|
||||||
glEnable(GL_PROGRAM_POINT_SIZE);
|
glEnable(GL_PROGRAM_POINT_SIZE);
|
||||||
glEnable(GL_POINT_SMOOTH);
|
glEnable(GL_POINT_SMOOTH);
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
@@ -154,19 +136,16 @@ int main(int argc, char *argv[]) {
|
|||||||
auto aspect = (float) width / (float) height;
|
auto aspect = (float) width / (float) height;
|
||||||
auto pheight = 1.4f;
|
auto pheight = 1.4f;
|
||||||
auto pwidth = aspect * pheight;
|
auto pwidth = aspect * pheight;
|
||||||
// glm::mat4 proj = glm::ortho(-pwidth, pwidth, -pheight, pheight, -2.0f, 2.0f);
|
|
||||||
glm::mat4 proj = glm::ortho(-pwidth, pwidth, -pheight, pheight, -10.0f, 10.0f);
|
glm::mat4 proj = glm::ortho(-pwidth, pwidth, -pheight, pheight, -10.0f, 10.0f);
|
||||||
glUniformMatrix4fv(0, 1, false, glm::value_ptr(proj));
|
glProgramUniformMatrix4fv(vs, 0, 1, false, glm::value_ptr(proj));
|
||||||
|
|
||||||
auto st = (float) glfwGetTime() / 8;
|
auto st = (float) glfwGetTime() / 8;
|
||||||
auto t = st / 7;
|
auto t = st / 7;
|
||||||
// printf("ts: [%f", ts[0]);
|
ts_temp[0] = ts[0] + alpha * (float) std::cos(rates[0] * t) + beta * (-ts[0]);
|
||||||
ts_temp[0] = ts[0] + alpha * (float)std::cos(rates[0] * t) + beta * (-ts[0]);
|
for (size_t i = 1; i < numts; i++) {
|
||||||
for (size_t i = 1; i < numts; i++){
|
ts_temp[i] = ts[i] + alpha * (float) std::cos(rates[i] * t) + beta * (-ts[i]);
|
||||||
// printf( ", %f", ts[i]);
|
|
||||||
ts_temp[i] = ts[i] + alpha * (float)std::cos(rates[i] * t) + beta * (-ts[i]);
|
|
||||||
}
|
}
|
||||||
// printf("]\n");
|
|
||||||
swap_t = ts;
|
swap_t = ts;
|
||||||
ts = ts_temp;
|
ts = ts_temp;
|
||||||
ts_temp = swap_t;
|
ts_temp = swap_t;
|
||||||
@@ -177,13 +156,12 @@ int main(int argc, char *argv[]) {
|
|||||||
view *= utilRotate(1, 2, st * ts[3]);
|
view *= utilRotate(1, 2, st * ts[3]);
|
||||||
// view *= utilRotate(1, 3, st * ts[4]);
|
// view *= utilRotate(1, 3, st * ts[4]);
|
||||||
// view *= utilRotate(2, 3, st * ts[5]);
|
// view *= utilRotate(2, 3, st * ts[5]);
|
||||||
glUniformMatrix4fv(1, 1, false, glm::value_ptr(view));
|
glProgramUniformMatrix4fv(vs, 1, 1, false, glm::value_ptr(view));
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
glUniform3f(2, 1.0f, 1.0f, 1.0f);
|
|
||||||
// glDrawArrays(GL_POINTS, 0, points.size());
|
// glDrawArrays(GL_POINTS, 0, points.size());
|
||||||
|
|
||||||
glUniform3f(2, 1.0f, 1.0f, 1.0f);
|
glProgramUniform3f(fs, 2, 1.0f, 1.0f, 1.0f);
|
||||||
for (int i = 0; i < group.ngens; ++i) {
|
for (int i = 0; i < group.ngens; ++i) {
|
||||||
auto ibo = edge_ibo[i];
|
auto ibo = edge_ibo[i];
|
||||||
auto count = edge_count[i];
|
auto count = edge_count[i];
|
||||||
|
|||||||
Reference in New Issue
Block a user