From e654a99d39891b2d01eff0301537c1f799022ef2 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 14 Apr 2018 10:40:11 +0200 Subject: [PATCH] - changed GLDebug to receive char pointers instead of FStrings. The most frequent call using this is the regular texture creation function where this results in a pointless allocation and destruction of a temporary string which is easily avoided. --- src/gl/renderer/gl_renderbuffers.cpp | 18 +++++++++--------- src/gl/renderer/gl_renderbuffers.h | 15 ++++++++------- src/gl/system/gl_debug.cpp | 8 ++++---- src/gl/system/gl_debug.h | 4 ++-- src/gl/textures/gl_hwtexture.cpp | 2 +- src/gl/textures/gl_hwtexture.h | 3 ++- src/gl/textures/gl_samplers.cpp | 2 +- 7 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/gl/renderer/gl_renderbuffers.cpp b/src/gl/renderer/gl_renderbuffers.cpp index acc2d5c0de..0d594dbbb8 100644 --- a/src/gl/renderer/gl_renderbuffers.cpp +++ b/src/gl/renderer/gl_renderbuffers.cpp @@ -428,8 +428,8 @@ void FGLRenderBuffers::CreateExposureLevels(int width, int height) FGLExposureTextureLevel level; level.Width = width; level.Height = height; - level.Texture = Create2DTexture(textureName, GL_R32F, level.Width, level.Height); - level.Framebuffer = CreateFrameBuffer(fbName, level.Texture); + level.Texture = Create2DTexture(textureName.GetChars(), GL_R32F, level.Width, level.Height); + level.Framebuffer = CreateFrameBuffer(fbName.GetChars(), level.Texture); ExposureLevels.Push(level); } while (width > 1 || height > 1); @@ -474,7 +474,7 @@ void FGLRenderBuffers::CreateEyeBuffers(int eye) // //========================================================================== -GLuint FGLRenderBuffers::Create2DTexture(const FString &name, GLuint format, int width, int height, const void *data) +GLuint FGLRenderBuffers::Create2DTexture(const char *name, GLuint format, int width, int height, const void *data) { GLuint handle = 0; glGenTextures(1, &handle); @@ -508,7 +508,7 @@ GLuint FGLRenderBuffers::Create2DTexture(const FString &name, GLuint format, int return handle; } -GLuint FGLRenderBuffers::Create2DMultisampleTexture(const FString &name, GLuint format, int width, int height, int samples, bool fixedSampleLocations) +GLuint FGLRenderBuffers::Create2DMultisampleTexture(const char *name, GLuint format, int width, int height, int samples, bool fixedSampleLocations) { GLuint handle = 0; glGenTextures(1, &handle); @@ -525,7 +525,7 @@ GLuint FGLRenderBuffers::Create2DMultisampleTexture(const FString &name, GLuint // //========================================================================== -GLuint FGLRenderBuffers::CreateRenderBuffer(const FString &name, GLuint format, int width, int height) +GLuint FGLRenderBuffers::CreateRenderBuffer(const char *name, GLuint format, int width, int height) { GLuint handle = 0; glGenRenderbuffers(1, &handle); @@ -535,7 +535,7 @@ GLuint FGLRenderBuffers::CreateRenderBuffer(const FString &name, GLuint format, return handle; } -GLuint FGLRenderBuffers::CreateRenderBuffer(const FString &name, GLuint format, int width, int height, int samples) +GLuint FGLRenderBuffers::CreateRenderBuffer(const char *name, GLuint format, int width, int height, int samples) { if (samples <= 1) return CreateRenderBuffer(name, format, width, height); @@ -554,7 +554,7 @@ GLuint FGLRenderBuffers::CreateRenderBuffer(const FString &name, GLuint format, // //========================================================================== -GLuint FGLRenderBuffers::CreateFrameBuffer(const FString &name, GLuint colorbuffer) +GLuint FGLRenderBuffers::CreateFrameBuffer(const char *name, GLuint colorbuffer) { GLuint handle = 0; glGenFramebuffers(1, &handle); @@ -566,7 +566,7 @@ GLuint FGLRenderBuffers::CreateFrameBuffer(const FString &name, GLuint colorbuff return handle; } -GLuint FGLRenderBuffers::CreateFrameBuffer(const FString &name, GLuint colorbuffer, GLuint depthstencil, bool colorIsARenderBuffer) +GLuint FGLRenderBuffers::CreateFrameBuffer(const char *name, GLuint colorbuffer, GLuint depthstencil, bool colorIsARenderBuffer) { GLuint handle = 0; glGenFramebuffers(1, &handle); @@ -582,7 +582,7 @@ GLuint FGLRenderBuffers::CreateFrameBuffer(const FString &name, GLuint colorbuff return handle; } -GLuint FGLRenderBuffers::CreateFrameBuffer(const FString &name, GLuint colorbuffer0, GLuint colorbuffer1, GLuint colorbuffer2, GLuint depthstencil, bool multisample) +GLuint FGLRenderBuffers::CreateFrameBuffer(const char *name, GLuint colorbuffer0, GLuint colorbuffer1, GLuint colorbuffer2, GLuint depthstencil, bool multisample) { GLuint handle = 0; glGenFramebuffers(1, &handle); diff --git a/src/gl/renderer/gl_renderbuffers.h b/src/gl/renderer/gl_renderbuffers.h index 1c8ea1690e..84c0f63ece 100644 --- a/src/gl/renderer/gl_renderbuffers.h +++ b/src/gl/renderer/gl_renderbuffers.h @@ -97,13 +97,14 @@ private: void CreateEyeBuffers(int eye); void CreateShadowMap(); void CreateAmbientOcclusion(int width, int height); - GLuint Create2DTexture(const FString &name, GLuint format, int width, int height, const void *data = nullptr); - GLuint Create2DMultisampleTexture(const FString &name, GLuint format, int width, int height, int samples, bool fixedSampleLocations); - GLuint CreateRenderBuffer(const FString &name, GLuint format, int width, int height); - GLuint CreateRenderBuffer(const FString &name, GLuint format, int width, int height, int samples); - GLuint CreateFrameBuffer(const FString &name, GLuint colorbuffer); - GLuint CreateFrameBuffer(const FString &name, GLuint colorbuffer, GLuint depthstencil, bool colorIsARenderBuffer); - GLuint CreateFrameBuffer(const FString &name, GLuint colorbuffer0, GLuint colorbuffer1, GLuint colorbuffer2, GLuint depthstencil, bool multisample); + + GLuint Create2DTexture(const char *name, GLuint format, int width, int height, const void *data = nullptr); + GLuint Create2DMultisampleTexture(const char *name, GLuint format, int width, int height, int samples, bool fixedSampleLocations); + GLuint CreateRenderBuffer(const char *name, GLuint format, int width, int height); + GLuint CreateRenderBuffer(const char *name, GLuint format, int width, int height, int samples); + GLuint CreateFrameBuffer(const char *name, GLuint colorbuffer); + GLuint CreateFrameBuffer(const char *name, GLuint colorbuffer, GLuint depthstencil, bool colorIsARenderBuffer); + GLuint CreateFrameBuffer(const char *name, GLuint colorbuffer0, GLuint colorbuffer1, GLuint colorbuffer2, GLuint depthstencil, bool multisample); bool CheckFrameBufferCompleteness(); void ClearFrameBuffer(bool stencil, bool depth); void DeleteTexture(GLuint &handle); diff --git a/src/gl/system/gl_debug.cpp b/src/gl/system/gl_debug.cpp index 1fca45f0ca..7aa425349a 100644 --- a/src/gl/system/gl_debug.cpp +++ b/src/gl/system/gl_debug.cpp @@ -101,19 +101,19 @@ void FGLDebug::Update() // //----------------------------------------------------------------------------- -void FGLDebug::LabelObject(GLenum type, GLuint handle, const FString &name) +void FGLDebug::LabelObject(GLenum type, GLuint handle, const char *name) { if (HasDebugApi() && gl_debug_level != 0) { - glObjectLabel(type, handle, (GLsizei)name.Len(), name.GetChars()); + glObjectLabel(type, handle, -1, name); } } -void FGLDebug::LabelObjectPtr(void *ptr, const FString &name) +void FGLDebug::LabelObjectPtr(void *ptr, const char *name) { if (HasDebugApi() && gl_debug_level != 0) { - glObjectPtrLabel(ptr, (GLsizei)name.Len(), name.GetChars()); + glObjectPtrLabel(ptr, -1, name); } } diff --git a/src/gl/system/gl_debug.h b/src/gl/system/gl_debug.h index 52645ec163..4b03d0835e 100644 --- a/src/gl/system/gl_debug.h +++ b/src/gl/system/gl_debug.h @@ -11,8 +11,8 @@ class FGLDebug public: void Update(); - static void LabelObject(GLenum type, GLuint handle, const FString &name); - static void LabelObjectPtr(void *ptr, const FString &name); + static void LabelObject(GLenum type, GLuint handle, const char *name); + static void LabelObjectPtr(void *ptr, const char *name); static void PushGroup(const FString &name); static void PopGroup(); diff --git a/src/gl/textures/gl_hwtexture.cpp b/src/gl/textures/gl_hwtexture.cpp index 855ae362f5..551f628f06 100644 --- a/src/gl/textures/gl_hwtexture.cpp +++ b/src/gl/textures/gl_hwtexture.cpp @@ -160,7 +160,7 @@ void FHardwareTexture::Resize(int swidth, int sheight, int width, int height, un // //=========================================================================== -unsigned int FHardwareTexture::CreateTexture(unsigned char * buffer, int w, int h, int texunit, bool mipmap, int translation, const FString &name) +unsigned int FHardwareTexture::CreateTexture(unsigned char * buffer, int w, int h, int texunit, bool mipmap, int translation, const char *name) { int rh,rw; int texformat=TexFormat[gl_texture_format]; diff --git a/src/gl/textures/gl_hwtexture.h b/src/gl/textures/gl_hwtexture.h index 7ddcd27a41..9b2fbf681e 100644 --- a/src/gl/textures/gl_hwtexture.h +++ b/src/gl/textures/gl_hwtexture.h @@ -86,7 +86,8 @@ public: void AllocateBuffer(int w, int h, int texelsize); uint8_t *MapBuffer(); - unsigned int CreateTexture(unsigned char * buffer, int w, int h, int texunit, bool mipmap, int translation, const FString &name); + unsigned int CreateTexture(unsigned char * buffer, int w, int h, int texunit, bool mipmap, int translation, const FString &name) = delete; + unsigned int CreateTexture(unsigned char * buffer, int w, int h, int texunit, bool mipmap, int translation, const char *name); unsigned int GetTextureHandle(int translation); void Clean(bool all); diff --git a/src/gl/textures/gl_samplers.cpp b/src/gl/textures/gl_samplers.cpp index 5ca9a8d0b9..ef6d9f3f45 100644 --- a/src/gl/textures/gl_samplers.cpp +++ b/src/gl/textures/gl_samplers.cpp @@ -58,7 +58,7 @@ FSamplerManager::FSamplerManager() { FString name; name.Format("mSamplers[%d]", i); - FGLDebug::LabelObject(GL_SAMPLER, mSamplers[i], name); + FGLDebug::LabelObject(GL_SAMPLER, mSamplers[i], name.GetChars()); } }