Browse Source

Reuse the same lightmap byte buffer, since the lightmap dimensions are static anyway. Reduces the amount of garbage produced by dynamic lightmap uploading.

readme
Nico de Poel 5 years ago
parent
commit
cce1ed6d47
  1. 3
      Assets/Scripts/Data/QConstants.cs
  2. 12
      Assets/Scripts/Modules/RenderModule.Interop.cs
  3. 2
      engine/Quake/gl_texmgr.h
  4. 4
      engine/Quake/r_brush.c
  5. 6
      engine/UniQuake/gl_uniquake.c

3
Assets/Scripts/Data/QConstants.cs

@ -5,4 +5,7 @@
public const int MaxSkins = 32; // Should correspond to MAX_SKINS public const int MaxSkins = 32; // Should correspond to MAX_SKINS
public const int MaxDLights = 64; // Should correspond to MAX_DLIGHTS public const int MaxDLights = 64; // Should correspond to MAX_DLIGHTS
public const int MaxLightmaps = 4; // Should correspond to MAXLIGHTMAPS 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
} }

12
Assets/Scripts/Modules/RenderModule.Interop.cs

@ -125,16 +125,18 @@ public partial class RenderModule: CallbackHandler<RenderModule>
return GetSelf(target).UploadTexture(texture, dataBytes, ref texNum); 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)] [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))] [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 // 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)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)]

2
engine/Quake/gl_texmgr.h

@ -107,7 +107,7 @@ void GL_Bind (gltexture_t *texture);
void GL_ClearBindings (void); void GL_ClearBindings (void);
extern qboolean UQ_GL_UploadTexture(gltexture_t *texture, unsigned *data); 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 */ #endif /* _GL_TEXMAN_H */

4
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); SRC_LIGHTMAP, lm->data, "", (src_offset_t)lm->data, TEXPREF_LINEAR | TEXPREF_NOPICMIP);
//johnfitz //johnfitz
UQ_GL_UploadLightmap(i, LMBLOCK_WIDTH, LMBLOCK_HEIGHT, lm->data);
UQ_GL_UploadLightmap(i, lm->data);
} }
//johnfitz -- warn about exceeding old limits //johnfitz -- warn about exceeding old limits
@ -1272,7 +1272,7 @@ static void R_UploadLightmap(int lmap)
lm->rectchange.h = 0; lm->rectchange.h = 0;
lm->rectchange.w = 0; lm->rectchange.w = 0;
UQ_GL_UploadLightmap(lmap, LMBLOCK_WIDTH, LMBLOCK_HEIGHT, lm->data);
UQ_GL_UploadLightmap(lmap, lm->data);
rs_dynamiclightmaps++; rs_dynamiclightmaps++;
} }

6
engine/UniQuake/gl_uniquake.c

@ -11,7 +11,7 @@ typedef struct unity_glcalls_s
int(*UploadBrushModel)(void *target, qmodel_t *model); int(*UploadBrushModel)(void *target, qmodel_t *model);
int(*UploadWorldModel)(void *target, qmodel_t *model); int(*UploadWorldModel)(void *target, qmodel_t *model);
qboolean(*UploadTexture)(void *target, gltexture_t *texture, unsigned *data, GLuint *texnum); 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); void(*SetupView)(void *target, vec3_t origin, vec3_t angles, mleaf_t *viewLeaf);
} unity_glcalls_t; } 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); 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) void UQ_GL_SetupView(vec3_t origin, vec3_t angles, mleaf_t *viewLeaf)

Loading…
Cancel
Save