mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
Revert to gl_FragData (future webgl)
This commit is contained in:
parent
c7eeae7189
commit
d1fd70495b
@ -396,7 +396,7 @@ func (c *context) newShader(shaderType uint32, source string) (shader, error) {
|
||||
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()
|
||||
if p == 0 {
|
||||
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)
|
||||
}
|
||||
|
||||
for i, name := range fragData {
|
||||
c.ctx.BindFragDataLocation(p, uint32(i), name)
|
||||
}
|
||||
|
||||
c.ctx.LinkProgram(p)
|
||||
if c.ctx.GetProgrami(p, gl.LINK_STATUS) == gl.FALSE {
|
||||
info := c.ctx.GetProgramInfoLog(p)
|
||||
|
@ -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) {
|
||||
d.Context.BindFramebuffer(arg0, arg1)
|
||||
fmt.Fprintln(os.Stderr, "BindFramebuffer")
|
||||
|
@ -128,6 +128,10 @@ package gl
|
||||
// typedef void (*fn)(GLuint 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) {
|
||||
// typedef void (*fn)(GLenum mode, GLsizei count, GLenum type, const uintptr_t indices);
|
||||
// ((fn)(fnptr))(mode, count, type, indices);
|
||||
@ -351,6 +355,7 @@ type defaultContext struct {
|
||||
gpDeleteVertexArrays C.uintptr_t
|
||||
gpDisable C.uintptr_t
|
||||
gpDisableVertexAttribArray C.uintptr_t
|
||||
gpDrawBuffers C.uintptr_t
|
||||
gpDrawElements C.uintptr_t
|
||||
gpEnable C.uintptr_t
|
||||
gpEnableVertexAttribArray C.uintptr_t
|
||||
@ -565,6 +570,10 @@ func (c *defaultContext) DisableVertexAttribArray(index uint32) {
|
||||
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) {
|
||||
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.gpDisable = C.uintptr_t(g.get("glDisable"))
|
||||
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.gpEnable = C.uintptr_t(g.get("glEnable"))
|
||||
c.gpEnableVertexAttribArray = C.uintptr_t(g.get("glEnableVertexAttribArray"))
|
||||
|
@ -28,7 +28,6 @@ type defaultContext struct {
|
||||
gpAttachShader uintptr
|
||||
gpBindAttribLocation uintptr
|
||||
gpBindBuffer uintptr
|
||||
gpBindFragDataLocation uintptr
|
||||
gpBindFramebuffer uintptr
|
||||
gpBindRenderbuffer uintptr
|
||||
gpBindTexture uintptr
|
||||
@ -141,12 +140,6 @@ func (c *defaultContext) BindBuffer(target uint32, buffer uint32) {
|
||||
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) {
|
||||
purego.SyscallN(c.gpBindFramebuffer, uintptr(target), uintptr(framebuffer))
|
||||
}
|
||||
@ -490,7 +483,6 @@ func (c *defaultContext) LoadFunctions() error {
|
||||
c.gpAttachShader = g.get("glAttachShader")
|
||||
c.gpBindAttribLocation = g.get("glBindAttribLocation")
|
||||
c.gpBindBuffer = g.get("glBindBuffer")
|
||||
c.gpBindFragDataLocation = g.get("glBindFragDataLocation")
|
||||
c.gpBindFramebuffer = g.get("glBindFramebuffer")
|
||||
c.gpBindRenderbuffer = g.get("glBindRenderbuffer")
|
||||
c.gpBindTexture = g.get("glBindTexture")
|
||||
|
@ -31,7 +31,6 @@ type Context interface {
|
||||
AttachShader(program uint32, shader uint32)
|
||||
BindAttribLocation(program uint32, index uint32, name string)
|
||||
BindBuffer(target uint32, buffer uint32)
|
||||
BindFragDataLocation(program uint32, index uint32, name string)
|
||||
BindFramebuffer(target uint32, framebuffer uint32)
|
||||
BindRenderbuffer(target uint32, renderbuffer uint32)
|
||||
BindTexture(target uint32, texture uint32)
|
||||
|
@ -47,7 +47,6 @@ type Graphics struct {
|
||||
|
||||
uniformVariableNameCache map[int]string
|
||||
textureVariableNameCache map[int]string
|
||||
colorBufferVariableNameCache map[int]string
|
||||
|
||||
uniformVars []uniformVariable
|
||||
|
||||
|
@ -258,18 +258,6 @@ func (g *Graphics) textureVariableName(idx int) string {
|
||||
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).
|
||||
func (g *Graphics) useProgram(program program, uniforms []uniformVariable, textures [graphics.ShaderSrcImageCount]textureVariable) error {
|
||||
if g.state.lastProgram != program {
|
||||
|
@ -69,11 +69,7 @@ func (s *Shader) compile() error {
|
||||
}
|
||||
defer s.graphics.context.ctx.DeleteShader(uint32(fs))
|
||||
|
||||
colorNames := make([]string, s.ir.ColorsOutCount)
|
||||
for i := range colorNames {
|
||||
colorNames[i] = s.graphics.colorBufferVariableName(i)
|
||||
}
|
||||
p, err := s.graphics.context.newProgram([]shader{vs, fs}, theArrayBufferLayout.names(), colorNames)
|
||||
p, err := s.graphics.context.newProgram([]shader{vs, fs}, theArrayBufferLayout.names())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -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))))
|
||||
}
|
||||
}
|
||||
for i := 0; i < p.ColorsOutCount; i++ {
|
||||
fslines = append(fslines, fmt.Sprintf("out vec4 fragColor%d;", i))
|
||||
}
|
||||
|
||||
var funcs []*shaderir.Func
|
||||
if p.VertexFunc.Block != nil {
|
||||
@ -423,7 +420,7 @@ func (c *compileContext) localVariableName(p *shaderir.Program, topBlock *shader
|
||||
case idx < nv+1:
|
||||
return fmt.Sprintf("V%d", idx-1)
|
||||
default:
|
||||
return fmt.Sprintf("fragColor%d", idx-(nv+1))
|
||||
return fmt.Sprintf("gl_FragData[%d]", idx-(nv+1))
|
||||
}
|
||||
default:
|
||||
return fmt.Sprintf("l%d", idx)
|
||||
|
Loading…
Reference in New Issue
Block a user