source: trunk/src/platform/ps3/ps3app.cpp @ 2316

Last change on this file since 2316 was 2316, checked in by sam, 7 years ago

ps3: fix typo in ps3app.cpp.

  • Property svn:keywords set to Id
File size: 4.3 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://www.wtfpl.net/ for more details.
9//
10
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#if defined __CELLOS_LV2__
16#   include <sys/ppu_thread.h> /* sys_ppu_thread_get_stack_information */
17#   include <sys/spu_initialize.h>
18#   include <sys/paths.h> /* SYS_HOST_ROOT */
19#   include <cell/sysmodule.h>
20#   include <PSGL/psgl.h>
21#endif
22
23#include "core.h"
24#include "lolgl.h"
25#include "ps3app.h"
26#include "ps3input.h"
27
28namespace lol
29{
30
31/*
32 * PS3 App implementation class
33 */
34
35class Ps3AppData
36{
37    friend class Ps3App;
38
39private:
40#if defined __CELLOS_LV2__
41    static void SysCallBack(uint64_t status, uint64_t param, void *data)
42    {
43        if (status == CELL_SYSUTIL_REQUEST_EXITGAME)
44            Ticker::Shutdown();
45    }
46#endif
47};
48
49/*
50 * Public Ps3App class
51 */
52
53Ps3App::Ps3App(char const *title, ivec2 res, float fps) :
54    data(new Ps3AppData())
55{
56#if defined __CELLOS_LV2__
57    sys_spu_initialize(6, 1);
58
59    /* FIXME: we should check for CELL_SYSMODULE_ERROR_UNKNOWN and others,
60     * but what could we do anyway? */
61    cellSysmoduleLoadModule(CELL_SYSMODULE_GCM_SYS);
62    cellSysmoduleLoadModule(CELL_SYSMODULE_FS);
63    cellSysmoduleLoadModule(CELL_SYSMODULE_USBD);
64    cellSysmoduleLoadModule(CELL_SYSMODULE_IO);
65
66    cellSysutilRegisterCallback(0, Ps3AppData::SysCallBack, NULL);
67
68    PSGLinitOptions psglio;
69    psglio.enable = PSGL_INIT_MAX_SPUS
70                  | PSGL_INIT_INITIALIZE_SPUS
71                  | PSGL_INIT_HOST_MEMORY_SIZE;
72    psglio.maxSPUs = 1;
73    psglio.initializeSPUs = false;
74    psglio.hostMemorySize = 128 * 1024 * 1024;
75
76    psglInit(&psglio);
77
78#if 0
79    sys_ppu_thread_stack_t stack;
80    sys_ppu_thread_get_stack_information(&stack);
81    printf("stack starts at %p, ends at %p\n", stack.pst_addr,
82           (uint8_t *)stack.pst_addr + stack.pst_size);
83#endif
84
85    PSGLdeviceParameters psgldp;
86    psgldp.enable = PSGL_DEVICE_PARAMETERS_COLOR_FORMAT
87                  | PSGL_DEVICE_PARAMETERS_DEPTH_FORMAT
88                  | PSGL_DEVICE_PARAMETERS_MULTISAMPLING_MODE
89                  | PSGL_DEVICE_PARAMETERS_WIDTH_HEIGHT;
90    psgldp.colorFormat = GL_ARGB_SCE; /* can also be GL_RGBA16F_ARB */
91    psgldp.depthFormat = GL_DEPTH_COMPONENT16; /* can also be 24-bit */
92    psgldp.multisamplingMode = GL_MULTISAMPLING_4X_SQUARE_ROTATED_SCE;
93    psgldp.width = 720;
94    psgldp.height = 480;
95
96    /* Find closest valid resolution */
97    ivec2 const valid_resolutions[8] =
98    {
99        ivec2( 720,  480),
100        ivec2( 720,  576),
101        ivec2(1280,  720),
102        ivec2(1920, 1080),
103        ivec2( 960, 1080),
104        ivec2(1280, 1080),
105        ivec2(1440, 1080),
106        ivec2(1600, 1080),
107    };
108
109    for (int i = 0; i < 8; ++i)
110    {
111        ivec2 cur(psgldp.width, psgldp.height);
112        if (sqlength(valid_resolutions[i] - res) < sqlength(cur - res))
113        {
114            psgldp.width = valid_resolutions[i].x;
115            psgldp.height = valid_resolutions[i].y;
116        }
117    }
118
119    /* Create graphics device */
120    PSGLdevice* psgl = psglCreateDeviceExtended(&psgldp);
121    if (!psgl)
122        Log::Error("could not create PSGL device; expect imminent crash\n");
123
124    GLuint w, h;
125    psglGetDeviceDimensions(psgl, &w, &h);
126    ivec2 newres(w, h);
127    Log::Debug("resolution asked %d×%d, closest valid %d×%d, final %d×%d\n",
128               res.x, res.y, psgldp.width, psgldp.height, newres.x, newres.y);
129
130    PSGLcontext *ctx = psglCreateContext();
131    psglMakeCurrent(ctx, psgl);
132    /* TODO: load our shaders when we actually ship them */
133    //psglLoadShaderLibrary("/shaders.bin");
134    psglResetCurrentContext();
135
136    /* Initialise everything */
137    Ticker::Setup(fps);
138    Video::Setup(newres);
139    Audio::Setup(2);
140
141    /* Autoreleased objects */
142    new Ps3Input();
143#endif
144}
145
146void Ps3App::ShowPointer(bool show)
147{
148    ;
149}
150
151void Ps3App::Tick()
152{
153    /* Tick the renderer, show the frame and clamp to desired framerate. */
154    Ticker::TickDraw();
155
156#if defined __CELLOS_LV2__
157    psglSwap();
158
159    /* Check if exit callback was called */
160    cellSysutilCheckCallback();
161#endif
162}
163
164Ps3App::~Ps3App()
165{
166#if defined __CELLOS_LV2__
167    glFinish();
168#endif
169    delete data;
170}
171
172} /* namespace lol */
173
Note: See TracBrowser for help on using the repository browser.