hardware_renderer.h 2.24 KB
Newer Older
Nick Sharp's avatar
Nick Sharp committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#ifndef CMU462_HARDWARE_RENDERER_H
#define CMU462_HARDWARE_RENDERER_H

#include <stdio.h>

#include "CMU462.h"
#include "svg_renderer.h"
#include "GLFW/glfw3.h"

namespace CMU462 {

class HardwareRenderer : public SVGRenderer {
 public:

  HardwareRenderer() { glClearColor(1,1,1,1); }

  // Implements Renderer
  ~HardwareRenderer() { }

  // 2D drawing mode
  void begin2DDrawing();
  void leave2DDrawing();

  // Draw an svg input to render target
  void draw_svg( SVG& svg );

  // GL context resize callback 
  void resize(size_t w, size_t h);

  // Clear render target
  inline void clear_target() {
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  }

  // Set svg to screen transformation
36
37
  inline void set_svg_2_screen( Matrix3x3 svg_2_screen ) {
    this->svg_2_screen = svg_2_screen;
Nick Sharp's avatar
Nick Sharp committed
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
  }

 private:

  // Primitive Drawing //

  // Draws an SVG element
  void draw_element( SVGElement* element );

  // Draws a point
  void draw_point( Point& p );

  // Draw a line
  void draw_line( Line& line );

  // Draw a polyline
  void draw_polyline( Polyline& polyline );

  // Draw a rectangle
  void draw_rect ( Rect& rect );

  // Draw a polygon
  void draw_polygon( Polygon& polygon );

  // Draw a ellipse
  void draw_ellipse( Ellipse& ellipse );

  // Draws a bitmap image
  void draw_image( Image& image );

  // Draw a group
  void draw_group( Group& group );

  // Rasterization //

  // rasterize a point
  void rasterize_point( float x, float y, Color color );

  // rasterize a line
  void rasterize_line( float x0, float y0,
                       float x1, float y1,
                       Color color);

  // rasterize a triangle
  void rasterize_triangle( float x0, float y0,
                           float x1, float y1,
                           float x2, float y2,
                           Color color );

  // rasterize an image
  void rasterize_image( float x0, float y0,
                        float x1, float y1,
                        Texture& tex );

  // resolve samples to render target
  // void resolve( void );

  // GL context dimension
  size_t context_w; size_t context_h;

  // SVG coordinates to screen space coordinates
99
  Matrix3x3 svg_2_screen;
Nick Sharp's avatar
Nick Sharp committed
100
101
102
103
104
105
    
}; // class HardwareRenderer

} // namespace CMU462

#endif // CMU462_HARDWARE_RENDERER_H