Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. /*virtual*/ uint32 HyOpenGL::AddTextureArray(uint32 uiNumColorChannels, uint32 uiWidth, uint32 uiHeight, vector<unsigned char *> &vPixelData)
  2. {
  3. GLenum eInternalFormat = uiNumColorChannels == 4 ? GL_RGBA8 : (uiNumColorChannels == 3 ? GL_RGB8 : GL_R8);
  4. GLenum eFormat = uiNumColorChannels == 4 ? GL_RGBA : (uiNumColorChannels == 3 ? GL_RGB : GL_RED);
  5.  
  6. glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, eInternalFormat, uiWidth, uiHeight, static_cast<uint32>(vPixelData.size()), 0, eFormat, GL_UNSIGNED_BYTE, NULL);
  7.  
  8. GLuint hGLTextureArray;
  9. glGenTextures(1, &hGLTextureArray);
  10. //glActiveTexture(GL_TEXTURE0);
  11. glBindTexture(GL_TEXTURE_2D_ARRAY, hGLTextureArray);
  12.  
  13. // Create storage for the texture
  14. glTexStorage3D(GL_TEXTURE_2D_ARRAY,
  15. 1, // Number of mipmaps
  16. eInternalFormat, // Internal format
  17. uiWidth, uiHeight, // width, height
  18. static_cast<uint32>(vPixelData.size()));
  19.  
  20. for(unsigned int i = 0; i != vPixelData.size(); ++i)
  21. {
  22. // Write each texture into storage
  23. glTexSubImage3D(GL_TEXTURE_2D_ARRAY,
  24. 0, // Mipmap number
  25. 0, 0, i, // xoffset, yoffset, zoffset
  26. uiWidth, uiHeight, 1, // width, height, depth (of texture you're copying in)
  27. eFormat, // format
  28. GL_UNSIGNED_BYTE, // type
  29. vPixelData[i]); // pointer to pixel data
  30.  
  31. GLenum eError = glGetError(); // Getting 'GL_INVALID_OPERATION' when > 1 texture depth. It's 'GL_NO_ERROR' otherwise
  32. }
  33.  
  34. glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  35. glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  36. glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  37. glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  38.  
  39. return hGLTextureArray;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement