From 4a9d1927c4703f9fe3f7abcaedffd63dd0ad4ff8 Mon Sep 17 00:00:00 2001 From: Eidolon Date: Fri, 3 Apr 2026 19:30:17 -0500 Subject: [PATCH] Convert legacy GL files to C++ --- src/cvars.cpp | 4 +- src/hardware/CMakeLists.txt | 26 ++-- .../{hw_batching.c => hw_batching.cpp} | 20 +-- src/hardware/{hw_bsp.c => hw_bsp.cpp} | 12 +- src/hardware/{hw_cache.c => hw_cache.cpp} | 68 +++++----- src/hardware/{hw_clip.c => hw_clip.cpp} | 0 src/hardware/{hw_draw.c => hw_draw.cpp} | 24 ++-- src/hardware/{hw_light.c => hw_light.cpp} | 4 +- src/hardware/{hw_main.c => hw_main.cpp} | 93 ++++++------- src/hardware/{hw_md2.c => hw_md2.cpp} | 123 +++++++++--------- src/hardware/{hw_md2load.c => hw_md2load.cpp} | 2 +- src/hardware/{hw_md3load.c => hw_md3load.cpp} | 2 +- src/hardware/{hw_model.c => hw_model.cpp} | 0 .../r_opengl/{ogl_win.c => ogl_win.cpp} | 4 +- .../r_opengl/{r_opengl.c => r_opengl.cpp} | 25 ++-- src/hardware/{u_list.c => u_list.cpp} | 0 16 files changed, 205 insertions(+), 202 deletions(-) rename src/hardware/{hw_batching.c => hw_batching.cpp} (94%) rename src/hardware/{hw_bsp.c => hw_bsp.cpp} (98%) rename src/hardware/{hw_cache.c => hw_cache.cpp} (94%) rename src/hardware/{hw_clip.c => hw_clip.cpp} (100%) rename src/hardware/{hw_draw.c => hw_draw.cpp} (97%) rename src/hardware/{hw_light.c => hw_light.cpp} (99%) rename src/hardware/{hw_main.c => hw_main.cpp} (98%) rename src/hardware/{hw_md2.c => hw_md2.cpp} (93%) rename src/hardware/{hw_md2load.c => hw_md2load.cpp} (99%) rename src/hardware/{hw_md3load.c => hw_md3load.cpp} (99%) rename src/hardware/{hw_model.c => hw_model.cpp} (100%) rename src/hardware/r_opengl/{ogl_win.c => ogl_win.cpp} (99%) rename src/hardware/r_opengl/{r_opengl.c => r_opengl.cpp} (99%) rename src/hardware/{u_list.c => u_list.cpp} (100%) diff --git a/src/cvars.cpp b/src/cvars.cpp index d589b33d5..7a232def2 100644 --- a/src/cvars.cpp +++ b/src/cvars.cpp @@ -1474,7 +1474,7 @@ consvar_t cv_voice_allowservervoice = NetVar("voice_allowservervoice", "Off") consvar_t cv_glshaders = OpenGL("gr_shaders", "On").values(glshaders_cons_t); extern CV_PossibleValue_t glanisotropicmode_cons_t[]; - void CV_glanisotropic_OnChange(void); + extern "C" void CV_glanisotropic_OnChange(void); consvar_t cv_glanisotropicmode = OpenGL("gr_anisotropicmode", "1").values(glanisotropicmode_cons_t).onchange(CV_glanisotropic_OnChange); consvar_t cv_glbatching = OpenGL("gr_batching", "On").on_off().dont_save(); @@ -1487,7 +1487,7 @@ consvar_t cv_voice_allowservervoice = NetVar("voice_allowservervoice", "Off") #endif extern CV_PossibleValue_t glfiltermode_cons_t[]; - void CV_glfiltermode_OnChange(void); + extern "C" void CV_glfiltermode_OnChange(void); consvar_t cv_glfiltermode = OpenGL("gr_filtermode", "Nearest").values(glfiltermode_cons_t).onchange(CV_glfiltermode_OnChange); #ifdef BAD_MODEL_OPTIONS diff --git a/src/hardware/CMakeLists.txt b/src/hardware/CMakeLists.txt index a0a0f280c..a3a9b2a72 100644 --- a/src/hardware/CMakeLists.txt +++ b/src/hardware/CMakeLists.txt @@ -1,15 +1,15 @@ target_sources(SRB2SDL2 PRIVATE - hw_bsp.c - hw_draw.c - hw_light.c - hw_main.c - hw_clip.c - hw_md2.c - hw_cache.c - hw_md2load.c - hw_md3load.c - hw_model.c - u_list.c - hw_batching.c - r_opengl/r_opengl.c + hw_bsp.cpp + hw_draw.cpp + hw_light.cpp + hw_main.cpp + hw_clip.cpp + hw_md2.cpp + hw_cache.cpp + hw_md2load.cpp + hw_md3load.cpp + hw_model.cpp + u_list.cpp + hw_batching.cpp + r_opengl/r_opengl.cpp ) diff --git a/src/hardware/hw_batching.c b/src/hardware/hw_batching.cpp similarity index 94% rename from src/hardware/hw_batching.c rename to src/hardware/hw_batching.cpp index 9c0e2f6e9..a7625e28b 100644 --- a/src/hardware/hw_batching.c +++ b/src/hardware/hw_batching.cpp @@ -50,11 +50,11 @@ void HWR_StartBatching(void) // init arrays if that has not been done yet if (!finalVertexArray) { - finalVertexArray = malloc(finalVertexArrayAllocSize * sizeof(FOutVector)); - finalVertexIndexArray = malloc(finalVertexArrayAllocSize * 3 * sizeof(UINT32)); - polygonArray = malloc(polygonArrayAllocSize * sizeof(PolygonArrayEntry)); - polygonIndexArray = malloc(polygonArrayAllocSize * sizeof(UINT32)); - unsortedVertexArray = malloc(unsortedVertexArrayAllocSize * sizeof(FOutVector)); + finalVertexArray = (FOutVector *)malloc(finalVertexArrayAllocSize * sizeof(FOutVector)); + finalVertexIndexArray = (UINT32 *)malloc(finalVertexArrayAllocSize * 3 * sizeof(UINT32)); + polygonArray = (PolygonArrayEntry *)malloc(polygonArrayAllocSize * sizeof(PolygonArrayEntry)); + polygonIndexArray = (UINT32 *)malloc(polygonArrayAllocSize * sizeof(UINT32)); + unsortedVertexArray = (FOutVector *)malloc(unsortedVertexArrayAllocSize * sizeof(FOutVector)); } currently_batching = true; @@ -104,13 +104,13 @@ void HWR_ProcessPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPt PolygonArrayEntry* new_array; // ran out of space, make new array double the size polygonArrayAllocSize *= 2; - new_array = malloc(polygonArrayAllocSize * sizeof(PolygonArrayEntry)); + new_array = (PolygonArrayEntry *)malloc(polygonArrayAllocSize * sizeof(PolygonArrayEntry)); memcpy(new_array, polygonArray, polygonArraySize * sizeof(PolygonArrayEntry)); free(polygonArray); polygonArray = new_array; // also need to redo the index array, dont need to copy it though free(polygonIndexArray); - polygonIndexArray = malloc(polygonArrayAllocSize * sizeof(UINT32)); + polygonIndexArray = (UINT32 *)malloc(polygonArrayAllocSize * sizeof(UINT32)); } while (unsortedVertexArraySize + (int)iNumPts > unsortedVertexArrayAllocSize) @@ -118,7 +118,7 @@ void HWR_ProcessPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPt FOutVector* new_array; // need more space for vertices in unsortedVertexArray unsortedVertexArrayAllocSize *= 2; - new_array = malloc(unsortedVertexArrayAllocSize * sizeof(FOutVector)); + new_array = (FOutVector *)malloc(unsortedVertexArrayAllocSize * sizeof(FOutVector)); memcpy(new_array, unsortedVertexArray, unsortedVertexArraySize * sizeof(FOutVector)); free(unsortedVertexArray); unsortedVertexArray = new_array; @@ -368,13 +368,13 @@ void HWR_RenderBatches(void) FOutVector* new_array; unsigned int* new_index_array; finalVertexArrayAllocSize *= 2; - new_array = malloc(finalVertexArrayAllocSize * sizeof(FOutVector)); + new_array = (FOutVector *)malloc(finalVertexArrayAllocSize * sizeof(FOutVector)); memcpy(new_array, finalVertexArray, finalVertexWritePos * sizeof(FOutVector)); free(finalVertexArray); finalVertexArray = new_array; // also increase size of index array, 3x of vertex array since // going from fans to triangles increases vertex count to 3x - new_index_array = malloc(finalVertexArrayAllocSize * 3 * sizeof(UINT32)); + new_index_array = (UINT32 *)malloc(finalVertexArrayAllocSize * 3 * sizeof(UINT32)); memcpy(new_index_array, finalVertexIndexArray, finalIndexWritePos * sizeof(UINT32)); free(finalVertexIndexArray); finalVertexIndexArray = new_index_array; diff --git a/src/hardware/hw_bsp.c b/src/hardware/hw_bsp.cpp similarity index 98% rename from src/hardware/hw_bsp.c rename to src/hardware/hw_bsp.cpp index 0b036ead0..fecd1128f 100644 --- a/src/hardware/hw_bsp.c +++ b/src/hardware/hw_bsp.cpp @@ -88,7 +88,7 @@ void HWR_InitPolyPool(void) POLYPOOLSIZE = atoi(myargv[pnum+1])*1024; // (in kb) CONS_Debug(DBG_RENDER, "HWR_InitPolyPool(): allocating %d bytes\n", POLYPOOLSIZE); - gl_polypool = malloc(POLYPOOLSIZE); + gl_polypool = (UINT8 *)malloc(POLYPOOLSIZE); if (!gl_polypool) I_Error("HWR_InitPolyPool(): couldn't malloc polypool\n"); HWR_ClearPolys(); @@ -109,7 +109,7 @@ static poly_t *HWR_AllocPoly(INT32 numpts) poly_t *p; size_t size = sizeof (poly_t) + sizeof (polyvertex_t) * numpts; #ifdef ZPLANALLOC - p = Z_Malloc(size, PU_HWRPLANE, NULL); + p = (poly_t *)Z_Malloc(size, PU_HWRPLANE, NULL); #else #ifdef PARANOIA if (!gl_polypool) @@ -135,7 +135,7 @@ static polyvertex_t *HWR_AllocVertex(void) polyvertex_t *p; size_t size = sizeof (polyvertex_t); #ifdef ZPLANALLOC - p = Z_Malloc(size, PU_HWRPLANE, NULL); + p = (polyvertex_t *)Z_Malloc(size, PU_HWRPLANE, NULL); #else if (gl_ppfree < size) I_Error("HWR_AllocVertex(): no more memory %u bytes left, %u bytes needed\n\n%s\n", @@ -715,8 +715,8 @@ void HWR_FreeExtraSubsectors(void) //#define MOVEVERTEX static boolean PointInSeg(polyvertex_t *a,polyvertex_t *v1,polyvertex_t *v2) { - register float ax,ay,bx,by,cx,cy,d,norm; - register polyvertex_t *p; + float ax,ay,bx,by,cx,cy,d,norm; + polyvertex_t *p; // check bbox of the seg first if (v1->x > v2->x) @@ -985,7 +985,7 @@ void HWR_CreatePlanePolygons(INT32 bspnum) HWR_FreeExtraSubsectors(); // allocate extra data for each subsector present in map totsubsectors = numsubsectors + NEWSUBSECTORS; - extrasubsectors = calloc(totsubsectors, sizeof (*extrasubsectors)); + extrasubsectors = (extrasubsector_t *)calloc(totsubsectors, sizeof (*extrasubsectors)); if (extrasubsectors == NULL) I_Error("couldn't malloc extrasubsectors totsubsectors %s\n", sizeu1(totsubsectors)); diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.cpp similarity index 94% rename from src/hardware/hw_cache.c rename to src/hardware/hw_cache.cpp index aee197ab5..f5ffbf1d5 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.cpp @@ -283,7 +283,7 @@ static void HWR_DrawPatchInCache(GLMipmap_t *mipmap, fixed_t xfrac, xfracstep; fixed_t yfracstep, scale_y; const column_t *patchcol; - UINT8 *block = mipmap->data; + UINT8 *block = (UINT8 *)mipmap->data; INT32 bpp; INT32 blockmodulo; @@ -330,7 +330,7 @@ static void HWR_DrawTexturePatchInCache(GLMipmap_t *mipmap, fixed_t xfrac, xfracstep; fixed_t yfracstep, scale_y; const column_t *patchcol; - UINT8 *block = mipmap->data; + UINT8 *block = (UINT8 *)mipmap->data; INT32 bpp; INT32 blockmodulo; INT32 width, height; @@ -423,7 +423,7 @@ static UINT8 *MakeBlock(GLMipmap_t *grMipmap) INT32 blocksize = (grMipmap->width * grMipmap->height); bpp = format2bpp(grMipmap->format); - block = Z_Malloc(blocksize*bpp, PU_HWRCACHE, &(grMipmap->data)); + block = (UINT8 *)Z_Malloc(blocksize*bpp, PU_HWRCACHE, &(grMipmap->data)); switch (bpp) { @@ -476,12 +476,12 @@ static void HWR_GenerateTexture(GLMapTexture_t *grtex, INT32 texnum, boolean noe grtex->mipmap.width = (UINT16)texture->width; grtex->mipmap.height = (UINT16)texture->height; - grtex->mipmap.format = textureformat; + grtex->mipmap.format = (GLTextureFormat_t)textureformat; if (!noencoremap && encoremap) colormap += COLORMAP_REMAPOFFSET; - grtex->mipmap.colormap = Z_Calloc(sizeof(*grtex->mipmap.colormap), PU_HWRPATCHCOLMIPMAP, NULL); + grtex->mipmap.colormap = (GLColormap_t *)Z_Calloc(sizeof(*grtex->mipmap.colormap), PU_HWRPATCHCOLMIPMAP, NULL); grtex->mipmap.colormap->source = colormap; M_Memcpy(grtex->mipmap.colormap->data, colormap, 256 * sizeof(UINT8)); @@ -513,17 +513,17 @@ static void HWR_GenerateTexture(GLMapTexture_t *grtex, INT32 texnum, boolean noe { boolean dealloc = true; size_t lumplength = W_LumpLengthPwad(patch->wad, patch->lump); - pdata = W_CacheLumpNumPwad(patch->wad, patch->lump, PU_CACHE); + pdata = (uint8_t*)W_CacheLumpNumPwad(patch->wad, patch->lump, PU_CACHE); realpatch = (softwarepatch_t *)pdata; #ifndef NO_PNG_LUMPS if (Picture_IsLumpPNG((UINT8 *)realpatch, lumplength)) - realpatch = (softwarepatch_t *)Picture_PNGConvert(pdata, PICFMT_DOOMPATCH, NULL, NULL, NULL, NULL, lumplength, NULL, 0); + realpatch = (softwarepatch_t *)Picture_PNGConvert(pdata, PICFMT_DOOMPATCH, NULL, NULL, NULL, NULL, lumplength, NULL, (pictureflags_t)0); else #endif #ifdef WALLFLATS if (texture->type == TEXTURETYPE_FLAT) - realpatch = (softwarepatch_t *)Picture_Convert(PICFMT_FLAT, pdata, PICFMT_DOOMPATCH, 0, NULL, texture->width, texture->height, 0, 0, 0); + realpatch = (softwarepatch_t *)Picture_Convert(PICFMT_FLAT, pdata, PICFMT_DOOMPATCH, 0, NULL, texture->width, texture->height, 0, 0, (pictureflags_t)0); else #endif { @@ -566,7 +566,7 @@ void HWR_MakePatch (const patch_t *patch, GLPatch_t *grPatch, GLMipmap_t *grMipm grMipmap->flags = 0; // setup the texture info - grMipmap->format = patchformat; + grMipmap->format = (GLTextureFormat_t)patchformat; grPatch->max_s = (float)patch->width / (float)grMipmap->width; grPatch->max_t = (float)patch->height / (float)grMipmap->height; @@ -601,7 +601,7 @@ void HWR_FreeTextureData(patch_t *patch) if (!patch || !patch->hardware) return; - grPatch = patch->hardware; + grPatch = (GLPatch_t*)patch->hardware; if (vid.glstate == VID_GL_LIBRARY_LOADED) HWD.pfnDeleteTexture(grPatch->mipmap); @@ -616,7 +616,7 @@ void HWR_FreeTexture(patch_t *patch) if (patch->hardware) { - GLPatch_t *grPatch = patch->hardware; + GLPatch_t *grPatch = (GLPatch_t*)patch->hardware; HWR_FreeTextureColormaps(patch); @@ -641,7 +641,7 @@ void HWR_FreeTextureColormaps(patch_t *patch) if (!patch) return; - pat = patch->hardware; + pat = (GLPatch_t*)patch->hardware; if (!pat) return; @@ -759,8 +759,8 @@ void HWR_LoadMapTextures(size_t pnumtextures) HWR_FreeMapTextures(); gl_numtextures = pnumtextures; - gl_textures = calloc(gl_numtextures, sizeof(*gl_textures)); - gl_flats = calloc(gl_numtextures, sizeof(*gl_flats)); + gl_textures = (GLMapTexture_t *)calloc(gl_numtextures, sizeof(*gl_textures)); + gl_flats = (GLMapTexture_t *)calloc(gl_numtextures, sizeof(*gl_flats)); if ((gl_textures == NULL) || (gl_flats == NULL)) I_Error("HWR_LoadMapTextures: ran out of memory for OpenGL textures"); @@ -879,7 +879,7 @@ static void HWR_CacheFlat(GLMipmap_t *grMipmap, lumpnum_t flatlumpnum) W_ReadLump(flatlumpnum, Z_Malloc(W_LumpLength(flatlumpnum), PU_HWRCACHE, &grMipmap->data)); - flat = grMipmap->data; + flat = (UINT8*)grMipmap->data; for (steppy = 0; steppy < size; steppy++) if (flat[steppy] != HWR_PATCHES_CHROMAKEY_COLORINDEX) flat[steppy] = grMipmap->colormap->source[flat[steppy]]; @@ -906,7 +906,7 @@ static void HWR_CacheTextureAsFlat(GLMipmap_t *grMipmap, INT32 texturenum, boole grMipmap->height = (UINT16)textures[texturenum]->height; size = (grMipmap->width * grMipmap->height); - flat = Z_Malloc(size, PU_HWRCACHE, &grMipmap->data); + flat = (UINT8 *)Z_Malloc(size, PU_HWRCACHE, &grMipmap->data); converted = (UINT8 *)Picture_TextureToFlat(texturenum); for (i = 0; i < size; i++) { @@ -934,7 +934,7 @@ void HWR_GetRawFlat(lumpnum_t flatlumpnum, boolean noencoremap) if (!noencoremap && encoremap) colormap += COLORMAP_REMAPOFFSET; - grmip->colormap = Z_Calloc(sizeof(*grmip->colormap), PU_HWRPATCHCOLMIPMAP, NULL); + grmip->colormap = (GLColormap_t *)Z_Calloc(sizeof(*grmip->colormap), PU_HWRPATCHCOLMIPMAP, NULL); grmip->colormap->source = colormap; M_Memcpy(grmip->colormap->data, colormap, 256 * sizeof(UINT8)); } @@ -1013,7 +1013,7 @@ void HWR_GetLevelFlat(levelflat_t *levelflat, boolean noencoremap) } else if (levelflat->type == LEVELFLAT_PATCH) { - patch_t *patch = W_CachePatchNum(levelflat->u.flat.lumpnum, PU_CACHE); + patch_t *patch = (patch_t *)W_CachePatchNum(levelflat->u.flat.lumpnum, PU_CACHE); levelflat->width = (UINT16)(patch->width); levelflat->height = (UINT16)(patch->height); HWR_GetPatch(patch); @@ -1021,13 +1021,13 @@ void HWR_GetLevelFlat(levelflat_t *levelflat, boolean noencoremap) #ifndef NO_PNG_LUMPS else if (levelflat->type == LEVELFLAT_PNG) { - GLMipmap_t *mipmap = levelflat->mipmap; + GLMipmap_t *mipmap = (GLMipmap_t *)levelflat->mipmap; // Cache the picture. if (!levelflat->mippic) { INT32 pngwidth = 0, pngheight = 0; - void *pic = Picture_PNGConvert(W_CacheLumpNum(levelflat->u.flat.lumpnum, PU_CACHE), PICFMT_FLAT, &pngwidth, &pngheight, NULL, NULL, W_LumpLength(levelflat->u.flat.lumpnum), NULL, 0); + void *pic = Picture_PNGConvert((const UINT8*)W_CacheLumpNum(levelflat->u.flat.lumpnum, PU_CACHE), PICFMT_FLAT, &pngwidth, &pngheight, NULL, NULL, W_LumpLength(levelflat->u.flat.lumpnum), NULL, (pictureflags_t)0); Z_ChangeTag(pic, PU_LEVEL); Z_SetUser(pic, &levelflat->mippic); @@ -1039,7 +1039,7 @@ void HWR_GetLevelFlat(levelflat_t *levelflat, boolean noencoremap) // Make the mipmap. if (mipmap == NULL) { - mipmap = Z_Calloc(sizeof(GLMipmap_t), PU_STATIC, NULL); + mipmap = (GLMipmap_t *)Z_Calloc(sizeof(GLMipmap_t), PU_STATIC, NULL); mipmap->format = GL_TEXFMT_P_8; mipmap->flags = TF_WRAPXY|TF_CHROMAKEYED; levelflat->mipmap = mipmap; @@ -1057,7 +1057,7 @@ void HWR_GetLevelFlat(levelflat_t *levelflat, boolean noencoremap) mipmap->height = levelflat->height; size = (mipmap->width * mipmap->height); - flat = Z_Malloc(size, PU_LEVEL, &mipmap->data); + flat = (UINT8 *)Z_Malloc(size, PU_LEVEL, &mipmap->data); M_Memcpy(flat, levelflat->mippic, size); } @@ -1074,7 +1074,7 @@ void HWR_GetLevelFlat(levelflat_t *levelflat, boolean noencoremap) // --------------------+ static void HWR_LoadPatchMipmap(patch_t *patch, GLMipmap_t *grMipmap) { - GLPatch_t *grPatch = patch->hardware; + GLPatch_t *grPatch = (GLPatch_t *)patch->hardware; if (!grMipmap->downloaded && !grMipmap->data) HWR_MakePatch(patch, grPatch, grMipmap, true); @@ -1092,7 +1092,7 @@ static void HWR_LoadPatchMipmap(patch_t *patch, GLMipmap_t *grMipmap) // ----------------------+ static void HWR_UpdatePatchMipmap(patch_t *patch, GLMipmap_t *grMipmap) { - GLPatch_t *grPatch = patch->hardware; + GLPatch_t *grPatch = (GLPatch_t *)patch->hardware; HWR_MakePatch(patch, grPatch, grMipmap, true); // If hardware does not have the texture, then call pfnSetTexture to upload it @@ -1127,7 +1127,7 @@ void HWR_GetMappedPatch(patch_t *patch, const UINT8 *colormap) if (!patch->hardware) Patch_CreateGL(patch); - grPatch = patch->hardware; + grPatch = (GLPatch_t *)patch->hardware; // Blatant hack for encore colormapping aside... if (colormap == colormaps || colormap == NULL || colormap == (const UINT8*)(COLORMAP_REMAPOFFSET)) @@ -1161,12 +1161,12 @@ void HWR_GetMappedPatch(patch_t *patch, const UINT8 *colormap) // (it have a liste of mipmap) // this malloc is cleared in HWR_FreeColormapCache // (...) unfortunately z_malloc fragment alot the memory :(so malloc is better - newMipmap = calloc(1, sizeof (*newMipmap)); + newMipmap = (GLMipmap_t *)calloc(1, sizeof (*newMipmap)); if (newMipmap == NULL) I_Error("%s: Out of memory", "HWR_GetMappedPatch"); grMipmap->nextcolormap = newMipmap; - newMipmap->colormap = Z_Calloc(sizeof(*newMipmap->colormap), PU_HWRPATCHCOLMIPMAP, NULL); + newMipmap->colormap = (GLColormap_t *)Z_Calloc(sizeof(*newMipmap->colormap), PU_HWRPATCHCOLMIPMAP, NULL); newMipmap->colormap->source = colormap; M_Memcpy(newMipmap->colormap->data, colormap, 256 * sizeof(UINT8)); @@ -1202,7 +1202,7 @@ static void HWR_DrawPicInCache(UINT8 *block, INT32 pblockwidth, INT32 pblockheig stepy = ((INT32)SHORT(pic->height)<width)<mode]); + picbpp = format2bpp((GLTextureFormat_t)picmode2GR[pic->mode]); posy = 0; for (j = 0; j < pblockheight; j++) { @@ -1270,7 +1270,7 @@ patch_t *HWR_GetPic(lumpnum_t lumpnum) UINT8 *block; size_t len; - pic = W_CacheLumpNum(lumpnum, PU_CACHE); + pic = (pic_t*)W_CacheLumpNum(lumpnum, PU_CACHE); patch->width = SHORT(pic->width); patch->height = SHORT(pic->height); len = W_LumpLength(lumpnum) - sizeof (pic_t); @@ -1279,9 +1279,9 @@ patch_t *HWR_GetPic(lumpnum_t lumpnum) grPatch->mipmap->height = (UINT16)patch->height; if (pic->mode == PALETTE) - grPatch->mipmap->format = textureformat; // can be set by driver + grPatch->mipmap->format = (GLTextureFormat_t)textureformat; // can be set by driver else - grPatch->mipmap->format = picmode2GR[pic->mode]; + grPatch->mipmap->format = (GLTextureFormat_t)picmode2GR[pic->mode]; Z_Free(grPatch->mipmap->data); @@ -1290,7 +1290,7 @@ patch_t *HWR_GetPic(lumpnum_t lumpnum) if (patch->width == SHORT(pic->width) && patch->height == SHORT(pic->height) && - format2bpp(grPatch->mipmap->format) == format2bpp(picmode2GR[pic->mode])) + format2bpp(grPatch->mipmap->format) == format2bpp((GLTextureFormat_t)picmode2GR[pic->mode])) { // no conversion needed M_Memcpy(grPatch->mipmap->data, pic->data,len); @@ -1318,7 +1318,7 @@ patch_t *HWR_GetCachedGLPatchPwad(UINT16 wadnum, UINT16 lumpnum) lumpcache_t *lumpcache = wadfiles[wadnum]->patchcache; if (!lumpcache[lumpnum]) { - void *ptr = Z_Calloc(sizeof(patch_t), PU_PATCH, &lumpcache[lumpnum]); + patch_t *ptr = (patch_t *)Z_Calloc(sizeof(patch_t), PU_PATCH, &lumpcache[lumpnum]); Patch_Create(NULL, 0, ptr); Patch_AllocateHardwarePatch(ptr); } @@ -1336,7 +1336,7 @@ static void HWR_DrawFadeMaskInCache(GLMipmap_t *mipmap, INT32 pblockwidth, INT32 { INT32 i,j; fixed_t posx, posy, stepx, stepy; - UINT8 *block = mipmap->data; // places the data directly into here + UINT8 *block = (UINT8 *)mipmap->data; // places the data directly into here UINT8 *flat; UINT8 *dest, *src, texel; RGBA_t col; diff --git a/src/hardware/hw_clip.c b/src/hardware/hw_clip.cpp similarity index 100% rename from src/hardware/hw_clip.c rename to src/hardware/hw_clip.cpp diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.cpp similarity index 97% rename from src/hardware/hw_draw.c rename to src/hardware/hw_draw.cpp index d4ba78614..1c2a2af17 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.cpp @@ -881,7 +881,7 @@ void HWR_DrawViewBorder(INT32 clearlines) // top edge if (clearlines > basewindowy - 8) { - patch = W_CachePatchNum(viewborderlump[BRDR_T], PU_PATCH); + patch = (patch_t*)W_CachePatchNum(viewborderlump[BRDR_T], PU_PATCH); for (x = 0; x < baseviewwidth; x += 8) HWR_DrawPatch(patch, basewindowx + x, basewindowy - 8, 0); @@ -890,7 +890,7 @@ void HWR_DrawViewBorder(INT32 clearlines) // bottom edge if (clearlines > basewindowy + baseviewheight) { - patch = W_CachePatchNum(viewborderlump[BRDR_B], PU_PATCH); + patch = (patch_t*)W_CachePatchNum(viewborderlump[BRDR_B], PU_PATCH); for (x = 0; x < baseviewwidth; x += 8) HWR_DrawPatch(patch, basewindowx + x, basewindowy + baseviewheight, 0); @@ -899,7 +899,7 @@ void HWR_DrawViewBorder(INT32 clearlines) // left edge if (clearlines > basewindowy) { - patch = W_CachePatchNum(viewborderlump[BRDR_L], PU_PATCH); + patch = (patch_t*)W_CachePatchNum(viewborderlump[BRDR_L], PU_PATCH); for (y = 0; y < baseviewheight && basewindowy + y < clearlines; y += 8) { @@ -911,7 +911,7 @@ void HWR_DrawViewBorder(INT32 clearlines) // right edge if (clearlines > basewindowy) { - patch = W_CachePatchNum(viewborderlump[BRDR_R], PU_PATCH); + patch = (patch_t*)W_CachePatchNum(viewborderlump[BRDR_R], PU_PATCH); for (y = 0; y < baseviewheight && basewindowy+y < clearlines; y += 8) { @@ -922,22 +922,22 @@ void HWR_DrawViewBorder(INT32 clearlines) // Draw beveled corners. if (clearlines > basewindowy - 8) - HWR_DrawPatch(W_CachePatchNum(viewborderlump[BRDR_TL], + HWR_DrawPatch((patch_t*)W_CachePatchNum(viewborderlump[BRDR_TL], PU_PATCH), basewindowx - 8, basewindowy - 8, 0); if (clearlines > basewindowy - 8) - HWR_DrawPatch(W_CachePatchNum(viewborderlump[BRDR_TR], + HWR_DrawPatch((patch_t*)W_CachePatchNum(viewborderlump[BRDR_TR], PU_PATCH), basewindowx + baseviewwidth, basewindowy - 8, 0); if (clearlines > basewindowy+baseviewheight) - HWR_DrawPatch(W_CachePatchNum(viewborderlump[BRDR_BL], + HWR_DrawPatch((patch_t*)W_CachePatchNum(viewborderlump[BRDR_BL], PU_PATCH), basewindowx - 8, basewindowy + baseviewheight, 0); if (clearlines > basewindowy + baseviewheight) - HWR_DrawPatch(W_CachePatchNum(viewborderlump[BRDR_BR], + HWR_DrawPatch((patch_t*)W_CachePatchNum(viewborderlump[BRDR_BR], PU_PATCH), basewindowx + baseviewwidth, basewindowy + baseviewheight, 0); @@ -1297,19 +1297,19 @@ static inline boolean saveTGA(const char *file_name, void *buffer, UINT8 *HWR_GetScreenshot(void) { - UINT8 *buf = malloc(vid.width * vid.height * 3 * sizeof (*buf)); + UINT8 *buf = (UINT8 *)malloc(vid.width * vid.height * 3 * sizeof (*buf)); if (!buf) return NULL; // returns 24bit 888 RGB - HWD.pfnReadRect(0, 0, vid.width, vid.height, vid.width * 3, (void *)buf); + HWD.pfnReadRect(0, 0, vid.width, vid.height, vid.width * 3, (UINT16 *)buf); return buf; } boolean HWR_Screenshot(const char *pathname) { boolean ret; - UINT8 *buf = malloc(vid.width * vid.height * 3 * sizeof (*buf)); + UINT8 *buf = (UINT8 *)malloc(vid.width * vid.height * 3 * sizeof (*buf)); if (!buf) { @@ -1318,7 +1318,7 @@ boolean HWR_Screenshot(const char *pathname) } // returns 24bit 888 RGB - HWD.pfnReadRect(0, 0, vid.width, vid.height, vid.width * 3, (void *)buf); + HWD.pfnReadRect(0, 0, vid.width, vid.height, vid.width * 3, (UINT16 *)buf); #ifdef USE_PNG ret = M_SavePNG(pathname, buf, vid.width, vid.height, NULL); diff --git a/src/hardware/hw_light.c b/src/hardware/hw_light.cpp similarity index 99% rename from src/hardware/hw_light.c rename to src/hardware/hw_light.cpp index 93b19179d..6293b4ff7 100644 --- a/src/hardware/hw_light.c +++ b/src/hardware/hw_light.cpp @@ -1233,7 +1233,7 @@ static void HWR_SetLight(void) if (!lightmappatch.mipmap->downloaded && !lightmappatch.mipmap->data) { - UINT16 *Data = Z_Malloc(129*128*sizeof (UINT16), PU_HWRCACHE, &lightmappatch.mipmap->data); + UINT16 *Data = (UINT16 *)Z_Malloc(129*128*sizeof (UINT16), PU_HWRCACHE, &lightmappatch.mipmap->data); for (i = 0; i < 128; i++) { @@ -1285,7 +1285,7 @@ static inline void HWR_BuildWallLightmaps(FVector *p1, FVector *p2, int lighnum, (void)lighnum; (void)p1; (void)p2; - lp = malloc(sizeof (*lp)); + lp = (lightmap_t *)malloc(sizeof (*lp)); lp->next = line->lightmaps; line->lightmaps = lp; diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.cpp similarity index 98% rename from src/hardware/hw_main.c rename to src/hardware/hw_main.cpp index b5e8fca5a..7867a85d8 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.cpp @@ -11,6 +11,7 @@ /// \file hw_main.c /// \brief hardware renderer, using the standard HardWareRender driver DLL for SRB2 +#include #include #include "../doomstat.h" @@ -226,7 +227,7 @@ void HWR_ObjectLightLevelPost(gl_vissprite_t *spr, const sector_t *sector, INT32 ); // Less change in contrast in dark sectors - extralight = FixedMul(extralight, min(max(0, *lightlevel), 255) * FRACUNIT / 255); + extralight = FixedMul(extralight, std::min(std::max(0, *lightlevel), 255) * FRACUNIT / 255); if (papersprite) { @@ -241,7 +242,7 @@ void HWR_ObjectLightLevelPost(gl_vissprite_t *spr, const sector_t *sector, INT32 // Less change in contrast at further distances, to counteract DOOM diminished light fixed_t n = FixedDiv(FixedMul(xscale, LIGHTRESOLUTIONFIX), ((MAXLIGHTSCALE-1) << LIGHTSCALESHIFT)); - extralight = FixedMul(extralight, min(n, FRACUNIT)); + extralight = FixedMul(extralight, std::min(n, FRACUNIT)); // Contrast is stronger for normal sprites, stronger than wall lighting is at the same distance *lightlevel += FixedFloor((extralight * 2) + (FRACUNIT / 2)) / FRACUNIT; @@ -290,8 +291,8 @@ void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *col fade_alpha = (float)(sqrt(255-light_level) * 12) / 255.0f; // Clamp the alpha values - tint_alpha = min(max(tint_alpha, 0.0f), 1.0f); - fade_alpha = min(max(fade_alpha, 0.0f), 1.0f); + tint_alpha = std::min(std::max(tint_alpha, 0.0f), 1.0f); + fade_alpha = std::min(std::max(fade_alpha, 0.0f), 1.0f); red = (tint_color.s.red * tint_alpha) + (red * (1.0f - tint_alpha)); green = (tint_color.s.green * tint_alpha) + (green * (1.0f - tint_alpha)); @@ -307,7 +308,7 @@ void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *col } // Clamp the light level, since it can sometimes go out of the 0-255 range from animations - light_level = min(max(light_level, 0), 255); + light_level = std::min(std::max(light_level, 0), 255); Surface->PolyColor.rgba = poly_color.rgba; Surface->TintColor.rgba = tint_color.rgba; @@ -737,7 +738,7 @@ FBITFIELD HWR_GetBlendModeFlag(INT32 ast) UINT8 HWR_GetTranstableAlpha(INT32 transtablenum) { - transtablenum = max(min(transtablenum, tr_trans90), 0); + transtablenum = std::max(std::min(transtablenum, (INT32)tr_trans90), 0); switch (transtablenum) { @@ -1332,20 +1333,20 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom } else { - popentop = min(worldtop, worldhigh); - popenbottom = max(worldbottom, worldlow); + popentop = std::min(worldtop, worldhigh); + popenbottom = std::max(worldbottom, worldlow); } if (gl_linedef->flags & ML_NOSKEW) { if (gl_linedef->flags & ML_MIDPEG) { - polybottom = max(front->floorheight, back->floorheight) + gl_sidedef->rowoffset; + polybottom = std::max(front->floorheight, back->floorheight) + gl_sidedef->rowoffset; polytop = polybottom + textureheight[gl_midtexture]*repeats; } else { - polytop = min(front->ceilingheight, back->ceilingheight) + gl_sidedef->rowoffset; + polytop = std::min(front->ceilingheight, back->ceilingheight) + gl_sidedef->rowoffset; polybottom = polytop - textureheight[gl_midtexture]*repeats; } } @@ -1374,8 +1375,8 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom highcut = popentop; } - h = min(highcut, polytop); - l = max(polybottom, lowcut); + h = std::min(highcut, polytop); + l = std::max(polybottom, lowcut); { // PEGGING @@ -1434,8 +1435,8 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom : worldlowslope-worldlow; // Texture stuff - h = min(highcut, polytop); - l = max(polybottom, lowcut); + h = std::min(highcut, polytop); + l = std::max(polybottom, lowcut); { // PEGGING @@ -1443,7 +1444,7 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom texturevpeg = textureheight[gl_sidedef->midtexture]*repeats - h + polybottom; else texturevpeg = polytop - h; - + // Apply tripwire flipping for slope correction as well if (R_ShouldFlipTripWire(gl_linedef)) { @@ -1643,10 +1644,10 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom INT32 texnum, basetexnum; line_t * newline = NULL; // Multi-Property FOF - lowcut = max(worldbottom, worldlow); - highcut = min(worldtop, worldhigh); - lowcutslope = max(worldbottomslope, worldlowslope); - highcutslope = min(worldtopslope, worldhighslope); + lowcut = std::max(worldbottom, worldlow); + highcut = std::min(worldtop, worldhigh); + lowcutslope = std::max(worldbottomslope, worldlowslope); + highcutslope = std::min(worldtopslope, worldhighslope); if (gl_backsector->ffloors) { @@ -1793,7 +1794,7 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (rover->alpha < 256 || rover->blend) { blendmode = HWR_GetBlendModeFlag(rover->blend); - Surf.PolyColor.s.alpha = max(0, min(rover->alpha, 255)); + Surf.PolyColor.s.alpha = std::max(0, std::min(rover->alpha, 255)); } } @@ -1922,7 +1923,7 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (rover->alpha < 256 || rover->blend) { blendmode = HWR_GetBlendModeFlag(rover->blend); - Surf.PolyColor.s.alpha = max(0, min(rover->alpha, 255)); + Surf.PolyColor.s.alpha = std::max(0, std::min(rover->alpha, 255)); } } @@ -2168,9 +2169,9 @@ static boolean HWR_CheckBBox(fixed_t *bspcoord) static inline void HWR_AddPolyObjectSegs(void) { size_t i, j; - seg_t *gl_fakeline = Z_Calloc(sizeof(seg_t), PU_STATIC, NULL); - polyvertex_t *pv1 = Z_Calloc(sizeof(polyvertex_t), PU_STATIC, NULL); - polyvertex_t *pv2 = Z_Calloc(sizeof(polyvertex_t), PU_STATIC, NULL); + seg_t *gl_fakeline = (seg_t *)Z_Calloc(sizeof(seg_t), PU_STATIC, NULL); + polyvertex_t *pv1 = (polyvertex_t *)Z_Calloc(sizeof(polyvertex_t), PU_STATIC, NULL); + polyvertex_t *pv2 = (polyvertex_t *)Z_Calloc(sizeof(polyvertex_t), PU_STATIC, NULL); // Sort through all the polyobjects for (i = 0; i < numpolys; ++i) @@ -2551,12 +2552,12 @@ static void HWR_Subsector(size_t num) light = R_GetPlaneLight(gl_frontsector, locFloorHeight, false); if (gl_frontsector->floorlightsec == -1 && !gl_frontsector->floorlightabsolute) - floorlightlevel = max(0, min(255, *gl_frontsector->lightlist[light].lightlevel + gl_frontsector->floorlightlevel)); + floorlightlevel = std::max(0, std::min(255, *gl_frontsector->lightlist[light].lightlevel + gl_frontsector->floorlightlevel)); floorcolormap = *gl_frontsector->lightlist[light].extra_colormap; light = R_GetPlaneLight(gl_frontsector, locCeilingHeight, false); if (gl_frontsector->ceilinglightsec == -1 && !gl_frontsector->ceilinglightabsolute) - ceilinglightlevel = max(0, min(255, *gl_frontsector->lightlist[light].lightlevel + gl_frontsector->ceilinglightlevel)); + ceilinglightlevel = std::max(0, std::min(255, *gl_frontsector->lightlist[light].lightlevel + gl_frontsector->ceilinglightlevel)); ceilingcolormap = *gl_frontsector->lightlist[light].extra_colormap; } @@ -2667,7 +2668,7 @@ static void HWR_Subsector(size_t num) false, *rover->bottomheight, *gl_frontsector->lightlist[light].lightlevel, - max(0, min(rover->alpha, 255)), rover->master->frontsector, blendmode, + std::max(0, std::min(rover->alpha, 255)), rover->master->frontsector, blendmode, false, *gl_frontsector->lightlist[light].extra_colormap); } else @@ -2715,7 +2716,7 @@ static void HWR_Subsector(size_t num) true, *rover->topheight, *gl_frontsector->lightlist[light].lightlevel, - max(0, min(rover->alpha, 255)), rover->master->frontsector, blendmode, + std::max(0, std::min(rover->alpha, 255)), rover->master->frontsector, blendmode, false, *gl_frontsector->lightlist[light].extra_colormap); } else @@ -4390,14 +4391,14 @@ static void HWR_CreateDrawNodes(void) // Dump EVERYTHING into a huge drawnode list. Then we'll sort it! // Could this be optimized into _AddTransparentWall/_AddTransparentPlane? // Hell yes! But sort algorithm must be modified to use a linked list. - sortnode = Z_Calloc((sizeof(planeinfo_t)*numplanes) + sortnode = (gl_drawnode_t *)Z_Calloc((sizeof(planeinfo_t)*numplanes) + (sizeof(polyplaneinfo_t)*numpolyplanes) + (sizeof(wallinfo_t)*numwalls) ,PU_STATIC, NULL); // todo: // However, in reality we shouldn't be re-copying and shifting all this information // that is already lying around. This should all be in some sort of linked list or lists. - sortindex = Z_Calloc(sizeof(size_t) * (numplanes + numpolyplanes + numwalls), PU_STATIC, NULL); + sortindex = (size_t *)Z_Calloc(sizeof(size_t) * (numplanes + numpolyplanes + numwalls), PU_STATIC, NULL); ps_hw_nodesorttime = I_GetPreciseTime(); @@ -4740,7 +4741,7 @@ static void HWR_ProjectSprite(mobj_t *thing) fixed_t jitters = HITLAGJITTERS; if (R_UsingFrameInterpolation() && !paused) jitters += (rendertimefrac / HITLAGDIV); - + fixed_t mul = thing->hitlag * jitters; if (leveltime & 1) @@ -5175,16 +5176,16 @@ static void HWR_ProjectSprite(mobj_t *thing) // Hide not-yet-unlocked characters in replays from other people if (skinnum >= 0 && !R_CanShowSkinInDemo(skinnum)) { - vis->colormap = R_GetTranslationColormap(TC_BLINK, thing->color, GTC_CACHE); + vis->colormap = R_GetTranslationColormap(TC_BLINK, (skincolornum_t)thing->color, GTC_CACHE); } //Hurdler: 25/04/2000: now support colormap in hardware mode else if (R_ThingIsFlashing(vis->mobj)) { - vis->colormap = R_GetTranslationColormap(TC_HITLAG, 0, GTC_CACHE); + vis->colormap = R_GetTranslationColormap(TC_HITLAG, (skincolornum_t)0, GTC_CACHE); } else if (thing->color) { - vis->colormap = R_GetTranslationColormap(thing->colorized ? TC_RAINBOW : skinnum, thing->color, GTC_CACHE); + vis->colormap = R_GetTranslationColormap(thing->colorized ? TC_RAINBOW : skinnum, (skincolornum_t)thing->color, GTC_CACHE); } else { @@ -5484,11 +5485,11 @@ void HWR_BuildSkyDome(void) sky->vertex_count = 2 * sky->rows * (sky->columns * 2 + 2) + sky->columns * 2; if (!sky->loops) - sky->loops = malloc((sky->rows * 2 + 2) * sizeof(sky->loops[0])); + sky->loops = (gl_skyloopdef_t *)malloc((sky->rows * 2 + 2) * sizeof(sky->loops[0])); // create vertex array if (!sky->data) - sky->data = malloc(sky->vertex_count * sizeof(sky->data[0])); + sky->data = (gl_skyvertex_t *)malloc(sky->vertex_count * sizeof(sky->data[0])); sky->texture = texturetranslation[skytexture]; sky->width = texture->width; @@ -5620,7 +5621,7 @@ static void HWR_DrawSkyBackground(player_t *player) dimensionmultiply = ((float)textures[texturetranslation[skytexture]]->width/256.0f); - v[0].s = v[3].s = (-1.0f * angle) / ((ANGLE_90-1)*dimensionmultiply); // left + v[0].s = v[3].s = (-1.0f * angle) / ((ANGLE_90-1.0f)*dimensionmultiply); // left v[2].s = v[1].s = v[0].s + (1.0f/dimensionmultiply); // right (or left + 1.0f) // use +angle and -1.0f above instead if you wanted old backwards behavior @@ -5782,10 +5783,10 @@ static void HWR_SetTransformAiming(FTransform *trans, player_t *player, boolean // static void HWR_SetShaderState(void) { - hwdshaderoption_t state = cv_glshaders.value; + hwdshaderoption_t state = (hwdshaderoption_t)cv_glshaders.value; if (!cv_glallowshaders.value) - state = (cv_glshaders.value == HWD_SHADEROPTION_ON ? HWD_SHADEROPTION_NOCUSTOM : cv_glshaders.value); + state = (hwdshaderoption_t)(cv_glshaders.value == HWD_SHADEROPTION_ON ? HWD_SHADEROPTION_NOCUSTOM : cv_glshaders.value); HWD.pfnSetSpecialState(HWD_SET_SHADERS, (INT32)state); HWD.pfnSetShader(SHADER_DEFAULT); @@ -6067,14 +6068,14 @@ CV_PossibleValue_t glfiltermode_cons_t[]= {{HWD_SET_TEXTUREFILTER_POINTSAMPLED, CV_PossibleValue_t glanisotropicmode_cons_t[] = {{1, "MIN"}, {16, "MAX"}, {0, NULL}}; -void CV_glfiltermode_OnChange(void); +extern "C" void CV_glfiltermode_OnChange(void); void CV_glfiltermode_OnChange(void) { if (rendermode == render_opengl) HWD.pfnSetSpecialState(HWD_SET_TEXTUREFILTERMODE, cv_glfiltermode.value); } -void CV_glanisotropic_OnChange(void); +extern "C" void CV_glanisotropic_OnChange(void); void CV_glanisotropic_OnChange(void) { if (rendermode == render_opengl) @@ -6466,10 +6467,10 @@ void HWR_LoadCustomShadersFromFile(UINT16 wadnum, boolean PK3) if (lump == INT16_MAX) return; - shaderdef = W_CacheLumpNumPwad(wadnum, lump, PU_CACHE); + shaderdef = (char *)W_CacheLumpNumPwad(wadnum, lump, PU_CACHE); size = W_LumpLengthPwad(wadnum, lump); - line = Z_Malloc(size+1, PU_STATIC, NULL); + line = (char *)Z_Malloc(size+1, PU_STATIC, NULL); M_Memcpy(line, shaderdef, size); line[size] = '\0'; @@ -6530,14 +6531,14 @@ skip_lump: if (PK3) { - shader_lumpname = Z_Malloc(strlen(value) + 12, PU_STATIC, NULL); + shader_lumpname = (char *)Z_Malloc(strlen(value) + 12, PU_STATIC, NULL); strcpy(shader_lumpname, "Shaders/sh_"); strcat(shader_lumpname, value); shader_lumpnum = W_CheckNumForFullNamePK3(shader_lumpname, wadnum, 0); } else { - shader_lumpname = Z_Malloc(strlen(value) + 4, PU_STATIC, NULL); + shader_lumpname = (char *)Z_Malloc(strlen(value) + 4, PU_STATIC, NULL); strcpy(shader_lumpname, "SH_"); strcat(shader_lumpname, value); shader_lumpnum = W_CheckNumForNamePwad(shader_lumpname, wadnum, 0); @@ -6551,7 +6552,7 @@ skip_lump: } shader_size = W_LumpLengthPwad(wadnum, shader_lumpnum); - shader_source = Z_Malloc(shader_size, PU_STATIC, NULL); + shader_source = (char *)Z_Malloc(shader_size, PU_STATIC, NULL); W_ReadLumpPwad(wadnum, shader_lumpnum, shader_source); HWD.pfnLoadCustomShader(shaderxlat[i].id, shader_source, shader_size, (shadertype == 2)); diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.cpp similarity index 93% rename from src/hardware/hw_md2.c rename to src/hardware/hw_md2.cpp index 81a7d9a49..beedbc80b 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.cpp @@ -15,6 +15,7 @@ #ifdef __GNUC__ #include #endif +#include #include #include #include @@ -100,11 +101,11 @@ static void md2_freeModel (model_t *model) static model_t *md2_readModel(const char *filename) { //Filename checking fixed ~Monster Iestyn and Golden - if (FIL_FileExists(va("%s"PATHSEP"%s", srb2home, filename))) - return LoadModel(va("%s"PATHSEP"%s", srb2home, filename), PU_STATIC); + if (FIL_FileExists(va("%s" PATHSEP "%s", srb2home, filename))) + return LoadModel(va("%s" PATHSEP "%s", srb2home, filename), PU_STATIC); - if (FIL_FileExists(va("%s"PATHSEP"%s", srb2path, filename))) - return LoadModel(va("%s"PATHSEP"%s", srb2path, filename), PU_STATIC); + if (FIL_FileExists(va("%s" PATHSEP "%s", srb2path, filename))) + return LoadModel(va("%s" PATHSEP "%s", srb2path, filename), PU_STATIC); return NULL; } @@ -168,18 +169,18 @@ static GLTextureFormat_t PNG_Load(const char *filename, int *w, int *h, GLPatch_ #endif volatile png_FILE_p png_FILE; //Filename checking fixed ~Monster Iestyn and Golden - char *pngfilename = va("%s"PATHSEP"models"PATHSEP"%s", srb2home, filename); + char *pngfilename = va("%s" PATHSEP "models" PATHSEP "%s", srb2home, filename); FIL_ForceExtension(pngfilename, ".png"); png_FILE = fopen(pngfilename, "rb"); if (!png_FILE) { - pngfilename = va("%s"PATHSEP"models"PATHSEP"%s", srb2path, filename); + pngfilename = va("%s" PATHSEP "models" PATHSEP "%s", srb2path, filename); FIL_ForceExtension(pngfilename, ".png"); png_FILE = fopen(pngfilename, "rb"); //CONS_Debug(DBG_RENDER, "M_SavePNG: Error on opening %s for loading\n", filename); if (!png_FILE) - return 0; + return (GLTextureFormat_t)0; } png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, @@ -188,7 +189,7 @@ static GLTextureFormat_t PNG_Load(const char *filename, int *w, int *h, GLPatch_ { CONS_Debug(DBG_RENDER, "PNG_Load: Error on initialize libpng\n"); fclose(png_FILE); - return 0; + return (GLTextureFormat_t)0; } png_info_ptr = png_create_info_struct(png_ptr); @@ -197,7 +198,7 @@ static GLTextureFormat_t PNG_Load(const char *filename, int *w, int *h, GLPatch_ CONS_Debug(DBG_RENDER, "PNG_Load: Error on allocate for libpng\n"); png_destroy_read_struct(&png_ptr, NULL, NULL); fclose(png_FILE); - return 0; + return (GLTextureFormat_t)0; } #ifdef USE_FAR_KEYWORD @@ -210,7 +211,7 @@ static GLTextureFormat_t PNG_Load(const char *filename, int *w, int *h, GLPatch_ png_destroy_read_struct(&png_ptr, &png_info_ptr, NULL); fclose(png_FILE); Z_Free(grpatch->mipmap->data); - return 0; + return (GLTextureFormat_t)0; } #ifdef USE_FAR_KEYWORD png_memcpy(png_jmpbuf(png_ptr), jmpbuf, sizeof jmp_buf); @@ -250,8 +251,8 @@ static GLTextureFormat_t PNG_Load(const char *filename, int *w, int *h, GLPatch_ { png_uint_32 i, pitch = png_get_rowbytes(png_ptr, png_info_ptr); - png_bytep PNG_image = Z_Malloc(pitch*height, PU_HWRMODELTEXTURE, &grpatch->mipmap->data); - png_bytepp row_pointers = png_malloc(png_ptr, height * sizeof (png_bytep)); + png_bytep PNG_image = (png_bytep)Z_Malloc(pitch*height, PU_HWRMODELTEXTURE, &grpatch->mipmap->data); + png_bytepp row_pointers = (png_bytepp)png_malloc(png_ptr, height * sizeof (png_bytep)); for (i = 0; i < height; i++) row_pointers[i] = PNG_image + i*pitch; png_read_image(png_ptr, row_pointers); @@ -301,42 +302,42 @@ static GLTextureFormat_t PCX_Load(const char *filename, int *w, int *h, INT32 ch, rep; FILE *file; //Filename checking fixed ~Monster Iestyn and Golden - char *pcxfilename = va("%s"PATHSEP"models"PATHSEP"%s", srb2home, filename); + char *pcxfilename = va("%s" PATHSEP "models" PATHSEP "%s", srb2home, filename); FIL_ForceExtension(pcxfilename, ".pcx"); file = fopen(pcxfilename, "rb"); if (!file) { - pcxfilename = va("%s"PATHSEP"models"PATHSEP"%s", srb2path, filename); + pcxfilename = va("%s" PATHSEP "models" PATHSEP "%s", srb2path, filename); FIL_ForceExtension(pcxfilename, ".pcx"); file = fopen(pcxfilename, "rb"); if (!file) - return 0; + return (GLTextureFormat_t)0; } if (fread(&header, sizeof (PcxHeader), 1, file) != 1) { fclose(file); - return 0; + return (GLTextureFormat_t)0; } if (header.bitsPerPixel != 8) { fclose(file); - return 0; + return (GLTextureFormat_t)0; } fseek(file, -PALSIZE, SEEK_END); pw = *w = header.xmax - header.xmin + 1; ph = *h = header.ymax - header.ymin + 1; - image = Z_Malloc(pw*ph*4, PU_HWRMODELTEXTURE, &grpatch->mipmap->data); + image = (RGBA_t *)Z_Malloc(pw*ph*4, PU_HWRMODELTEXTURE, &grpatch->mipmap->data); if (fread(palette, sizeof (UINT8), PALSIZE, file) != PALSIZE) { Z_Free(image); fclose(file); - return 0; + return (GLTextureFormat_t)0; } fseek(file, sizeof (PcxHeader), SEEK_SET); @@ -378,7 +379,7 @@ static void md2_loadTexture(md2_t *model) if (model->grpatch) { - patch = model->grpatch; + patch = (patch_t*)(model->grpatch); grPatch = (GLPatch_t *)(patch->hardware); if (grPatch) Z_Free(grPatch->mipmap->data); @@ -418,7 +419,7 @@ static void md2_loadTexture(md2_t *model) grPatch->mipmap->height = (UINT16)h; // Lactozilla: Apply colour cube - image = grPatch->mipmap->data; + image = (RGBA_t*)(grPatch->mipmap->data); size = w*h; while (size--) { @@ -437,14 +438,14 @@ static void md2_loadBlendTexture(md2_t *model) { patch_t *patch; GLPatch_t *grPatch = NULL; - char *filename = Z_Malloc(strlen(model->filename)+7, PU_STATIC, NULL); + char *filename = (char *)Z_Malloc(strlen(model->filename)+7, PU_STATIC, NULL); strcpy(filename, model->filename); FIL_ForceExtension(filename, "_blend.png"); if (model->blendgrpatch) { - patch = model->blendgrpatch; + patch = (patch_t*)(model->blendgrpatch); grPatch = (GLPatch_t *)(patch->hardware); if (grPatch) Z_Free(grPatch->mipmap->data); @@ -495,10 +496,10 @@ void HWR_InitModels(void) size_t i; INT32 s; FILE *f; - char name[26], filename[32]; + char name[24], filename[32]; // name[24] is used to check for names in the models.dat file that match with sprites or player skins - // sprite names are always 4 characters long, and names is for player skins can be up to 19 characters long - // PLAYERMODELPREFIX is 6 characters long + // sprite names are always 4 characters long, and names is for player skins can be up to 16+1 characters long + // PLAYERMODELPREFIX is 6 characters long - 24 fits in (16 + 6) + 1 float scale, offset; size_t prefixlen; @@ -528,11 +529,11 @@ void HWR_InitModels(void) // read the models.dat file //Filename checking fixed ~Monster Iestyn and Golden - f = fopen(va("%s"PATHSEP"%s", srb2home, "models.dat"), "rt"); + f = fopen(va("%s" PATHSEP "%s", srb2home, "models.dat"), "rt"); if (!f) { - f = fopen(va("%s"PATHSEP"%s", srb2path, "models.dat"), "rt"); + f = fopen(va("%s" PATHSEP "%s", srb2path, "models.dat"), "rt"); if (!f) { CONS_Printf("%s %s\n", M_GetText("Error while loading models.dat:"), strerror(errno)); @@ -544,7 +545,7 @@ void HWR_InitModels(void) // length of the player model prefix prefixlen = strlen(PLAYERMODELPREFIX); - while (fscanf(f, "%25s %31s %f %f", name, filename, &scale, &offset) == 4) + while (fscanf(f, "%23s %31s %f %f", name, filename, &scale, &offset) == 4) { char *skinname = name; size_t len = strlen(name); @@ -609,11 +610,11 @@ void HWR_AddPlayerModel(INT32 skin) // For skins that were added after startup // read the models.dat file //Filename checking fixed ~Monster Iestyn and Golden - f = fopen(va("%s"PATHSEP"%s", srb2home, "models.dat"), "rt"); + f = fopen(va("%s" PATHSEP "%s", srb2home, "models.dat"), "rt"); if (!f) { - f = fopen(va("%s"PATHSEP"%s", srb2path, "models.dat"), "rt"); + f = fopen(va("%s" PATHSEP "%s", srb2path, "models.dat"), "rt"); if (!f) { CONS_Printf("%s %s\n", M_GetText("Error while loading models.dat:"), strerror(errno)); @@ -626,7 +627,7 @@ void HWR_AddPlayerModel(INT32 skin) // For skins that were added after startup prefixlen = strlen(PLAYERMODELPREFIX); // Check for any models that match the names of player skins! - while (fscanf(f, "%25s %31s %f %f", name, filename, &scale, &offset) == 4) + while (fscanf(f, "%23s %31s %f %f", name, filename, &scale, &offset) == 4) { char *skinname = name; size_t len = strlen(name); @@ -655,8 +656,8 @@ void HWR_AddSpriteModel(size_t spritenum) // For sprites that were added after s { FILE *f; // name[24] is used to check for names in the models.dat file that match with sprites or player skins - // sprite names are always 4 characters long, and names is for player skins can be up to 19 characters long - // PLAYERMODELPREFIX is 6 characters long + // sprite names are always 4 characters long, and names is for player skins can be up to 16+1 characters long + // PLAYERMODELPREFIX is 6 characters long - 24 fits in (16 + 6) + 1 char name[24], filename[32]; float scale, offset; @@ -668,11 +669,11 @@ void HWR_AddSpriteModel(size_t spritenum) // For sprites that were added after s // Read the models.dat file //Filename checking fixed ~Monster Iestyn and Golden - f = fopen(va("%s"PATHSEP"%s", srb2home, "models.dat"), "rt"); + f = fopen(va("%s" PATHSEP" %s", srb2home, "models.dat"), "rt"); if (!f) { - f = fopen(va("%s"PATHSEP"%s", srb2path, "models.dat"), "rt"); + f = fopen(va("%s" PATHSEP" %s", srb2path, "models.dat"), "rt"); if (!f) { CONS_Printf("%s %s\n", M_GetText("Error while loading models.dat:"), strerror(errno)); @@ -682,7 +683,7 @@ void HWR_AddSpriteModel(size_t spritenum) // For sprites that were added after s } // Check for any models that match the names of sprite names! - while (fscanf(f, "%25s %31s %f %f", name, filename, &scale, &offset) == 4) + while (fscanf(f, "%23s %31s %f %f", name, filename, &scale, &offset) == 4) { // length of the sprite name size_t len = strlen(name); @@ -713,8 +714,8 @@ spritemodelfound: static void HWR_CreateBlendedTexture(patch_t *gpatch, patch_t *blendgpatch, GLMipmap_t *grMipmap, INT32 skinnum, skincolornum_t color) { - GLPatch_t *hwrPatch = gpatch->hardware; - GLPatch_t *hwrBlendPatch = blendgpatch->hardware; + GLPatch_t *hwrPatch = (GLPatch_t*)(gpatch->hardware); + GLPatch_t *hwrBlendPatch = (GLPatch_t*)(blendgpatch->hardware); UINT16 w = gpatch->width, h = gpatch->height; UINT32 size = w*h; RGBA_t *image, *blendimage, *cur, blendcolor; @@ -747,11 +748,11 @@ static void HWR_CreateBlendedTexture(patch_t *gpatch, patch_t *blendgpatch, GLMi grMipmap->data = NULL; } - cur = Z_Malloc(size*4, PU_HWRMODELTEXTURE, &grMipmap->data); + cur = (RGBA_t *)Z_Malloc(size*4, PU_HWRMODELTEXTURE, &grMipmap->data); memset(cur, 0x00, size*4); - image = hwrPatch->mipmap->data; - blendimage = hwrBlendPatch->mipmap->data; + image = (RGBA_t*)(hwrPatch->mipmap->data); + blendimage = (RGBA_t*)(hwrBlendPatch->mipmap->data); // TC_METALSONIC includes an actual skincolor translation, on top of its flashing. if (skinnum == TC_METALSONIC) @@ -1068,15 +1069,15 @@ static void HWR_CreateBlendedTexture(patch_t *gpatch, patch_t *blendgpatch, GLMi } tempcolor = (brightness * blendcolor.s.red) / colorbright; - tempcolor = min(255, tempcolor); + tempcolor = std::min(255, tempcolor); cur->s.red = (UINT8)tempcolor; tempcolor = (brightness * blendcolor.s.green) / colorbright; - tempcolor = min(255, tempcolor); + tempcolor = std::min(255, tempcolor); cur->s.green = (UINT8)tempcolor; tempcolor = (brightness * blendcolor.s.blue) / colorbright; - tempcolor = min(255, tempcolor); + tempcolor = std::min(255, tempcolor); cur->s.blue = (UINT8)tempcolor; cur->s.alpha = image->s.alpha; } @@ -1086,15 +1087,15 @@ static void HWR_CreateBlendedTexture(patch_t *gpatch, patch_t *blendgpatch, GLMi INT32 tempcolor; tempcolor = ((image->s.red * (255-blendimage->s.alpha)) / 255) + ((blendcolor.s.red * blendimage->s.alpha) / 255); - tempcolor = min(255, tempcolor); + tempcolor = std::min(255, tempcolor); cur->s.red = (UINT8)tempcolor; tempcolor = ((image->s.green * (255-blendimage->s.alpha)) / 255) + ((blendcolor.s.green * blendimage->s.alpha) / 255); - tempcolor = min(255, tempcolor); + tempcolor = std::min(255, tempcolor); cur->s.green = (UINT8)tempcolor; tempcolor = ((image->s.blue * (255-blendimage->s.alpha)) / 255) + ((blendcolor.s.blue * blendimage->s.alpha) / 255); - tempcolor = min(255, tempcolor); + tempcolor = std::min(255, tempcolor); cur->s.blue = (UINT8)tempcolor; cur->s.alpha = image->s.alpha; } @@ -1129,7 +1130,7 @@ skippixel: static void HWR_GetBlendedTexture(patch_t *patch, patch_t *blendpatch, INT32 skinnum, const UINT8 *colormap, skincolornum_t color) { // mostly copied from HWR_GetMappedPatch, hence the similarities and comment - GLPatch_t *grPatch = patch->hardware; + GLPatch_t *grPatch = (GLPatch_t*)(patch->hardware); GLPatch_t *grBlendPatch = NULL; GLMipmap_t *grMipmap, *newMipmap; @@ -1140,7 +1141,7 @@ static void HWR_GetBlendedTexture(patch_t *patch, patch_t *blendpatch, INT32 ski return; } - if ((blendpatch && (grBlendPatch = blendpatch->hardware) && grBlendPatch->mipmap->format) + if ((blendpatch && (grBlendPatch = (GLPatch_t*)blendpatch->hardware) && grBlendPatch->mipmap->format) && (patch->width != blendpatch->width || patch->height != blendpatch->height)) { // Blend image exists, but it's bad. @@ -1179,12 +1180,12 @@ static void HWR_GetBlendedTexture(patch_t *patch, patch_t *blendpatch, INT32 ski // (it have a liste of mipmap) // this malloc is cleared in HWR_FreeColormapCache // (...) unfortunately z_malloc fragment alot the memory :(so malloc is better - newMipmap = calloc(1, sizeof (*newMipmap)); + newMipmap = (GLMipmap_t *)calloc(1, sizeof (*newMipmap)); if (newMipmap == NULL) I_Error("%s: Out of memory", "HWR_GetBlendedTexture"); grMipmap->nextcolormap = newMipmap; - newMipmap->colormap = Z_Calloc(sizeof(*newMipmap->colormap), PU_HWRPATCHCOLMIPMAP, NULL); + newMipmap->colormap = (GLColormap_t*) Z_Calloc(sizeof(*newMipmap->colormap), PU_HWRPATCHCOLMIPMAP, NULL); newMipmap->colormap->source = colormap; M_Memcpy(newMipmap->colormap->data, colormap, 256 * sizeof(UINT8)); @@ -1297,7 +1298,7 @@ static void adjustTextureCoords(model_t *model, patch_t *patch) // if originaluvs points to uvs, we need to allocate new memory for adjusted uvs // the old uvs are kept around for use in possible readjustments if (mesh->uvs == mesh->originaluvs) - mesh->uvs = Z_Malloc(numVertices * 2 * sizeof(float), PU_STATIC, NULL); + mesh->uvs = (float *)Z_Malloc(numVertices * 2 * sizeof(float), PU_STATIC, NULL); uvWritePtr = mesh->uvs; @@ -1465,7 +1466,7 @@ boolean HWR_DrawModel(gl_vissprite_t *spr) // texture loading before model init, so it knows if sprite graphics are used, which // means that texture coordinates have to be adjusted - gpatch = md2->grpatch; + gpatch = (patch_t*)(md2->grpatch); if (gpatch) hwrPatch = ((GLPatch_t *)gpatch->hardware); @@ -1474,12 +1475,12 @@ boolean HWR_DrawModel(gl_vissprite_t *spr) md2_loadTexture(md2); // Load it again, because it isn't being loaded into gpatch after md2_loadtexture... - gpatch = md2->grpatch; + gpatch = (patch_t*)(md2->grpatch); if (gpatch) hwrPatch = ((GLPatch_t *)gpatch->hardware); // Load blend texture - blendgpatch = md2->blendgrpatch; + blendgpatch = (patch_t*)(md2->blendgrpatch); if (blendgpatch) hwrBlendPatch = ((GLPatch_t *)blendgpatch->hardware); @@ -1489,7 +1490,7 @@ boolean HWR_DrawModel(gl_vissprite_t *spr) md2_loadBlendTexture(md2); // Load it again, because it isn't being loaded into blendgpatch after md2_loadblendtexture... - blendgpatch = md2->blendgrpatch; + blendgpatch = (patch_t*)(md2->blendgrpatch); if (blendgpatch) hwrBlendPatch = ((GLPatch_t *)blendgpatch->hardware); @@ -1573,7 +1574,7 @@ boolean HWR_DrawModel(gl_vissprite_t *spr) frame = (spr->mobj->frame & FF_FRAMEMASK); if (spr->mobj->skin && spr->mobj->sprite == SPR_PLAY && md2->model->spr2frames) { - spr2 = HWR_GetModelSprite2(md2, spr->mobj->skin, spr->mobj->sprite2, spr->mobj->player); + spr2 = HWR_GetModelSprite2(md2, (skin_t*)spr->mobj->skin, spr->mobj->sprite2, spr->mobj->player); mod = md2->model->spr2frames[spr2].numframes; #ifndef DONTHIDEDIFFANIMLENGTH // by default, different anim length is masked by the mod if (mod > (INT32)((skin_t *)spr->mobj->skin)->sprites[spr2].numframes) @@ -1610,7 +1611,7 @@ boolean HWR_DrawModel(gl_vissprite_t *spr) && (spr->mobj->frame & FF_ANIMATE || (spr->mobj->state->nextstate != S_NULL && states[spr->mobj->state->nextstate].sprite == SPR_PLAY - && ((P_GetSkinSprite2(spr->mobj->skin, (states[spr->mobj->state->nextstate].frame) & FF_FRAMEMASK, spr->mobj->player) == spr->mobj->sprite2))))) + && ((P_GetSkinSprite2((skin_t*)spr->mobj->skin, (states[spr->mobj->state->nextstate].frame) & FF_FRAMEMASK, spr->mobj->player) == spr->mobj->sprite2))))) { nextFrame = (spr->mobj->frame & FF_FRAMEMASK) + 1; if (nextFrame >= mod) @@ -1780,7 +1781,7 @@ boolean HWR_DrawModel(gl_vissprite_t *spr) // x offset xx = FIXED_TO_FLOAT(FixedMul(FixedMul( FixedMul(xoffs,spr->mobj->spritexscale), - hflipmul), + hflipmul), FINECOSINE(pitchR >> ANGLETOFINESHIFT) )); xy = FIXED_TO_FLOAT(FixedMul(FixedMul( @@ -1792,7 +1793,7 @@ boolean HWR_DrawModel(gl_vissprite_t *spr) // y offset yx = FIXED_TO_FLOAT(FixedMul(FixedMul( FixedMul(yoffs,spr->mobj->spritexscale), - hflipmul), + hflipmul), FINECOSINE(rollR >> ANGLETOFINESHIFT) )); diff --git a/src/hardware/hw_md2load.c b/src/hardware/hw_md2load.cpp similarity index 99% rename from src/hardware/hw_md2load.c rename to src/hardware/hw_md2load.cpp index 7530fc91c..c3f61a02f 100644 --- a/src/hardware/hw_md2load.c +++ b/src/hardware/hw_md2load.cpp @@ -320,7 +320,7 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) fseek(f, 0, SEEK_SET); // read in file - buffer = malloc(fileLen); + buffer = (char *)malloc(fileLen); if (fread(buffer, fileLen, 1, f)) { } // squash ignored fread error fclose(f); diff --git a/src/hardware/hw_md3load.c b/src/hardware/hw_md3load.cpp similarity index 99% rename from src/hardware/hw_md3load.c rename to src/hardware/hw_md3load.cpp index 6d2667cd4..c4ed01d5a 100644 --- a/src/hardware/hw_md3load.c +++ b/src/hardware/hw_md3load.cpp @@ -188,7 +188,7 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) fseek(f, 0, SEEK_SET); // read in file - buffer = malloc(fileLen); + buffer = (char *)malloc(fileLen); fileReadLen = fread(buffer, fileLen, 1, f); fclose(f); diff --git a/src/hardware/hw_model.c b/src/hardware/hw_model.cpp similarity index 100% rename from src/hardware/hw_model.c rename to src/hardware/hw_model.cpp diff --git a/src/hardware/r_opengl/ogl_win.c b/src/hardware/r_opengl/ogl_win.cpp similarity index 99% rename from src/hardware/r_opengl/ogl_win.c rename to src/hardware/r_opengl/ogl_win.cpp index 02c785e78..177a0d733 100644 --- a/src/hardware/r_opengl/ogl_win.c +++ b/src/hardware/r_opengl/ogl_win.cpp @@ -429,7 +429,7 @@ EXPORT void HWRAPI(GetModeList) (vmode_t** pvidmodes, INT32 *numvidmodes) video_modes[iMode].pnext = &video_modes[iMode+1]; video_modes[iMode].windowed = 0; // fullscreen is the default video_modes[iMode].misc = 0; - video_modes[iMode].name = malloc(12 * sizeof (CHAR)); + video_modes[iMode].name = (char *)malloc(12 * sizeof (CHAR)); sprintf(video_modes[iMode].name, "%dx%d", (INT32)Tmp.dmPelsWidth, (INT32)Tmp.dmPelsHeight); GL_DBG_Printf ("Mode: %s\n", video_modes[iMode].name); video_modes[iMode].width = Tmp.dmPelsWidth; @@ -482,7 +482,7 @@ EXPORT void HWRAPI(GetModeList) (vmode_t** pvidmodes, INT32 *numvidmodes) video_modes[i].pnext = &video_modes[i+1]; video_modes[i].windowed = 0; // fullscreen is the default video_modes[i].misc = 0; - video_modes[i].name = malloc(12 * sizeof (CHAR)); + video_modes[i].name = (char *)malloc(12 * sizeof (CHAR)); sprintf(video_modes[i].name, "%dx%d", res[i][0], res[i][1]); GL_DBG_Printf ("Mode: %s\n", video_modes[i].name); video_modes[i].width = res[i][0]; diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.cpp similarity index 99% rename from src/hardware/r_opengl/r_opengl.c rename to src/hardware/r_opengl/r_opengl.cpp index 900bae98d..f22d56325 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.cpp @@ -20,6 +20,7 @@ #include #endif +#include #include #include #include "r_opengl.h" @@ -1107,7 +1108,7 @@ EXPORT void HWRAPI(LoadCustomShader) (int number, char *code, size_t size, boole #define COPYSHADER(source) { \ if (shader->source) \ free(shader->source); \ - shader->source = malloc(size+1); \ + shader->source = (char *)malloc(size+1); \ strncpy(shader->source, code, size); \ shader->source[size] = 0; \ } @@ -1516,8 +1517,8 @@ EXPORT void HWRAPI(ReadRect) (INT32 x, INT32 y, INT32 width, INT32 height, // GL_DBG_Printf ("ReadRect()\n"); if (dst_stride == width*3) { - GLubyte*top = (GLvoid*)dst_data, *bottom = top + dst_stride * (height - 1); - GLubyte *row = malloc(dst_stride); + GLubyte*top = (GLubyte*)dst_data, *bottom = top + dst_stride * (height - 1); + GLubyte *row = (GLubyte *)malloc(dst_stride); if (!row) return; pglPixelStorei(GL_PACK_ALIGNMENT, 1); pglReadPixels(x, y, width, height, GL_RGB, GL_UNSIGNED_BYTE, dst_data); @@ -1535,7 +1536,7 @@ EXPORT void HWRAPI(ReadRect) (INT32 x, INT32 y, INT32 width, INT32 height, else { INT32 j; - GLubyte *image = malloc(width*height*3*sizeof (*image)); + GLubyte *image = (GLubyte *)malloc(width*height*3*sizeof (*image)); if (!image) return; pglPixelStorei(GL_PACK_ALIGNMENT, 1); pglReadPixels(x, y, width, height, GL_RGB, GL_UNSIGNED_BYTE, image); @@ -1870,7 +1871,7 @@ static void AllocTextureBuffer(GLMipmap_t *pTexInfo) size_t size = pTexInfo->width * pTexInfo->height; if (size > textureBufferSize) { - textureBuffer = realloc(textureBuffer, size * sizeof(RGBA_t)); + textureBuffer = (RGBA_t *)realloc(textureBuffer, size * sizeof(RGBA_t)); if (textureBuffer == NULL) I_Error("AllocTextureBuffer: out of memory allocating %s bytes", sizeu1(size * sizeof(RGBA_t))); textureBufferSize = size; @@ -2112,7 +2113,7 @@ EXPORT void HWRAPI(SetTexture) (GLMipmap_t *pTexInfo) } else { - FTextureInfo *newTex = calloc(1, sizeof (*newTex)); + FTextureInfo *newTex = (FTextureInfo *)calloc(1, sizeof (*newTex)); UpdateTexture(pTexInfo); @@ -2334,7 +2335,7 @@ static void Shader_CompileError(const char *message, GLuint program, INT32 shade if (logLength) { - infoLog = malloc(logLength); + infoLog = (GLchar *)malloc(logLength); pglGetShaderInfoLog(program, logLength, NULL, infoLog); } @@ -2635,7 +2636,7 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) break; case HWD_SET_TEXTUREANISOTROPICMODE: - anisotropic_filter = min(Value,maximumAnisotropy); + anisotropic_filter = std::min(Value,maximumAnisotropy); if (maximumAnisotropy) Flush(); //??? if we want to change filter mode by texture, remove this break; @@ -2666,8 +2667,8 @@ static void AllocLerpBuffer(size_t size) free(normBuffer); lerpBufferSize = size; - vertBuffer = malloc(lerpBufferSize); - normBuffer = malloc(lerpBufferSize); + vertBuffer = (float *)malloc(lerpBufferSize); + normBuffer = (float *)malloc(lerpBufferSize); } // Static temporary buffer for doing frame interpolation @@ -2684,8 +2685,8 @@ static void AllocLerpTinyBuffer(size_t size) free(normTinyBuffer); lerpTinyBufferSize = size; - vertTinyBuffer = malloc(lerpTinyBufferSize); - normTinyBuffer = malloc(lerpTinyBufferSize / 2); + vertTinyBuffer = (short *)malloc(lerpTinyBufferSize); + normTinyBuffer = (char *)malloc(lerpTinyBufferSize / 2); } #ifndef GL_STATIC_DRAW diff --git a/src/hardware/u_list.c b/src/hardware/u_list.cpp similarity index 100% rename from src/hardware/u_list.c rename to src/hardware/u_list.cpp