From 3edb391f9c032e6259eb8c64416240225c17dbef Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Tue, 5 Dec 2017 08:59:20 +0100 Subject: [PATCH 1/8] fix file modes --- premake5.lua | 0 src/base.cpp | 0 src/camera.cpp | 0 src/d3d/d3ddevice.cpp | 0 src/engine.cpp | 0 src/gl/gl3device.cpp | 0 src/matfx.cpp | 0 src/pipeline.cpp | 0 src/ps2/pds.cpp | 0 src/ps2/ps2.cpp | 0 src/ps2/ps2device.cpp | 0 src/ps2/rwps2.h | 0 src/rwengine.h | 0 src/rwobjects.h | 0 src/rwplugins.h | 0 src/world.cpp | 0 tools/ps2test/gs.h | 0 tools/ps2test/main.cpp | 0 tools/ps2test/mem.h | 0 tools/ps2test/ps2.h | 0 tools/ps2test/vu/defaultpipe.dsm | 0 tools/ps2test/vu/light.vu | 0 tools/ps2test/vu/setup_persp.vu | 0 tools/ps2test/vu/skinpipe.dsm | 0 24 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 premake5.lua mode change 100755 => 100644 src/base.cpp mode change 100755 => 100644 src/camera.cpp mode change 100755 => 100644 src/d3d/d3ddevice.cpp mode change 100755 => 100644 src/engine.cpp mode change 100755 => 100644 src/gl/gl3device.cpp mode change 100755 => 100644 src/matfx.cpp mode change 100755 => 100644 src/pipeline.cpp mode change 100755 => 100644 src/ps2/pds.cpp mode change 100755 => 100644 src/ps2/ps2.cpp mode change 100755 => 100644 src/ps2/ps2device.cpp mode change 100755 => 100644 src/ps2/rwps2.h mode change 100755 => 100644 src/rwengine.h mode change 100755 => 100644 src/rwobjects.h mode change 100755 => 100644 src/rwplugins.h mode change 100755 => 100644 src/world.cpp mode change 100755 => 100644 tools/ps2test/gs.h mode change 100755 => 100644 tools/ps2test/main.cpp mode change 100755 => 100644 tools/ps2test/mem.h mode change 100755 => 100644 tools/ps2test/ps2.h mode change 100755 => 100644 tools/ps2test/vu/defaultpipe.dsm mode change 100755 => 100644 tools/ps2test/vu/light.vu mode change 100755 => 100644 tools/ps2test/vu/setup_persp.vu mode change 100755 => 100644 tools/ps2test/vu/skinpipe.dsm diff --git a/premake5.lua b/premake5.lua old mode 100755 new mode 100644 diff --git a/src/base.cpp b/src/base.cpp old mode 100755 new mode 100644 diff --git a/src/camera.cpp b/src/camera.cpp old mode 100755 new mode 100644 diff --git a/src/d3d/d3ddevice.cpp b/src/d3d/d3ddevice.cpp old mode 100755 new mode 100644 diff --git a/src/engine.cpp b/src/engine.cpp old mode 100755 new mode 100644 diff --git a/src/gl/gl3device.cpp b/src/gl/gl3device.cpp old mode 100755 new mode 100644 diff --git a/src/matfx.cpp b/src/matfx.cpp old mode 100755 new mode 100644 diff --git a/src/pipeline.cpp b/src/pipeline.cpp old mode 100755 new mode 100644 diff --git a/src/ps2/pds.cpp b/src/ps2/pds.cpp old mode 100755 new mode 100644 diff --git a/src/ps2/ps2.cpp b/src/ps2/ps2.cpp old mode 100755 new mode 100644 diff --git a/src/ps2/ps2device.cpp b/src/ps2/ps2device.cpp old mode 100755 new mode 100644 diff --git a/src/ps2/rwps2.h b/src/ps2/rwps2.h old mode 100755 new mode 100644 diff --git a/src/rwengine.h b/src/rwengine.h old mode 100755 new mode 100644 diff --git a/src/rwobjects.h b/src/rwobjects.h old mode 100755 new mode 100644 diff --git a/src/rwplugins.h b/src/rwplugins.h old mode 100755 new mode 100644 diff --git a/src/world.cpp b/src/world.cpp old mode 100755 new mode 100644 diff --git a/tools/ps2test/gs.h b/tools/ps2test/gs.h old mode 100755 new mode 100644 diff --git a/tools/ps2test/main.cpp b/tools/ps2test/main.cpp old mode 100755 new mode 100644 diff --git a/tools/ps2test/mem.h b/tools/ps2test/mem.h old mode 100755 new mode 100644 diff --git a/tools/ps2test/ps2.h b/tools/ps2test/ps2.h old mode 100755 new mode 100644 diff --git a/tools/ps2test/vu/defaultpipe.dsm b/tools/ps2test/vu/defaultpipe.dsm old mode 100755 new mode 100644 diff --git a/tools/ps2test/vu/light.vu b/tools/ps2test/vu/light.vu old mode 100755 new mode 100644 diff --git a/tools/ps2test/vu/setup_persp.vu b/tools/ps2test/vu/setup_persp.vu old mode 100755 new mode 100644 diff --git a/tools/ps2test/vu/skinpipe.dsm b/tools/ps2test/vu/skinpipe.dsm old mode 100755 new mode 100644 From b38cbc79617d77c7d33d0944d31a6cb540d19ffc Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Fri, 13 Jul 2018 01:09:45 +0200 Subject: [PATCH 2/8] fix 'comma at end of enumerator list [-Wpedantic]' --- src/base.err | 18 +++++++++--------- src/d3d/d3d.cpp | 2 +- src/d3d/rwd3d.h | 2 +- src/d3d/rwxbox.h | 2 +- src/d3d/xbox.cpp | 2 +- src/error.cpp | 2 +- src/gl/rwgl3.h | 2 +- src/ps2/ps2.cpp | 2 +- src/ps2/ps2raster.cpp | 2 +- src/ps2/rwps2.h | 2 +- src/rwbase.h | 12 ++++++------ src/rwengine.h | 2 +- src/rwobjects.h | 8 ++++---- src/rwrender.h | 4 ++-- src/rwuserdata.h | 2 +- 15 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/base.err b/src/base.err index 5e06a86..a1a37af 100644 --- a/src/base.err +++ b/src/base.err @@ -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") diff --git a/src/d3d/d3d.cpp b/src/d3d/d3d.cpp index f6465a9..f98e005 100644 --- a/src/d3d/d3d.cpp +++ b/src/d3d/d3d.cpp @@ -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 diff --git a/src/d3d/rwd3d.h b/src/d3d/rwd3d.h index c5bc854..b427eee 100644 --- a/src/d3d/rwd3d.h +++ b/src/d3d/rwd3d.h @@ -103,7 +103,7 @@ enum { D3DDECLUSAGE_COLOR, // 10 D3DDECLUSAGE_FOG, // 11 D3DDECLUSAGE_DEPTH, // 12 - D3DDECLUSAGE_SAMPLE, // 13 + D3DDECLUSAGE_SAMPLE // 13 }; #endif diff --git a/src/d3d/rwxbox.h b/src/d3d/rwxbox.h index b828c05..848bfb9 100644 --- a/src/d3d/rwxbox.h +++ b/src/d3d/rwxbox.h @@ -184,7 +184,7 @@ enum { D3DFMT_LIN_F16 = 0x00000031, D3DFMT_VERTEXDATA = 100, - D3DFMT_INDEX16 = 101, + D3DFMT_INDEX16 = 101 }; } diff --git a/src/d3d/xbox.cpp b/src/d3d/xbox.cpp index 725bec7..a798241 100644 --- a/src/d3d/xbox.cpp +++ b/src/d3d/xbox.cpp @@ -189,7 +189,7 @@ registerNativeDataPlugin(void) enum { D3DPT_TRIANGLELIST = 5, - D3DPT_TRIANGLESTRIP = 6, + D3DPT_TRIANGLESTRIP = 6 }; static void diff --git a/src/error.cpp b/src/error.cpp index 65e65af..5f26d97 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -23,7 +23,7 @@ getError(Error *e) return e; } -#define ECODE(c, s) s, +#define ECODE(c, s) s const char *errstrs[] = { "No error", diff --git a/src/gl/rwgl3.h b/src/gl/rwgl3.h index ac3150a..b4b032a 100644 --- a/src/gl/rwgl3.h +++ b/src/gl/rwgl3.h @@ -43,7 +43,7 @@ enum AttribIndices ATTRIB_TEXCOORDS4, ATTRIB_TEXCOORDS5, ATTRIB_TEXCOORDS6, - ATTRIB_TEXCOORDS7, + ATTRIB_TEXCOORDS7 }; // default uniform indices diff --git a/src/ps2/ps2.cpp b/src/ps2/ps2.cpp index b307ca0..a6c097d 100644 --- a/src/ps2/ps2.cpp +++ b/src/ps2/ps2.cpp @@ -521,7 +521,7 @@ enum { VIF_MARK = 0x07000000, VIF_FLUSH = 0x11000000, VIF_MSCALF = 0x15000000, - VIF_MSCNT = 0x17000000, + VIF_MSCNT = 0x17000000 }; struct InstMeshInfo diff --git a/src/ps2/ps2raster.cpp b/src/ps2/ps2raster.cpp index 94bc955..ab3b72b 100644 --- a/src/ps2/ps2raster.cpp +++ b/src/ps2/ps2raster.cpp @@ -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 diff --git a/src/ps2/rwps2.h b/src/ps2/rwps2.h index f580d5f..a2d70ac 100644 --- a/src/ps2/rwps2.h +++ b/src/ps2/rwps2.h @@ -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 diff --git a/src/rwbase.h b/src/rwbase.h index 1e871bc..4b39d1d 100644 --- a/src/rwbase.h +++ b/src/rwbase.h @@ -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 { diff --git a/src/rwengine.h b/src/rwengine.h index d886b96..cbe8b43 100644 --- a/src/rwengine.h +++ b/src/rwengine.h @@ -13,7 +13,7 @@ enum DeviceReq DEVICETERM, // Device initialization after Engine/Driver plugins are opened - DEVICEFINALIZE, + DEVICEFINALIZE // TODO? counterpart to FINALIZE? }; diff --git a/src/rwobjects.h b/src/rwobjects.h index 017c4ee..d5afdc2 100644 --- a/src/rwobjects.h +++ b/src/rwobjects.h @@ -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 }; }; @@ -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, diff --git a/src/rwrender.h b/src/rwrender.h index 207c232..d60469f 100644 --- a/src/rwrender.h +++ b/src/rwrender.h @@ -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 }; diff --git a/src/rwuserdata.h b/src/rwuserdata.h index 4bf7eb1..29c9ec6 100644 --- a/src/rwuserdata.h +++ b/src/rwuserdata.h @@ -5,7 +5,7 @@ enum UserDataType USERDATANA = 0, USERDATAINT = 1, USERDATAFLOAT = 2, - USERDATASTRING = 3, + USERDATASTRING = 3 }; struct UserDataArray From add55f08c5e6059a516bbd1d6939261104d81ce0 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Fri, 13 Jul 2018 01:33:18 +0200 Subject: [PATCH 3/8] =?UTF-8?q?fix=20'warning:=20implicit=20conversion=20f?= =?UTF-8?q?rom=20=E2=80=98rw::float32=E2=80=99=20{aka=20=E2=80=98float?= =?UTF-8?q?=E2=80=99}=20to=20=E2=80=98double=E2=80=99=20to=20match=20other?= =?UTF-8?q?=20operand=20of=20binary=20expression=20[-Wdouble-promotion]'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/base.cpp | 28 ++++++++++++++-------------- src/camera.cpp | 4 ++-- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/base.cpp b/src/base.cpp index fce04ad..4540028 100644 --- a/src/base.cpp +++ b/src/base.cpp @@ -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; } diff --git a/src/camera.cpp b/src/camera.cpp index e293d32..6311cc5 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -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); From 020e66a28285babbefc67465349ec01a6ea9c1b1 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Fri, 13 Jul 2018 01:50:18 +0200 Subject: [PATCH 4/8] =?UTF-8?q?fix=20'warning:=20overflow=20in=20conversio?= =?UTF-8?q?n=20from=20=E2=80=98rw::Errors=E2=80=99=20to=20=E2=80=98rw::int?= =?UTF-8?q?32=E2=80=99=20{aka=20=E2=80=98int=E2=80=99}=20changes=20value?= =?UTF-8?q?=20from=20=E2=80=98(rw::Errors)2147483650=E2=80=99=20to=20?= =?UTF-8?q?=E2=80=98-2147483646=E2=80=99=20[-Woverflow]'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/error.cpp | 2 +- src/rwerror.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/error.cpp b/src/error.cpp index 5f26d97..889cd47 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -33,7 +33,7 @@ const char *errstrs[] = { #undef ECODE char* -dbgsprint(int32 code, ...) +dbgsprint(uint32 code, ...) { va_list ap; static char strbuf[512]; diff --git a/src/rwerror.h b/src/rwerror.h index 937cc0e..2575626 100644 --- a/src/rwerror.h +++ b/src/rwerror.h @@ -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{ \ From 12269003dafa4c3fe81ce3f3cfcbb22c120fa8f6 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Fri, 13 Jul 2018 02:05:00 +0200 Subject: [PATCH 5/8] =?UTF-8?q?fix=20'error:=20=E2=80=98uint8=E2=80=99=20w?= =?UTF-8?q?as=20not=20declared=20in=20this=20scope'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/rwbase.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rwbase.h b/src/rwbase.h index 4b39d1d..5058697 100644 --- a/src/rwbase.h +++ b/src/rwbase.h @@ -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) \ From 9ef08cbb19bac0dc1e636d8762a70a54ad02c065 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Fri, 13 Jul 2018 21:39:06 +0200 Subject: [PATCH 6/8] =?UTF-8?q?fix=20'warning:=20suggest=20parentheses=20a?= =?UTF-8?q?round=20arithmetic=20in=20operand=20of=20=E2=80=98|=E2=80=99'?= =?UTF-8?q?=20in=20public=20headers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/rwbase.h | 4 ++-- src/rwobjects.h | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/rwbase.h b/src/rwbase.h index 5058697..984ebba 100644 --- a/src/rwbase.h +++ b/src/rwbase.h @@ -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; diff --git a/src/rwobjects.h b/src/rwobjects.h index d5afdc2..a259e1a 100644 --- a/src/rwobjects.h +++ b/src/rwobjects.h @@ -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); From 75dbb7e67e70aec50caa9a4a2d64021bcdbadb15 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Wed, 25 Jul 2018 20:42:03 +0200 Subject: [PATCH 7/8] Add travis and appveyor support --- .appveyor.yml | 28 ++++++++++++++++++++ .travis.yml | 33 ++++++++++++++++++++++++ Dockerfile | 60 +++++++++++++++++++++++++++++++++++++++++++ docker_rebuild_ps2.sh | 22 ++++++++++++++++ premake5.lua | 28 ++++++++++++++------ 5 files changed, 163 insertions(+), 8 deletions(-) create mode 100644 .appveyor.yml create mode 100644 .travis.yml create mode 100644 Dockerfile create mode 100755 docker_rebuild_ps2.sh mode change 100755 => 100644 premake5.lua diff --git a/.appveyor.yml b/.appveyor.yml new file mode 100644 index 0000000..79268a1 --- /dev/null +++ b/.appveyor.yml @@ -0,0 +1,28 @@ +image: Visual Studio 2017 +configuration: Release +platform: + - win-amd64-null + - win-amd64-gl3 + - win-amd64-d3d9 +environment: + APPVEYOR_SAVE_CACHE_ON_ERROR: true + GLFW_BASE: glfw-3.2.1.bin.WIN64 + GLFW_URL: https://github.com/glfw/glfw/releases/download/3.2.1/%GLFW_BASE%.zip + GLEW_BASE: glew-2.1.0 + GLEW_URL: https://github.com/nigels-com/glew/releases/download/glew-2.1.0/%GLEW_BASE%-win32.zip + PREMAKE5_URL: https://github.com/premake/premake-core/releases/download/v5.0.0-alpha12/premake-5.0.0-alpha12-windows.zip +install: + - appveyor DownloadFile %GLFW_URL% -FileName "%APPVEYOR_BUILD_FOLDER%/%GLFW_BASE%.zip" + - 7z x "%APPVEYOR_BUILD_FOLDER%/%GLFW_BASE%.zip" + - appveyor DownloadFile %GLEW_URL% -FileName "%APPVEYOR_BUILD_FOLDER%/%GLEW_BASE%.zip" + - 7z x "%APPVEYOR_BUILD_FOLDER%/%GLEW_BASE%.zip" + - appveyor DownloadFile %PREMAKE5_URL% -FileName "%APPVEYOR_BUILD_FOLDER%/premake5.zip" + - mkdir "%APPVEYOR_BUILD_FOLDER%/bin" && cd "%APPVEYOR_BUILD_FOLDER%/bin" && 7z x "%APPVEYOR_BUILD_FOLDER%/premake5.zip" + - set PATH=%APPVEYOR_BUILD_FOLDER%/bin;%PATH% +before_build: + - mkdir "%APPVEYOR_BUILD_FOLDER%/build" + - cd "%APPVEYOR_BUILD_FOLDER%" + - premake5 vs2017 --glfwdir=%APPVEYOR_BUILD_FOLDER%/%GLFW_BASE% --glewdir=%APPVEYOR_BUILD_FOLDER%/%GLEW_BASE% +build: + project: c:\projects\librw\build\librw.sln + verbosity: minimal diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..4ff4231 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,33 @@ +language: cpp + +matrix: + include: + - os: linux + env: TARGET="release_linux-amd64-null" + script: + - mkdir -p "$TRAVIS_BUILD_DIR/build" + #- docker build -t librw "$TRAVIS_BUILD_DIR" + #- docker run -v "$TRAVIS_BUILD_DIR:/librw:rw,z" --name librw_instance -d librw sleep infinity + - docker pull librw/librw + - docker run -v "$TRAVIS_BUILD_DIR:/librw:rw,z" -v "$TRAVIS_BUILD_DIR/build:/build:rw,z" --name librw_instance -d librw/librw sleep infinity + - docker exec -u builder librw_instance /bin/bash -c "cd /librw && premake5 gmake && cd /librw/build && make config=$TARGET verbose=1" + - os: linux + env: TARGET="release_linux-amd64-gl3" + services: docker + script: + - mkdir -p "$TRAVIS_BUILD_DIR/build" + #- docker build -t librw "$TRAVIS_BUILD_DIR" + #- docker run -v "$TRAVIS_BUILD_DIR:/librw:rw,z" --name librw_instance -d librw sleep infinity + - docker pull librw/librw + - docker run -v "$TRAVIS_BUILD_DIR:/librw:rw,z" -v "$TRAVIS_BUILD_DIR/build:/build:rw,z" --name librw_instance -d librw/librw sleep infinity + - docker exec -u builder librw_instance /bin/bash -c "cd /librw && premake5 gmake && cd /librw/build && make config=$TARGET verbose=1" + - os: linux + env: TARGET="release_ps2" + services: docker + script: + - mkdir -p "$TRAVIS_BUILD_DIR/build" + #- docker build -t librw "$TRAVIS_BUILD_DIR" + #- docker run -v "$TRAVIS_BUILD_DIR:/librw:rw,z" --name librw_instance -d librw sleep infinity + - docker pull librw/librw + - docker run -v "$TRAVIS_BUILD_DIR:/librw:rw,z" -v "$TRAVIS_BUILD_DIR/build:/build:rw,z" --name librw_instance -d librw/librw sleep infinity + - docker exec -u builder librw_instance /bin/bash -c "cd /librw && premake5 gmake && cd /librw/build && make config=$TARGET verbose=1" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2792091 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,60 @@ +FROM ubuntu:rolling + +ENV PS2DEV /ps2dev +ENV PS2SDK $PS2DEV/ps2sdk +ENV PATH $PATH:$PS2DEV/bin:$PS2DEV/ee/bin:$PS2DEV/iop/bin:$PS2DEV/dvp/bin:$PS2SDK/bin + +ENV DEBIAN_FRONTEND noninteractive + +ENV TOOLCHAIN_GIT_URL git://github.com/ps2dev/ps2toolchain.git +ENV TOOLCHAIN_GIT_BRANCH master + +ENV PREMAKE5_URL=https://github.com/premake/premake-core/releases/download/v5.0.0-alpha12/premake-5.0.0-alpha12-linux.tar.gz + +RUN mkdir -p "$PS2DEV" "$PS2SDK" \ + && apt-get update \ + && apt-get upgrade -y \ + && apt-get install -y \ + build-essential \ + cmake \ + autoconf \ + bzip2 \ + gcc \ + git \ + libucl-dev \ + make \ + patch \ + vim \ + wget \ + zip \ + zlib1g-dev \ + libglew-dev \ + libglfw3-dev \ + && git clone -b $TOOLCHAIN_GIT_BRANCH $TOOLCHAIN_GIT_URL /toolchain \ + && cd /toolchain \ + && ./toolchain.sh \ + && git clone git://github.com/ps2dev/ps2eth.git /ps2dev/ps2eth \ + && make -C /ps2dev/ps2eth \ + && git clone git://github.com/ps2dev/ps2-packer.git /ps2-packer \ + && make install -C /ps2-packer \ + && rm -rf \ + /ps2-packer \ + /ps2dev/ps2eth/.git \ + /ps2dev/ps2sdk/test.tmp \ + /ps2dev/test.tmp \ + /toolchain \ + && rm -rf /var/lib/apt/lists/* \ + && wget "$PREMAKE5_URL" -O /tmp/premake5.tar.gz \ + && tar xf /tmp/premake5.tar.gz -C /usr/bin/ \ + && rm /tmp/premake5.tar.gz \ + && groupadd 1000 -g 1000 \ + && groupadd 1001 -g 1001 \ + && groupadd 2000 -g 2000 \ + && groupadd 999 -g 999 \ + && useradd -ms /bin/bash builder -g 1001 -G 1000,2000,999 \ + && printf "builder:builder" | chpasswd \ + && adduser builder sudo \ + && printf "builder ALL= NOPASSWD: ALL\\n" >> /etc/sudoers + +USER builder +WORKDIR /home/builder diff --git a/docker_rebuild_ps2.sh b/docker_rebuild_ps2.sh new file mode 100755 index 0000000..cf8148f --- /dev/null +++ b/docker_rebuild_ps2.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +TARGET=release_ps2 + +set -e + +LIBRWDIR=$(dirname "$(readlink -f "$0")") +echo "LIBRWDIR is $LIBRWDIR" + +cd "$LIBRWDIR" + +premake5 gmake + +docker rm librw_instance -f >/dev/null 2>&1 || true +docker stop librw_instance -t 0 >/dev/null 2>&1 || true + +docker pull librw/librw +docker run -v "$LIBRWDIR:/librw:rw,z" --name librw_instance -d librw/librw sleep infinity +docker exec -u builder librw_instance /bin/bash -c "cd /librw/build && make clean config=$TARGET && make config=$TARGET verbose=1" + +docker rm librw_instance -f >/dev/null 2>&1 || true +docker stop librw_instance -t 0 >/dev/null 2>&1 || true diff --git a/premake5.lua b/premake5.lua old mode 100755 new mode 100644 index b53f860..be7a38b --- a/premake5.lua +++ b/premake5.lua @@ -1,5 +1,16 @@ -GLEWdir = "C:/Users/aap/src/glew-2.1.0" -GLFW64dir = "C:/Users/aap/src/glfw-3.2.1.bin.WIN64" +newoption { + trigger = "glewdir", + value = "path", + description = "Directory of GLEW", + default = "C:/Users/aap/src/glew-2.1.0", +} + +newoption { + trigger = "glfwdir", + value = "path", + description = "Directory of glfw", + default = "C:/Users/aap/src/glfw-3.2.1.bin.WIN64", +} workspace "librw" location "build" @@ -37,6 +48,7 @@ workspace "librw" gccprefix 'ee-' buildoptions { "-nostdlib", "-fno-common" } includedirs { "$(PS2SDK)/ee/include", "$(PS2SDK)/common/include" } + optimize "Off" filter { "platforms:*amd64*" } architecture "x86_64" @@ -50,8 +62,8 @@ workspace "librw" filter { "platforms:win*gl3" } defines { "GLEW_STATIC" } - includedirs { path.join(GLEWdir, "include") } - includedirs { path.join(GLFW64dir, "include") } + includedirs { path.join(_OPTIONS["glewdir"], "include") } + includedirs { path.join(_OPTIONS["glfwdir"], "include") } filter "action:vs*" buildoptions { "/wd4996", "/wd4244" } @@ -83,10 +95,10 @@ function findlibs() filter { "platforms:win*gl3" } defines { "GLEW_STATIC" } filter { "platforms:win-amd64-gl3" } - libdirs { path.join(GLEWdir, "lib/Release/x64") } - libdirs { path.join(GLFW64dir, "lib-vc2015") } + libdirs { path.join(_OPTIONS["glewdir"], "lib/Release/x64") } + libdirs { path.join(_OPTIONS["glfwdir"], "lib-vc2015") } filter { "platforms:win-x86-gl3" } - libdirs { path.join(GLEWdir, "lib/Release/Win32") } + libdirs { path.join(_OPTIONS["glewdir"], "lib/Release/Win32") } filter { "platforms:win*gl3" } links { "glew32s", "glfw3", "opengl32" } filter { "platforms:*d3d9" } @@ -157,7 +169,7 @@ project "ps2test" libdirs { "$(PS2SDK)/ee/lib" } links { "librw" } -- "c -lc" is a hack because we need -lc twice for some reason - links { "c -lc", "kernel", "mf" } + links { "c", "kernel", "mf" } --project "ps2rastertest" -- kind "ConsoleApp" From 86571b650b9addb3d89006ea768c7752e860fceb Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Wed, 8 Aug 2018 19:55:45 +0200 Subject: [PATCH 8/8] Add support for SDL2 --- .appveyor.yml | 24 ++-- .travis.yml | 18 ++- Dockerfile | 1 + premake5.lua | 45 +++++- skeleton/glfw.cpp | 3 + skeleton/sdl2.cpp | 325 +++++++++++++++++++++++++++++++++++++++++++ src/gl/gl3device.cpp | 102 ++++++++++++++ src/gl/rwgl3.h | 9 ++ 8 files changed, 511 insertions(+), 16 deletions(-) create mode 100644 skeleton/sdl2.cpp diff --git a/.appveyor.yml b/.appveyor.yml index 79268a1..41dd89f 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,28 +1,36 @@ image: Visual Studio 2017 configuration: Release -platform: - - win-amd64-null - - win-amd64-gl3 - - win-amd64-d3d9 environment: - APPVEYOR_SAVE_CACHE_ON_ERROR: true - GLFW_BASE: glfw-3.2.1.bin.WIN64 - GLFW_URL: https://github.com/glfw/glfw/releases/download/3.2.1/%GLFW_BASE%.zip GLEW_BASE: glew-2.1.0 GLEW_URL: https://github.com/nigels-com/glew/releases/download/glew-2.1.0/%GLEW_BASE%-win32.zip + GLFW_BASE: glfw-3.2.1.bin.WIN64 + GLFW_URL: https://github.com/glfw/glfw/releases/download/3.2.1/%GLFW_BASE%.zip + SDL2_BASE: SDL2-devel-2.0.8-VC + SDL2_URL: https://www.libsdl.org/release/%SDL2_BASE%.zip + SDL2_DIRAME: SDL2-2.0.8 PREMAKE5_URL: https://github.com/premake/premake-core/releases/download/v5.0.0-alpha12/premake-5.0.0-alpha12-windows.zip + matrix: + - PLATFORM: win-amd64-null + - PLATFORM: win-amd64-gl3 + PREMAKE5_EXTRA_ARGS: --gfxlib=glfw + - PLATFORM: win-amd64-gl3 + PREMAKE5_EXTRA_ARGS: --gfxlib=sdl2 + - PLATFORM: win-amd64-d3d9 + install: - appveyor DownloadFile %GLFW_URL% -FileName "%APPVEYOR_BUILD_FOLDER%/%GLFW_BASE%.zip" - 7z x "%APPVEYOR_BUILD_FOLDER%/%GLFW_BASE%.zip" - appveyor DownloadFile %GLEW_URL% -FileName "%APPVEYOR_BUILD_FOLDER%/%GLEW_BASE%.zip" - 7z x "%APPVEYOR_BUILD_FOLDER%/%GLEW_BASE%.zip" + - appveyor DownloadFile %SDL2_URL% -FileName "%APPVEYOR_BUILD_FOLDER%/%SDL2_BASE%.zip" + - 7z x "%APPVEYOR_BUILD_FOLDER%/%SDL2_BASE%.zip" - appveyor DownloadFile %PREMAKE5_URL% -FileName "%APPVEYOR_BUILD_FOLDER%/premake5.zip" - mkdir "%APPVEYOR_BUILD_FOLDER%/bin" && cd "%APPVEYOR_BUILD_FOLDER%/bin" && 7z x "%APPVEYOR_BUILD_FOLDER%/premake5.zip" - set PATH=%APPVEYOR_BUILD_FOLDER%/bin;%PATH% before_build: - mkdir "%APPVEYOR_BUILD_FOLDER%/build" - cd "%APPVEYOR_BUILD_FOLDER%" - - premake5 vs2017 --glfwdir=%APPVEYOR_BUILD_FOLDER%/%GLFW_BASE% --glewdir=%APPVEYOR_BUILD_FOLDER%/%GLEW_BASE% + - premake5 vs2017 --glewdir=%APPVEYOR_BUILD_FOLDER%/%GLEW_BASE% --glfwdir=%APPVEYOR_BUILD_FOLDER%/%GLFW_BASE% --sdl2dir=%APPVEYOR_BUILD_FOLDER%/%SDL2_DIRAME% %PREMAKE5_EXTRA_ARGS% build: project: c:\projects\librw\build\librw.sln verbosity: minimal diff --git a/.travis.yml b/.travis.yml index 4ff4231..c9e73a0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ language: cpp matrix: include: - os: linux - env: TARGET="release_linux-amd64-null" + env: TARGET=release_linux-amd64-null script: - mkdir -p "$TRAVIS_BUILD_DIR/build" #- docker build -t librw "$TRAVIS_BUILD_DIR" @@ -12,7 +12,7 @@ matrix: - docker run -v "$TRAVIS_BUILD_DIR:/librw:rw,z" -v "$TRAVIS_BUILD_DIR/build:/build:rw,z" --name librw_instance -d librw/librw sleep infinity - docker exec -u builder librw_instance /bin/bash -c "cd /librw && premake5 gmake && cd /librw/build && make config=$TARGET verbose=1" - os: linux - env: TARGET="release_linux-amd64-gl3" + env: TARGET=release_linux-amd64-gl3 GFXLIB=glfw services: docker script: - mkdir -p "$TRAVIS_BUILD_DIR/build" @@ -20,9 +20,19 @@ matrix: #- docker run -v "$TRAVIS_BUILD_DIR:/librw:rw,z" --name librw_instance -d librw sleep infinity - docker pull librw/librw - docker run -v "$TRAVIS_BUILD_DIR:/librw:rw,z" -v "$TRAVIS_BUILD_DIR/build:/build:rw,z" --name librw_instance -d librw/librw sleep infinity - - docker exec -u builder librw_instance /bin/bash -c "cd /librw && premake5 gmake && cd /librw/build && make config=$TARGET verbose=1" + - docker exec -u builder librw_instance /bin/bash -c "cd /librw && premake5 --gfxlib=$GFXLIB gmake && cd /librw/build && make config=$TARGET verbose=1" - os: linux - env: TARGET="release_ps2" + env: TARGET=release_linux-amd64-gl3 GFXLIB=sdl2 + services: docker + script: + - mkdir -p "$TRAVIS_BUILD_DIR/build" + #- docker build -t librw "$TRAVIS_BUILD_DIR" + #- docker run -v "$TRAVIS_BUILD_DIR:/librw:rw,z" --name librw_instance -d librw sleep infinity + - docker pull librw/librw + - docker run -v "$TRAVIS_BUILD_DIR:/librw:rw,z" -v "$TRAVIS_BUILD_DIR/build:/build:rw,z" --name librw_instance -d librw/librw sleep infinity + - docker exec -u builder librw_instance /bin/bash -c "cd /librw && premake5 --gfxlib=$GFXLIB gmake && cd /librw/build && make config=$TARGET verbose=1" + - os: linux + env: TARGET=release_ps2 services: docker script: - mkdir -p "$TRAVIS_BUILD_DIR/build" diff --git a/Dockerfile b/Dockerfile index 2792091..695e259 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,6 +30,7 @@ RUN mkdir -p "$PS2DEV" "$PS2SDK" \ zlib1g-dev \ libglew-dev \ libglfw3-dev \ + libsdl2-dev \ && git clone -b $TOOLCHAIN_GIT_BRANCH $TOOLCHAIN_GIT_URL /toolchain \ && cd /toolchain \ && ./toolchain.sh \ diff --git a/premake5.lua b/premake5.lua index be7a38b..b50d6ab 100644 --- a/premake5.lua +++ b/premake5.lua @@ -1,17 +1,35 @@ newoption { trigger = "glewdir", - value = "path", + value = "PATH", description = "Directory of GLEW", default = "C:/Users/aap/src/glew-2.1.0", } +newoption { + trigger = "gfxlib", + value = "LIBRARY", + description = "Choose a particular development library", + default = "glfw", + allowed = { + { "glfw", "GLFW" }, + { "sdl2", "SDL2" }, + }, +} + newoption { trigger = "glfwdir", - value = "path", + value = "PATH", description = "Directory of glfw", default = "C:/Users/aap/src/glfw-3.2.1.bin.WIN64", } +newoption { + trigger = "sdl2dir", + value = "PATH", + description = "Directory of sdl2", + default = "C:/Users/aap/src/SDL2-2.0.8", +} + workspace "librw" location "build" language "C++" @@ -25,6 +43,9 @@ workspace "librw" platforms { "linux-x86-null", "linux-x86-gl3", "linux-amd64-null", "linux-amd64-gl3", "ps2" } + if _OPTIONS["gfxlib"] == "sdl2" then + includedirs { "/usr/include/SDL2" } + end filter {} filter "configurations:Debug" @@ -40,6 +61,9 @@ workspace "librw" defines { "RW_NULL" } filter { "platforms:*gl3" } defines { "RW_GL3" } + if _OPTIONS["gfxlib"] == "sdl2" then + defines { "LIBRW_SDL2" } + end filter { "platforms:*d3d9" } defines { "RW_D3D9" } filter { "platforms:ps2" } @@ -64,6 +88,7 @@ workspace "librw" defines { "GLEW_STATIC" } includedirs { path.join(_OPTIONS["glewdir"], "include") } includedirs { path.join(_OPTIONS["glfwdir"], "include") } + includedirs { path.join(_OPTIONS["sdl2dir"], "include") } filter "action:vs*" buildoptions { "/wd4996", "/wd4244" } @@ -91,16 +116,28 @@ project "dumprwtree" function findlibs() filter { "platforms:linux*gl3" } - links { "GL", "GLEW", "glfw" } + links { "GL", "GLEW" } + if _OPTIONS["gfxlib"] == "glfw" then + links { "glfw" } + else + links { "SDL2" } + end filter { "platforms:win*gl3" } defines { "GLEW_STATIC" } filter { "platforms:win-amd64-gl3" } libdirs { path.join(_OPTIONS["glewdir"], "lib/Release/x64") } libdirs { path.join(_OPTIONS["glfwdir"], "lib-vc2015") } + libdirs { path.join(_OPTIONS["sdl2dir"], "lib/x64") } filter { "platforms:win-x86-gl3" } libdirs { path.join(_OPTIONS["glewdir"], "lib/Release/Win32") } + libdirs { path.join(_OPTIONS["sdl2dir"], "lib/x86") } filter { "platforms:win*gl3" } - links { "glew32s", "glfw3", "opengl32" } + links { "glew32s", "opengl32" } + if _OPTIONS["gfxlib"] == "glfw" then + links { "glfw3" } + else + links { "SDL2" } + end filter { "platforms:*d3d9" } links { "d3d9", "Xinput9_1_0" } filter {} diff --git a/skeleton/glfw.cpp b/skeleton/glfw.cpp index cfd3efd..5c513d6 100644 --- a/skeleton/glfw.cpp +++ b/skeleton/glfw.cpp @@ -1,3 +1,5 @@ +#ifndef LIBRW_SDL2 + #include #include "skeleton.h" @@ -257,3 +259,4 @@ SetMousePosition(int x, int y) } #endif +#endif diff --git a/skeleton/sdl2.cpp b/skeleton/sdl2.cpp new file mode 100644 index 0000000..264afe5 --- /dev/null +++ b/skeleton/sdl2.cpp @@ -0,0 +1,325 @@ +#ifdef LIBRW_SDL2 + +#include +#include "skeleton.h" + +using namespace sk; +using namespace rw; + +#ifdef RW_OPENGL + +SDL_Window *window; + +static int keyCodeToSkKey(SDL_Keycode keycode) { + switch (keycode) { + case SDLK_SPACE: return ' '; + case SDLK_QUOTE: return '\''; + case SDLK_COMMA: return ','; + case SDLK_MINUS: return '-'; + case SDLK_PERIOD: return '.'; + case SDLK_SLASH: return '/'; + + case SDLK_0: return '0'; + case SDLK_1: return '1'; + case SDLK_2: return '2'; + case SDLK_3: return '3'; + case SDLK_4: return '4'; + case SDLK_5: return '5'; + case SDLK_6: return '6'; + case SDLK_7: return '7'; + case SDLK_8: return '8'; + case SDLK_9: return '9'; + + case SDLK_SEMICOLON: return ';'; + case SDLK_EQUALS: return '='; + + case SDLK_a: return 'A'; + case SDLK_b: return 'B'; + case SDLK_c: return 'C'; + case SDLK_d: return 'D'; + case SDLK_e: return 'E'; + case SDLK_f: return 'F'; + case SDLK_g: return 'G'; + case SDLK_h: return 'H'; + case SDLK_i: return 'I'; + case SDLK_j: return 'J'; + case SDLK_k: return 'K'; + case SDLK_l: return 'L'; + case SDLK_m: return 'M'; + case SDLK_n: return 'N'; + case SDLK_o: return 'O'; + case SDLK_p: return 'P'; + case SDLK_q: return 'Q'; + case SDLK_r: return 'R'; + case SDLK_s: return 'S'; + case SDLK_t: return 'T'; + case SDLK_u: return 'U'; + case SDLK_v: return 'V'; + case SDLK_w: return 'W'; + case SDLK_x: return 'X'; + case SDLK_y: return 'Y'; + case SDLK_z: return 'Z'; + + case SDLK_LEFTBRACKET: return '['; + case SDLK_BACKSLASH: return '\\'; + case SDLK_RIGHTBRACKET: return ']'; + case SDLK_BACKQUOTE: return '`'; + case SDLK_ESCAPE: return KEY_ESC; + case SDLK_RETURN: return KEY_ENTER; + case SDLK_TAB: return KEY_TAB; + case SDLK_BACKSPACE: return KEY_BACKSP; + case SDLK_INSERT: return KEY_INS; + case SDLK_DELETE: return KEY_DEL; + case SDLK_RIGHT: return KEY_RIGHT; + case SDLK_DOWN: return KEY_DOWN; + case SDLK_UP: return KEY_UP; + case SDLK_PAGEUP: return KEY_PGUP; + case SDLK_PAGEDOWN: return KEY_PGDN; + case SDLK_HOME: return KEY_HOME; + case SDLK_END: return KEY_END; + case SDLK_CAPSLOCK: return KEY_CAPSLK; + case SDLK_SCROLLLOCK: return KEY_NULL; + case SDLK_NUMLOCKCLEAR: return KEY_NULL; + case SDLK_PRINTSCREEN: return KEY_NULL; + case SDLK_PAUSE: return KEY_NULL; + + case SDLK_F1: return KEY_F1; + case SDLK_F2: return KEY_F2; + case SDLK_F3: return KEY_F3; + case SDLK_F4: return KEY_F4; + case SDLK_F5: return KEY_F5; + case SDLK_F6: return KEY_F6; + case SDLK_F7: return KEY_F7; + case SDLK_F8: return KEY_F8; + case SDLK_F9: return KEY_F9; + case SDLK_F10: return KEY_F10; + case SDLK_F11: return KEY_F11; + case SDLK_F12: return KEY_F12; + case SDLK_F13: return KEY_NULL; + case SDLK_F14: return KEY_NULL; + case SDLK_F15: return KEY_NULL; + case SDLK_F16: return KEY_NULL; + case SDLK_F17: return KEY_NULL; + case SDLK_F18: return KEY_NULL; + case SDLK_F19: return KEY_NULL; + case SDLK_F20: return KEY_NULL; + case SDLK_F21: return KEY_NULL; + case SDLK_F22: return KEY_NULL; + case SDLK_F23: return KEY_NULL; + case SDLK_F24: return KEY_NULL; + + case SDLK_KP_0: return KEY_NULL; + case SDLK_KP_1: return KEY_NULL; + case SDLK_KP_2: return KEY_NULL; + case SDLK_KP_3: return KEY_NULL; + case SDLK_KP_4: return KEY_NULL; + case SDLK_KP_5: return KEY_NULL; + case SDLK_KP_6: return KEY_NULL; + case SDLK_KP_7: return KEY_NULL; + case SDLK_KP_8: return KEY_NULL; + case SDLK_KP_9: return KEY_NULL; + case SDLK_KP_DECIMAL: return KEY_NULL; + case SDLK_KP_DIVIDE: return KEY_NULL; + case SDLK_KP_MULTIPLY: return KEY_NULL; + case SDLK_KP_MINUS: return KEY_NULL; + case SDLK_KP_PLUS: return KEY_NULL; + case SDLK_KP_ENTER: return KEY_NULL; + case SDLK_KP_EQUALS: return KEY_NULL; + + case SDLK_LSHIFT: return KEY_LSHIFT; + case SDLK_LCTRL: return KEY_LCTRL; + case SDLK_LALT: return KEY_LALT; + case SDLK_LGUI: return KEY_NULL; + case SDLK_RSHIFT: return KEY_RSHIFT; + case SDLK_RCTRL: return KEY_RCTRL; + case SDLK_RALT: return KEY_RALT; + case SDLK_RGUI: return KEY_NULL; + case SDLK_MENU: return KEY_NULL; + } + return KEY_NULL; +} + +#if 0 +static void +keypress(SDL_Window *window, int key, int scancode, int action, int mods) +{ + if(key >= 0 && key <= GLFW_KEY_LAST){ + if(action == GLFW_RELEASE) KeyUp(keymap[key]); + else if(action == GLFW_PRESS) KeyDown(keymap[key]); + else if(action == GLFW_REPEAT) KeyDown(keymap[key]); + } +} + +static void +charinput(GLFWwindow *window, unsigned int c) +{ + EventHandler(CHARINPUT, (void*)(uintptr)c); +} + +static void +resize(GLFWwindow *window, int w, int h) +{ + rw::Rect r; + r.x = 0; + r.y = 0; + r.w = w; + r.h = h; + EventHandler(RESIZE, &r); +} + +static void +mousebtn(GLFWwindow *window, int button, int action, int mods) +{ + static int buttons = 0; + sk::MouseState ms; + + switch(button){ + case GLFW_MOUSE_BUTTON_LEFT: + if(action == GLFW_PRESS) + buttons |= 1; + else + buttons &= ~1; + break; + case GLFW_MOUSE_BUTTON_MIDDLE: + if(action == GLFW_PRESS) + buttons |= 2; + else + buttons &= ~2; + break; + case GLFW_MOUSE_BUTTON_RIGHT: + if(action == GLFW_PRESS) + buttons |= 4; + else + buttons &= ~4; + break; + } + + sk::MouseState ms; + ms.buttons = buttons; + EventHandler(MOUSEBTN, &ms); +} +#endif + +enum mousebutton { +BUTTON_LEFT = 0x1, +BUTTON_MIDDLE = 0x2, +BUTTON_RIGHT = 0x4, +}; + +int +main(int argc, char *argv[]) +{ + args.argc = argc; + args.argv = argv; + + if(EventHandler(INITIALIZE, nil) == EVENTERROR) + return 0; + + engineStartParams.width = sk::globals.width; + engineStartParams.height = sk::globals.height; + engineStartParams.windowtitle = sk::globals.windowtitle; + engineStartParams.window = &window; + + if(EventHandler(RWINITIALIZE, nil) == EVENTERROR) + return 0; + + float lastTime = SDL_GetTicks(); + SDL_Event event; + int mouseButtons = 0; + + SDL_StartTextInput(); + + while(!sk::globals.quit){ + while(SDL_PollEvent(&event)){ + switch(event.type){ + case SDL_QUIT: + sk::globals.quit = true; + break; + case SDL_WINDOWEVENT: + switch (event.window.event) { + case SDL_WINDOWEVENT_RESIZED: { + rw::Rect r; + SDL_GetWindowPosition(window, &r.x, &r.y); + r.w = event.window.data1; + r.h = event.window.data2; + EventHandler(RESIZE, &r); + break; + } + } + break; + case SDL_KEYUP: { + int c = keyCodeToSkKey(event.key.keysym.sym); + EventHandler(KEYUP, &c); + break; + } + case SDL_KEYDOWN: { + int c = keyCodeToSkKey(event.key.keysym.sym); + EventHandler(KEYDOWN, &c); + break; + } + case SDL_TEXTINPUT: { + char *c = event.text.text; + while (int ci = *c) { + EventHandler(CHARINPUT, (void*)(uintptr)ci); + ++c; + } + break; + } + case SDL_MOUSEMOTION: { + sk::MouseState ms; + ms.posx = event.motion.x; + ms.posy = event.motion.y; + EventHandler(MOUSEMOVE, &ms); + break; + } + case SDL_MOUSEBUTTONDOWN: { + switch (event.button.button) { + case SDL_BUTTON_LEFT: mouseButtons |= BUTTON_LEFT; break; + case SDL_BUTTON_MIDDLE: mouseButtons |= BUTTON_MIDDLE; break; + case SDL_BUTTON_RIGHT: mouseButtons |= BUTTON_RIGHT; break; + } + sk::MouseState ms; + ms.buttons = mouseButtons; + EventHandler(MOUSEBTN, &ms); + break; + } + case SDL_MOUSEBUTTONUP: { + switch (event.button.button) { + case SDL_BUTTON_LEFT: mouseButtons &= ~BUTTON_LEFT; break; + case SDL_BUTTON_MIDDLE: mouseButtons &= ~BUTTON_MIDDLE; break; + case SDL_BUTTON_RIGHT: mouseButtons &= ~BUTTON_RIGHT; break; + } + sk::MouseState ms; + ms.buttons = mouseButtons; + EventHandler(MOUSEBTN, &ms); + break; + } + } + } + float currTime = SDL_GetTicks(); + float timeDelta = (currTime - lastTime) * 0.001f; + + EventHandler(IDLE, &timeDelta); + + lastTime = currTime; + } + + SDL_StopTextInput(); + + EventHandler(RWTERMINATE, nil); + + return 0; +} + +namespace sk { + +void +SetMousePosition(int x, int y) +{ + SDL_WarpMouseInWindow(*engineStartParams.window, x, y); +} + +} + +#endif +#endif diff --git a/src/gl/gl3device.cpp b/src/gl/gl3device.cpp index 2bde1b9..189bf1e 100755 --- a/src/gl/gl3device.cpp +++ b/src/gl/gl3device.cpp @@ -12,7 +12,11 @@ #include "../rwobjects.h" #ifdef RW_OPENGL #include +#ifdef LIBRW_SDL2 +#include +#else #include +#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(); diff --git a/src/gl/rwgl3.h b/src/gl/rwgl3.h index ac3150a..da7533f 100644 --- a/src/gl/rwgl3.h +++ b/src/gl/rwgl3.h @@ -1,15 +1,24 @@ #ifdef RW_GL3 #include +#ifdef LIBRW_SDL2 +#include +#else #include #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