Advertisement
Guest User

crap

a guest
May 20th, 2016
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.37 KB | None | 0 0
  1. #ifndef GLUT2_IMAGE_H
  2. #define GLUT2_IMAGE_H
  3.  
  4. #include <GL/glew.h>
  5. #include <GL/gl.h>
  6. #include <helper.h>
  7.  
  8.  
  9. GLuint glob_program;
  10. GLuint glob_texture;
  11. bool once = false;
  12.  
  13. void draw() {
  14.     if (once) {
  15.         return;
  16.     }
  17.     once = true;
  18.     gl(glBindImageTexture(0, glob_texture, 0, GL_FALSE, 0, GL_WRITE_ONLY,
  19.         GL_RGBA16UI));
  20.  
  21.     std::cout << "glob_program is progam "
  22.         << (glIsProgram(glob_program) == GL_TRUE)
  23.         << std::endl;
  24.     GLint uniformTexPosition = gl(glGetUniformLocation(glob_program, "u_image"));
  25.     std::cout << "u_image position " << uniformTexPosition << std::endl;
  26.     gl(glUniform1i(uniformTexPosition, 0));
  27.     gl(glUseProgram(glob_program));
  28. }
  29.  
  30. void initTextures() {
  31.  
  32.     GLushort texturePtr[256 * 256 * 4];
  33.  
  34.     gl(glGenTextures(1, &glob_texture));
  35.     gl(glBindTexture(GL_TEXTURE_2D, glob_texture));
  36.     gl(glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA, 256, 256));
  37.     gl(glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 256, 256, GL_RGBA,
  38.         GL_UNSIGNED_SHORT_4_4_4_4, texturePtr));
  39. }
  40.  
  41. void initShader() {
  42.     const GLchar *vShaderT =
  43.         "#version 440 core\n"
  44.         "void main() { };\n";
  45.  
  46.     const GLchar *fShaderT =
  47.         "#version 440 core\n"
  48.         "layout (location = 1, rgba16ui) uniform uimage2D u_image;\n"
  49.         "uniform atomic_uint u_counter;\n"
  50.         "void main() {\n"
  51.             "uint value = atomicCounterIncrement(u_counter);\n"
  52.             "ivec2 size = imageSize(u_image);\n"
  53.             "if (gl_FragCoord.x < size.x && gl_FragCoord.y < size.y)"
  54.             "imageStore(u_image, ivec2(gl_FragCoord.xy), "
  55.                 "uvec4(vec3(value), 0xffff));"
  56.         "}\n";
  57.  
  58.     GLuint vertexShader = gl(glCreateShader(GL_VERTEX_SHADER));
  59.     GLuint fragmentShader = gl(glCreateShader(GL_FRAGMENT_SHADER));
  60.     gl(glShaderSource(vertexShader, 1, &vShaderT, nullptr));
  61.     gl(glShaderSource(fragmentShader, 1, &fShaderT, nullptr));
  62.     gl(glCompileShader(vertexShader));
  63.     gl(glCompileShader(fragmentShader));
  64.  
  65.     glShaderLog(vertexShader);
  66.     glShaderLog(fragmentShader);
  67.  
  68.     glob_program = gl(glCreateProgram());
  69.     gl(glAttachShader(glob_program, vertexShader));
  70.     gl(glAttachShader(glob_program, fragmentShader));
  71.     gl(glLinkProgram(glob_program));
  72.  
  73.     gl(glDeleteShader(vertexShader));
  74.     gl(glDeleteShader(fragmentShader));
  75.  
  76.     glProgramLog(glob_program);
  77. }
  78.  
  79. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement