buffer.h 805 B

123456789101112131415161718192021222324252627282930313233343536
  1. #ifndef BUFFER_H
  2. #define BUFFER_H
  3. #include "SDL.h"
  4. #include <type_traits>
  5. template<class T>
  6. struct Buffer{
  7. int mWidth;
  8. int mHeight;
  9. int mPixelCount;
  10. int mPitch;
  11. T *buffer;
  12. Buffer(int w, int h, T * array)
  13. : mWidth(w), mHeight(h), mPixelCount(w*h),
  14. mPitch(w*sizeof(T)), buffer(array)
  15. {}
  16. ~Buffer(){
  17. delete [] buffer;
  18. };
  19. void clear(){
  20. if(std::is_same<T,float>::value){
  21. for(int i = 0; i < mPixelCount;++i){
  22. buffer[i] = 0.0f;
  23. }
  24. }
  25. else{
  26. memset(buffer,0, mPitch*mHeight);
  27. }
  28. }
  29. };
  30. #endif