openMSX
SDLGLOutputSurface.cc
Go to the documentation of this file.
2 #include "GLContext.hh"
3 #include "OutputSurface.hh"
4 #include "PNG.hh"
5 #include "build-info.hh"
6 #include "Math.hh"
7 #include "MemBuffer.hh"
8 #include "vla.hh"
9 #include <SDL.h>
10 
11 using namespace gl;
12 
13 namespace openmsx {
14 
16  : fbTex(Null())
18 {
19 }
20 
22 {
23  // This is logically a part of the constructor, but the constructor
24  // of the child class needs to run before this code (to create a
25  // openGL context). So we split the constructor in two parts, the
26  // child class is responsible for calling this second part.
27 
33 
34  if (frameBuffer == FB_NONE) {
35  output.setBufferPtr(nullptr, 0); // direct access not allowed
36  } else {
37  // TODO 64 byte aligned (see RawFrame)
38  unsigned width = output.getWidth();
39  unsigned height = output.getHeight();
40  unsigned texW = Math::ceil2(width);
41  unsigned texH = Math::ceil2(height);
43  unsigned pitch = width * format->BytesPerPixel;
45 
46  texCoordX = float(width) / texW;
47  texCoordY = float(height) / texH;
48 
49  fbTex.allocate();
50  fbTex.setInterpolation(false);
51  if (frameBuffer == FB_16BPP) {
52  // TODO: Why use RGB texture instead of RGBA?
55  } else {
58  }
59  }
60 }
61 
63 {
64  assert((frameBuffer == FB_16BPP) || (frameBuffer == FB_32BPP));
65 
66  fbTex.bind();
67  if (frameBuffer == FB_16BPP) {
70  } else {
73  }
74 
75  vec2 pos[4] = {
76  vec2(0, height),
77  vec2(width, height),
78  vec2(width, 0 ),
79  vec2(0, 0 ),
80  };
81  vec2 tex[4] = {
82  vec2(0.0f, texCoordY),
84  vec2(texCoordX, 0.0f ),
85  vec2(0.0f, 0.0f ),
86  };
88  glUniform4f(gl::context->unifTexColor, 1.0f, 1.0f, 1.0f, 1.0f);
90  &gl::context->pixelMvp[0][0]);
98 }
99 
101 {
102  glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
104 }
105 
107  const std::string& filename, const OutputSurface& output) const
108 {
111 
112  VLA(const void*, rowPointers, size[1]);
113  MemBuffer<uint8_t> buffer(size[0] * size[1] * 3);
114  for (int i = 0; i < size[1]; ++i) {
115  rowPointers[size[1] - 1 - i] = &buffer[size[0] * 3 * i];
116  }
118  PNG::save(size[0], size[1], rowPointers, filename);
119 }
120 
121 } // namespace openmsx
bool getEnum() const noexcept
Definition: EnumSetting.hh:96
#define VLA(TYPE, NAME, LENGTH)
Definition: vla.hh:10