diff --git a/Assets/Scripts/Data/QConstants.cs b/Assets/Scripts/Data/QConstants.cs index 942cc5c..90a47d4 100644 --- a/Assets/Scripts/Data/QConstants.cs +++ b/Assets/Scripts/Data/QConstants.cs @@ -5,4 +5,7 @@ public const int MaxSkins = 32; // Should correspond to MAX_SKINS public const int MaxDLights = 64; // Should correspond to MAX_DLIGHTS public const int MaxLightmaps = 4; // Should correspond to MAXLIGHTMAPS + + public const int LightmapBlockWidth = 256; // Should correspond to LMBLOCK_WIDTH + public const int LightmapBlockHeight = 256; // Should correspond to LMBLOCK_HEIGHT } diff --git a/Assets/Scripts/Modules/RenderModule.Interop.cs b/Assets/Scripts/Modules/RenderModule.Interop.cs index cc5b9ca..a14af10 100644 --- a/Assets/Scripts/Modules/RenderModule.Interop.cs +++ b/Assets/Scripts/Modules/RenderModule.Interop.cs @@ -125,16 +125,18 @@ public partial class RenderModule: CallbackHandler return GetSelf(target).UploadTexture(texture, dataBytes, ref texNum); } + private readonly byte[] lightmapBytes = new byte[QConstants.LightmapBlockWidth * QConstants.LightmapBlockHeight * 4]; // 32 bits per pixel + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate bool UploadLightmapCallback(IntPtr target, int lmap, int width, int height, IntPtr data); + private delegate bool UploadLightmapCallback(IntPtr target, int lmap, IntPtr data); [MonoPInvokeCallback(typeof(UploadLightmapCallback))] - private static bool Callback_UploadLightmap(IntPtr target, int lmap, int width, int height, IntPtr data) + private static bool Callback_UploadLightmap(IntPtr target, int lmap, IntPtr data) { // TODO: this is a fairly pointless additional data copy step; we could probably make this faster by wrapping the IntPtr directly into a NativeArray - byte[] dataBytes = new byte[width * height * 4]; // 32 bits per pixel (RGBA) - Marshal.Copy(data, dataBytes, 0, dataBytes.Length); - return GetSelf(target).UploadLightmap(lmap, width, height, dataBytes); + var self = GetSelf(target); + Marshal.Copy(data, self.lightmapBytes, 0, self.lightmapBytes.Length); + return self.UploadLightmap(lmap, QConstants.LightmapBlockWidth, QConstants.LightmapBlockHeight, self.lightmapBytes); } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] diff --git a/engine/Quake/gl_texmgr.h b/engine/Quake/gl_texmgr.h index d982b3e..5702612 100644 --- a/engine/Quake/gl_texmgr.h +++ b/engine/Quake/gl_texmgr.h @@ -107,7 +107,7 @@ void GL_Bind (gltexture_t *texture); void GL_ClearBindings (void); extern qboolean UQ_GL_UploadTexture(gltexture_t *texture, unsigned *data); -extern qboolean UQ_GL_UploadLightmap(int lmap, int width, int height, byte *data); +extern qboolean UQ_GL_UploadLightmap(int lmap, byte *data); #endif /* _GL_TEXMAN_H */ diff --git a/engine/Quake/r_brush.c b/engine/Quake/r_brush.c index 2ca839d..0929ba5 100644 --- a/engine/Quake/r_brush.c +++ b/engine/Quake/r_brush.c @@ -941,7 +941,7 @@ void GL_BuildLightmaps (void) SRC_LIGHTMAP, lm->data, "", (src_offset_t)lm->data, TEXPREF_LINEAR | TEXPREF_NOPICMIP); //johnfitz - UQ_GL_UploadLightmap(i, LMBLOCK_WIDTH, LMBLOCK_HEIGHT, lm->data); + UQ_GL_UploadLightmap(i, lm->data); } //johnfitz -- warn about exceeding old limits @@ -1272,7 +1272,7 @@ static void R_UploadLightmap(int lmap) lm->rectchange.h = 0; lm->rectchange.w = 0; - UQ_GL_UploadLightmap(lmap, LMBLOCK_WIDTH, LMBLOCK_HEIGHT, lm->data); + UQ_GL_UploadLightmap(lmap, lm->data); rs_dynamiclightmaps++; } diff --git a/engine/UniQuake/gl_uniquake.c b/engine/UniQuake/gl_uniquake.c index 3ac445c..ddea92e 100644 --- a/engine/UniQuake/gl_uniquake.c +++ b/engine/UniQuake/gl_uniquake.c @@ -11,7 +11,7 @@ typedef struct unity_glcalls_s int(*UploadBrushModel)(void *target, qmodel_t *model); int(*UploadWorldModel)(void *target, qmodel_t *model); qboolean(*UploadTexture)(void *target, gltexture_t *texture, unsigned *data, GLuint *texnum); - qboolean(*UploadLightmap)(void *target, int lmap, int width, int height, byte *data); + qboolean(*UploadLightmap)(void *target, int lmap, byte *data); void(*SetupView)(void *target, vec3_t origin, vec3_t angles, mleaf_t *viewLeaf); } unity_glcalls_t; @@ -40,9 +40,9 @@ qboolean UQ_GL_UploadTexture(gltexture_t *texture, unsigned *data) return unity_glcalls->UploadTexture(unity_glcalls->target, texture, data, &texture->texnum); } -qboolean UQ_GL_UploadLightmap(int lmap, int width, int height, byte *data) +qboolean UQ_GL_UploadLightmap(int lmap, byte *data) { - return unity_glcalls->UploadLightmap(unity_glcalls->target, lmap, width, height, data); + return unity_glcalls->UploadLightmap(unity_glcalls->target, lmap, data); } void UQ_GL_SetupView(vec3_t origin, vec3_t angles, mleaf_t *viewLeaf)