You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.4 KiB

5 years ago
  1. #pragma once
  2. #include "CELLMath.hpp"
  3. namespace CELL
  4. {
  5. enum DRAWMODE
  6. {
  7. DM_POINTS = 0,
  8. DM_LINES = 1,
  9. DM_LINE_LOOP = 2,
  10. DM_LINE_STRIP = 3,
  11. };
  12. class Raster
  13. {
  14. public:
  15. Rgba* _buffer;
  16. int _width;
  17. int _height;
  18. Rgba _color;
  19. public:
  20. Raster(int w,int h,void* buffer);
  21. ~Raster(void);
  22. void clear();
  23. void drawPoint(int x,int y, Rgba color,int ptSize);
  24. void drawArrays(DRAWMODE mode,const float2* points,int count)
  25. {
  26. switch (mode)
  27. {
  28. case DM_POINTS:
  29. {
  30. for (int i = 0 ;i < count ; ++ i)
  31. {
  32. drawPoints(points[i],_color);
  33. }
  34. }
  35. break;
  36. case DM_LINES:
  37. {
  38. count = count/2 * 2;
  39. for (int i = 0 ;i < count ; i += 2)
  40. {
  41. drawLine(points[i],points[i + 1],_color,_color);
  42. }
  43. }
  44. break;
  45. case DM_LINE_LOOP:
  46. {
  47. drawLine(points[0],points[1],_color,_color);
  48. for (int i = 2 ;i < count ; ++ i)
  49. {
  50. drawLine(points[i - 1],points[i],_color,_color);
  51. }
  52. drawLine(points[0],points[count - 1],_color,_color);
  53. }
  54. break;
  55. case DM_LINE_STRIP:
  56. {
  57. drawLine(points[0],points[1],_color,_color);
  58. for (int i = 2 ;i < count ; ++ i)
  59. {
  60. drawLine(points[i - 1],points[i],_color,_color);
  61. }
  62. }
  63. break;
  64. default:
  65. break;
  66. }
  67. }
  68. public:
  69. void drawLine(float2 pt1,float2 pt2,Rgba color1,Rgba color2);
  70. void drawPoints(float2 pt1,Rgba4Byte color)
  71. {
  72. }
  73. inline void setPixel(unsigned x,unsigned y,Rgba color)
  74. {
  75. if (x >= _width || y >= _height)
  76. {
  77. return;
  78. }
  79. _buffer[y * _width + x] = color;
  80. }
  81. };
  82. }