3#ifndef GDK_GRAPHICS_NULL_CONTEXT_H
4#define GDK_GRAPHICS_NULL_CONTEXT_H
6#include <gdk/graphics/context.h>
7#include <gdk/graphics/profile.h>
21namespace gdk::graphics {
25 std::string_view aVertexSource, std::string_view aFragmentSource)>;
27 [[nodiscard]]
static std::shared_ptr<null_context> make(std::optional<graphics::profile> aProfile = {},
28 shader_check_type aShaderCheck = {});
33 [[nodiscard]]
virtual scene_ptr_type
make_scene()
override;
34 [[nodiscard]]
virtual screen_camera_ptr_type
make_camera()
override;
36 [[nodiscard]]
virtual texture_camera_ptr_type
make_texture_camera(
const intvector2_type &aSize)
override;
38 [[nodiscard]]
virtual entity_ptr_type
make_entity(
const const_model_ptr_type pModel,
39 const const_material_ptr_type pMaterial)
override;
41 [[nodiscard]]
virtual model_ptr_type
make_model()
override;
46 [[nodiscard]]
virtual material_ptr_type
make_material(
const const_shader_ptr_type pShader,
51 const const_material_ptr_type &aPrototype)
override;
61 [[nodiscard]] std::size_t texture_count()
const;
64 [[nodiscard]]
virtual model_ptr_type make_sphere_model()
const override;
72 [[nodiscard]] shader_ptr_type make_shader(
const std::string_view aVertexSource,
73 const std::string_view aFragmentSource);
75 [[nodiscard]] std::size_t resources_made()
const;
78 null_context() =
default;
80 std::shared_ptr<const graphics::profile> mProfile;
82 shader_check_type mShaderCheck;
84 std::size_t mTextureCount{0};
86 mutable std::size_t mResourcesMade{0};
88 mutable shader_ptr_type mpAlphaCutoff;
89 mutable shader_ptr_type mpAlphaBlend;
92 class null_shader final :
public shader_program {
94 null_shader(std::string aVertexSource = {}, std::string aFragmentSource = {});
96 [[nodiscard]]
const std::string &vertex_source()
const;
97 [[nodiscard]]
const std::string &fragment_source()
const;
100 std::string mVertexSource;
101 std::string mFragmentSource;
106 null_texture() =
default;
108 null_texture(std::size_t aWidth, std::size_t aHeight);
110 void hold_to(std::shared_ptr<const profile> pProfile);
115 const std::size_t aOffsetY)
override;
117 [[nodiscard]] std::size_t width()
const;
118 [[nodiscard]] std::size_t height()
const;
120 [[nodiscard]] std::size_t upload_count()
const;
122 [[nodiscard]]
const texture_data::channel_data &data()
const;
125 std::shared_ptr<const profile> mProfile;
126 std::size_t mWidth{0};
127 std::size_t mHeight{0};
128 std::size_t mUploadCount{0};
129 std::size_t mChannels{0};
130 std::optional<format> mFormat;
131 texture_data::channel_data mData;
136 class null_model final :
public model {
138 null_model() =
default;
141 void hold_to(std::shared_ptr<const profile> pProfile);
145 [[nodiscard]] std::size_t vertex_count()
const;
147 [[nodiscard]] std::size_t index_count()
const;
149 [[nodiscard]] std::size_t upload_count()
const;
151 [[nodiscard]]
const model_data &last_upload()
const;
154 std::shared_ptr<const profile> mProfile;
155 std::size_t mVertexCount{0};
156 std::size_t mIndexCount{0};
157 std::size_t mUploadCount{0};
158 model_data mLastUpload{};
163 explicit null_material(const_shader_ptr_type pShader =
nullptr,
167 virtual void set_texture(
const std::string_view aName,
texture_ptr_type aValue)
override;
168 virtual void set_float(
const std::string_view aName,
float aValue)
override;
169 virtual void set_vector2(
const std::string_view aName, vector2_type aValue)
override;
170 virtual void set_vector3(
const std::string_view aName, vector3_type aValue)
override;
171 virtual void set_vector4(
const std::string_view aName, vector4_type aValue)
override;
173 virtual void set_integer(
const std::string_view aName,
int aValue)
override;
174 virtual void set_integer2(
const std::string_view aName,
int a1,
int a2)
override;
175 virtual void set_integer3(
const std::string_view aName,
int a1,
int a2,
int a3)
override;
176 virtual void set_integer4(
const std::string_view aName,
int a1,
int a2,
int a3,
int a4)
override;
179 const std::vector<intvector2_type> &aValue)
override;
181 [[nodiscard]] std::optional<float> float_at(std::string_view aName)
const;
182 [[nodiscard]] std::optional<vector4_type> vector4_at(std::string_view aName)
const;
185 [[nodiscard]] std::vector<std::string> uniforms()
const;
190 const_shader_ptr_type mpShader;
194 std::map<std::string, float, std::less<>> mFloats;
195 std::map<std::string, vector4_type, std::less<>> mVector4s;
196 std::map<std::string, texture_ptr_type, std::less<>> mTextures;
197 std::set<std::string> mNames;
200 class null_entity final :
public entity {
204 null_entity(const_model_ptr_type pModel, const_material_ptr_type pMaterial);
211 const quaternion_type &aRotation,
const vector3_type &aScale)
override;
215 virtual void set_bounds(
const vector3_type &aCentre, floating_point_type aRadius)
override;
217 [[nodiscard]]
const matrix4x4_type &transform()
const;
219 [[nodiscard]]
const std::optional<std::pair<vector3_type, floating_point_type>> &bounds()
const;
220 [[nodiscard]] const_model_ptr_type model()
const;
221 [[nodiscard]] const_material_ptr_type material()
const;
224 const_model_ptr_type mpModel;
225 const_material_ptr_type mpMaterial;
227 matrix4x4_type mTransform;
229 std::optional<std::pair<vector3_type, floating_point_type>> mBounds;
235 const floating_point_type aNear,
const floating_point_type aFar,
236 const floating_point_type aAspectRatio)
override;
239 const floating_point_type aNear,
const floating_point_type aFar,
240 const floating_point_type aAspectRatio,
const vector2_type &aShift)
override;
243 const floating_point_type aNear,
const floating_point_type aFar,
244 const floating_point_type aAspectRatio)
override;
249 const quaternion_type &aRotation)
override;
255 const float aWidth,
const float aHeight)
override;
258 const float aWidth,
const float aHeight)
override;
260 virtual void clear_scissor()
override;
262 [[nodiscard]] std::array<float, 4> scissor()
const;
264 [[nodiscard]]
const vector3_type &position()
const;
265 [[nodiscard]]
const quaternion_type &rotation()
const;
266 [[nodiscard]]
const matrix4x4_type &transform()
const;
267 [[nodiscard]]
const color &clear_color()
const;
270 [[nodiscard]] floating_point_type field_of_view()
const;
271 [[nodiscard]] floating_point_type aspect_ratio()
const;
272 [[nodiscard]] floating_point_type near_clip()
const;
273 [[nodiscard]] floating_point_type far_clip()
const;
276 vector3_type mPosition;
277 quaternion_type mRotation;
278 matrix4x4_type mTransform;
282 floating_point_type mFieldOfView{0};
283 floating_point_type mAspectRatio{0};
284 floating_point_type mNear{0};
285 floating_point_type mFar{0};
287 std::array<float, 4> mViewport{0, 0, 1, 1};
289 std::optional<std::array<float, 4>> mScissor;
294 explicit null_texture_camera(
const intvector2_type &aSize = {1024, 1024});
297 const floating_point_type aNear,
const floating_point_type aFar,
298 const floating_point_type aAspectRatio)
override;
301 const floating_point_type aNear,
const floating_point_type aFar,
302 const floating_point_type aAspectRatio,
const vector2_type &aShift)
override;
305 const floating_point_type aNear,
const floating_point_type aFar,
306 const floating_point_type aAspectRatio)
override;
311 const quaternion_type &aRotation)
override;
321 texture_ptr_type mpColor;
322 texture_ptr_type mpDepth;
327 virtual void add(
const std::shared_ptr<const screen_camera> &pCamera)
override;
328 virtual void remove(
const std::shared_ptr<const screen_camera> &pCamera)
override;
330 virtual void add(
const std::shared_ptr<const texture_camera> &pCamera)
override;
331 virtual void remove(
const std::shared_ptr<const texture_camera> &pCamera)
override;
333 virtual void add(
const std::shared_ptr<const entity> &pEntity)
override;
334 virtual void remove(
const std::shared_ptr<const entity> &pEntity)
override;
336 virtual void draw(
const gdk::graphics::intvector2_type &aFrameBufferSize)
const override;
338 virtual void set_float(
const std::string_view aName,
float aValue)
override;
339 virtual void set_vector2(
const std::string_view aName, vector2_type aValue)
override;
340 virtual void set_vector3(
const std::string_view aName, vector3_type aValue)
override;
341 virtual void set_vector4(
const std::string_view aName, vector4_type aValue)
override;
342 virtual void set_vector4(
const std::string_view aName,
const color &aValue)
override;
343 virtual void set_integer(
const std::string_view aName,
int aValue)
override;
345 [[nodiscard]] std::optional<float> float_at(std::string_view aName)
const;
346 [[nodiscard]] std::optional<vector3_type> vector3_at(std::string_view aName)
const;
347 [[nodiscard]] std::optional<vector4_type> vector4_at(std::string_view aName)
const;
349 [[nodiscard]] std::size_t entity_count()
const;
351 [[nodiscard]] std::vector<std::shared_ptr<const entity>> entities()
const;
353 [[nodiscard]] std::size_t camera_count()
const;
354 [[nodiscard]]
bool contains(
const std::shared_ptr<const entity> &pEntity)
const;
356 [[nodiscard]] std::size_t draw_count()
const;
358 [[nodiscard]] intvector2_type last_frame_buffer_size()
const;
361 mutable std::vector<std::weak_ptr<const entity>> mEntities;
362 mutable std::vector<std::weak_ptr<const screen_camera>> mScreenCameras;
363 mutable std::vector<std::weak_ptr<const texture_camera>> mTextureCameras;
365 std::map<std::string, float, std::less<>> mFloats;
366 std::map<std::string, vector2_type, std::less<>> mVector2s;
367 std::map<std::string, vector3_type, std::less<>> mVector3s;
368 std::map<std::string, vector4_type, std::less<>> mVector4s;
369 std::map<std::string, int, std::less<>> mIntegers;
371 mutable std::size_t mDrawCount{0};
372 mutable intvector2_type mLastFrameBufferSize{0, 0};
clear_mode
controls which buffers in the active frame buffer object to clear
Definition camera.h:15
@ color_and_depth
Clear the color and depth buffers.
Definition camera.h:17
entry point for gdk-graphics
Definition context.h:23
virtual material_ptr_type make_material(const const_shader_ptr_type pShader, const material::render_mode aRenderMode, const material::face_culling_mode aFaceCullingMode)=0
make a material.
virtual texture_ptr_type make_texture(const texture_data::view &aTextureDataView, const texture::wrap_mode aWrapModeU, const texture::wrap_mode aWrapModeV, const texture::filter_mode aFilterMode)=0
make a texture
represents an observable 3d object.
Definition entity.h:13
virtual void set_transform(const vector3_type &aWorldPos, const quaternion_type &aRotation, const vector3_type &aScale)=0
sets the model matrix using a vec3 position, quat rotation, vec3 scale
decides how models using the material should be drawn.
Definition material.h:21
std::shared_ptr< gdk::graphics::texture > texture_ptr_type
textures can be shared among many materials.
Definition material.h:39
render_mode
render mode decides transparency etc
Definition material.h:32
@ opaque
no transparency
Definition material.h:33
face_culling_mode
specify whether front- or back-facing polygons can be culled
Definition material.h:24
@ none
do not cull any polygons
Definition material.h:28
vertex data stored in system memory.
Definition model_data.h:25
usage_hint
Definition model.h:12
Definition null_context.h:232
virtual void set_clear_mode(const clear_mode aClearMode) override
clear mode decides which buffers to clear. see enum
virtual void set_clear_color(const color &aColor) override
sets the clear color, used to fill color buffer after it is cleared.
virtual void set_transform(const matrix4x4_type &aTransform) override
sets the camera's world and view matrix
virtual void set_viewport(const float aX, const float aY, const float aWidth, const float aHeight) override
sets the normalized size and position of the viewport within the window
virtual void set_orthographic_projection(const vector2_type &aOrthographicSize, const floating_point_type aNear, const floating_point_type aFar, const floating_point_type aAspectRatio) override
use an orthographic projection with the given view volume aOrthographicSize is the full extent of the...
virtual void set_perspective_projection(const floating_point_type aFieldOfView, const floating_point_type aNear, const floating_point_type aFar, const floating_point_type aAspectRatio) override
use a perspective projection with the given view volume
virtual void set_scissor(const float aX, const float aY, const float aWidth, const float aHeight) override
clip this camera to a rectangle of the window without moving what it draws
virtual void set_perspective_projection(const floating_point_type aFieldOfView, const floating_point_type aNear, const floating_point_type aFar, const floating_point_type aAspectRatio, const vector2_type &aShift) override
use a perspective projection whose window is off the view's axis: an asymmetric frustum,...
virtual graphics::limits limits() const override
the limits of the device, narrowed to the context's profile when it was given one
virtual entity_ptr_type make_entity(const const_model_ptr_type pModel, const const_material_ptr_type pMaterial) override
make an entity
virtual model_ptr_type make_model(const gdk::graphics::model::usage_hint, const model_data &aModelData) override
make a model
virtual material_ptr_type make_material(const const_shader_ptr_type pShader, const material::render_mode aRenderMode, const material::face_culling_mode aFaceCullingMode) override
make a material.
virtual material_ptr_type make_material(const const_material_ptr_type &aPrototype) override
make a material that starts as a copy of another
virtual shader_ptr_type make_alpha_blend_shader() const override
a shader that keeps the texel's alpha, for the blender to use.
virtual texture_ptr_type make_texture() override
make an empty texture
virtual scene_ptr_type make_scene() override
makes a scene
virtual shader_ptr_type make_alpha_cutoff_shader() const override
Basic unlit forward renderer program: Attributes:
virtual model_ptr_type make_cube_model() const override
a 1x1x1 cube model
virtual texture_camera_ptr_type make_texture_camera() override
makes a texture_camera drawing into textures 1024 texels square
virtual screen_camera_ptr_type make_camera() override
makes a camera that draws to the screen
virtual texture_ptr_type make_texture(const texture_data::view &aTextureDataView, const texture::wrap_mode aWrapModeU, const texture::wrap_mode aWrapModeV, const texture::filter_mode aFilterMode) override
make a texture
virtual model_ptr_type make_model() override
make an empty model
virtual texture_camera_ptr_type make_texture_camera(const intvector2_type &aSize) override
makes a texture_camera drawing into textures aSize texels across
virtual bool is_hidden() const override
check if the entity is hidden
virtual void set_transform(const vector3_type &aWorldPos, const quaternion_type &aRotation, const vector3_type &aScale) override
sets the model matrix using a vec3 position, quat rotation, vec3 scale
virtual void set_transform(const matrix4x4_type &aTransform) override
set the model matrix using a matrix
virtual void set_bounds(const vector3_type &aCentre, floating_point_type aRadius) override
the bounding sphere of the model, used for culling
virtual void show() override
allow this entity to be drawn
virtual void hide() override
do not allow this entity to be drawn
virtual void set_integer(const std::string_view aName, int aValue) override
assigns an integer to the material.
virtual void set_int_vector2_array(const std::string_view aName, const std::vector< intvector2_type > &aValue) override
assigns an array of integer vector2s to the material
virtual void set_vector4(const std::string_view aName, const color &aValue) override
assign an RGBA colour to a vec4 uniform
virtual void set_vector2(const std::string_view aName, vector2_type aValue) override
assigns a 2 component vector
virtual void set_integer3(const std::string_view aName, int a1, int a2, int a3) override
assigns a 3 integer array to the material.
virtual void set_float(const std::string_view aName, float aValue) override
assigns a float to the material.
virtual void set_vector4(const std::string_view aName, vector4_type aValue) override
assigns a 4 component vector
virtual void set_vector3(const std::string_view aName, vector3_type aValue) override
assigns a 3 component vector
virtual void set_integer2(const std::string_view aName, int a1, int a2) override
assigns a 2 integer array to the material.
virtual void set_integer4(const std::string_view aName, int a1, int a2, int a3, int a4) override
assigns a 4 integer array to the material.
virtual void upload(const usage_hint &aUsage, const model_data &aModelData) override
replace vertex data held by this model
Definition null_context.h:325
virtual void draw(const gdk::graphics::intvector2_type &aFrameBufferSize) const override
draws the scene
virtual void set_clear_color(const color &aColor) override
sets the clear color, used to fill color buffer after it is cleared.
virtual texture_ptr_type depth_texture() const override
the texture the camera draws depth into
virtual texture_ptr_type color_texture() const override
the texture the camera draws colour into
virtual void set_perspective_projection(const floating_point_type aFieldOfView, const floating_point_type aNear, const floating_point_type aFar, const floating_point_type aAspectRatio) override
use a perspective projection with the given view volume
virtual void set_perspective_projection(const floating_point_type aFieldOfView, const floating_point_type aNear, const floating_point_type aFar, const floating_point_type aAspectRatio, const vector2_type &aShift) override
use a perspective projection whose window is off the view's axis: an asymmetric frustum,...
virtual void set_orthographic_projection(const vector2_type &aOrthographicSize, const floating_point_type aNear, const floating_point_type aFar, const floating_point_type aAspectRatio) override
use an orthographic projection with the given view volume aOrthographicSize is the full extent of the...
virtual void set_clear_mode(const clear_mode aClearMode) override
clear mode decides which buffers to clear. see enum
virtual void set_transform(const matrix4x4_type &aTransform) override
sets the camera's world and view matrix
virtual void update_data(const texture_data::view &aView) override
replace the texture data with new data
virtual void update_data(const texture_data::view &aView, const std::size_t aOffsetX, const std::size_t aOffsetY) override
update a section of texture data
a 3d environment within which cameras draw entities
Definition scene.h:18
Position, orientation and perspective from which entity(s) are drawn.
Definition screen_camera.h:12
texture camera renders to textures instead of the screen
Definition texture_camera.h:12
texture()=default
interface type cannot be instantiated
filter_mode
how a texel is chosen when a pixel does not land exactly on one
Definition texture.h:27
wrap_mode
behavior when sampling outside of the normalized texture range (u0-1, v0-1)
Definition texture.h:20
@ repeat
sampled values repeat. e.g: {2,2}, {3,3}, 100,100} would all sample {1,1}
Definition texture.h:22
Represents a 4 channel color: {Red, Green, Blue, Alpha}.
Definition color.h:10
static const color black
opaque black color
Definition color.h:51
used to (optionally) enforce limits on graphical types used across graphics apis
Definition limits.h:12
a target's limits
Definition profile.h:18
provides a pointer a contiguous list of channel data representing 2D texture metadata that contains i...
Definition texture_data.h:27
what the core takes: decoded channel data and the metadata describing it