Codea 2.0 Beta

Just an idea, following up on @Ignatz’s opinion (which is very good), you might try simply creating an extra project tab (when copying) that hold all the shaders that are used, so each shader is in the code once.

@Ignatz very good point about multiple instances.

The idea was to keep the code neat (with simple easy-to-read shader references) for the developer, and then in the exported version automatically integrate it just for export — not changing the project inside Codea in any way.

I do like the idea of copying the code from the Shader Lab, or even directly from the shader picker (a “copy” button next to each shader that copies the shader as a shader(...) function call).

But I don’t like the idea of having to do this manually if you want to use asset references. As @Zoyt mentioned, project based assets might be a different path towards resolving this.

Perhaps we could offer the option on copy? We could add a table to the end of the code with all shaders in it and then change shader asset references to reference the table, but only if the option is selected.

Edit: @Zoyt yes, a separate tab with a two tables named something relatively unique like _codeaVShaderExport = {...} / _codeaFShaderExport = {...} could work.

Here’s what I do when exporting shaders.

--The name of the project must match your Codea project name if dependencies are used. 
--Project: Place Project Name Here
--Author:
--Version: Alpha 1.0
--Comments:
--Options: NoConnect

if localise then localise("CopyShader") end

function setup()
    addShader("Gradient Fill", "GradientFill")
end

function addShader(name,tab)
    local s = shader("Documents:" .. name)
    local str = "\
\
function shader" .. 
                name .. 
                " ()\
return shader([[\
" .. 
                s.vertexProgram .. 
                "]],[[\
" .. 
                s.fragmentProgram .. 
                "]])\
end"
    local code = readProjectTab(tab)
    saveProjectTab(tab,code .. str)
    print("Saved shader " .. name .. " to tab " .. tab)
end

(It should remove blanks from the shader name, though)

While we’re talking about shaders, if a shader can have a texture but one isn’t passed, it should use a pure white texture by default. It seems to use the last image the GPU loaded.

@Andrew_Stacey good example, I’d like to do something like that.

Debug textures are a good idea also, a checkerboard or bright green, or even a “missing image” texture might be more useful?

I’m thinking of shaders that can be used with or without a texture and just work either way. Take my Gradient Fill texture (thread in steven8tr’s colour chooser). That makes sense with and without a texture but I basically have to have two shaders for the two situations.

####Bug

  • When trying to import an image from photo library into documents, the save as text field is hidden at the top of the viewer. You can select it but you can not read what you type.

Thanks @Briarfox

@Andrew_Stacey that’s a good case for a plain white default

####Bug

  • No error popup when a table is incorrectly declared. Codea will not launch the project. Example: test = {{1,1}{2,2}} (note missing the comma)

@Simeon

+1 for Andrew’s suggestion of a default white texture for shaders.

The red flags don’t seem to be working when I run some code. That is, I have a project that when I click “run” doesn’t run. But there are no helpful red highlights anywhere (none of the tabs is red, and I can’t find any red highlighting in any of them).

@Andrew_Stacey yes, buffer errors had to be taken out for a while — they are coming back. At the moment only errors detected while you type are shown, which does not encompass all possible pre-runtime errors. Other errors might still appear when you hit play (e.g., the table example from @Briarfox).

@Simeon With regard to indentation, I’ve tracked it down. It isn’t anonymous functions, it’s the word “function” appearing inside a long comment.

--[[
function
--]]

throws off the indenter.

Ah thanks @Andrew_Stacey, I’ll be able to fix that.

@Simeon If you long press on – and try to select, nothing happends.

@Briarfox thanks, I’ll look into it. If you are trying to uncomment something remember that you can just press the comment button (it will toggle whole-line comment off if it exists).

@Simeon Yeah I get the comment thing, but I was trying to select code, cut and paste. Not a huge hassle but you cant select --. You need to select past it then drag over.

@toffer switching between tabs should maintain the cursor position, I’ll look into it. I thought I fixed this a few builds ago.

Maybe already tracked. When switching between tabs, the scrolling point is lost or ‘arbitrary’ defined, sometimes cursor is visible near the bottom, sometimes hidden because the tab is scrolled to far from top. And I wonder if it’s possible to keep the scrolling/cursor point and keyboard opening state when return back from the viewer ? Hope that make sens.

nvm, it’s simply the tab bar that hide the ‘current line’, that’s just arbitrary scroll up or down to find the cursor. ie: cursor is near bottom, I scroll up to grap tabs (so the cursor is hidden at bottom), swith to another tab, come back to the first one, and the cursor is hidden by tabs at the top. Anyway, that don’t really matter. May I suggest, what about 2/3 fingers swipe or tap twice left/right to switch prev/next tab (I find annoying to have to scroll to catch tabs) ?

Good suggestion on the gestures. I’ll try to fix the tab bar hiding the cursor.