diff --git a/luarules/gadgets/cus_gl4.lua b/luarules/gadgets/cus_gl4.lua index 195c6d48678..2c955ddc0fe 100644 --- a/luarules/gadgets/cus_gl4.lua +++ b/luarules/gadgets/cus_gl4.lua @@ -1641,7 +1641,7 @@ local function ExecuteDrawPass(drawPass) local shaderTable = shaders[drawPass][shaderName] if unitscountforthisshader > 0 then - gl.UseShader(shaderTable.shaderObj) + shaderTable:Activate() shaderswaps = shaderswaps + 1 for uniformBinID, uniformBin in pairs(data) do @@ -1672,7 +1672,7 @@ local function ExecuteDrawPass(drawPass) end end - gl.UseShader(0) + shaderTable:Deactivate() end end end diff --git a/luaui/Widgets/Include/LuaShader.lua b/luaui/Widgets/Include/LuaShader.lua index f89a5601412..fa5ddd8dfce 100644 --- a/luaui/Widgets/Include/LuaShader.lua +++ b/luaui/Widgets/Include/LuaShader.lua @@ -545,8 +545,9 @@ function LuaShader:Compile(suppresswarnings) end ]]-- - self.shaderObj = gl.CreateShader(self.shaderParams) - local shaderObj = self.shaderObj + local shaderObj, gl_program_id = gl.CreateShader(self.shaderParams) + self.shaderObj = shaderObj + self.gl_program_id = gl_program_id local shLog = gl.GetShaderLog() or "" self.shLog = shLog @@ -557,6 +558,11 @@ function LuaShader:Compile(suppresswarnings) self:ShowWarning(shLog) end + if gl_program_id and self.shaderName then + local GL_PROGRAM = 0x82E2 + gl.ObjectLabel(GL_PROGRAM, gl_program_id, self.shaderName) + end + local uniforms = self.uniforms for idx, info in ipairs(gl.GetActiveUniforms(shaderObj)) do local uniName = string.gsub(info.name, "%[0%]", "") -- change array[0] to array @@ -613,6 +619,7 @@ LuaShader.Finalize = LuaShader.Delete function LuaShader:Activate() if self.shaderObj ~= nil then self.active = true + gl.PushDebugGroup(self.gl_program_id * 1000, self.shaderName) return glUseShader(self.shaderObj) else local funcName = (debug and debug.getinfo(1).name) or "UnknownFunction" @@ -644,6 +651,7 @@ end function LuaShader:Deactivate() self.active = false glUseShader(0) + gl.PopDebugGroup() end diff --git a/luaui/Widgets/Include/instancevbotable.lua b/luaui/Widgets/Include/instancevbotable.lua index fd6defbed5c..cfb29a3b376 100644 --- a/luaui/Widgets/Include/instancevbotable.lua +++ b/luaui/Widgets/Include/instancevbotable.lua @@ -12,6 +12,9 @@ function makeInstanceVBOTable(layout, maxElements, myName, unitIDattribID) maxElements, layout ) + + + local instanceStep = 0 for i,attribute in pairs(layout) do instanceStep = instanceStep + attribute.size @@ -37,7 +40,6 @@ function makeInstanceVBOTable(layout, maxElements, myName, unitIDattribID) lastInstanceID = 0, } - if unitIDattribID ~= nil then instanceTable.indextoUnitID = {} instanceTable.unitIDattribID = unitIDattribID @@ -164,6 +166,11 @@ function makeInstanceVBOTable(layout, maxElements, myName, unitIDattribID) newInstanceVBO:Upload(instanceData) + -- I believe that the openGL spec doesnt guarantee that a buffer has an idea before data is uploaded to it, so we will fill it with zeros. + local GL_BUFFER = 0x82E0 + gl.ObjectLabel(GL_BUFFER, newInstanceVBO:GetID(), myName) + + --register self in WG if possible if WG then if WG.VBOTableRegistry == nil then @@ -391,6 +398,9 @@ function resizeInstanceVBOTable(iT) iT.instanceVBO:Upload(iT.instanceData,nil,0,1,iT.usedElements * iT.instanceStep) + local GL_BUFFER = 0x82E0 + gl.ObjectLabel(GL_BUFFER, iT.instanceVBO:GetID(), iT.myName) + if iT.VAO then -- reattach new if updated :D iT.VAO:Delete() iT.VAO = makeVAOandAttach(iT.vertexVBO,iT.instanceVBO, iT.indexVBO) @@ -758,7 +768,7 @@ end --------- HELPERS FOR PRIMITIVES ------------------ -function makeCircleVBO(circleSegments, radius) +function makeCircleVBO(circleSegments, radius, name) -- Makes circle of radius in xy space -- can be used in both GL.LINES and GL.TRIANGLE_FAN mode if not radius then radius = 1 end @@ -784,10 +794,13 @@ function makeCircleVBO(circleSegments, radius) VBOLayout ) circleVBO:Upload(VBOData) + + local GL_BUFFER = 0x82E0 + gl.ObjectLabel(GL_BUFFER, circleVBO:GetID(), name or "CircleVBO") return circleVBO, #VBOData/4 end -function makePlaneVBO(xsize, ysize, xresolution, yresolution) -- makes a plane from [-xsize to xsize] with xresolution subdivisions +function makePlaneVBO(xsize, ysize, xresolution, yresolution, name) -- makes a plane from [-xsize to xsize] with xresolution subdivisions if not xsize then xsize = 1 end if not ysize then ysize = xsize end if not xresolution then xresolution = 1 end @@ -816,11 +829,14 @@ function makePlaneVBO(xsize, ysize, xresolution, yresolution) -- makes a plane f ) planeVBO:Upload(VBOData) + local GL_BUFFER = 0x82E0 + gl.ObjectLabel(GL_BUFFER, planeVBO:GetID(), name or "PlaneVBO") + --Spring.Echo("PlaneVBOData up:",#VBOData, "Down", #planeVBO:Download()) return planeVBO, #VBOData/2 end -function makePlaneIndexVBO(xresolution, yresolution, cutcircle) +function makePlaneIndexVBO(xresolution, yresolution, cutcircle, name) xresolution = math.floor(xresolution) if not yresolution then yresolution = xresolution end local planeIndexVBO = gl.GetVBO(GL.ELEMENT_ARRAY_BUFFER,false) @@ -860,11 +876,14 @@ function makePlaneIndexVBO(xresolution, yresolution, cutcircle) # IndexVBOData ) planeIndexVBO:Upload(IndexVBOData) + + local GL_BUFFER = 0x82E0 + gl.ObjectLabel(GL_BUFFER, planeIndexVBO:GetID(), name or "planeIndexVBO") --Spring.Echo("PlaneIndexVBO up:",#IndexVBOData, "Down", #planeIndexVBO:Download()) return planeIndexVBO, IndexVBOData end -function makePointVBO(numPoints, randomFactor) +function makePointVBO(numPoints, randomFactor, name) -- makes points with xyzw -- can be used in both GL.LINES and GL.TRIANGLE_FAN mode numPoints = numPoints or 1 @@ -890,10 +909,13 @@ function makePointVBO(numPoints, randomFactor) VBOLayout ) pointVBO:Upload(VBOData) + + local GL_BUFFER = 0x82E0 + gl.ObjectLabel(GL_BUFFER, pointVBO:GetID(), name or "pointVBO") return pointVBO, numPoints end -function makeRectVBO(minX,minY, maxX, maxY, minU, minV, maxU, maxV) +function makeRectVBO(minX,minY, maxX, maxY, minU, minV, maxU, maxV, name) if minX == nil then minX, minY, maxX, maxY, minU, minV, maxU, maxV = 0,0,1,1,0,0,1,1 end @@ -921,10 +943,13 @@ function makeRectVBO(minX,minY, maxX, maxY, minU, minV, maxU, maxV) VBOLayout ) rectVBO:Upload(VBOData) + + local GL_BUFFER = 0x82E0 + gl.ObjectLabel(GL_BUFFER, rectVBO:GetID(), name or "rectVBO") return rectVBO, 6 end -function makeRectIndexVBO() +function makeRectIndexVBO(name) local rectIndexVBO = gl.GetVBO(GL.ELEMENT_ARRAY_BUFFER,false) if rectIndexVBO == nil then return nil end @@ -932,12 +957,14 @@ function makeRectIndexVBO() 6 ) rectIndexVBO:Upload({0,1,2,3,4,5}) + local GL_BUFFER = 0x82E0 + gl.ObjectLabel(GL_BUFFER, rectIndexVBO:GetID(), name or "rectIndexVBO") return rectIndexVBO,6 end -function makeConeVBO(numSegments, height, radius) +function makeConeVBO(numSegments, height, radius, name) -- make a cone that points up, (y = height), with radius specified -- returns the VBO object, and the number of elements in it (usually == numvertices) -- needs GL.TRIANGLES @@ -989,12 +1016,16 @@ function makeConeVBO(numSegments, height, radius) coneVBO:Define(#VBOData/4, {{id = 0, name = "localpos_progress", size = 4}}) coneVBO:Upload(VBOData) + + local GL_BUFFER = 0x82E0 + gl.ObjectLabel(GL_BUFFER, coneVBO:GetID(), name or "coneVBO") + return coneVBO, #VBOData/4 end -function makeCylinderVBO(numSegments, height, radius, hastop, hasbottom) +function makeCylinderVBO(numSegments, height, radius, hastop, hasbottom, name) -- make a cylinder that points up, (y = height), with radius specified -- returns the VBO object, and the number of elements in it (usually == numvertices) -- needs GL.TRIANGLES @@ -1093,12 +1124,16 @@ function makeCylinderVBO(numSegments, height, radius, hastop, hasbottom) cylinderVBO:Define(#VBOData/4, {{id = 0, name = "localpos_progress", size = 4}}) cylinderVBO:Upload(VBOData) + + local GL_BUFFER = 0x82E0 + gl.ObjectLabel(GL_BUFFER, cylinderVBO:GetID(), name or "cylinderVBO") + return cylinderVBO, #VBOData/4 end -function makeBoxVBO(minX, minY, minZ, maxX, maxY, maxZ) -- make a box +function makeBoxVBO(minX, minY, minZ, maxX, maxY, maxZ, name) -- make a box -- needs GL.TRIANGLES local boxVBO = gl.GetVBO(GL.ARRAY_BUFFER,true) if boxVBO == nil then return nil end @@ -1143,6 +1178,10 @@ function makeBoxVBO(minX, minY, minZ, maxX, maxY, maxZ) -- make a box } boxVBO:Define(#VBOData/4, {{id = 0, name = "localpos_progress", size = 4}}) boxVBO:Upload(VBOData) + + local GL_BUFFER = 0x82E0 + gl.ObjectLabel(GL_BUFFER, boxVBO:GetID(), name or "boxVBO") + return boxVBO, #VBOData/4 end @@ -1157,7 +1196,7 @@ end ---@param sectorCount number is the number of orange slices around the belly in XY ---@param stackCount number how many horizontal slices along Z, usually less than sectorcount ---@param radius number how many elmos in radius, default 1 -function makeSphereVBO(sectorCount, stackCount, radius) -- http://www.songho.ca/opengl/gl_sphere.html +function makeSphereVBO(sectorCount, stackCount, radius, name) -- http://www.songho.ca/opengl/gl_sphere.html local sphereVBO = gl.GetVBO(GL.ARRAY_BUFFER,true) @@ -1219,6 +1258,10 @@ function makeSphereVBO(sectorCount, stackCount, radius) -- http://www.songho.ca/ end sphereVBO:Define(#VBOData/9, vertVBOLayout) sphereVBO:Upload(VBOData) + + local GL_BUFFER = 0x82E0 + gl.ObjectLabel(GL_BUFFER, sphereVBO:GetID(), name or "sphereVBO") + local numVerts = #VBOData/9 local sphereIndexVBO = gl.GetVBO(GL.ELEMENT_ARRAY_BUFFER,false) @@ -1263,12 +1306,15 @@ function makeSphereVBO(sectorCount, stackCount, radius) -- http://www.songho.ca/ sphereIndexVBO:Define(#VBOData) sphereIndexVBO:Upload(VBOData) + + local GL_BUFFER = 0x82E0 + gl.ObjectLabel(GL_BUFFER, sphereIndexVBO:GetID(), name or "sphereIndexVBO") return sphereVBO, numVerts, sphereIndexVBO, #VBOData end -function MakeTexRectVAO(minX,minY, maxX, maxY, minU, minV, maxU, maxV) +function MakeTexRectVAO(minX,minY, maxX, maxY, minU, minV, maxU, maxV, name) -- Draw with myGL4TexRectVAO:DrawArrays(GL.TRIANGLES) minX,minY,maxX,maxY,minU,minV,maxU,maxV = minX or -1,minY or -1,maxX or 1, maxY or 1, minU or 0, minV or 0, maxU or 1, maxV or 1 @@ -1290,15 +1336,9 @@ function MakeTexRectVAO(minX,minY, maxX, maxY, minU, minV, maxU, maxV) minX,minY, minU, minV, --bl }) - --[[rectVBO:Upload( { - minX,minY,z,w, minU, minV,0,0, --bl - minX,maxY,z,w, minU, maxV,0,0, --br - maxX,maxY,z,w, maxU, maxV,0,0,--tr - maxX,maxY,z,w,maxU, maxV,0,0, --tr - maxX,minY,z,w, maxU, minV,0,0, --br - minX,minY,z,w, minU, minV,0,0, --bl - }) - ]]-- + + local GL_BUFFER = 0x82E0 + gl.ObjectLabel(GL_BUFFER, rectVBO:GetID(), name or "rectVBO") myGL4TexRectVAO = gl.GetVAO() if myGL4TexRectVAO == nil then return nil end diff --git a/luaui/Widgets/gfx_ssao.lua b/luaui/Widgets/gfx_ssao.lua index ef85e275c9d..b1f8e1bcbd2 100644 --- a/luaui/Widgets/gfx_ssao.lua +++ b/luaui/Widgets/gfx_ssao.lua @@ -448,7 +448,7 @@ local function InitGL() uniformFloat = {}, silent = true, -- suppress compilation messages shaderConfig = shaderConfig, - shaderName = widgetName..": G-buffer Fuse", + shaderName = widgetName.." G-buffer Fuse", } gbuffFuseShader = LuaShader.CheckShaderUpdates(gbuffFuseShaderCache) @@ -472,7 +472,7 @@ local function InitGL() }, silent = true, -- suppress compilation messages shaderConfig = shaderConfig, - shaderName = widgetName..": SSAO", + shaderName = widgetName.." SSAO", } ssaoShader = LuaShader.CheckShaderUpdates(ssaoShaderCache) @@ -501,7 +501,7 @@ local function InitGL() }, silent = true, -- suppress compilation messages shaderConfig = shaderConfig, - shaderName = widgetName..": gaussianBlur", + shaderName = widgetName.." gaussianBlur", } gaussianBlurShader = LuaShader.CheckShaderUpdates(gaussianBlurShaderCache) @@ -758,8 +758,10 @@ function widget:DrawWorld() drawFrame = df end if shaderConfig.ENABLE == 0 then return end + gl.PushDebugGroup(9999, "SSAO") DoDrawSSAO(false) + gl.PopDebugGroup() if delayedUpdateSun and os.clock() > delayedUpdateSun then Spring.SendCommands("luarules updatesun") delayedUpdateSun = nil diff --git a/luaui/Widgets/gui_sensor_ranges_los.lua b/luaui/Widgets/gui_sensor_ranges_los.lua index 12d600d4b4c..72cd2508748 100644 --- a/luaui/Widgets/gui_sensor_ranges_los.lua +++ b/luaui/Widgets/gui_sensor_ranges_los.lua @@ -274,7 +274,8 @@ end function widget:DrawWorld() --if spec and fullview then return end - + local GL_DEBUG_SOURCE_APPLICATION = 0x824A + gl.PushDebugGroup(1000, "Sensor Ranges LOS") if Spring.IsGUIHidden() or (WG['topbar'] and WG['topbar'].showingQuit()) then return end if circleInstanceVBO.usedElements == 0 then return end if opacity < 0.01 then return end @@ -319,6 +320,8 @@ function widget:DrawWorld() --glColor(1.0, 1.0, 1.0, 1.0) --reset like a nice boi glLineWidth(1.0) gl.Clear(GL.STENCIL_BUFFER_BIT) + + gl.PopDebugGroup() end