Framebuffer.h
1 /*
2 
3 Copyright (c) 2018, Johnathan Corkery. (jcorkery@umich.edu)
4 All rights reserved.
5 
6 This file is part of the Dynacoe project (https://github.com/jcorks/Dynacoe)
7 Dynacoe was released under the MIT License, as detailed below.
8 
9 
10 
11 Permission is hereby granted, free of charge, to any person obtaining a copy
12 of this software and associated documentation files (the "Software"), to deal
13 in the Software without restriction, including without limitation the rights
14 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 copies of the Software, and to permit persons to whom the Software is furnished
16 to do so, subject to the following conditions:
17 
18 The above copyright notice and this permission notice shall
19 be included in all copies or substantial portions of the Software.
20 
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 DEALINGS IN THE SOFTWARE.
28 
29 
30 
31 */
32 
33 #ifndef H_DC_FRAMEBUFFER_INCLUDED
34 #define H_DC_FRAMEBUFFER_INCLUDED
35 
36 #include <Dynacoe/Backends/Backend.h>
37 namespace Dynacoe {
38 
39 
49 class Framebuffer : public Backend {
50  public:
51 
55  enum class Type {
57  GLFBPacket,
58  Unknown,
60  };
61 
62 
65  bool Resize(int newW, int newH) {
66  if (!OnResize(data, newW, newH))
67  return false;
68 
69  w = newW;
70  h = newH;
71  return true;
72  }
73 
78  void * GetHandle() {return data;}
79 
82  int Width() {return w;}
83 
86  int Height() {return h;}
87 
90  Type GetHandleType() {return type;}
91 
97  virtual bool GetRawData(uint8_t *) = 0;
98 
110  void SetFilteredHint(bool filter) {if (filtered!=filter) {filtered=filter; OnFilterChange(filter);}}
111 
116  bool GetFilteredHint() {return filtered;}
117 
118  protected:
119  // can only create new framebuffers from a direct constructor
120  Framebuffer(Type type_, int w_, int h_, void * data_ ) :
121  type(type_),
122  w(w_),
123  h(w_),
124  data(data_),
125  filtered(true)
126  {}
127 
128  // called on resize event to actually perform the resize action
129  // on the data.
130  virtual bool OnResize(void * source, int newW, int newH) = 0;
131 
132  // Called when SetFilteredHint is called
133  virtual void OnFilterChange(bool) = 0;
134  private:
135  int w;
136  int h;
137  void * data;
138  Type type;
139  bool filtered;
140 };
141 }
142 
143 #endif
Type
Types refer to the internal class by which visual information is passed to the Display.
Definition: Framebuffer.h:55
(uint8_t *) RGBA-ordered pixel array with no padding, matched to the dimensions given ...
Backend.
Definition: Backend.h:56
Contains a visual state.
Definition: Framebuffer.h:49
bool GetFilteredHint()
Returns whether to interpret the Framebuffer's data in a filtered way.
Definition: Framebuffer.h:116
Definition: AssetID.h:37
void * GetHandle()
Returns the source data that reflects the framebuffer's data in the context of the implemented child...
Definition: Framebuffer.h:78
bool Resize(int newW, int newH)
Resizes the framebuffer. Success is returned.
Definition: Framebuffer.h:65
Type GetHandleType()
Returns what type the handle refers to.
Definition: Framebuffer.h:90
int Height()
Returns the height of the framebuffer.
Definition: Framebuffer.h:86
void SetFilteredHint(bool filter)
Sets whether to interpret the Framebuffer's data in a filtered way.
Definition: Framebuffer.h:110
The framebuffer's data contents are unknown and should not be relied on.
int Width()
Returns the width of the framebuffer.
Definition: Framebuffer.h:82
virtual bool GetRawData(uint8_t *)=0
returns a RGBF pixel reduction by setting the buffer given. if this isnt possible, false is returned. the buffer should be of size Width*Height*4. Note that on hardware-accelerated implementations, calling this could be very costly. Alpha color information is always 1.f