Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Texture releasing #891

Merged
merged 5 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 2 additions & 23 deletions CSS.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@ func ParseCSSStyleSheet(data []byte) error {

for styleVarName, styleVarValue := range style {
// convert style variable name to giu style variable name
var styleVarID StyleVarID

err := panicToErr(func() {
styleVarID = StyleVarIDFromString(styleVarName)
})
styleVarID, err := StyleVarIDString(styleVarName)

if err == nil {
// the style is StyleVarID - set it
Expand Down Expand Up @@ -94,11 +90,7 @@ func ParseCSSStyleSheet(data []byte) error {
continue
}

var styleColorID StyleColorID

err = panicToErr(func() {
styleColorID = StyleColorIDFromString(styleVarName)
})
styleColorID, err := StyleColorIDString(styleVarName)
if err != nil {
return ErrCSSParse{What: "style variable ID", Value: styleVarName}
}
Expand All @@ -117,19 +109,6 @@ func ParseCSSStyleSheet(data []byte) error {
return nil
}

func panicToErr(f func()) (err error) {
defer func() {
if r := recover(); r != nil {
//nolint:goerr113 // Not worth wrapping
err = fmt.Errorf("%v", r)
}
}()

f()

return err
}

// cssStylesheet is a map tag:StyleSetter.
type cssStylesheet map[string]*StyleSetter

Expand Down
2 changes: 2 additions & 0 deletions Context.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type GIUContext struct {
FontAtlas *FontAtlas

textureLoadingQueue *queue.Queue
textureFreeingQueue *queue.Queue

cssStylesheet cssStylesheet

Expand All @@ -80,6 +81,7 @@ func CreateContext(b backend.Backend[glfwbackend.GLFWWindowFlags]) *GIUContext {
backend: b,
FontAtlas: newFontAtlas(),
textureLoadingQueue: queue.New(),
textureFreeingQueue: queue.New(),
m: &sync.Mutex{},
widgetIndex: make(map[string]int),
}
Expand Down
11 changes: 10 additions & 1 deletion MasterWindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (w *MasterWindow) setTheme() (fin func()) {
imgui.PushStyleColorVec4(imgui.ColPlotHistogramHovered, imgui.Vec4{X: 1.00, Y: 0.60, Z: 0.00, W: 1.00})
imgui.PushStyleColorVec4(imgui.ColTextSelectedBg, imgui.Vec4{X: 0.26, Y: 0.59, Z: 0.98, W: 0.35})
imgui.PushStyleColorVec4(imgui.ColDragDropTarget, imgui.Vec4{X: 1.00, Y: 1.00, Z: 0.00, W: 0.90})
imgui.PushStyleColorVec4(imgui.ColNavHighlight, imgui.Vec4{X: 0.26, Y: 0.59, Z: 0.98, W: 1.00})
imgui.PushStyleColorVec4(imgui.ColNavWindowingHighlight, imgui.Vec4{X: 0.26, Y: 0.59, Z: 0.98, W: 1.00})
imgui.PushStyleColorVec4(imgui.ColNavWindowingHighlight, imgui.Vec4{X: 1.00, Y: 1.00, Z: 1.00, W: 0.70})
imgui.PushStyleColorVec4(imgui.ColTableHeaderBg, imgui.Vec4{X: 0.12, Y: 0.20, Z: 0.28, W: 1.00})
imgui.PushStyleColorVec4(imgui.ColTableBorderStrong, imgui.Vec4{X: 0.20, Y: 0.25, Z: 0.29, W: 1.00})
Expand All @@ -210,6 +210,15 @@ func (w *MasterWindow) beforeRender() {
NewTextureFromRgba(request.img, request.cb)
}
}

// process texture free requests
if Context.textureFreeingQueue != nil && Context.textureFreeingQueue.Length() > 0 {
for Context.textureFreeingQueue.Length() > 0 {
request, ok := Context.textureFreeingQueue.Remove().(textureFreeRequest)
Assert(ok, "MasterWindow", "Run", "processing texture requests: wrong type of texture request")
request.tex.tex.Release()
}
}
}

func (w *MasterWindow) afterRender() {
Expand Down
173 changes: 86 additions & 87 deletions StyleIDs.go

Large diffs are not rendered by default.

156 changes: 0 additions & 156 deletions StyleIDs_string.go

This file was deleted.

Loading
Loading