Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. void createCubemapArray(GLuint& cubemap)
  2. {
  3. //Generate an array texture
  4. glGenTextures(1, &cubemap);
  5. glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, cubemap);
  6.  
  7. //Create storage for the texture. (4 layers of 1x1 texels)
  8. glTexStorage3D(GL_TEXTURE_CUBE_MAP_ARRAY,
  9. 1, //No mipmaps as textures are 1x1
  10. GL_RGB8, //Internal format
  11. width, height, //width,height
  12. 4 //Number of layers
  13. );
  14.  
  15. for (unsigned int i(0); i != 4; ++i)
  16. {
  17. glTexSubImage3D(GL_TEXTURE_CUBE_MAP_ARRAY,
  18. 0, //Mipmap number
  19. 0, 0, i, //xoffset, yoffset, zoffset
  20. 1, 1, 1, //width, height, depth
  21. GL_RGB, //format
  22. GL_UNSIGNED_BYTE, //type
  23. 0); //pointer to data
  24. }
  25.  
  26. glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  27. glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  28. glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  29. glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  30. }
  31.  
  32. vec3 position = mirrorCam.getPosition();
  33. view = look_at(position, position + normalise(viewsX[i]), vec3(0.0, -0.5, -0.5));
  34. drawloop(view, proj, fb[0][i].framebuffer);
  35. glFramebufferTexture3D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, cubemapArray, 0, 0);
  36.  
  37. glBindTexture(GL_TEXTURE_2D, cubemapArray);
  38. glUniform1i(glGetUniformLocation(reflectiveShaderID, "cube_array"), 0);
  39.  
  40. uniform samplerCube cube_texture;
  41. //....
  42. void main()
  43. {
  44. //...
  45. fragment_color = texture(cube_array, vec4(textureCoordinates, 0));
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement