Revert to gl_FragData (future webgl)

This commit is contained in:
Zyko 2024-04-09 02:26:29 +02:00
parent c7eeae7189
commit d1fd70495b
9 changed files with 13 additions and 44 deletions

View File

@ -396,7 +396,7 @@ func (c *context) newShader(shaderType uint32, source string) (shader, error) {
return shader(s), nil return shader(s), nil
} }
func (c *context) newProgram(shaders []shader, attributes, fragData []string) (program, error) { func (c *context) newProgram(shaders []shader, attributes []string) (program, error) {
p := c.ctx.CreateProgram() p := c.ctx.CreateProgram()
if p == 0 { if p == 0 {
return 0, errors.New("opengl: glCreateProgram failed") return 0, errors.New("opengl: glCreateProgram failed")
@ -410,10 +410,6 @@ func (c *context) newProgram(shaders []shader, attributes, fragData []string) (p
c.ctx.BindAttribLocation(p, uint32(i), name) c.ctx.BindAttribLocation(p, uint32(i), name)
} }
for i, name := range fragData {
c.ctx.BindFragDataLocation(p, uint32(i), name)
}
c.ctx.LinkProgram(p) c.ctx.LinkProgram(p)
if c.ctx.GetProgrami(p, gl.LINK_STATUS) == gl.FALSE { if c.ctx.GetProgrami(p, gl.LINK_STATUS) == gl.FALSE {
info := c.ctx.GetProgramInfoLog(p) info := c.ctx.GetProgramInfoLog(p)

View File

@ -61,14 +61,6 @@ func (d *DebugContext) BindBuffer(arg0 uint32, arg1 uint32) {
} }
} }
func (d *DebugContext) BindFragDataLocation(arg0 uint32, arg1 uint32, arg2 string) {
d.Context.BindFragDataLocation(arg0, arg1, arg2)
fmt.Fprintln(os.Stderr, "BindFragDataLocation")
if e := d.Context.GetError(); e != NO_ERROR {
panic(fmt.Sprintf("gl: GetError() returned %d at BindFragDataLocation", e))
}
}
func (d *DebugContext) BindFramebuffer(arg0 uint32, arg1 uint32) { func (d *DebugContext) BindFramebuffer(arg0 uint32, arg1 uint32) {
d.Context.BindFramebuffer(arg0, arg1) d.Context.BindFramebuffer(arg0, arg1)
fmt.Fprintln(os.Stderr, "BindFramebuffer") fmt.Fprintln(os.Stderr, "BindFramebuffer")

View File

@ -128,6 +128,10 @@ package gl
// typedef void (*fn)(GLuint index); // typedef void (*fn)(GLuint index);
// ((fn)(fnptr))(index); // ((fn)(fnptr))(index);
// } // }
// static void glowDrawBuffers(GLsizei n, const GLenum* bufs) {
// typedef void (*fn)(GLsizei n, const GLenum* bufs);
// ((fn)(fnptr))(n, bufs);
// }
// static void glowDrawElements(uintptr_t fnptr, GLenum mode, GLsizei count, GLenum type, const uintptr_t indices) { // static void glowDrawElements(uintptr_t fnptr, GLenum mode, GLsizei count, GLenum type, const uintptr_t indices) {
// typedef void (*fn)(GLenum mode, GLsizei count, GLenum type, const uintptr_t indices); // typedef void (*fn)(GLenum mode, GLsizei count, GLenum type, const uintptr_t indices);
// ((fn)(fnptr))(mode, count, type, indices); // ((fn)(fnptr))(mode, count, type, indices);
@ -351,6 +355,7 @@ type defaultContext struct {
gpDeleteVertexArrays C.uintptr_t gpDeleteVertexArrays C.uintptr_t
gpDisable C.uintptr_t gpDisable C.uintptr_t
gpDisableVertexAttribArray C.uintptr_t gpDisableVertexAttribArray C.uintptr_t
gpDrawBuffers C.uintptr_t
gpDrawElements C.uintptr_t gpDrawElements C.uintptr_t
gpEnable C.uintptr_t gpEnable C.uintptr_t
gpEnableVertexAttribArray C.uintptr_t gpEnableVertexAttribArray C.uintptr_t
@ -565,6 +570,10 @@ func (c *defaultContext) DisableVertexAttribArray(index uint32) {
C.glowDisableVertexAttribArray(c.gpDisableVertexAttribArray, C.GLuint(index)) C.glowDisableVertexAttribArray(c.gpDisableVertexAttribArray, C.GLuint(index))
} }
func (c *defaultContext) DrawBuffers(bufs []uint32) {
C.glowDrawBuffers(c.gpDrawBuffers, C.GLsizei(len(bufs)), (*C.GLenum)(unsafe.Pointer(&bufs[0])))
}
func (c *defaultContext) DrawElements(mode uint32, count int32, xtype uint32, offset int) { func (c *defaultContext) DrawElements(mode uint32, count int32, xtype uint32, offset int) {
C.glowDrawElements(c.gpDrawElements, C.GLenum(mode), C.GLsizei(count), C.GLenum(xtype), C.uintptr_t(offset)) C.glowDrawElements(c.gpDrawElements, C.GLenum(mode), C.GLsizei(count), C.GLenum(xtype), C.uintptr_t(offset))
} }
@ -801,6 +810,7 @@ func (c *defaultContext) LoadFunctions() error {
c.gpDeleteVertexArrays = C.uintptr_t(g.get("glDeleteVertexArrays")) c.gpDeleteVertexArrays = C.uintptr_t(g.get("glDeleteVertexArrays"))
c.gpDisable = C.uintptr_t(g.get("glDisable")) c.gpDisable = C.uintptr_t(g.get("glDisable"))
c.gpDisableVertexAttribArray = C.uintptr_t(g.get("glDisableVertexAttribArray")) c.gpDisableVertexAttribArray = C.uintptr_t(g.get("glDisableVertexAttribArray"))
c.gpDrawBuffers = C.uintptr_t(g.get("glDrawBuffers"))
c.gpDrawElements = C.uintptr_t(g.get("glDrawElements")) c.gpDrawElements = C.uintptr_t(g.get("glDrawElements"))
c.gpEnable = C.uintptr_t(g.get("glEnable")) c.gpEnable = C.uintptr_t(g.get("glEnable"))
c.gpEnableVertexAttribArray = C.uintptr_t(g.get("glEnableVertexAttribArray")) c.gpEnableVertexAttribArray = C.uintptr_t(g.get("glEnableVertexAttribArray"))

View File

@ -28,7 +28,6 @@ type defaultContext struct {
gpAttachShader uintptr gpAttachShader uintptr
gpBindAttribLocation uintptr gpBindAttribLocation uintptr
gpBindBuffer uintptr gpBindBuffer uintptr
gpBindFragDataLocation uintptr
gpBindFramebuffer uintptr gpBindFramebuffer uintptr
gpBindRenderbuffer uintptr gpBindRenderbuffer uintptr
gpBindTexture uintptr gpBindTexture uintptr
@ -141,12 +140,6 @@ func (c *defaultContext) BindBuffer(target uint32, buffer uint32) {
purego.SyscallN(c.gpBindBuffer, uintptr(target), uintptr(buffer)) purego.SyscallN(c.gpBindBuffer, uintptr(target), uintptr(buffer))
} }
func (c *defaultContext) BindFragDataLocation(program uint32, index uint32, name string) {
cname, free := cStr(name)
defer free()
purego.SyscallN(c.gpBindFragDataLocation, uintptr(program), uintptr(index), uintptr(unsafe.Pointer(cname)))
}
func (c *defaultContext) BindFramebuffer(target uint32, framebuffer uint32) { func (c *defaultContext) BindFramebuffer(target uint32, framebuffer uint32) {
purego.SyscallN(c.gpBindFramebuffer, uintptr(target), uintptr(framebuffer)) purego.SyscallN(c.gpBindFramebuffer, uintptr(target), uintptr(framebuffer))
} }
@ -490,7 +483,6 @@ func (c *defaultContext) LoadFunctions() error {
c.gpAttachShader = g.get("glAttachShader") c.gpAttachShader = g.get("glAttachShader")
c.gpBindAttribLocation = g.get("glBindAttribLocation") c.gpBindAttribLocation = g.get("glBindAttribLocation")
c.gpBindBuffer = g.get("glBindBuffer") c.gpBindBuffer = g.get("glBindBuffer")
c.gpBindFragDataLocation = g.get("glBindFragDataLocation")
c.gpBindFramebuffer = g.get("glBindFramebuffer") c.gpBindFramebuffer = g.get("glBindFramebuffer")
c.gpBindRenderbuffer = g.get("glBindRenderbuffer") c.gpBindRenderbuffer = g.get("glBindRenderbuffer")
c.gpBindTexture = g.get("glBindTexture") c.gpBindTexture = g.get("glBindTexture")

View File

@ -31,7 +31,6 @@ type Context interface {
AttachShader(program uint32, shader uint32) AttachShader(program uint32, shader uint32)
BindAttribLocation(program uint32, index uint32, name string) BindAttribLocation(program uint32, index uint32, name string)
BindBuffer(target uint32, buffer uint32) BindBuffer(target uint32, buffer uint32)
BindFragDataLocation(program uint32, index uint32, name string)
BindFramebuffer(target uint32, framebuffer uint32) BindFramebuffer(target uint32, framebuffer uint32)
BindRenderbuffer(target uint32, renderbuffer uint32) BindRenderbuffer(target uint32, renderbuffer uint32)
BindTexture(target uint32, texture uint32) BindTexture(target uint32, texture uint32)

View File

@ -47,7 +47,6 @@ type Graphics struct {
uniformVariableNameCache map[int]string uniformVariableNameCache map[int]string
textureVariableNameCache map[int]string textureVariableNameCache map[int]string
colorBufferVariableNameCache map[int]string
uniformVars []uniformVariable uniformVars []uniformVariable

View File

@ -258,18 +258,6 @@ func (g *Graphics) textureVariableName(idx int) string {
return name return name
} }
func (g *Graphics) colorBufferVariableName(idx int) string {
if v, ok := g.colorBufferVariableNameCache[idx]; ok {
return v
}
if g.colorBufferVariableNameCache == nil {
g.colorBufferVariableNameCache = map[int]string{}
}
name := fmt.Sprintf("fragColor%d", idx)
g.colorBufferVariableNameCache[idx] = name
return name
}
// useProgram uses the program (programTexture). // useProgram uses the program (programTexture).
func (g *Graphics) useProgram(program program, uniforms []uniformVariable, textures [graphics.ShaderSrcImageCount]textureVariable) error { func (g *Graphics) useProgram(program program, uniforms []uniformVariable, textures [graphics.ShaderSrcImageCount]textureVariable) error {
if g.state.lastProgram != program { if g.state.lastProgram != program {

View File

@ -69,11 +69,7 @@ func (s *Shader) compile() error {
} }
defer s.graphics.context.ctx.DeleteShader(uint32(fs)) defer s.graphics.context.ctx.DeleteShader(uint32(fs))
colorNames := make([]string, s.ir.ColorsOutCount) p, err := s.graphics.context.newProgram([]shader{vs, fs}, theArrayBufferLayout.names())
for i := range colorNames {
colorNames[i] = s.graphics.colorBufferVariableName(i)
}
p, err := s.graphics.context.newProgram([]shader{vs, fs}, theArrayBufferLayout.names(), colorNames)
if err != nil { if err != nil {
return err return err
} }

View File

@ -229,9 +229,6 @@ func Compile(p *shaderir.Program, version GLSLVersion) (vertexShader, fragmentSh
fslines = append(fslines, fmt.Sprintf("in %s;", c.varDecl(p, &t, fmt.Sprintf("V%d", i)))) fslines = append(fslines, fmt.Sprintf("in %s;", c.varDecl(p, &t, fmt.Sprintf("V%d", i))))
} }
} }
for i := 0; i < p.ColorsOutCount; i++ {
fslines = append(fslines, fmt.Sprintf("out vec4 fragColor%d;", i))
}
var funcs []*shaderir.Func var funcs []*shaderir.Func
if p.VertexFunc.Block != nil { if p.VertexFunc.Block != nil {
@ -423,7 +420,7 @@ func (c *compileContext) localVariableName(p *shaderir.Program, topBlock *shader
case idx < nv+1: case idx < nv+1:
return fmt.Sprintf("V%d", idx-1) return fmt.Sprintf("V%d", idx-1)
default: default:
return fmt.Sprintf("fragColor%d", idx-(nv+1)) return fmt.Sprintf("gl_FragData[%d]", idx-(nv+1))
} }
default: default:
return fmt.Sprintf("l%d", idx) return fmt.Sprintf("l%d", idx)