Simulant  21.12-194
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
screen.h
1 #pragma once
2 
3 #include <vector>
4 
5 #include "generic/managed.h"
6 #include "generic/data_carrier.h"
7 #include "threads/mutex.h"
8 
9 namespace smlt {
10 
11 class Window;
12 
13 enum ScreenFormat {
14  SCREEN_FORMAT_G1, /* 1 grey bit per pixel */
15  SCREEN_FORMAT_MAX
16 };
17 
18 class Screen:
19  public RefCounted<Screen>,
20  public generic::DataCarrier {
21 
22 public:
23  Screen(Window* window, const std::string& name);
24 
25  /* Render image data. data must be of size width x height x bits where bits
26  * is defined by the ScreenFormat. Data should be arranged from top-left.
27  *
28  * Rendering is not instantaneous, submitting images too quickly could result
29  * in some images being skipped.
30  *
31  * refresh_rate will give you some indication of the rate to submit images,
32  * but if you experience frame skipping then reduce the update time.
33  *
34  * You can use a Scene fixed_update, a Behaviour or window->idle->add_timeout
35  * to update with a regular frequency.
36  */
37  void render(const uint8_t* data, ScreenFormat format);
38 
39  uint16_t height() const {
40  return height_;
41  }
42 
43  uint16_t width() const {
44  return width_;
45  }
46 
47  ScreenFormat format() const {
48  return format_;
49  }
50 
51  uint16_t refresh_rate() const {
52  return refresh_rate_;
53  }
54 
55  /*
56  * If this is greater than one, then
57  * all data sent via render is integer scaled
58  */
59  uint16_t integer_scale() const {
60  return integer_scale_;
61  }
62 
63  /* Private API, should only be called by the window
64  * class that knows how to handle it */
65  void _set_integer_scale(uint8_t scale) {
66  integer_scale_ = scale;
67  }
68 
69  uint32_t data_size() const;
70  std::string name() const;
71 
72 private:
73  Window* window_;
74  std::string name_;
75 
76  uint16_t width_ = 0;
77  uint16_t height_ = 0;
78  ScreenFormat format_ = SCREEN_FORMAT_G1;
79  uint16_t refresh_rate_ = 60;
80  uint8_t integer_scale_ = 1;
81 
82  std::vector<uint8_t> buffer_;
83  thread::Mutex buffer_mutex_;
84 
85  friend class Window;
86 };
87 
88 }
smlt::RefCounted
Definition: managed.h:65
smlt
Definition: animation.cpp:25
smlt::Window
Definition: window.h:65
smlt::Screen
Definition: screen.h:20
smlt::generic::DataCarrier
Definition: data_carrier.h:37
smlt::thread::Mutex
Definition: mutex.h:25