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

Mesh not being updated when data changes in v2-dev #88

Closed
oal opened this issue Jan 3, 2015 · 6 comments
Closed

Mesh not being updated when data changes in v2-dev #88

oal opened this issue Jan 3, 2015 · 6 comments
Assignees
Milestone

Comments

@oal
Copy link

oal commented Jan 3, 2015

When I get an existing mesh like this, and try to change vertices and other attributes, the changes never show up on screen. I can set vertices and make changes before I start rendering anything, but as soon as the render loop starts, no changes are picked up. So it appears that the changed arrays aren't uploaded to the GPU.

    mesh := t.Meshes[0] // has .Dynamic = true

    mesh.Vertices = verts
    mesh.VerticesChanged = true

    mesh.TexCoords = []gfx.TexCoordSet{
        {
            Slice:   texCoords,
            Changed: true,
        },
    }

Let me know if you need more information.

@slimsag
Copy link
Contributor

slimsag commented Jan 3, 2015

Is this with v2-dev still, or v1?

@oal
Copy link
Author

oal commented Jan 3, 2015

Yes, v2-dev master.

@slimsag
Copy link
Contributor

slimsag commented Jan 3, 2015

Thanks, I can reproduce the issue.

// Copyright 2014 The Azul3D Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Issue 88 test.
package main

import (
    "log"

    "azul3d.org/gfx.v2-dev"
    "azul3d.org/gfx.v2-dev/gfxutil"
    "azul3d.org/gfx.v2-dev/window"
    math "azul3d.org/lmath.v1"
)

// gfxLoop is responsible for drawing things to the window.
func gfxLoop(w window.Window, d gfx.Device) {
    // Setup a camera to use a perspective projection.
    camera := gfx.NewCamera()
    camera.SetPersp(d.Bounds(), 75.0, 0.0001, 1000.0)
    camera.SetPos(math.Vec3{0, -2, 0})

    // Read the GLSL shaders from disk.
    shader, err := gfxutil.OpenShader("basic")
    if err != nil {
        log.Fatal(err)
    }

    // Initialize the triangle mesh.
    triMesh := gfx.NewMesh()
    triMesh.Vertices = []gfx.Vec3{
        // Top
        {0, 0, 1},
        {-.5, 0, 0},
        {.5, 0, 0},
    }
    triMesh.Colors = []gfx.Color{
        {1, 0, 0, 1},
        {0, 1, 0, 1},
        {0, 0, 1, 1},
    }

    // Do not set the data slices to nil when loading is complete.
    triMesh.KeepDataOnLoad = true

    // Create a triangle object.
    triangle := gfx.NewObject()
    triangle.Shader = shader
    triangle.State = gfx.NewState()
    triangle.Meshes = []*gfx.Mesh{triMesh}

    for {
        for i, c := range triMesh.Colors {
            c.R += 0.01
            if c.R > 1.0 {
                c.R = 0.0
            }
            triMesh.Colors[i] = c
        }
        log.Println(triMesh.Colors[0])
        triMesh.ColorsChanged = true

        // Clear color and depth buffers.
        d.Clear(d.Bounds(), gfx.Color{1, 1, 1, 1})
        d.ClearDepth(d.Bounds(), 1.0)

        // Draw the triangle to the screen.
        d.Draw(d.Bounds(), triangle, camera)

        // Render the whole frame.
        d.Render()
    }
}

func main() {
    window.Run(gfxLoop, nil)
}

@slimsag
Copy link
Contributor

slimsag commented Jan 3, 2015

@oal please pull the changes I've just made and see if that fixes the issue:

go get -u azul3d.org/gfx.v2-dev

P.S. I just saw the v2-dev in the title -- sorry bout that!

@slimsag slimsag added this to the Version 2 milestone Jan 3, 2015
@slimsag slimsag self-assigned this Jan 3, 2015
@oal
Copy link
Author

oal commented Jan 3, 2015

Yes, it works now! Thanks again for a quick and helpful response. 👍

@slimsag
Copy link
Contributor

slimsag commented Jan 3, 2015

Awesome. 👍 Thank you for the bug report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants