PS2GL
OpenGL*-like API for the PS2
Loading...
Searching...
No Matches
displaycontext.cpp
1/* Copyright (C) 2000,2001,2002 Sony Computer Entertainment America
2
3 This file is subject to the terms and conditions of the GNU Lesser
4 General Public License Version 2.1. See the file "COPYING" in the
5 main directory of this archive for more details. */
6
7#include "GL/ps2gl.h"
8
9#include "ps2gl/displaycontext.h"
10#include "ps2gl/dlist.h"
11
12#include "ps2s/displayenv.h"
13
14CDisplayContext::CDisplayContext(CGLContext& context)
15 : GLContext(context)
16 , Frame0Mem(NULL)
17 , Frame1Mem(NULL)
18 , CurFrameMem(NULL)
19 , LastFrameMem(NULL)
20 , DisplayEnv(NULL)
21 , DisplayIsDblBuffered(true)
22 , DisplayIsInterlaced(true)
23{
24 DisplayEnv = new GS::CDisplayEnv;
25}
26
27CDisplayContext::~CDisplayContext()
28{
29 // don't delete the frame mem areas -- they are created/destroyed by
30 // the app
31
32 delete DisplayEnv;
33}
34
35void CDisplayContext::SetDisplayBuffers(bool interlaced,
36 GS::CMemArea* frame0Mem, GS::CMemArea* frame1Mem)
37{
38 Frame0Mem = frame0Mem;
39 Frame1Mem = frame1Mem;
40
41 DisplayIsDblBuffered = (frame0Mem && frame1Mem);
42 DisplayIsInterlaced = interlaced;
43
44 // "current" means the frame being drawn to by the loop of code executing on the core
45 // "last" will be the frame being displayed if drawing immediately, or the frame not
46 // displayed now if building up a packet to be sent next frame.
47 CurFrameMem = Frame0Mem;
48 LastFrameMem = Frame1Mem;
49
50 int width = frame0Mem->GetWidth(), height = frame0Mem->GetHeight();
51 int displayHeight = (DisplayIsInterlaced) ? height * 2 : height;
52
53 DisplayEnv->SetFB2(frame0Mem->GetWordAddr(), width, 0, 0, frame0Mem->GetPixFormat());
54 DisplayEnv->SetDisplay2(width, displayHeight);
55 DisplayEnv->SendSettings();
56}
57
58void CDisplayContext::SwapBuffers()
59{
60 // flip frame buffer ptrs
61 if (DisplayIsDblBuffered) {
62 GS::CMemArea* temp = CurFrameMem;
63 CurFrameMem = LastFrameMem;
64 LastFrameMem = temp;
65
66 // display the last completed frame (which is frame n-2 because we're not
67 // drawing immediately but building up a packet)
68 // remember this is immediately sent, not delayed through a packet
69 DisplayEnv->SetFB2Addr(CurFrameMem->GetWordAddr());
70 DisplayEnv->SendSettings();
71 }
72}
73
74/********************************************
75 * ps2gl C interface
76 */
77
89void pglSetDisplayBuffers(int interlaced, pgl_area_handle_t frame0_mem, pgl_area_handle_t frame1_mem)
90{
91 pGLContext->GetDisplayContext().SetDisplayBuffers(interlaced,
92 reinterpret_cast<GS::CMemArea*>(frame0_mem),
93 reinterpret_cast<GS::CMemArea*>(frame1_mem));
94}
95
// pgl_api
97
98/********************************************
99 * gl api
100 */
101
102void glPixelStorei(GLenum pname, int param)
103{
104 GL_FUNC_DEBUG("%s\n", __FUNCTION__);
105
106 mNotImplemented();
107}
108
109void glReadPixels(int x, int y, int width, int height,
110 GLenum format, GLenum type, void* pixels)
111{
112 GL_FUNC_DEBUG("%s(%d,%d,%d,%d,...)\n", __FUNCTION__, x, y, width, height);
113
114 mNotImplemented();
115}
116
117void glViewport(GLint x, GLint y,
118 GLsizei width, GLsizei height)
119{
120 GL_FUNC_DEBUG("%s(%d,%d,%d,%d)\n", __FUNCTION__, x, y, width, height);
121
122 mNotImplemented();
123}
void pglSetDisplayBuffers(int interlaced, pgl_area_handle_t frame0_mem, pgl_area_handle_t frame1_mem)