Merge branch 'master' of github.com:aap/librw

This commit is contained in:
aap
2018-12-17 21:24:11 +01:00
42 changed files with 716 additions and 66 deletions

28
src/base.cpp Executable file → Normal file
View File

@@ -110,9 +110,9 @@ slerp(const Quat &q, const Quat &p, float32 a)
}
float32 phi = acos(c);
if(phi > 0.00001f){
float32 s = sin(phi);
return add(scale(q1, sin((1.0f-a)*phi)/s),
scale(p, sin(a*phi)/s));
float32 s = sinf(phi);
return add(scale(q1, sinf((1.0f-a)*phi)/s),
scale(p, sinf(a*phi)/s));
}
return q1;
}
@@ -424,25 +424,25 @@ Matrix::getRotation(void)
float32 tr = right.x + up.y + at.z;
float s;
if(tr > 0.0f){
s = sqrt(1.0f + tr) * 2.0f;
s = sqrtf(1.0f + tr) * 2.0f;
q.w = s / 4.0f;
q.x = (up.z - at.y) / s;
q.y = (at.x - right.z) / s;
q.z = (right.y - up.x) / s;
}else if(right.x > up.y && right.x > at.z){
s = sqrt(1.0f + right.x - up.y - at.z) * 2.0f;
s = sqrtf(1.0f + right.x - up.y - at.z) * 2.0f;
q.w = (up.z - at.y) / s;
q.x = s / 4.0f;
q.y = (up.x + right.y) / s;
q.z = (at.x + right.z) / s;
}else if(up.y > at.z){
s = sqrt(1.0f + up.y - right.x - at.z) * 2.0f;
s = sqrtf(1.0f + up.y - right.x - at.z) * 2.0f;
q.w = (at.x - right.z) / s;
q.x = (up.x + right.y) / s;
q.y = s / 4.0f;
q.z = (at.y + up.z) / s;
}else{
s = sqrt(1.0f + at.z - right.x - up.y) * 2.0f;
s = sqrtf(1.0f + at.z - right.x - up.y) * 2.0f;
q.w = (right.y - up.x) / s;
q.x = (at.x + right.z) / s;
q.y = (at.y + up.z) / s;
@@ -513,8 +513,8 @@ Matrix::invertGeneral(Matrix *dst, const Matrix *src)
// get the determinant from that
det = src->up.x * dst->right.y + src->at.x * dst->right.z + dst->right.x * src->right.x;
invdet = 1.0;
if(det != 0.0)
invdet = 1.0/det;
if(det != 0.0f)
invdet = 1.0f/det;
dst->right.x *= invdet;
dst->right.y *= invdet;
dst->right.z *= invdet;
@@ -535,10 +535,10 @@ void
Matrix::makeRotation(Matrix *dst, V3d *axis, float32 angle)
{
V3d v = normalize(*axis);
angle = angle*M_PI/180.0f;
angle = angle*(float)M_PI/180.0f;
float32 s = sin(angle);
float32 c = cos(angle);
float32 t = 1.0f - cos(angle);
float32 t = 1.0f - c;
dst->right.x = c + v.x*v.x*t;
dst->right.y = v.x*v.y*t + v.z*s;
@@ -588,9 +588,9 @@ float32
Matrix::normalError(void)
{
float32 x, y, z;
x = dot(right, right) - 1.0;
y = dot(up, up) - 1.0;
z = dot(at, at) - 1.0;
x = dot(right, right) - 1.0f;
y = dot(up, up) - 1.0f;
z = dot(at, at) - 1.0f;
return x*x + y*y + z*z;
}

View File

@@ -1,20 +1,20 @@
ECODE(ERR_GENERAL,
"Error: %s")
"Error: %s"),
ECODE(ERR_ALLOC,
"Couldn't allocate 0x%X bytes")
"Couldn't allocate 0x%X bytes"),
ECODE(ERR_FILE,
"Couldn't open file %s")
"Couldn't open file %s"),
ECODE(ERR_CHUNK,
"Couldn't find chunk %s")
"Couldn't find chunk %s"),
ECODE(ERR_VERSION,
"Unsupported version %X")
"Unsupported version %X"),
ECODE(ERR_PLATFORM,
"Unsupported platform %d")
"Unsupported platform %d"),
ECODE(ERR_ENGINEINIT,
"Engine could not be initialized")
"Engine could not be initialized"),
ECODE(ERR_ENGINEOPEN,
"Engine could not be opened")
"Engine could not be opened"),
ECODE(ERR_ENGINESTART,
"Engine could not be started")
"Engine could not be started"),
ECODE(ERR_INVRASTER,
"Invalid raster format")

4
src/camera.cpp Executable file → Normal file
View File

@@ -502,8 +502,8 @@ Camera::setFOV(float32 hfov, float32 ratio)
float ar1 = 4.0/3.0;
float ar2 = w/h;
float vfov = atan(tan(hfov/2) / ar1) *2;
hfov = atan(tan(vfov/2) * ar2) *2;
float vfov = atanf(tanf(hfov/2) / ar1) *2;
hfov = atanf(tanf(vfov/2) * ar2) *2;
float32 a = tan(hfov);
v.set(a, a/ratio);

View File

@@ -110,7 +110,7 @@ enum {
// 2.8 biased fixed point
D3DFMT_A2B10G10R10_XR_BIAS = 119,
// Binary format indicating that the data has no inherent type
D3DFMT_BINARYBUFFER = 199,
D3DFMT_BINARYBUFFER = 199
};
#endif

0
src/d3d/d3ddevice.cpp Executable file → Normal file
View File

View File

@@ -118,7 +118,7 @@ enum {
D3DDECLUSAGE_COLOR, // 10
D3DDECLUSAGE_FOG, // 11
D3DDECLUSAGE_DEPTH, // 12
D3DDECLUSAGE_SAMPLE, // 13
D3DDECLUSAGE_SAMPLE // 13
};
#endif

View File

@@ -184,7 +184,7 @@ enum {
D3DFMT_LIN_F16 = 0x00000031,
D3DFMT_VERTEXDATA = 100,
D3DFMT_INDEX16 = 101,
D3DFMT_INDEX16 = 101
};
}

View File

@@ -189,7 +189,7 @@ registerNativeDataPlugin(void)
enum {
D3DPT_TRIANGLELIST = 5,
D3DPT_TRIANGLESTRIP = 6,
D3DPT_TRIANGLESTRIP = 6
};
static void

0
src/engine.cpp Executable file → Normal file
View File

View File

@@ -23,7 +23,7 @@ getError(Error *e)
return e;
}
#define ECODE(c, s) s,
#define ECODE(c, s) s
const char *errstrs[] = {
"No error",
@@ -33,7 +33,7 @@ const char *errstrs[] = {
#undef ECODE
char*
dbgsprint(int32 code, ...)
dbgsprint(uint32 code, ...)
{
va_list ap;
static char strbuf[512];

102
src/gl/gl3device.cpp Executable file → Normal file
View File

@@ -12,7 +12,11 @@
#include "../rwobjects.h"
#ifdef RW_OPENGL
#include <GL/glew.h>
#ifdef LIBRW_SDL2
#include <SDL.h>
#else
#include <GLFW/glfw3.h>
#endif
#include "rwgl3.h"
#include "rwgl3shader.h"
#include "rwgl3impl.h"
@@ -24,7 +28,12 @@ namespace gl3 {
struct GlGlobals
{
#ifdef LIBRW_SDL2
SDL_Window *window;
SDL_GLContext glcontext;
#else
GLFWwindow *window;
#endif
int presentWidth, presentHeight;
} glGlobals;
@@ -625,7 +634,11 @@ static void
showRaster(Raster *raster)
{
// TODO: do this properly!
#ifdef LIBRW_SDL2
SDL_GL_SwapWindow(glGlobals.window);
#else
glfwSwapBuffers(glGlobals.window);
#endif
}
static void
@@ -701,7 +714,11 @@ beginUpdate(Camera *cam)
}
int w, h;
#ifdef LIBRW_SDL2
SDL_GetWindowSize(glGlobals.window, &w, &h);
#else
glfwGetWindowSize(glGlobals.window, &w, &h);
#endif
if(w != glGlobals.presentWidth || h != glGlobals.presentHeight){
glViewport(0, 0, w, h);
glGlobals.presentWidth = w;
@@ -709,6 +726,74 @@ beginUpdate(Camera *cam)
}
}
#ifdef LIBRW_SDL2
static int
openSDL2(EngineStartParams *startparams)
{
if (!startparams){
RWERROR((ERR_GENERAL, "startparams invalid"));
return 0;
}
GLenum status;
SDL_Window *win;
SDL_GLContext ctx;
/* Init SDL */
if(SDL_InitSubSystem(SDL_INIT_VIDEO)){
RWERROR((ERR_ENGINEOPEN, SDL_GetError()));
return 0;
}
SDL_ClearHints();
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
int flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL;
if (startparams->fullscreen)
flags |= SDL_WINDOW_FULLSCREEN;
win = SDL_CreateWindow(startparams->windowtitle, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, startparams->width, startparams->height, flags);
if(win == nil){
RWERROR((ERR_ENGINEOPEN, SDL_GetError()));
SDL_QuitSubSystem(SDL_INIT_VIDEO);
return 0;
}
ctx = SDL_GL_CreateContext(win);
/* Init GLEW */
glewExperimental = GL_TRUE;
status = glewInit();
if(status != GLEW_OK){
RWERROR((ERR_ENGINEOPEN, glewGetErrorString(status)));
SDL_GL_DeleteContext(ctx);
SDL_DestroyWindow(win);
SDL_QuitSubSystem(SDL_INIT_VIDEO);
return 0;
}
if(!GLEW_VERSION_3_3){
RWERROR((ERR_VERSION, "OpenGL 3.3 needed"));
SDL_GL_DeleteContext(ctx);
SDL_DestroyWindow(win);
SDL_QuitSubSystem(SDL_INIT_VIDEO);
return 0;
}
glGlobals.window = win;
glGlobals.glcontext = ctx;
*startparams->window = win;
return 1;
}
static int
closeSDL2(void)
{
SDL_GL_DeleteContext(glGlobals.glcontext);
SDL_DestroyWindow(glGlobals.window);
SDL_QuitSubSystem(SDL_INIT_VIDEO);
return 1;
}
#else
static int
openGLFW(EngineStartParams *startparams)
{
@@ -732,6 +817,14 @@ openGLFW(EngineStartParams *startparams)
glfwTerminate();
return 0;
}
if(startparams->fullscreen){
int nbmonitors;
auto monitors = glfwGetMonitors(&nbmonitors);
if (nbmonitors){
const GLFWvidmode* mode = glfwGetVideoMode(monitors[0]);
glfwSetWindowMonitor(win, monitors[0], 0, 0, mode->width, mode->height, mode->refreshRate);
}
}
glfwMakeContextCurrent(win);
/* Init GLEW */
@@ -761,6 +854,7 @@ closeGLFW(void)
glfwTerminate();
return 1;
}
#endif
static int
initOpenGL(void)
@@ -836,9 +930,17 @@ deviceSystem(DeviceReq req, void *arg0)
{
switch(req){
case DEVICEOPEN:
#ifdef LIBRW_SDL2
return openSDL2((EngineStartParams*)arg0);
#else
return openGLFW((EngineStartParams*)arg0);
#endif
case DEVICECLOSE:
#ifdef LIBRW_SDL2
return closeSDL2();
#else
return closeGLFW();
#endif
case DEVICEINIT:
return initOpenGL();

View File

@@ -1,15 +1,24 @@
#ifdef RW_GL3
#include <GL/glew.h>
#ifdef LIBRW_SDL2
#include <SDL.h>
#else
#include <GLFW/glfw3.h>
#endif
#endif
namespace rw {
#ifdef RW_GL3
struct EngineStartParams
{
#ifdef LIBRW_SDL2
SDL_Window **window;
#else
GLFWwindow **window;
#endif
int width, height;
bool32 fullscreen;
const char *windowtitle;
};
#endif
@@ -43,7 +52,7 @@ enum AttribIndices
ATTRIB_TEXCOORDS4,
ATTRIB_TEXCOORDS5,
ATTRIB_TEXCOORDS6,
ATTRIB_TEXCOORDS7,
ATTRIB_TEXCOORDS7
};
// default uniform indices

0
src/matfx.cpp Executable file → Normal file
View File

0
src/pipeline.cpp Executable file → Normal file
View File

0
src/ps2/pds.cpp Executable file → Normal file
View File

2
src/ps2/ps2.cpp Executable file → Normal file
View File

@@ -521,7 +521,7 @@ enum {
VIF_MARK = 0x07000000,
VIF_FLUSH = 0x11000000,
VIF_MSCALF = 0x15000000,
VIF_MSCNT = 0x17000000,
VIF_MSCNT = 0x17000000
};
struct InstMeshInfo

0
src/ps2/ps2device.cpp Executable file → Normal file
View File

View File

@@ -37,7 +37,7 @@ enum Psm {
PSMZ32 = 0x30,
PSMZ24 = 0x31,
PSMZ16 = 0x32,
PSMZ16S = 0x3A,
PSMZ16S = 0x3A
};
// i don't really understand this, stolen from RW

2
src/ps2/rwps2.h Executable file → Normal file
View File

@@ -185,7 +185,7 @@ struct Ps2Raster
enum Flags {
NEWSTYLE = 0x1, // has GIF tags and transfer DMA chain
SWIZZLED8 = 0x2,
SWIZZLED4 = 0x4,
SWIZZLED4 = 0x4
};
struct PixelPtr {
// RW has pixels as second element but we don't want this struct

View File

@@ -80,7 +80,7 @@ struct LLLink
};
#define LLLinkGetData(linkvar,type,entry) \
((type*)(((uint8*)(linkvar))-offsetof(type,entry)))
((type*)(((rw::uint8*)(linkvar))-offsetof(type,entry)))
// Have to be careful since the link might be deleted.
#define FORLIST(_link, _list) \
@@ -269,7 +269,7 @@ enum CombineOp
{
COMBINEREPLACE,
COMBINEPRECONCAT,
COMBINEPOSTCONCAT,
COMBINEPOSTCONCAT
};
struct RawMatrix
@@ -398,7 +398,7 @@ enum PrimitiveType
PRIMTYPETRILIST,
PRIMTYPETRISTRIP,
PRIMTYPETRIFAN,
PRIMTYPEPOINTLIST,
PRIMTYPEPOINTLIST
};
/*
@@ -503,7 +503,7 @@ enum VendorID
// Used for rasters (platform-specific)
VEND_RASTER = 10,
// Used for driver/device allocation tags
VEND_DRIVER = 11,
VEND_DRIVER = 11
};
// TODO: modules (VEND_CRITERIONINT)
@@ -559,17 +559,17 @@ enum PluginID
ID_RASTERGL3 = MAKEPLUGINID(VEND_RASTER, PLATFORM_GL3),
// anything driver/device related (only as allocation tag)
ID_DRIVER = MAKEPLUGINID(VEND_DRIVER, 0),
ID_DRIVER = MAKEPLUGINID(VEND_DRIVER, 0)
};
enum CoreModuleID
{
ID_NAMODULE = MAKEPLUGINID(VEND_CRITERIONINT, 0x00),
ID_FRAMEMODULE = MAKEPLUGINID(VEND_CRITERIONINT, 0x03),
ID_TEXTUREMODULE = MAKEPLUGINID(VEND_CRITERIONINT, 0x08),
ID_TEXTUREMODULE = MAKEPLUGINID(VEND_CRITERIONINT, 0x08)
};
#define ECODE(c, s) c,
#define ECODE(c, s) c
enum Errors
{
@@ -601,7 +601,7 @@ libraryIDPack(int version, int build)
{
if(version <= 0x31000)
return version>>8;
return (version-0x30000 & 0x3FF00) << 14 | (version&0x3F) << 16 |
return ((version-0x30000) & 0x3FF00) << 14 | (version&0x3F) << 16 |
(build & 0xFFFF);
}
@@ -609,7 +609,7 @@ inline int
libraryIDUnpackVersion(uint32 libid)
{
if(libid & 0xFFFF0000)
return (libid>>14 & 0x3FF00) + 0x30000 |
return ((libid>>14 & 0x3FF00) + 0x30000) |
(libid>>16 & 0x3F);
else
return libid<<8;

2
src/rwengine.h Executable file → Normal file
View File

@@ -13,7 +13,7 @@ enum DeviceReq
DEVICETERM,
// Device initialization after Engine/Driver plugins are opened
DEVICEFINALIZE,
DEVICEFINALIZE
// TODO? counterpart to FINALIZE?
};

View File

@@ -10,7 +10,7 @@ void setError(Error *e);
Error *getError(Error *e);
#define _ERRORCODE(code, ...) code
char *dbgsprint(int32 code, ...);
char *dbgsprint(uint32 code, ...);
/* ecode is supposed to be in format "(errorcode, printf-arguments..)" */
#define RWERROR(ecode) do{ \

14
src/rwobjects.h Executable file → Normal file
View File

@@ -41,7 +41,7 @@ struct Frame
SUBTREESYNCOBJ = 0x08,
SUBTREESYNC = SUBTREESYNCLTM | SUBTREESYNCOBJ,
SYNCLTM = HIERARCHYSYNCLTM | SUBTREESYNCLTM,
SYNCOBJ = HIERARCHYSYNCOBJ | SUBTREESYNCOBJ,
SYNCOBJ = HIERARCHYSYNCOBJ | SUBTREESYNCOBJ
// STATIC = 0x10
};
@@ -219,7 +219,7 @@ struct Raster
CAMERA = 0x02,
TEXTURE = 0x04,
CAMERATEXTURE = 0x05,
DONTALLOCATE = 0x80,
DONTALLOCATE = 0x80
};
};
@@ -258,11 +258,11 @@ struct Texture
static Texture *fromDict(LLLink *lnk){
return LLLinkGetData(lnk, Texture, inDict); }
FilterMode getFilter(void) { return (FilterMode)(filterAddressing & 0xFF); }
void setFilter(FilterMode f) { filterAddressing = filterAddressing & ~0xFF | f; }
void setFilter(FilterMode f) { filterAddressing = (filterAddressing & ~0xFF) | f; }
Addressing getAddressU(void) { return (Addressing)((filterAddressing >> 8) & 0xF); }
Addressing getAddressV(void) { return (Addressing)((filterAddressing >> 12) & 0xF); }
void setAddressU(Addressing u) { filterAddressing = filterAddressing & ~0xF00 | u<<8; }
void setAddressV(Addressing v) { filterAddressing = filterAddressing & ~0xF000 | v<<12; }
void setAddressU(Addressing u) { filterAddressing = (filterAddressing & ~0xF00) | u<<8; }
void setAddressV(Addressing v) { filterAddressing = (filterAddressing & ~0xF000) | v<<12; }
static Texture *streamRead(Stream *stream);
bool streamWrite(Stream *stream);
uint32 streamGetSize(void);
@@ -451,7 +451,7 @@ struct Atomic
// private flags
WORLDBOUNDDIRTY = 0x01,
// for setGeometry
SAMEBOUNDINGSPHERE = 0x01,
SAMEBOUNDINGSPHERE = 0x01
};
ObjectWithFrame object;
@@ -541,7 +541,7 @@ struct Light
AMBIENT,
POINT = 0x80, // positioned
SPOT,
SOFTSPOT,
SOFTSPOT
};
enum Flags {
LIGHTATOMICS = 1,

0
src/rwplugins.h Executable file → Normal file
View File

View File

@@ -24,7 +24,7 @@ enum RenderState
// platform specific or opaque?
ALPHATESTFUNC,
ALPHATESTREF,
ALPHATESTREF
};
enum AlphaTestFunc
@@ -53,7 +53,7 @@ enum BlendFunction
BLENDINVDESTALPHA,
BLENDDESTCOLOR,
BLENDINVDESTCOLOR,
BLENDSRCALPHASAT,
BLENDSRCALPHASAT
// TODO: add more perhaps
};

View File

@@ -5,7 +5,7 @@ enum UserDataType
USERDATANA = 0,
USERDATAINT = 1,
USERDATAFLOAT = 2,
USERDATASTRING = 3,
USERDATASTRING = 3
};
struct UserDataArray

0
src/world.cpp Executable file → Normal file
View File