gdk-graphics  1b6d84e044c2c953fd7c9501e628a67e80f4da0d
webgl1es2_texture_camera.h
1 // © Joseph Cameron - All Rights Reserved
2 
3 #ifndef GDK_GFX_WEBGL1ES2_TEXTURE_CAMERA_H
4 #define GDK_GFX_WEBGL1ES2_TEXTURE_CAMERA_H
5 
6 #include <gdk/color.h>
7 #include <gdk/graphics_types.h>
8 #include <gdk/texture_camera.h>
9 #include <gdk/webgl1es2_camera.h>
10 #include <gdk/webgl1es2_texture.h>
11 
12 #include <jfc/unique_handle.h>
13 
14 #include <memory>
15 #include <optional>
16 #include <vector>
17 
18 namespace gdk
19 {
20  class entity;
21 
24  {
25  public:
28  //
29  virtual void set_perspective_projection(const float aFieldOfView,
30  const float aNearClippingPlane,
31  const float aFarClippingPlane,
32  const float aViewportAspectRatio) override;
33 
34  virtual void set_orthographic_projection(const float aWidth,
35  const float aHeight,
36  const float aNearClippingPlane,
37  const float aFarClippingPlane,
38  const float aViewportAspectRatio) override;
39 
40  virtual void set_clear_color(const gdk::color& acolor) override;
41 
42  virtual void set_clear_mode(const clear_mode aClearMode) override;
43 
44  virtual void set_view_matrix(const gdk::graphics_vector3_type& aWorldPos,
45  const gdk::graphics_quaternion_type& aRotation) override;
46 
47  virtual const std::shared_ptr<gdk::texture> get_color_texture(size_t i) const override;
48 
49  virtual const std::shared_ptr<gdk::texture> get_depth_texture() const override;
51 
54  //
55  void activate() const;
57 
58  webgl1es2_texture_camera(const graphics_intvector2_type &textureSize = {1024, 1024});
59 
60  ~webgl1es2_texture_camera() = default;
61 
62  private:
63  graphics_intvector2_type m_TextureSize;
64 
66  jfc::unique_handle<GLuint> m_FrameBufferHandle;
67 
69  jfc::unique_handle<GLuint> m_DepthBuffer;
70 
72  mutable std::optional<std::shared_ptr<webgl1es2_texture>> m_ColorBufferTexture;
73 
75  mutable std::optional<std::shared_ptr<webgl1es2_texture>> m_DepthBufferTexture;
76  };
77 }
78 
79 #endif
80 
texture camera renders to textures instead of the screen
Definition: texture_camera.h:13
virtual void set_clear_color(const gdk::color &acolor) override
sets the clear color, used to fill color buffer after it is cleared.
virtual void set_clear_mode(const clear_mode aClearMode) override
clear mode decides which buffers to clear. see enum
Definition: camera.h:9
webgl1es2_camera implementation of texture_camera
Definition: webgl1es2_texture_camera.h:23
virtual void set_perspective_projection(const float aFieldOfView, const float aNearClippingPlane, const float aFarClippingPlane, const float aViewportAspectRatio) override
sets the projection matrix to a perspective projection
virtual const std::shared_ptr< gdk::texture > get_color_texture(size_t i) const override
get a texture attached to the color buffer
virtual void set_orthographic_projection(const float aWidth, const float aHeight, const float aNearClippingPlane, const float aFarClippingPlane, const float aViewportAspectRatio) override
sets the projection matrix to an orthographic projection
clear_mode
Describes camera clear behaviour: which buffers in the current FBO should be cleared?
Definition: camera.h:16
virtual void set_view_matrix(const gdk::graphics_vector3_type &aWorldPos, const gdk::graphics_quaternion_type &aRotation) override
rebuilds the view matrix from a 3d position and rotation
webgl1es2_camera implementation of camera
Definition: webgl1es2_camera.h:21
virtual const std::shared_ptr< gdk::texture > get_depth_texture() const override
get the texture attached to the depth buffer
Represents a 4 channel color: {Red, Green, Blue, Alpha}.
Definition: color.h:11