Ver código fonte

ps3: start a minimal PS3 port using PSGL, but not CG yet.

legacy
Sam Hocevar sam 13 anos atrás
pai
commit
3d4af0869a
23 arquivos alterados com 262 adições e 4 exclusões
  1. +2
    -0
      src/debugfps.cpp
  2. +4
    -0
      src/debugquad.cpp
  3. +2
    -0
      src/debugrecord.cpp
  4. +2
    -0
      src/debugsphere.cpp
  5. +2
    -0
      src/debugstats.cpp
  6. +2
    -0
      src/dict.cpp
  7. +4
    -2
      src/font.cpp
  8. +2
    -0
      src/image.cpp
  9. +2
    -0
      src/layer.cpp
  10. +3
    -0
      src/lolgl.h
  11. +2
    -0
      src/map.cpp
  12. +2
    -0
      src/matrix.cpp
  13. +1
    -1
      src/matrix.h
  14. +1
    -1
      src/numeric.h
  15. +128
    -0
      src/ps3app.cpp
  16. +41
    -0
      src/ps3app.h
  17. +2
    -0
      src/sample.cpp
  18. +6
    -0
      src/scene.cpp
  19. +18
    -0
      src/shader.cpp
  20. +2
    -0
      src/text.cpp
  21. +2
    -0
      src/tileset.cpp
  22. +19
    -0
      src/timer.cpp
  23. +13
    -0
      src/video.cpp

+ 2
- 0
src/debugfps.cpp Ver arquivo

@@ -17,6 +17,8 @@
#include "core.h"
#include "debugfps.h"

using namespace std;

