openMSX
OutputSurface.cc
Go to the documentation of this file.
1 #include "OutputSurface.hh"
2 #include "unreachable.hh"
3 #include "build-info.hh"
4 
5 namespace openmsx {
6 
8 {
9  if (isLocked()) return;
10  locked = true;
11  if (surface && SDL_MUSTLOCK(surface)) {
12  // Note: we ignore the return value from SDL_LockSurface()
13  SDL_LockSurface(surface);
14  }
15 }
16 
18 {
19  if (!isLocked()) return;
20  locked = false;
21  if (surface && SDL_MUSTLOCK(surface)) {
22  SDL_UnlockSurface(surface);
23  }
24 }
25 
27 {
28  m_physSize = physSize_;
29  gl::vec2 physSize(physSize_);
30 
31  gl::vec2 logSize = gl::vec2(getLogicalSize());
32  float scale = min_component(physSize / logSize);
33  m_viewScale = gl::vec2(scale); // for now always same X and Y scale
34 
35  gl::vec2 viewSize = logSize * scale;
36  m_viewSize = round(viewSize);
37 
38  gl::vec2 viewOffset = (physSize - viewSize) / 2.0f;
39  m_viewOffset = round(viewOffset);
40 }
41 
42 void OutputSurface::setSDLFormat(const SDL_PixelFormat& format_)
43 {
44  format = format_;
45 #if HAVE_32BPP
46  // SDL sets an alpha channel only for GL modes. We want an alpha channel
47  // for all 32bpp output surfaces, so we add one ourselves if necessary.
48  if (format.BytesPerPixel == 4 && format.Amask == 0) {
49  unsigned rgbMask = format.Rmask | format.Gmask | format.Bmask;
50  if ((rgbMask & 0x000000FF) == 0) {
51  format.Amask = 0x000000FF;
52  format.Ashift = 0;
53  format.Aloss = 0;
54  } else if ((rgbMask & 0xFF000000) == 0) {
55  format.Amask = 0xFF000000;
56  format.Ashift = 24;
57  format.Aloss = 0;
58  } else {
60  }
61  }
62 #endif
63 }
64 
65 void OutputSurface::setBufferPtr(char* data_, unsigned pitch_)
66 {
67  data = data_;
68  pitch = pitch_;
69 }
70 
72 {
73 }
74 
75 } // namespace openmsx
T min_component(const vecN< N, T > &x)
Definition: gl_vec.hh:278
void lock()
Lock this OutputSurface.
Definition: OutputSurface.cc:7
void setBufferPtr(char *data, unsigned pitch)
gl::ivec2 getLogicalSize() const
mat4 scale(const vec3 &xyz)
Definition: gl_transform.hh:19
void setSDLFormat(const SDL_PixelFormat &format)
virtual void flushFrameBuffer()
For SDLGL-FB-nn, copy frame buffer to OpenGL display.
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
void unlock()
Unlock this OutputSurface.
void calculateViewPort(gl::ivec2 physSize)
vecN< 2, float > vec2
Definition: gl_vec.hh:139
bool isLocked() const
Is this OutputSurface currently locked?
#define UNREACHABLE
Definition: unreachable.hh:38