Shiokaze Framework
A research-oriented fluid solver for computer graphics
graphics_engine.h
Go to the documentation of this file.
1 /*
2 ** graphics_engine.h
3 **
4 ** This is part of Shiokaze, a research-oriented fluid solver for computer graphics.
5 ** Created by Ryoichi Ando <rand@nii.ac.jp> on Jan 13, 2018.
6 **
7 ** Permission is hereby granted, free of charge, to any person obtaining a copy of
8 ** this software and associated documentation files (the "Software"), to deal in
9 ** the Software without restriction, including without limitation the rights to use,
10 ** copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
11 ** Software, and to permit persons to whom the Software is furnished to do so,
12 ** subject to the following conditions:
13 **
14 ** The above copyright notice and this permission notice shall be included in all copies
15 ** or substantial portions of the Software.
16 **
17 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
18 ** INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
19 ** PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 ** HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
21 ** CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
22 ** OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24 //
25 #ifndef SHKZ_GRAPHICS_ENGINE_H
26 #define SHKZ_GRAPHICS_ENGINE_H
27 //
28 #include <shiokaze/core/common.h>
29 #include <string>
30 #include <map>
31 #include <functional>
32 //
34 //
36 class graphics_engine {
39 public:
44  virtual ~graphics_engine() = default;
49  virtual void setup_graphics ( std::map<std::string,const void *> params=std::map<std::string,const void *>() ) = 0;
50  //
53  enum class FEATURE {
56  OPACITY,
59  _3D
60  };
67  virtual std::string get_graphics_engine_name () const = 0;
76  virtual bool get_supported ( FEATURE feature ) const = 0;
81  virtual void set_viewport( unsigned x, unsigned y, unsigned width, unsigned height ) = 0;
86  virtual void get_viewport( unsigned &x, unsigned &y, unsigned &width, unsigned &height ) const = 0;
99  virtual void set_2D_coordinate( double left, double right, double bottom, double top ) = 0;
116  virtual void look_at( const double target[3], const double position[3], const double up[3], double fov, double near, double far ) = 0;
121  virtual void clear() = 0;
126  virtual void get_background_color( double color[3] ) const = 0;
131  virtual void get_foreground_color( double color[3] ) const = 0;
136  void color3( double r, double g, double b ) {
137  double v[] = { r, g, b };
138  color3v(v);
139  }
144  void color4( double r, double g, double b, double a ) {
145  double v[] = { r, g, b, a };
146  color4v(v);
147  }
152  template <class T> void color3v( const T *v ) {
153  double v_plus_alpha[] = { v[0], v[1], v[2], 1.0 };
154  color4v(v_plus_alpha);
155  }
160  virtual void color4v( const double *v ) = 0;
165  void color4v( const float *v ) {
166  double p[] = { v[0], v[1], v[2], v[3] };
167  color4v(p);
168  }
173  void vertex2( double x, double y ) {
174  double v[] = { x, y, 0.0 };
175  vertex3v(v);
176  }
181  void vertex3( double x, double y, double z ) {
182  double v[] = { x, y, z};
183  vertex3v(v);
184  }\
185  //
188  enum class MODE {
191  POINTS,
194  LINES,
197  LINE_STRIP,
200  LINE_LOOP,
203  TRIANGLES,
210  };
215  virtual void begin( MODE mode ) = 0;
220  virtual void end() = 0;
225  virtual void point_size( double size ) = 0;
230  virtual void line_width( double width ) = 0;
235  template <class T> void vertex2v( const T *v ) {
236  double v_3d_added[] = { v[0], v[1], 0.0 };
237  vertex3v(v_3d_added);
238  }
243  virtual void vertex3v( const double *v ) = 0;
248  void vertex3v( const float *v ) {
249  double p[] = { v[0], v[1], v[2] };
250  vertex3v(p);
251  }
262  virtual void draw_string( const double *v, std::string str, unsigned size=0 ) = 0;
263 };
264 //
266 //
267 #endif
graphics_engine::vertex2v
void vertex2v(const T *v)
Equivalebt to glVertex. See https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glVertex....
Definition: graphics_engine.h:235
color
Class that converts color spaces.
Definition: color.h:25
graphics_engine::MODE::LINE_LOOP
@ LINE_LOOP
Closed lines.
graphics_engine::MODE::TRIANGLE_FAN
@ TRIANGLE_FAN
Connected group of triangles as fan.
graphics_engine::set_2D_coordinate
virtual void set_2D_coordinate(double left, double right, double bottom, double top)=0
Configure 2D coordinate view.
graphics_engine::FEATURE
FEATURE
List of features that can be specified to get_supported().
Definition: graphics_engine.h:53
graphics_engine::end
virtual void end()=0
Equivalebt to glEnd. See https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glEnd....
graphics_engine::get_supported
virtual bool get_supported(FEATURE feature) const =0
Get if a specified feature is supported.
graphics_engine::vertex3
void vertex3(double x, double y, double z)
Equivalebt to glVertex. See https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glVertex....
Definition: graphics_engine.h:181
graphics_engine::color4v
void color4v(const float *v)
Equivalebt to glColor. See https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glColor....
Definition: graphics_engine.h:165
graphics_engine::MODE::LINES
@ LINES
Independent lines segmemts.
graphics_engine::point_size
virtual void point_size(double size)=0
Equivalebt to glPointSize. See https://www.khronos.org/registry/OpenGL-Refpages/gl2....
graphics_engine::get_graphics_engine_name
virtual std::string get_graphics_engine_name() const =0
Get the name of the graphics engine.
graphics_engine::color4
void color4(double r, double g, double b, double a)
Equivalebt to glColor. See https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glColor....
Definition: graphics_engine.h:144
graphics_engine::set_viewport
virtual void set_viewport(unsigned x, unsigned y, unsigned width, unsigned height)=0
Set view port.
graphics_engine::get_viewport
virtual void get_viewport(unsigned &x, unsigned &y, unsigned &width, unsigned &height) const =0
Get view port.
graphics_engine::~graphics_engine
virtual ~graphics_engine()=default
Default destructor.
graphics_engine::vertex2
void vertex2(double x, double y)
Equivalebt to glVertex. See https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glVertex....
Definition: graphics_engine.h:173
graphics_engine::vertex3v
virtual void vertex3v(const double *v)=0
Equivalebt to glVertex. See https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glVertex....
SHKZ_BEGIN_NAMESPACE
#define SHKZ_BEGIN_NAMESPACE
Name space beggining definition for shiokaze.
Definition: common.h:39
graphics_engine::FEATURE::_3D
@ _3D
Support for 3D perspective.
graphics_engine::color3
void color3(double r, double g, double b)
Equivalebt to glColor. See https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glColor....
Definition: graphics_engine.h:136
graphics_engine::setup_graphics
virtual void setup_graphics(std::map< std::string, const void * > params=std::map< std::string, const void * >())=0
Initialize graphics engine.
graphics_engine::vertex3v
void vertex3v(const float *v)
Equivalebt to glVertex. See https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glVertex....
Definition: graphics_engine.h:248
graphics_engine::draw_string
virtual void draw_string(const double *v, std::string str, unsigned size=0)=0
Draw a string at the current position.
graphics_engine::color3v
void color3v(const T *v)
Equivalebt to glColor. See https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glColor....
Definition: graphics_engine.h:152
graphics_engine::MODE
MODE
List of drawing mode that is to be specified with begin() function. See https://www....
Definition: graphics_engine.h:188
graphics_engine::MODE::LINE_STRIP
@ LINE_STRIP
Connected group of line segments.
graphics_engine::line_width
virtual void line_width(double width)=0
Equivalebt to glLineWidth. See https://www.khronos.org/registry/OpenGL-Refpages/gl2....
common.h
graphics_engine::MODE::TRIANGLE_STRIP
@ TRIANGLE_STRIP
Connected group of triangles.
graphics_engine::FEATURE::OPACITY
@ OPACITY
Support for opacity (alpha) drawing.
graphics_engine::clear
virtual void clear()=0
Clear out the canvas.
graphics_engine::look_at
virtual void look_at(const double target[3], const double position[3], const double up[3], double fov, double near, double far)=0
Set up a camera with a target position, origin position and fov.
graphics_engine::get_background_color
virtual void get_background_color(double color[3]) const =0
Get the background color.
graphics_engine::MODE::TRIANGLES
@ TRIANGLES
Independent triangles.
graphics_engine::begin
virtual void begin(MODE mode)=0
Equivalebt to glBegin. See https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glBegin....
SHKZ_END_NAMESPACE
#define SHKZ_END_NAMESPACE
Name space end definition for shiokaze.
Definition: common.h:44
graphics_engine
Interface for handling drawing operations.
Definition: graphics_engine.h:38
graphics_engine::MODE::POINTS
@ POINTS
Points.
graphics_engine::get_foreground_color
virtual void get_foreground_color(double color[3]) const =0
Get the foreground color.
graphics_engine::color4v
virtual void color4v(const double *v)=0
Equivalebt to glColor. See https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glColor....