PolyGLES1Texture.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * PolyGLES1Texture.cpp
  3. * Poly
  4. *
  5. * Created by Ivan Safrin on 2/1/10.
  6. * Copyright 2010 Ivan Safrin. All rights reserved.
  7. *
  8. */
  9. #include "PolyGLES1Texture.h"
  10. using namespace Polycode;
  11. OpenGLES1Texture::OpenGLES1Texture(unsigned int width, unsigned int height, char *textureData, bool clamp, int filteringMode) : Texture(width, height, textureData,clamp) {
  12. this->filteringMode = filteringMode;
  13. recreateFromImageData();
  14. }
  15. void OpenGLES1Texture::recreateFromImageData() {
  16. glGenTextures(1, &textureID);
  17. glBindTexture(GL_TEXTURE_2D, textureID);
  18. if(clamp) {
  19. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  20. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  21. } else {
  22. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  23. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  24. }
  25. switch(filteringMode) {
  26. case Renderer::TEX_FILTERING_LINEAR:
  27. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  28. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  29. break;
  30. case Renderer::TEX_FILTERING_NEAREST:
  31. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  32. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  33. break;
  34. }
  35. if(textureData)
  36. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData);
  37. }
  38. OpenGLES1Texture::OpenGLES1Texture(unsigned int width, unsigned int height) : Texture(width, height, NULL ,true) {
  39. }
  40. void OpenGLES1Texture::setGLInfo(GLuint textureID, GLuint frameBufferID) {
  41. this->textureID = textureID;
  42. this->frameBufferID = frameBufferID;
  43. }
  44. void OpenGLES1Texture::setTextureData(char *data) {
  45. /*
  46. glBindTexture(GL_TEXTURE_2D, textureID);
  47. glDrawBuffer(GL_AUX0);
  48. glDrawPixels(width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);
  49. glReadBuffer(GL_AUX0);
  50. // glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 128, 128, 0);
  51. */
  52. }
  53. OpenGLES1Texture::~OpenGLES1Texture() {
  54. glDeleteTextures(1, &textureID);
  55. }
  56. GLuint OpenGLES1Texture::getFrameBufferID() {
  57. return frameBufferID;
  58. }
  59. GLuint OpenGLES1Texture::getTextureID() {
  60. return textureID;
  61. }