Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef GLUT2_IMAGE_H
- #define GLUT2_IMAGE_H
- #include <GL/glew.h>
- #include <GL/gl.h>
- #include <helper.h>
- GLuint glob_program;
- GLuint glob_texture;
- bool once = false;
- void draw() {
- if (once) {
- return;
- }
- once = true;
- gl(glBindImageTexture(0, glob_texture, 0, GL_FALSE, 0, GL_WRITE_ONLY,
- GL_RGBA16UI));
- std::cout << "glob_program is progam "
- << (glIsProgram(glob_program) == GL_TRUE)
- << std::endl;
- GLint uniformTexPosition = gl(glGetUniformLocation(glob_program, "u_image"));
- std::cout << "u_image position " << uniformTexPosition << std::endl;
- gl(glUseProgram(glob_program));
- gl(glUniform1i(uniformTexPosition, 0));
- gl(glDispatchCompute(32, 32, 1));
- }
- void initTextures() {
- gl(glGenTextures(1, &glob_texture));
- gl(glBindTexture(GL_TEXTURE_2D, glob_texture));
- gl(glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA16UI, 32, 32));
- }
- void initShader() {
- const GLchar *compShaderT =
- "#version 440 core\n"
- "layout (local_size_x = 32, local_size_y = 32) in;\n"
- "layout (location = 1, rgba16ui) uniform uimage2D u_image;\n"
- "uniform atomic_uint u_counter;\n"
- "void main() {\n"
- "uint value = atomicCounterIncrement(u_counter);\n"
- "ivec2 size = imageSize(u_image);\n"
- "if (gl_GlobalInvocationID.x < size.x && gl_GlobalInvocationID.y < size.y)"
- "imageStore(u_image, ivec2(gl_GlobalInvocationID.xy), "
- "uvec4(vec3(value), 0xffff));"
- "}\n";
- GLuint computeShader = gl(glCreateShader(GL_COMPUTE_SHADER));
- gl(glShaderSource(computeShader, 1, &compShaderT, nullptr));
- gl(glCompileShader(computeShader));
- glShaderLog(computeShader);
- glob_program = gl(glCreateProgram());
- gl(glAttachShader(glob_program, computeShader));
- gl(glLinkProgram(glob_program));
- gl(glDeleteShader(computeShader));
- glProgramLog(glob_program);
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement