gdk-graphics  1b6d84e044c2c953fd7c9501e628a67e80f4da0d
graphics_context.h
1 // © Joseph Cameron - All Rights Reserved
2 
3 #ifndef GDK_GFX_CONTEXT_H
4 #define GDK_GFX_CONTEXT_H
5 
6 #include <memory>
7 
8 #include <gdk/entity.h>
9 #include <gdk/material.h>
10 #include <gdk/model.h>
11 #include <gdk/scene.h>
12 #include <gdk/screen_camera.h>
13 #include <gdk/shader_program.h>
14 #include <gdk/texture.h>
15 #include <gdk/texture_camera.h>
16 #include <gdk/vertex_data.h>
17 
18 namespace gdk::graphics
19 {
20  class entity_owner;
21 
30  class context
31  {
32  public:
34  using context_ptr_type = std::shared_ptr<context>;
36  using scene_ptr_type = std::shared_ptr<scene>;
38  using entity_ptr_type = std::shared_ptr<entity>;
40  using shader_program_ptr_type = std::shared_ptr<shader_program>;
42  using model_ptr_type = std::shared_ptr<model>;
44  using material_ptr_type = std::shared_ptr<material>;
46  using texture_ptr_type = std::shared_ptr<texture>;
48  using built_in_model_ptr_type = std::shared_ptr<model>;
50  using built_in_shader_ptr_type = std::shared_ptr<shader_program>;
52  using context_shared_ptr_type = std::shared_ptr<context>;
54  using scene_shared_ptr_type = std::shared_ptr<scene>;
56  using shader_program_shared_ptr_type = std::shared_ptr<shader_program>;
58  using material_shared_ptr_type = std::shared_ptr<material>;
60  using model_shared_ptr_type = std::shared_ptr<model>;
62  using texture_shared_ptr_type = std::shared_ptr<texture>;
63 
65  enum class implementation
66  {
70  null
71  };
72 
75  //
77  [[nodiscard]] static context_ptr_type make(
78  const implementation &
79  );
80 
82  [[nodiscard]] virtual scene_ptr_type make_scene() const = 0;
83 
85  [[nodiscard]] virtual std::shared_ptr<screen_camera> make_camera() const = 0;
87  [[nodiscard]] virtual std::shared_ptr<screen_camera> make_camera(
88  const camera &other
89  ) const = 0;
90 
92  [[nodiscard]] virtual std::shared_ptr<texture_camera> make_texture_camera() const = 0;
93 
95  [[nodiscard]] virtual entity_ptr_type make_entity(
97  model_shared_ptr_type pModel,
99  material_shared_ptr_type pMaterial
100  ) const = 0;
102  [[nodiscard]] virtual entity_ptr_type make_entity(
103  const entity &other
104  ) const = 0;
105 
107  [[nodiscard]] virtual model_ptr_type make_model(
108  const gdk::model::UsageHint &,
109  const vertex_data &vertexDataView
110  ) const = 0;
111 
113  [[nodiscard]] virtual model_ptr_type make_model() const = 0;
114 
116  [[nodiscard]] virtual material_ptr_type make_material(
123  material::FaceCullingMode aFaceCullingMode = material::FaceCullingMode::None) const = 0;
124 
126  [[nodiscard]] virtual shader_program_ptr_type make_shader(
127  const std::string &aVertexStageSource,
128  const std::string &aFragmentStageSource
129  ) const = 0;
130 
132  [[nodiscard]] virtual texture_ptr_type make_texture(
133  const texture::image_data_2d_view &imageView
134  ) const = 0;
135 
137  [[nodiscard]] virtual texture_ptr_type make_texture(
138  const std::vector<std::underlying_type<std::byte>::type> &aRGBA32PNGData
139  ) const = 0;
141 
144  //
150  [[nodiscard]] virtual built_in_shader_ptr_type get_alpha_cutoff_shader() const = 0;
151 
156  [[nodiscard]] virtual built_in_shader_ptr_type get_pink_shader_of_death() const = 0;
157 
160  [[nodiscard]] virtual built_in_model_ptr_type get_cube_model() const = 0;
161 
164  [[nodiscard]] virtual built_in_model_ptr_type get_quad_model() const = 0;
166 
168  virtual ~context() = default;
169  };
170 }
171 
172 #endif
173 
static context_ptr_type make(const implementation &)
context factory method
represents an observable 3d object.
Definition: entity.h:14
used to construct a model. Vertex data represents a set of vertex data in system memory ...
Definition: vertex_data.h:44
std::shared_ptr< model > model_ptr_type
model factory return type
Definition: graphics_context.h:42
std::shared_ptr< model > model_shared_ptr_type
shared ptr to a model
Definition: graphics_context.h:60
virtual ~context()=default
virtual destructor
std::shared_ptr< model > built_in_model_ptr_type
ptr type for built in models provided by the implementation
Definition: graphics_context.h:48
virtual entity_ptr_type make_entity(model_shared_ptr_type pModel, material_shared_ptr_type pMaterial) const =0
make an entity
virtual built_in_shader_ptr_type get_pink_shader_of_death() const =0
A forward renderer shader program useful for displaying render errors:
std::shared_ptr< context > context_ptr_type
ptr type returned by factory method
Definition: graphics_context.h:34
Definition: graphics_context.h:30
std::shared_ptr< scene > scene_shared_ptr_type
shared ptr for scene
Definition: graphics_context.h:54
implementation
specifies implementation to use in context construction
Definition: graphics_context.h:65
std::shared_ptr< context > context_shared_ptr_type
shared ptr to a context
Definition: graphics_context.h:52
std::shared_ptr< shader_program > shader_program_shared_ptr_type
shared ptr to a shader_program
Definition: graphics_context.h:56
virtual scene_ptr_type make_scene() const =0
makes a scene
std::shared_ptr< shader_program > shader_program_ptr_type
shader_program factory return type
Definition: graphics_context.h:40
do not cull any polygons
std::shared_ptr< material > material_shared_ptr_type
shared ptr to a material
Definition: graphics_context.h:58
Definition: batch_model.h:15
virtual built_in_model_ptr_type get_quad_model() const =0
a 1x1 quad model
virtual built_in_model_ptr_type get_cube_model() const =0
a 1x1x1 cube model
virtual std::shared_ptr< screen_camera > make_camera() const =0
makes a camera TODO: rename to make_screen_camera probably
std::shared_ptr< texture > texture_shared_ptr_type
shared ptr to a texture
Definition: graphics_context.h:62
virtual std::shared_ptr< texture_camera > make_texture_camera() const =0
makes a texture_camera
Definition: camera.h:11
std::shared_ptr< entity > entity_ptr_type
entity factory return type
Definition: graphics_context.h:38
virtual model_ptr_type make_model() const =0
construct an empty model
render_mode
render mode decides transparency etc
Definition: material.h:33
virtual texture_ptr_type make_texture(const texture::image_data_2d_view &imageView) const =0
make a texture using a 2d image view
pod struct representing a view on decoded image data
Definition: texture.h:35
std::shared_ptr< texture > texture_ptr_type
texture factory return type
Definition: graphics_context.h:46
std::shared_ptr< shader_program > built_in_shader_ptr_type
ptr type for built in shaders provided by the implementation
Definition: graphics_context.h:50
virtual material_ptr_type make_material(shader_program_shared_ptr_type pShader, material::render_mode aRenderMode=material::render_mode::opaque, material::FaceCullingMode aFaceCullingMode=material::FaceCullingMode::None) const =0
make a material.
FaceCullingMode
specify whether front- or back-facing polygons can be culled
Definition: material.h:24
virtual shader_program_ptr_type make_shader(const std::string &aVertexStageSource, const std::string &aFragmentStageSource) const =0
make a shader program containing a user-defined vertex shader stage and fragment shader stage ...
std::shared_ptr< material > material_ptr_type
material factory return type
Definition: graphics_context.h:44
std::shared_ptr< scene > scene_ptr_type
scene factory return type
Definition: graphics_context.h:36
virtual built_in_shader_ptr_type get_alpha_cutoff_shader() const =0
A forward renderer shader program with the following properties: