-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathComputer.cpp
More file actions
51 lines (40 loc) · 1.45 KB
/
Computer.cpp
File metadata and controls
51 lines (40 loc) · 1.45 KB
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
#include "Computer.h"
#include "Application.h"
#include <iostream>
using namespace std;
Computer::Computer(GLuint compute_shader)
{
glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_COUNT, 0, &workgroup_count[0]);
glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_COUNT, 1, &workgroup_count[1]);
glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_COUNT, 2, &workgroup_count[2]);
glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 0, &workgroup_size[0]);
glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 1, &workgroup_size[1]);
glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 2, &workgroup_size[2]);
glGetIntegerv (GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS, &workgroup_invocations);
program = glCreateProgram();
glAttachShader(program, compute_shader);
glLinkProgram(program);
GLint status;
glGetProgramiv (program, GL_LINK_STATUS, &status);
if (status == GL_FALSE)
{
GLint infoLogLength;
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infoLogLength);
GLchar *strInfoLog = new GLchar[infoLogLength + 1];
glGetProgramInfoLog(program, infoLogLength, NULL, strInfoLog);
cout << "Program link error: " << strInfoLog;
delete[] strInfoLog;
}
}
void Computer::setData(int index, GLuint data)
{
glUseProgram(program);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, index, data);
glUseProgram(0);
}
void Computer::compute(int count_x, int count_y, int count_z)
{
glUseProgram(program);
glDispatchCompute(count_x, count_y, count_z);
glUseProgram(0);
}