Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Codea 2.3.2 Beta

124

Comments

  • Posts: 2,020

    From the above Apple doc:

    GLSL ES 3.0 removes the gl_FragData and gl_FragColor builtin fragment output variables. Instead, you declare your own fragment output variables with the out qualifier

    @Simeon do you know what output variable the Codea mesh API is expecting when using 3.0? I guessed it might be out vec4 FragColor but that didn't work

  • edited October 2015 Posts: 2,020

    Here's my current (non-functioning) code:

    EDIT: got it working! Buffers seem to work too

    -- test of GLES 300 Matrix Mesh Buffer Test
    --
    
    function setup()
        m = mesh()
        m:addRect(0,0,200,200)
        m:setColors(color(255,200,0))
        m.shader = shader(vert, frag)
    
        dummy = m:buffer("dummy") --test vec4 attribute
        transform = m:buffer("transform") --test mat4 attribute
        local mat = matrix():translate(0,100,0) --should move rectangle up
        for i=1,m.size do
            dummy[i] = vec4(60,0,0,0) --works, moves rectangle to right
            transform[i] = mat
        end
    
    end
    
    function draw()
        background(40, 40, 50)
        perspective()
        camera(0,0,400, 0,0,0)
    
        m:draw()
    end
    
    vert=[[
    #version 300 es
    
    uniform mat4 modelViewProjection;
    
    in mat4 transform;
    in vec4 position;
    in vec4 color;
    in vec4 dummy;
    
    out lowp vec4 vColor;
    
    void main()
    {
        vColor = color;
        gl_Position = modelViewProjection * (transform * position + dummy);
    }
    ]]
    
    frag=[[
    #version 300 es
    
    in lowp vec4 vColor; //NB varying becomes "in" in fragment shader
    out lowp vec4 fragColor;
    
    void main()
    {
        fragColor = vColor;
    }
    ]]
    
    
  • edited October 2015 Posts: 2,020

    @Simeon ignore my question at the top of this page, it seems the output variable can be named whatever you want it to be, FragColor, fragmentColor etc.

    My mistake was this: if you switch on 3.0, in the vertex shader, attribute becomes in and varying becomes out. I think this naming makes sense. But, in the fragment shader, varying becomes in, not out. I think this also makes sense, in that the output of the vertex shader becomes the input of the fragment shader. But it means you can't just do a find and replace on varying

  • Posts: 1,976

    I'm getting a really weird bug...If I long press on any link in the Codea Forums, no option to copy the URL pops up, and everything seems a bit laggy. If I then press the little button in the bottom right corner to open the page in Safari, Codea crashes. Happens consistently, every time I long press on a link and then try to open the page in Safari. iPad Air, iOS 9.1.

  • dave1707dave1707 Mod
    Posts: 8,389

    @SkyTheCoder Can you give a specific link you're having the problem with. If I'm doing what I think you're doing, I get the following popup.

    Open
    Open in a New Tab
    Add to Reading List
    Copy
    
  • dave1707dave1707 Mod
    Posts: 8,389

    @SkyTheCoder Never mind. I get the same thing happening if I go to the forum from within Codea. I never go to the forum that way, I go thru codea.io/talk .

  • SimeonSimeon Admin Mod
    Posts: 5,363

    I think it's time to replace the Codea forum web view with the new Safari View Controller. That does mean it will lose the "COPY" links on code blocks, but it's probably worth the change.

  • dave1707dave1707 Mod
    Posts: 8,389

    @Simeon After reading thru this discussion again, I'm losing track of what's fixed and what's still broken. I just updated my iPad to version iOS 9.1 and when I checked the cut,copy,paste,re-indent,lookup problem, it seems to be working correctly. That makes my coding a lot easier now.

  • SimeonSimeon Admin Mod
    Posts: 5,363

    @dave1707 yes, that was a bug with iOS 9.0 unfortunately (not much we can do about it except hope people upgrade to 9.1)

  • Posts: 2,020

    @Simeon GLES 3.0 seems to be working great.

    There is one issue: in 3.0, the old texture2D and texture3D commands have been replaced with a single texture command. The problem is that this clashes with the uniform texture variable that the Codea Mesh API passes to the shader:

    frag = [[
    #version 300 es
    
    uniform lowp sampler2D texture;
    in highp vec2 vTexCoord;
    out lowp vec4 fragColor;
    
    void main()
    {
      fragColor = texture(texture, vTexCoord); // error: "Invalid call of 'texture' (not a function or subroutine uniform)
    }
    ]]
    

    produces this error:

    error: "Invalid call of 'texture' (not a function or subroutine uniform)

    What works as a workaround is to define your own custom texture variable eg:

    frag = [[
    #version 300 es
    
    uniform lowp sampler2D textureMap;
    in highp vec2 vTexCoord;
    out lowp vec4 fragColor;
    
    void main()
    {
      fragColor = texture(textureMap, vTexCoord); 
    }
    ]]
    

    Then, in the Codea code, replace

    myMesh.texture = readImage("Dropbox:grass")

    with:

    myMesh.shader.textureMap = readImage("Dropbox:grass")

    (note the .shader).

  • Posts: 2,020

    I use the "COPY" link all the time. It also works (most of the time) when people post Gists to the forum, if you click through to the Raw code page.

    I think it would be a real shame to lose the COPY links, given that copy and paste on iOS (and especially on web pages in Safari) is still, in 2015, a complete sh!t show.

  • Posts: 2,020

    Should I start a separate thread for GLES 3.0 stuff (and tag it with beta)?

  • IgnatzIgnatz Mod
    Posts: 5,396

    @yojimbo2000 - yes please! :-bd

  • Posts: 2,020

    Here's a page for discussion of Codea 2.3.2 features specific to shaders, including GLES 3.0, but also the new support for the 2.0 specification:

    http://codea.io/talk/discussion/6991/gles-3-0-and-other-changes-to-shaders-in-codea-2-3-2-beta

  • SimeonSimeon Admin Mod
    edited October 2015 Posts: 5,363

    @yojimbo2000 I was intrigued by instancing in OpenGL ES 3.0 and have added it to mesh. New build is uploading.

    For anyone who is unfamiliar with instancing:

    While the API is simple (at least compared to the convoluted way OpenGL exposes the feature), the concept can take a bit to get your head around.

    Instancing in OpenGL means rendering the same mesh geometry many times over, having only submitted it to the GPU once. Each "instance" of the mesh can be differentiated through the use of attributes in shaders, or uniforms in shaders (typically arrays) where you can use the gl_InstanceID variable to assign some particular piece of data to your instance. This lets you render a large amount of geometry efficiently.

    It's good for things like trees or rocks, particles, and so on.

    The API in Codea is as follows:

    mesh:draw() now accepts an optional count parameter indicating how many instances of the mesh to draw. E.g., mesh:draw(10)

    When you create a buffer, you can now indicate to Codea that it should be instanced, e.g.

    positions = m:buffer("myPositions")
    positions.instanced = true
    positions:resize(10)
    

    A buffer marked as instanced will assign its attributes per instance rather than per vertex. If the buffer is the same size as the number of instances you render, then one attribute from the buffer will map to one instance rendered. If the buffer is smaller than the number of instances, the instances will be divided amongst the attributes in the buffer.

    I have modified @yojimbo2000's example code to demonstrate the feature.

    function setup()
        m = mesh()
    
        m:addRect(0,0,30,30)
        m:setColors(color(255,200,0))
        m.shader = shader(vert, frag)
    
        numInstances = 100
    
        dummy = m:buffer("dummy") --test vec4 attribute
        transform = m:buffer("transform") --test mat4 attribute
    
        -- Here we resize the transform buffer to
        -- the number of instances, rather than vertices
        -- note that the buffer can be any size:
        --  if you render N instances with a buffer sized to M
        --  where N > M then the instances will use a divided
        --  version of the buffer
        --
        -- E.g. I render 10 instances with 5 transforms then
        --  instance 1,2 use transform 1
        --  instance 3,4 use transform 2
        --  instance 5,6 use transform 3
        --  ... etc
        transform:resize(numInstances)
    
        -- We have to tell Codea to treat this buffer as an
        -- instanced buffer, that is, it is not per-vertex
        transform.instanced = true
    
        for i=1,m.size do
            -- Set per vertex
            dummy[i] = vec4(0,0,0,0)
        end
    
        for i=1,numInstances do
            -- Sets one transform *per instance*
            local x = (i-1)%10
            local y = math.floor((i-1)/10)
            transform[i] = matrix():translate(x * 40, y * 40, 0)
        end
    
    end
    
    function draw()
        background(40, 40, 50)
    
        translate(WIDTH/2 - 200, HEIGHT/2 - 200)
    
        -- mesh:draw can now take a number of instances
        -- it draws this many, instanced buffers can be
        -- used to differentiate each instance within a
        -- shader
        m:draw(numInstances)
    end
    
    vert=[[
    uniform mat4 modelViewProjection;
    
    attribute mat4 transform;
    attribute vec4 position;
    attribute vec4 color;
    attribute vec4 dummy;
    
    varying lowp vec4 vColor;
    
    void main()
    {
        vColor = color;
        gl_Position = modelViewProjection * (transform * position + dummy);
    }
    ]]
    
    frag=[[
    
    varying lowp vec4 vColor;
    
    void main()
    {
        gl_FragColor = vColor;
    }
    ]]
    
  • Posts: 2,020

    INSTANCING!! Cannot. Wait. To. Try. This. ^:)^

    I can confirm that textures in the vertex shader work in 3.0! http://codea.io/talk/discussion/6991/gles-3-0-and-other-changes-to-shaders-in-codea-2-3-2-beta#latest

  • edited October 2015 Posts: 1,255

    @Simeon Getting a failure when I try to export to Xcode. Any build stops with a "library not found for -lcodea" message resulting in linker failure.

  • SimeonSimeon Admin Mod
    edited October 2015 Posts: 5,363

    @Mark you didn't just happen to try the build a few minutes ago? I was in the middle of uploading new libraries, so perhaps the zip was corrupted when your Xcode attempted to download?

    Edit: try deleting the static libraries (.a files) from your Libs folder and try the build again. This should make Xcode re-download the files.

  • edited October 2015 Posts: 1,255

    Yep, that was it. I just happened to be building while you were uploading. I went back and regenerated the project and it works fine now.

    Oh, and let me mention that this was by far the easiest compile / upload cycle in many a moon. All those little tweaks that have accumulated since the last release seem to have been stomped. Thanks.

  • Posts: 1,255

    Dang. In fact I just went through two submissions to the app store without having to do much more than update my Build Settings to select my developer profile. It went so quickly, that it makes me worry I forgot something.

  • edited October 2015 Posts: 1,255

    @Simeon Things didn't go quite as neatly as I thought. Images in the Project didn't make it into resources for the app. Weirdly enough, even the launch screens aren't showing.

    It's clearly not picking up the Launch Screen from the Launch Image file. Even if I replace them all, or delete them all, I'm still getting the generic "made with Codea" screen. It looks like it's stomping the Codea LaunchBackground and LaunchLogo over the top of the standard LaunchImage. Which is not a good thing.

  • Posts: 1,255

    @Simeon After trying several options, here's what I've found. Assets in the Project folder aren't coming along with exports. This is true even if you turn off automatic detection and specifically select Project as one of the folders to include. On the other hand, you're getting DropBox as a folder even if you don't include it.

    Images in the Document folder work fine.

    The LaunchImage that you can maintain within Xcode now appears to have no affect. No matter what you put in any of them, you get the generic "Made with Codea" screen. You can delete LaunchBackground and LaunchLogo out of the assets, and get a blank screen, but it still doesn't show the standard LaunchImage screens.

  • SimeonSimeon Admin Mod
    Posts: 5,363

    @Mark thanks for all the feedback. I've been wondering when the corruption issue would happen! It was only a matter of time.

    I think the launch image is being overridden by the new launch storyboard, it is preferred on newer deployment targets. I have tried to keep iOS 7 compatibility in the runtime, but perhaps that is not needed and we could just go all-in on the launch storyboard.

    Assets failing to copy sounds like a bug. Will experiment with it.

  • Posts: 2,020

    Instances drawing is working, and it works with GLES 3.0 too. I am so, so pleased that this has been added (and really impressed at how simple you've managed to keep the Codea API). If the performance graphs I linked to on the other thread are accurate, instancing could lead to big performance increases in some cases. I'm going to try it out with my 3D animation interpolation shaders.

  • SimeonSimeon Admin Mod
    Posts: 5,363

    @Mark I've fixed the project assets not copying across. I wasn't able to reproduce the Dropbox folder coming across unnecessarily.

    The Launch images are deprecated in iOS 8 and later. So if you are building and testing on iOS 8 or 9 you will see the Launch Storyboard. This is also part of the exported Xcode project and you can edit it to remove the Codea logo and add your own.

    @SkyTheCoder looks like the old web view is quite unsupported on iOS 9. I've migrated to the proper Safari view controller for the forums under iOS 9. This does mean that the "COPY" links are gone, but I'll be looking at ways to re-integrate them. Perhaps via a separate Safari-extension app.

  • edited October 2015 Posts: 1,976

    @Simeon Kind of off-topic, but is there any chance of getting a more advanced alert API? Right now it's just a basic popup, alert(message, title) which just has an "OK" button. Perhaps it could accept a third parameter, a table of buttons to display? i.e. alert(message, title, {"Yes", "No", "Cancel"}) And it could return the ID of the button which was pressed (if you gave it the buttons {"Yes", "No", "Cancel"} and the user pressed "No," it would return 2, because it was the 2nd element in the table)

  • edited October 2015 Posts: 505

    I would rather like to see a photos integration, so we could save images to photo roll. Or 3D sounds *hint*! Something more useful, which we cannot code ourself in lua

  • Posts: 1,976

    @se24vad I think you can already make 3D sounds, but +1 for photos integration

  • SimeonSimeon Admin Mod
    Posts: 5,363

    Build 59 is release candidate 1 for version 2.3.2. Will submit for review unless there are any major issues. So let me know if you think there's something that can't wait until the next update. (I'd like to get it out sooner as it fixes a number of iOS 9 related issues.)

    @SkyTheCoder I agree, I keep thinking about the API for alert views. Your suggestion is a synchronous API, that is, your Lua code blocks until the alert returns.

    I had thought maybe an async API would be good, something like:

    alert(message, title, { "Yes", function() end },
                          { "No", function() end },
                          "Cancel")
    

    Where you could put your callbacks in the functions for each option. A string only would just assume a nil function.

    Alternatively we could return an "alert" object that needs to be configured before it is shown:

    local a = alert(message, title)
    
    a["Some Option"] = function() end
    a["No"] = function() end
    
    a.show()
    
  • dave1707dave1707 Mod
    edited October 2015 Posts: 8,389

    @Simeon When you post release 59, can you include a list of everything that you added to make it easy to verify what's been fixed and what might need to be checked.

  • SimeonSimeon Admin Mod
    Posts: 5,363

    @dave1707 good point, all release notes have been added to the first post on page 1 of this thread.

  • dave1707dave1707 Mod
    Posts: 8,389

    @Simeon I'm still getting the popup cut,copy,paste,re-indent,lookup to show up and down instead of across the page. Exit Codea and start it again. Hold the iPad at about a 30 degree angle up from being flat and in portrait orientation. Execute the below code, then exit the program. Tap the screen to show the keyboard and then select some code. The popup will be up/down instead of across the page. No big deal because it still works and I think if the iPad is held at a higher angle when this is done, the popup is in the correct orientation.

    supportedOrientations(LANDSCAPE_ANY)
    
    function setup()
    end
    
  • SimeonSimeon Admin Mod
    Posts: 5,363

    @dave1707 I don't even know how you are able to discover bugs like that. Unfortunately this one (and the previous one you reported) are actually bugs in iOS. I was able to work around the first one, but I can't see a way to fix this one short of ditching the iOS keyboard for a completely custom keyboard.

  • Posts: 196

    @Simeon Hey, I may have missed a previous similar report, but there seems to be a cache problem with different projects using assets of the same name.
    To reproduce, open project A to display an image "Project:BG" for example. run project B and display its own "Project:BG" image. The image from project A will be shown (until you exit Codea)
    Cheers

  • SimeonSimeon Admin Mod
    Posts: 5,363

    @Xavier thank you for that, can you log it on the issue tracker? (Link at top of forums)

  • Jmv38Jmv38 Mod
    Posts: 3,295

    for the alert api, the most practical one that we implement when doing it ouselves is

    alert( "message", {"a", "b", "c"}, callback)
    

    which when "b" is pressed calls

    callback("b")
    

    managing the variuous cases with explicit strings and in the same function is the clearest method. just my 50 cents.

  • edited October 2015 Posts: 2,020

    @Simeon I just tested the Xcode export and I'm having an issue with assets.

    I have 3D text files in the dropbox, Tank.mtl and Tank.obj. Because the extension is not .txt I can't use readText and I instead use io.open and file.read.

    In Codea, this is the path I use to find these assets os.getenv("HOME").."/Documents/Dropbox.assets/", and this works fine within Codea.

    However, when I run the project in the Xcode iPhone simulator, the io.open command creates a "no such file or directory" error (I've checked of course that the files are actually in the folder). I've tried changing the path to reflect the new Xcode folder structure, to:

    1. os.getenv("HOME").."/Assets/Dropbox.assets/"

    2. os.getenv("HOME").."/Resources/Assets/Dropbox.assets/"

    3. os.getenv("HOME").."/Dropbox.assets/"

    But I get the same error.

    The literal path to the asset is:

    ~/Xcode/TankBattle/Assets/Dropbox.assets/Tank.mtl

    And the path created by os.getenv("HOME").."/Assets/Dropbox.assets/", as reported by the file.read error message is:

    ~/Library/Developer/CoreSimulator/Device/ ...(long hex code).../data/Containers/Data/Application/ ...(long hex code)... /Assets/Dropbox.assets/Tank.mtl

    Before (when it was Dropbox.assetpack), using os.getenv io.open in this way used to work fine in the Xcode iPhone simulator.

    Is there something I can do to fix this? Is there a way to access the path of the new Dropbox.assets from within Codea?

    Or is this something that needs to be fixed in the Codea Xcode library?

  • Posts: 1,255

    @Simeon – Resources now coming through. Thanks.

    Two things, one very minor and one baffling (and important).

    The minor: when doing an export, the name of the project appears in the subject line of the email the first time you do it. However, if you do the same project or another project again, the subject line is blank until you exit and return to Codea.

    The baffling: http.request doesn't seem to be working. Even calls to Bing or Google just wander away and never return. I'm desperately scanning developer docs and forums in hopes of finding some new switch that needs to be thrown.

  • SimeonSimeon Admin Mod
    Posts: 5,363

    @Mark re. http.request is this in your exported app? Or in Codea itself?

    If it's the former, then you probably need to enable an App Transport Security exception for the domains you wish to use. iOS 9 disallows all insecure http requests by default, only valid https requests will go through. You can add an App Transport Security exception in your application's Info.plist.

  • SimeonSimeon Admin Mod
    Posts: 5,363

    @yojimbo2000 hmm, the path your error reported looks like a correct path for the iOS simulator. Have you tried copying it, going to the Finder, press Cmd+Shift+G and paste the path into there, then see if it takes you to a valid location? If it does then it should be able to load the asset.

    Alternatively, you could rename the assets to Tank_mtl.txt and Tank_obj.txt and then read them with readText. Not a great solution but it should work.

  • edited October 2015 Posts: 2,020

    @Simeon I'll try that in the finder later today (I'm away from my Mac just now). What about the section after the "HOME" path, should I leave it as /Documents/Dropbox.assets (which is what works when running the code in Codea 2.3.2), or should I change it to /Assets/Dropbox.assets so that it resembles the literal path in the Xcode project? My understanding of the way this variable works is that it is not meant to be a literal path, but some kind of remapping. When it was working before for example, Documents/Dropbox.assetpack located assets whose literal path (if I remember correctly), was actually Assetpacks/Dropbox.assetpack. Could it be possible that this Documents path is not being correctly remapped to the new Assets folder in the new version of the Xcode export?

  • Posts: 1,255

    @Simeon Jeebus. It seems that every time I upload an app, I find that Apple has made me jump through another hoop to protect me from myself. No search that I could think of turned up that requirement. I'll make the additions. It would be nice to run through the http requests in an app that don't reference an https site and create these keys as part of the export. Thanks.

  • SimeonSimeon Admin Mod
    Posts: 5,363

    @Mark that's a pretty good idea, though I think Apple wants everyone to just use https. You can add a blanket exception for all http requests.

  • Posts: 1,255

    @Simeon Yep, I grok that Apple would like all requests to be through https, but among other things I'm fetching maps off Bing, which doesn't seem to give that option. And I admit, I just did the blanket "Allow Arbitrary" rather than trying to get in every domain at the moment. But before I go to final on this app, I'll trim it down. Thanks again for pointing this out when the dev forums seemed to not get what I was asking.

  • Posts: 1,255

    @Simeon now that I think about it, MapKit access wouldn't be a bad thing for Codea. Would be spiffy for my apps, and would be nice for those doing location-based gaming.

  • Posts: 1,255

    @Simeon just to note it down, the icons created by the export don't include the 3x versions necessary for the plus series iPhones, and is still creating that odd 60x60 version that Xcode complains about. Not a big deal, of course.

  • edited November 2015 Posts: 2,020

    @Simeon here's the strange thing. The path produced byos.getenv("HOME").."/Documents/Dropbox.assets/" is a genuine path (it works in Finder), but the folder is empty.

    The paths look like this: ~/Library/Developer/CoreSimulator/Devices/55235AAC-1EB8-4B73-A206-C8E8FFC7AE84/data/Containers/Data/Application/0AD821D3-365E-4041-9206-CC381388B852/Documents/Dropbox.assets/

  • Posts: 2,020

    @Simeon looking at other Codea Xcode projects, they all have an empty "/Documents/Dropbox.assets" folder, even if they don't use any Dropbox assets.

  • Posts: 1,255

    Ah. See? It's not just me. That's a relief.

  • edited November 2015 Posts: 2,020

    Doing a bit more digging, it seems that the Dropbox.assets folder that has the data files I'm trying to read in it, is actually in the application package itself:

    ~/Library/Developer/CoreSimulator/Devices/55235AAC-1EB8-4B73-A206-C8E8FFC7AE84/data/Containers/Bundle/Application/69AE0D7F-8696-48D3-BAB0-14235864E384/TankBattle.app/Assets/Dropbox.assets

    or, to try to make it more readable:

    [device UDID]/data/Containers/Bundle/Application/[app UDID]

    whereas the path to the empty folder is the data folder:

    [device UDID]/data/Containers/Data/Application/[app UDID]

    So, the issue is that os.getenv("HOME") points to the data folder (where the asset packs used to be stored?), and it seems that assets are now stored in the executable folder. I don't know whether this is to do with changes in XCode 7/ iOS 9 or the Codea 2.3.2 runtime. It seems to reduce our options though, if the assets are in the executable folder and not accessible with Lua file io commands?

    Edit: I noticed that in Xcode's build settings pane, there's a "Embed Assets in Product Bundle" flag (which seems to be where the assets are ending up), but it's set to "no".

    Edit2: I had a look back at my previous Xcode project, using the older, assetpacks runtime, and that project also has its assets embedded in the executable, so the placement of the assets has not changed with the new export (apologies for getting this wrong in the above paragraphs). I had forgotten that in that older project I had also saved the 3d assets as .txt files, and added a check to the loader, where if opening the file using Lua file operations failed, it loaded the assets with readText as a fallback. Everything seems to be working now.

Sign In or Register to comment.