namespace lol
{



+ 4
- 0
src/debugquad.cpp Ver arquivo

@@ -18,6 +18,8 @@
#include "lolgl.h"
#include "loldebug.h"

using namespace std;

namespace lol
{

@@ -159,6 +161,7 @@ void DebugQuad::TickDraw(float deltams)
attr_col = data->shader->GetAttribLocation("in_Color");
attr_tex = data->shader->GetAttribLocation("in_TexCoord");

#if !defined __CELLOS_LV2__
glEnableVertexAttribArray(attr_pos);
glEnableVertexAttribArray(attr_col);
glEnableVertexAttribArray(attr_tex);
@@ -184,6 +187,7 @@ void DebugQuad::TickDraw(float deltams)
glDisableVertexAttribArray(attr_pos);
glDisableVertexAttribArray(attr_col);
glDisableVertexAttribArray(attr_tex);
#endif
}

DebugQuad::~DebugQuad()


+ 2
- 0
src/debugrecord.cpp Ver arquivo

@@ -21,6 +21,8 @@
#include "core.h"
#include "debugrecord.h"

using namespace std;

namespace lol
{



+ 2
- 0
src/debugsphere.cpp Ver arquivo

@@ -24,6 +24,8 @@
#include "lolgl.h"
#include "debugsphere.h"

using namespace std;

namespace lol
{



+ 2
- 0
src/debugstats.cpp Ver arquivo

@@ -17,6 +17,8 @@
#include "core.h"
#include "debugstats.h"

using namespace std;

namespace lol
{



+ 2
- 0
src/dict.cpp Ver arquivo

@@ -21,6 +21,8 @@
# define strcasecmp _stricmp
#endif

using namespace std;

namespace lol
{



+ 4
- 2
src/font.cpp Ver arquivo

@@ -12,11 +12,13 @@
# include "config.h"
#endif

#include <string.h>
#include <stdio.h>
#include <cstring>
#include <cstdio>

#include "core.h"

using namespace std;

namespace lol
{



+ 2
- 0
src/image.cpp Ver arquivo

@@ -26,6 +26,8 @@

#include "core.h"

using namespace std;

namespace lol
{



+ 2
- 0
src/layer.cpp Ver arquivo

@@ -16,6 +16,8 @@

#include "core.h"

using namespace std;

namespace lol
{



+ 3
- 0
src/lolgl.h Ver arquivo

@@ -35,6 +35,9 @@
# if defined __APPLE__ && defined __MACH__
# include <OpenGLES/ES2/gl.h>
# include <OpenGLES/ES2/glext.h>
# elif defined __CELLOS_LV2__
# include <PSGL/psgl.h>
# include <PSGL/psglu.h>
# else
# include <GLES2/gl2.h>
# include <GLES2/gl2ext.h>


+ 2
- 0
src/map.cpp Ver arquivo

@@ -20,6 +20,8 @@

#include "core.h"

using namespace std;

namespace lol
{



+ 2
- 0
src/matrix.cpp Ver arquivo

@@ -17,6 +17,8 @@

#include "core.h"

using namespace std;

namespace lol
{



+ 1
- 1
src/matrix.h Ver arquivo

@@ -113,7 +113,7 @@ namespace lol
\
inline float len() const \
{ \
return sqrtf((float)sqlen()); \
return std::sqrtf((float)sqlen()); \
}

template <typename T> struct Vec2;


+ 1
- 1
src/numeric.h Ver arquivo

@@ -26,7 +26,7 @@ namespace lol
/* Random float value */
static inline float RandF()
{
return (float)rand() / RAND_MAX;
return (float)std::rand() / RAND_MAX;
}

static inline float RandF(float val)


+ 128
- 0
src/ps3app.cpp Ver arquivo

@@ -0,0 +1,128 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
// This program is free software; you can redistribute it and/or
// modify it under the terms of the Do What The Fuck You Want To
// Public License, Version 2, as published by Sam Hocevar. See
// http://sam.zoy.org/projects/COPYING.WTFPL for more details.
//

#if defined HAVE_CONFIG_H
# include "config.h"
#endif

#if defined __CELLOS_LV2__
# include <sys/spu_initialize.h>
# include <sys/paths.h> /* SYS_HOST_ROOT */
# include <cell/sysmodule.h>
# include <PSGL/psgl.h>
#endif

#include "core.h"
#include "lolgl.h"
#include "ps3app.h"

namespace lol
{

/*
* PS3 App implementation class
*/

class Ps3AppData
{
friend class Ps3App;

private:
#if defined __CELLOS_LV2__
static void SysCallBack(uint64_t status, uint64_t param, void *data)
{
if (status == CELL_SYSUTIL_REQUEST_EXITGAME)
Ticker::Shutdown();
}
#endif
};

/*
* Public Ps3App class
*/

Ps3App::Ps3App(char const *title, vec2i res, float fps) :
data(new Ps3AppData())
{
#if defined __CELLOS_LV2__
sys_spu_initialize(6, 1);

/* FIXME: we should check for CELL_SYSMODULE_ERROR_UNKNOWN and others,
* but what could we do anyway? */
cellSysmoduleLoadModule(CELL_SYSMODULE_GCM_SYS);
cellSysmoduleLoadModule(CELL_SYSMODULE_FS);
cellSysmoduleLoadModule(CELL_SYSMODULE_USBD);
cellSysmoduleLoadModule(CELL_SYSMODULE_IO);

cellSysutilRegisterCallback(0, Ps3AppData::SysCallBack, NULL);

PSGLinitOptions psglio =
{
enable: PSGL_INIT_MAX_SPUS | PSGL_INIT_INITIALIZE_SPUS
| PSGL_INIT_HOST_MEMORY_SIZE,
maxSPUs: 1,
initializeSPUs: false,
persistentMemorySize: 0,
transientMemorySize: 0,
errorConsole: 0,
fifoSize: 0,
hostMemorySize: 128 * 1024 * 1024,
};

psglInit(&psglio);

PSGLdevice* psgl = psglCreateDeviceAuto(GL_ARGB_SCE, GL_DEPTH_COMPONENT24,
GL_MULTISAMPLING_4X_SQUARE_ROTATED_SCE);
GLuint w, h;
psglGetDeviceDimensions(psgl, &w, &h);

PSGLcontext *ctx = psglCreateContext();
psglMakeCurrent(ctx, psgl);
psglLoadShaderLibrary(REMOTE_PATH "/shaders.bin");
psglResetCurrentContext();

/* Initialise everything */
Ticker::Setup(fps);
Video::Setup(res);
Audio::Setup(2);
#endif
}

void Ps3App::Run()
{
while (!Ticker::Finished())
{
/* Tick the game */
Ticker::TickGame();

/* Tick the renderer, show the frame and clamp to desired framerate. */
Ticker::TickDraw();

#if defined __CELLOS_LV2__
psglSwap();

/* Check if exit callback was called */
cellSysutilCheckCallback();
#endif

Ticker::ClampFps();
}
}

Ps3App::~Ps3App()
{
#if defined __CELLOS_LV2__
glFinish();
#endif
delete data;
}

} /* namespace lol */


+ 41
- 0
src/ps3app.h Ver arquivo

@@ -0,0 +1,41 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
// This program is free software; you can redistribute it and/or
// modify it under the terms of the Do What The Fuck You Want To
// Public License, Version 2, as published by Sam Hocevar. See
// http://sam.zoy.org/projects/COPYING.WTFPL for more details.
//

//
// The Ps3App class
// ----------------
//

#if !defined __LOL_PS3APP_H__
#define __LOL_PS3APP_H__

#include "matrix.h"

namespace lol
{

class Ps3AppData;

class Ps3App
{
public:
Ps3App(char const *title, vec2i res, float fps);
virtual ~Ps3App();

void Run();

private:
Ps3AppData *data;
};

} /* namespace lol */

#endif // __LOL_PS3APP_H__


+ 2
- 0
src/sample.cpp Ver arquivo

@@ -24,6 +24,8 @@

#include "core.h"

using namespace std;

namespace lol
{



+ 6
- 0
src/scene.cpp Ver arquivo

@@ -157,11 +157,13 @@ void Scene::Render() // XXX: rename to Blit()
attr_pos = stdshader->GetAttribLocation("in_Position");
attr_tex = stdshader->GetAttribLocation("in_TexCoord");

#if !defined __CELLOS_LV2__ // Use cgGetNamedParameter etc.
stdshader->Bind();
uni_mat = stdshader->GetUniformLocation("model_matrix");
glUniformMatrix4fv(uni_mat, 1, GL_FALSE, &model_matrix[0][0]);
uni_tex = stdshader->GetUniformLocation("in_Texture");
glUniform1i(uni_tex, 0);
#endif

glEnable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
@@ -208,6 +210,7 @@ void Scene::Render() // XXX: rename to Blit()
#if defined HAVE_GL_2X
glBindVertexArray(data->vao);
#endif
#if !defined __CELLOS_LV2__ // Use cgGLEnableClientState etc.
glEnableVertexAttribArray(attr_pos);
glEnableVertexAttribArray(attr_tex);

@@ -220,6 +223,7 @@ void Scene::Render() // XXX: rename to Blit()
glBufferData(GL_ARRAY_BUFFER, 12 * (n - i) * sizeof(GLfloat),
texture, GL_STATIC_DRAW);
glVertexAttribPointer(attr_tex, 2, GL_FLOAT, GL_FALSE, 0, 0);
#endif

/* Draw arrays */
glDrawArrays(GL_TRIANGLES, 0, (n - i) * 6);
@@ -227,8 +231,10 @@ void Scene::Render() // XXX: rename to Blit()
#if defined HAVE_GL_2X
glBindVertexArray(0);
#endif
#if !defined __CELLOS_LV2__ // Use cgGLEnableClientState etc.
glDisableVertexAttribArray(attr_pos);
glDisableVertexAttribArray(attr_tex);
#endif

free(vertex);
free(texture);


+ 18
- 0
src/shader.cpp Ver arquivo

@@ -79,6 +79,7 @@ Shader::Shader(char const *vert, char const *frag)
char buf[4096];
GLsizei len;

#if !defined __CELLOS_LV2__
data->vert_crc = Hash::Crc32(vert);
data->vert_id = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(data->vert_id, 1, &vert, NULL);
@@ -103,31 +104,48 @@ Shader::Shader(char const *vert, char const *frag)

glLinkProgram(data->prog_id);
glValidateProgram(data->prog_id);
#endif
}

int Shader::GetAttribLocation(char const *attr) const
{
#if defined __CELLOS_LV2__
return 0;
#else
return glGetAttribLocation(data->prog_id, attr);
#endif
}

int Shader::GetUniformLocation(char const *uni) const
{
#if defined __CELLOS_LV2__
return 0;
#else
return glGetUniformLocation(data->prog_id, uni);
#endif
}

void Shader::Bind() const
{
#if defined __CELLOS_LV2__
;
#else
glUseProgram(data->prog_id);
#endif
}

Shader::~Shader()
{
#if defined __CELLOS_LV2__
;
#else
glDetachShader(data->prog_id, data->vert_id);
glDetachShader(data->prog_id, data->frag_id);
glDeleteShader(data->vert_id);
glDeleteShader(data->frag_id);
glDeleteProgram(data->prog_id);
delete data;
#endif
}

} /* namespace lol */


+ 2
- 0
src/text.cpp Ver arquivo

@@ -18,6 +18,8 @@

#include "core.h"

using namespace std;

namespace lol
{



+ 2
- 0
src/tileset.cpp Ver arquivo

@@ -25,6 +25,8 @@
#include "core.h"
#include "lolgl.h"

using namespace std;

namespace lol
{



+ 19
- 0
src/timer.cpp Ver arquivo

@@ -21,6 +21,10 @@
#elif defined _WIN32
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
#elif defined __CELLOS_LV2__
# include <sys/sys_time.h>
# include <sys/timer.h>
# include <sys/time_util.h>
#else
# include <SDL.h>
#endif
@@ -48,6 +52,9 @@ private:
QueryPerformanceFrequency(&tmp);
ms_per_cycle = 1e3f / tmp.QuadPart;
QueryPerformanceCounter(&cycles0);
#elif defined __CELLOS_LV2__
ms_per_cycle = 1e3f / sys_time_get_timebase_frequency();
SYS_TIMEBASE_GET(cycles0);
#else
SDL_Init(SDL_INIT_TIMER);
ticks0 = SDL_GetTicks();
@@ -76,6 +83,15 @@ private:
towait = deltams - ret;
if (towait > 5e-4f)
Sleep((int)(towait + 0.5f));
#elif defined __CELLOS_LV2__
uint64_t cycles;
SYS_TIMEBASE_GET(cycles);
ret = ms_per_cycle * cycles;
if (update)
cycles0 = cycles;
towait = deltams - ret;
if (towait > 0.0f)
sys_timer_usleep((int)(towait * 1e3f));
#else
/* The crappy SDL fallback */
Uint32 ticks = SDL_GetTicks();
@@ -94,6 +110,9 @@ private:
#elif defined _WIN32
float ms_per_cycle;
LARGE_INTEGER cycles0;
#elif defined __CELLOS_LV2__
float ms_per_cycle;
uint64_t cycles0;
#else
Uint32 ticks0;
#endif


+ 13
- 0
src/video.cpp Ver arquivo

@@ -22,6 +22,8 @@
#include "core.h"
#include "lolgl.h"

using namespace std;

namespace lol
{

@@ -188,11 +190,13 @@ void Video::SetFov(float theta)
view_matrix = mat4(1.0f);

stdshader->Bind(); /* Required on GLES 2.x? */
#if !defined __CELLOS_LV2__ // Use cgGetNamedParameter etc.
GLuint uni;
uni = stdshader->GetUniformLocation("proj_matrix");
glUniformMatrix4fv(uni, 1, GL_FALSE, &proj_matrix[0][0]);
uni = stdshader->GetUniformLocation("view_matrix");
glUniformMatrix4fv(uni, 1, GL_FALSE, &view_matrix[0][0]);
#endif
}

void Video::SetDepth(bool set)
@@ -220,7 +224,13 @@ void Video::Destroy()
void Video::Capture(uint32_t *buffer)
{
GLint v[4];
#if defined __CELLOS_LV2__
// FIXME: use psglCreateDeviceAuto && psglGetDeviceDimensions
v[2] = 1920;
v[3] = 1080;
#else
glGetIntegerv(GL_VIEWPORT, v);
#endif
int width = v[2], height = v[3];

#if defined HAVE_GL_2X
@@ -247,6 +257,9 @@ vec2i Video::GetSize()
{
#if defined ANDROID_NDK
return saved_viewport;
#elif defined __CELLOS_LV2__
// FIXME: use psglCreateDeviceAuto && psglGetDeviceDimensions
return vec2i(1920, 1080);
#else
GLint v[4];
glGetIntegerv(GL_VIEWPORT, v);


Carregando…
Cancelar
Salvar