Skip to content

Commit

Permalink
Revert "Merge pull request #2179 and #2180 from ikemen-engine/refactor"
Browse files Browse the repository at this point in the history
Revert commits 61eb31f, 2551cd2, 1e10324, cd8a61d, and 8a9cf06 to undo recent changes
  • Loading branch information
K4thos committed Dec 12, 2024
1 parent f8235b6 commit dda9d0b
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 91 deletions.
24 changes: 12 additions & 12 deletions external/script/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ function options.f_displayRatio(value)
end

local function f_externalShaderName()
if config.ExternalShader ~= "" then
return config.ExternalShader:gsub('^.+/', '')
end
return motif.option_info.menu_valuename_disabled
if #config.ExternalShaders > 0 and config.PostProcessingShader ~= 0 then
return config.ExternalShaders[1]:gsub('^.+/', '')
end
return motif.option_info.menu_valuename_disabled
end

local function changeLanguageSetting(val)
Expand Down Expand Up @@ -155,6 +155,7 @@ options.t_itemname = {
config.DebugMode = true
config.Difficulty = 5
--config.EscOpensMenu = true
config.ExternalShaders = {}
--config.FirstRun = false
--config.FontShaderVer = 120
--config.ForceStageZoomin = 0
Expand Down Expand Up @@ -189,7 +190,7 @@ options.t_itemname = {
config.PanningRange = 30
config.Players = 4
--config.PngSpriteFilter = true
config.ExternalShader = ''
config.PostProcessingShader = 0
config.QuickContinue = false
config.RatioAttack = {0.82, 1.0, 1.17, 1.30}
config.RatioLife = {0.80, 1.0, 1.17, 1.40}
Expand Down Expand Up @@ -942,7 +943,7 @@ options.t_itemname = {
return true
end
for k, v in ipairs(t.submenu[t.items[item].itemname].items) do
if config.ExternalShader == v.itemname then
if config.ExternalShaders[1] == v.itemname then
v.selected = true
else
v.selected = false
Expand All @@ -959,7 +960,8 @@ options.t_itemname = {
['noshader'] = function(t, item, cursorPosY, moveTxt)
if main.f_input(main.t_players, {'pal', 's'}) then
sndPlay(motif.files.snd_data, motif.option_info.cancel_snd[1], motif.option_info.cancel_snd[2])
config.ExternalShader = ""
config.ExternalShaders = {}
config.PostProcessingShader = 0
options.modified = true
options.needReload = true
return false
Expand Down Expand Up @@ -1600,13 +1602,11 @@ function options.f_start()
table.insert(options.t_shaders, {path = path, filename = filename})
end
if ext:match('vert') or ext:match('frag') --[[or ext:match('shader')]] then
local shaderPath = path .. filename
options.t_itemname[shaderPath] = function(t, item, cursorPosY, moveTxt)
options.t_itemname[path .. filename] = function(t, item, cursorPosY, moveTxt)
if main.f_input(main.t_players, {'pal', 's'}) then
sndPlay(motif.files.snd_data, motif.option_info.cursor_done_snd[1], motif.option_info.cursor_done_snd[2])
config.ExternalShader = shaderPath
options.modified = true
options.needReload = true
config.ExternalShaders = {path .. filename}
config.PostProcessingShader = 1
return false
end
return true
Expand Down
6 changes: 4 additions & 2 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ type configSettings struct {
DebugMode bool
Difficulty int
EscOpensMenu bool
ExternalShaders []string
EnableModel bool
EnableModelShadow bool
ExternalShader string
FirstRun bool
ForceStageZoomin float32
ForceStageZoomout float32
Expand Down Expand Up @@ -261,6 +261,7 @@ type configSettings struct {
PauseMasterVolume int
Players int
PngSpriteFilter bool
PostProcessingShader int32
QuickContinue bool
RatioAttack [4]float32
RatioLife [4]float32
Expand Down Expand Up @@ -384,6 +385,7 @@ func setupConfig() configSettings {
sys.enableModel = tmp.EnableModel
sys.enableModelShadow = tmp.EnableModelShadow
sys.explodMax = tmp.MaxExplod
sys.externalShaderList = tmp.ExternalShaders
// Resoluion stuff
sys.fullscreen = tmp.Fullscreen
sys.fullscreenRefreshRate = tmp.FullscreenRefreshRate
Expand Down Expand Up @@ -412,7 +414,7 @@ func setupConfig() configSettings {
sys.pauseMasterVolume = tmp.PauseMasterVolume
sys.panningRange = tmp.PanningRange
sys.playerProjectileMax = tmp.MaxPlayerProjectile
sys.externalShader = strings.Replace(tmp.ExternalShader, "\\", "/", -1)
sys.postProcessingShader = tmp.PostProcessingShader
sys.pngFilter = tmp.PngSpriteFilter
sys.powerShare = [...]bool{tmp.TeamPowerShare, tmp.TeamPowerShare}
tmp.ScreenshotFolder = strings.TrimSpace(tmp.ScreenshotFolder)
Expand Down
58 changes: 21 additions & 37 deletions src/render_gl.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"encoding/binary"
"fmt"
"math"
"os"
"runtime"
"strconv"
"unsafe"
Expand Down Expand Up @@ -75,14 +74,14 @@ type ShaderProgram struct {

func newShaderProgram(vert, frag, geo, id string, crashWhenFail bool) (s *ShaderProgram, err error) {
var vertObj, fragObj, geoObj, prog uint32
if vertObj, err = compileShader(gl.VERTEX_SHADER, vert); chkEX(err, "Shader compilation error on "+id+"\n", crashWhenFail) {
if vertObj, err = compileShader(gl.VERTEX_SHADER, vert); chkEX(err, "Shader compliation error on "+id+"\n", crashWhenFail) {
return nil, err
}
if fragObj, err = compileShader(gl.FRAGMENT_SHADER, frag); chkEX(err, "Shader compilation error on "+id+"\n", crashWhenFail) {
if fragObj, err = compileShader(gl.FRAGMENT_SHADER, frag); chkEX(err, "Shader compliation error on "+id+"\n", crashWhenFail) {
return nil, err
}
if len(geo) > 0 {
if geoObj, err = compileShader(gl.GEOMETRY_SHADER_EXT, geo); chkEX(err, "Shader compilation error on "+id+"\n", crashWhenFail) {
if geoObj, err = compileShader(gl.GEOMETRY_SHADER_EXT, geo); chkEX(err, "Shader compliation error on "+id+"\n", crashWhenFail) {
return nil, err
}
if prog, err = linkProgram(vertObj, fragObj, geoObj); chkEX(err, "Link program error on "+id+"\n", crashWhenFail) {
Expand Down Expand Up @@ -339,9 +338,9 @@ type Renderer struct {
fbo_shadow_texture [4]uint32
fbo_shadow_cube_texture [4]uint32
fbo_env uint32
// Post-processing shader
postVertBuffer uint32
postProcessingShader *ShaderProgram
// Post-processing shaders
postVertBuffer uint32
postShaderSelect []*ShaderProgram
// Shader and vertex data for primitive rendering
spriteShader *ShaderProgram
vertexBuffer uint32
Expand Down Expand Up @@ -454,6 +453,8 @@ func (r *Renderer) Init() {
// Store current timestamp
sys.prevTimestamp = glfw.GetTime()

r.postShaderSelect = make([]*ShaderProgram, 1+len(sys.externalShaderList))

// Data buffers for rendering
postVertData := f32.Bytes(binary.LittleEndian, -1, -1, 1, -1, -1, 1, 1, 1)

Expand All @@ -478,38 +479,21 @@ func (r *Renderer) Init() {
}
}

// Compile postprocessing shader
// Compile postprocessing shaders

// Load identity shader as default
r.postProcessingShader, _ = newShaderProgram(identVertShader, identFragShader, "", "Identity Postprocess", true)
r.postProcessingShader.RegisterAttributes("VertCoord")
r.postProcessingShader.RegisterUniforms("Texture", "TextureSize", "CurrentTime")
// Calculate total amount of shaders loaded.
r.postShaderSelect = make([]*ShaderProgram, 1+len(sys.externalShaderList))

// If a post-processing shader is specified in the configuration, load it
if sys.externalShader != "" {
// Load vertex shader
vertPath := sys.externalShader + ".vert"
vertContent, err := os.ReadFile(vertPath)
if err != nil {
chk(fmt.Errorf("failed to read vertex shader %s: %w", vertPath, err))
}
// Ident shader (no postprocessing)
r.postShaderSelect[0], _ = newShaderProgram(identVertShader, identFragShader, "", "Identity Postprocess", true)
r.postShaderSelect[0].RegisterAttributes("VertCoord")
r.postShaderSelect[0].RegisterUniforms("Texture", "TextureSize", "CurrentTime")

// Load fragment shader
fragPath := sys.externalShader + ".frag"
fragContent, err := os.ReadFile(fragPath)
if err != nil {
chk(fmt.Errorf("failed to read fragment shader %s: %w", fragPath, err))
}

// Use loaded shader contents from System
customPostShader, err := newShaderProgram(string(vertContent)+"\x00", string(fragContent)+"\x00", "", "Postprocess Shader", true)
if err != nil {
sys.errLog.Printf("Failed to compile post-processing shader: %v", err)
// Fallback to identity shader
} else {
r.postProcessingShader = customPostShader
r.postProcessingShader.RegisterUniforms("Texture", "TextureSize", "CurrentTime")
}
// External Shaders
for i := 0; i < len(sys.externalShaderList); i++ {
r.postShaderSelect[1+i], _ = newShaderProgram(sys.externalShaders[0][i],
sys.externalShaders[1][i], "", fmt.Sprintf("Postprocess Shader #%v", i+1), true)
r.postShaderSelect[1+i].RegisterUniforms("Texture", "TextureSize", "CurrentTime")
}

if sys.multisampleAntialiasing > 0 {
Expand Down Expand Up @@ -642,7 +626,7 @@ func (r *Renderer) EndFrame() {
}

x, y, resizedWidth, resizedHeight := sys.window.GetScaledViewportSize()
postShader := r.postProcessingShader
postShader := r.postShaderSelect[sys.postProcessingShader]

var scaleMode int32 // GL enum
if sys.windowScaleMode == true {
Expand Down
62 changes: 25 additions & 37 deletions src/render_gl_gl32.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"encoding/binary"
"fmt"
"math"
"os"
"runtime"
"unsafe"

Expand Down Expand Up @@ -75,14 +74,14 @@ type ShaderProgram struct {

func newShaderProgram(vert, frag, geo, id string, crashWhenFail bool) (s *ShaderProgram, err error) {
var vertObj, fragObj, geoObj, prog uint32
if vertObj, err = compileShader(gl.VERTEX_SHADER, vert); chkEX(err, "Shader compilation error on "+id+"\n", crashWhenFail) {
if vertObj, err = compileShader(gl.VERTEX_SHADER, vert); chkEX(err, "Shader compliation error on "+id+"\n", crashWhenFail) {
return nil, err
}
if fragObj, err = compileShader(gl.FRAGMENT_SHADER, frag); chkEX(err, "Shader compilation error on "+id+"\n", crashWhenFail) {
if fragObj, err = compileShader(gl.FRAGMENT_SHADER, frag); chkEX(err, "Shader compliation error on "+id+"\n", crashWhenFail) {
return nil, err
}
if len(geo) > 0 {
if geoObj, err = compileShader(gl.GEOMETRY_SHADER, geo); chkEX(err, "Shader compilation error on "+id+"\n", crashWhenFail) {
if geoObj, err = compileShader(gl.GEOMETRY_SHADER, geo); chkEX(err, "Shader compliation error on "+id+"\n", crashWhenFail) {
return nil, err
}
if prog, err = linkProgram(vertObj, fragObj, geoObj); chkEX(err, "Link program error on "+id+"\n", crashWhenFail) {
Expand Down Expand Up @@ -339,9 +338,9 @@ type Renderer struct {
fbo_shadow_texture uint32
fbo_shadow_cube_texture uint32
fbo_env uint32
// Post-processing shader
postVertBuffer uint32
postProcessingShader *ShaderProgram
// Post-processing shaders
postVertBuffer uint32
postShaderSelect []*ShaderProgram
// Shader and vertex data for primitive rendering
spriteShader *ShaderProgram
vertexBuffer uint32
Expand Down Expand Up @@ -452,6 +451,8 @@ func (r *Renderer) Init() {
// Store current timestamp
sys.prevTimestamp = glfw.GetTime()

r.postShaderSelect = make([]*ShaderProgram, 1+len(sys.externalShaderList))

// Data buffers for rendering
postVertData := f32.Bytes(binary.LittleEndian, -1, -1, 1, -1, -1, 1, 1, 1)

Expand Down Expand Up @@ -483,38 +484,25 @@ func (r *Renderer) Init() {
}
}

// Compile postprocessing shader
// Compile postprocessing shaders

// Load identity shader as default
r.postProcessingShader, _ = newShaderProgram(identVertShader, identFragShader, "", "Identity Postprocess", true)
r.postProcessingShader.RegisterAttributes("VertCoord")
r.postProcessingShader.RegisterUniforms("Texture", "TextureSize", "CurrentTime")
// Calculate total amount of shaders loaded.
r.postShaderSelect = make([]*ShaderProgram, 1+len(sys.externalShaderList))

// If a post-processing shader is specified in the configuration, load it
if sys.externalShader != "" {
// Load vertex shader
vertPath := sys.externalShader + ".vert"
vertContent, err := os.ReadFile(vertPath)
if err != nil {
chk(fmt.Errorf("failed to read vertex shader %s: %w", vertPath, err))
}

// Load fragment shader
fragPath := sys.externalShader + ".frag"
fragContent, err := os.ReadFile(fragPath)
if err != nil {
chk(fmt.Errorf("failed to read fragment shader %s: %w", fragPath, err))
}
// Ident shader (no postprocessing)
r.postShaderSelect[0], _ = newShaderProgram(identVertShader, identFragShader, "", "Identity Postprocess", true)
r.postShaderSelect[0].RegisterAttributes("VertCoord", "TexCoord")
r.postShaderSelect[0].RegisterUniforms("Texture", "TextureSize", "CurrentTime")

// Use loaded shader contents from System
customPostShader, err := newShaderProgram(string(vertContent)+"\x00", string(fragContent)+"\x00", "", "Postprocess Shader", true)
if err != nil {
sys.errLog.Printf("Failed to compile post-processing shader: %v", err)
// Fallback to identity shader
} else {
r.postProcessingShader = customPostShader
r.postProcessingShader.RegisterUniforms("Texture", "TextureSize", "CurrentTime")
}
// External Shaders
for i := 0; i < len(sys.externalShaderList); i++ {
r.postShaderSelect[1+i], _ = newShaderProgram(sys.externalShaders[0][i],
sys.externalShaders[1][i], "", fmt.Sprintf("Postprocess Shader #%v", i+1), true)
r.postShaderSelect[1+i].RegisterAttributes("VertCoord", "TexCoord")
loc := r.postShaderSelect[0].a["TexCoord"]
gl.VertexAttribPointer(uint32(loc), 3, gl.FLOAT, false, 5*4, gl.PtrOffset(2*4))
gl.EnableVertexAttribArray(uint32(loc))
r.postShaderSelect[1+i].RegisterUniforms("Texture", "TextureSize", "CurrentTime")
}

if sys.multisampleAntialiasing > 0 {
Expand Down Expand Up @@ -645,7 +633,7 @@ func (r *Renderer) EndFrame() {
}

x, y, resizedWidth, resizedHeight := sys.window.GetScaledViewportSize()
postShader := r.postProcessingShader
postShader := r.postShaderSelect[sys.postProcessingShader]

var scaleMode int32 // GL enum
if sys.windowScaleMode {
Expand Down
3 changes: 2 additions & 1 deletion src/resources/defaultConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"EnableModel": true,
"EnableModelShadow": true,
"EscOpensMenu": true,
"ExternalShader": "",
"ExternalShaders": [],
"FirstRun": true,
"ForceStageZoomin": 0,
"ForceStageZoomout": 0,
Expand Down Expand Up @@ -90,6 +90,7 @@
"PauseMasterVolume": 0,
"Players": 4,
"PngSpriteFilter": true,
"PostProcessingShader": 0,
"QuickContinue": false,
"RatioAttack": [
0.82,
Expand Down
Loading

0 comments on commit dda9d0b

Please sign in to comment.