3Dickulus / FragM

Derived from https://github.com/Syntopia/Fragmentarium/
GNU General Public License v3.0
349 stars 30 forks source link

macOS Release Build error (Catalina) #148

Closed iRyanBell closed 4 years ago

iRyanBell commented 4 years ago

Describe the bug On the macOS build from the releases tab, I receive an error:

Could not create vertex shader: QOpenGLShader::compile(Vertex): ERROR: 0:1: '' : #version required and missing. ERROR: 3:27: 'varying' : syntax error: syntax error Failed to compile script (13 ms). Failed to resolve OpenGL functions required to enable AsmBrowser

To Reproduce Steps to reproduce the behavior:

Desktop (please complete the following information):


If building from source is the best way around this issue, what's the recommended way to install the dependencies (eg. Qt5LinguistTools), configure the application for retina displays, and compile?

3Dickulus commented 4 years ago

QOpenGLShader::compile(Vertex): ERROR: 0:1: '' : #version required and missing. ERROR: 3:27: 'varying' : syntax error: syntax error

is the first line of the shader in the editor #version 410 compatibility ??? Mac doesn't support any higher than that, may not support compatibility either, maybe only core, you may also have difficulty if it's using GL ES?

Failed to resolve OpenGL functions required to enable AsmBrowser

this is expected on AMD Radeon R9 M395, there will be no Asm Browser entry in the Edit menu, just info, not critical, Asm Browser is a nVidia feature

many of the shaders may require tweaking when running on Mac because... https://www.reddit.com/r/opengl/comments/b44tyu/apple_is_deprecating_opengl/ (posted 1 year ago)

"For now, Apple is deprecating OpenGL — leaving it in each OS but not supporting it — while keeping its removal date ambiguous. Once it’s removed, which could be two years from now, apps using OpenGL will stop working on devices running the latest operating systems, but will continue to work on devices with older OSes. "

Due to this I only test the Mac package to the extent that it compiles and seems to produce an installable app. I do not support Mac, but you are welcome to fix things in the Examples repo or the main sources repo. In the case of the Examples repo I invite you to create your own repo for converted/tweaked Mac frags and I will add it as a submodule to the Examples super-repo. In the case of the main sources repo, fork, branch, patch, commit, push, request review or submit pull request.

3Dickulus commented 4 years ago

please see issue #40 for info re: retina display

iRyanBell commented 4 years ago

Got it. I was hoping this was an issue with the build and not the compatibility against the operating system itself, which seems to be the case.

These are the errors I receive with anything from the included Examples menu.

3Dickulus commented 4 years ago

most of the frags are written for legacy GL, the Mac GLSL compiler (?) insists on #version statements so for most frags #version 110 or #version 120 should be ok as the first line of code

also these files may be helpful...

Examples/3DickUlus/3D-gl4.frag
Examples/3DickUlus/BufferShader-gl4.frag
Examples/3DickUlus/DE-Raytracer-gl4.frag

(hint: move these into the Examples/Include/ folder to allow all frags to access them) they use modern...

layout(location = 0) in vec4 vertex_position;
uniform mat4 projectionMatrix;

this represents the beginning of moving away from legacy GLSL, vertex_position and projectionMatrix are "known" to Fragmentarium and used for rendering.

there is another thing Macs might not like, internally FragM uses a couple of fragment shaders to render the spline paths for keyframe camera movement, I wrote one for modern #version 410 core and one for Legacy, FragM detects which one to use, but have not been able to test on Macs. if this does cause a problem and you can manage to compile from source you could change those values to match the GL version your machine needs.

edit: hmm.... the lower #version statements may not work if Mac insists on GLSL 4.1 only

iRyanBell commented 4 years ago

Running a baseline distance estimation with #version 110 or 120 using:

#version 110
#include "MathUtils.frag"
#include "Examples/3DickUlus/DE-Raytracer-gl4.frag" 

float DE(vec3 pos) {
    return abs(length(abs(pos)+vec3(-1.0))-1.2);
}

Throws:

Could not create vertex shader: 
ERROR: 0:1: '' :  version '110' is not supported
ERROR: 0:2: '' :  #version required and missing.
ERROR: 3:19: '0' : syntax error: integers in layouts require GLSL 140 or later

Failed to compile script (13 ms).

#version 150 seems to be accepted, but throws other errors (varying keyword not supported, invalid use of layout 'location', undeclared identifiers.)

It's surprising how poor the 3D support is from Apple -- everything from Nvidia drivers/cards being unsupported (preventing CUDA or GPU-accelerated machine learning), to VR being unsupported, to modern GLSL being unsupported.

3Dickulus commented 4 years ago

I should have been more specific, DE-Raytracer-gl4.frag requires #version 410 also try #version 410 compatibility (the compatibility option is only valid for > 320) Use #version 110 with the non-gl4 DE-Raytracer.frag

also you should not use path #include "Examples/3DickUlus/DE-Raytracer-gl4.frag", only use filename #include "DE-Raytracer-gl4.frag" in the Edit->Preferences menu you can change or add search paths, just add a semicolon separator and the full path to Examples/3DickUlus, then Fragmentarium will search that folder for includes too, an effort to keep full paths out of fragments. You can also move the 3DickUlus/*-gl4 frags into the default search folder Examples/Includes.

...and I agree, Mac support for established standards is lacking.

3Dickulus commented 4 years ago

oops, I keep hitting that button...

iRyanBell commented 4 years ago

With #version 110, I receive the error: "version '110' is not supported". With #version 410 compatibility, I receive the error: "syntax error: #version".

Adding the search path for the gl4 version, then using #verison 410, two errors are thrown:

ERROR: 3:174: Invalid call of undeclared identifier 'texture2D'
ERROR: 3:180: Use of undeclared identifier 'prev'
3Dickulus commented 4 years ago

the culprits...

3D-gl4.frag:   vec4 prev = texture2D(backbuffer,(viewCoord+vec2(1.0))*0.5);
BufferShader-gl4.frag: vec4 tex = texture2D(frontbuffer, pos);

these should be fixable by using the GL4 equivalent to texture2D()

warning C7555: 'varying' is deprecated, use 'in/out' instead these are easily fixed, if you intend to use Fragmentarium you should be able to fix this yourself. (sorry for the lame support I'm a bit overwhelmed and don't have time to update all the frags, FraM is a programming environment so you need to know how to write code for GLSL or wait for someone to fix the sources for you)

and I have to mention again, I don't support Mac/Apple, but if you figure it out I would be more than happy to add the modifications to FragM.

3Dickulus commented 4 years ago

Found some time and no distractions ;) I have adapted 3DKn-1.0.5.frag and BufferShader-1.0.1.frag, these are used by the raytracer frag DE-Kn2cr11.frag

Wrapping the offending GLSL in version tests, this could be developed further to account for other versions of GLSL too, currently setup as...

#if __VERSION__ <= 400
    // legacy GLSL here
#else
    // modern GLSL here
#endif

They compile and run using #version 110 and #version 410 core I will be pushing these changes to https://github.com/3Dickulus/Fragmentarium_Examples_Folder and will eventually migrate the others, it's not as complicated as I thought, fortunately the raytracers and user frags don't require alteration just 2D, 3D and BufferShader frags.

These should go in Examples/Include/ folder. (rename as .frag not .txt) 3DKn-1.0.5.frag.txt BufferShader-1.0.1.frag.txt

edit:not tested on Mac only linux+nVidia

iRyanBell commented 4 years ago

not tested on Mac only linux+nVidia

Very nice! Everything compiles now. There might be a small tweak needed to get the font rendered correctly.

After compiling the hello world DE shader, I'm not sure if this empty stage is user error on my part, or a mac issue.

Screen Shot 2020-06-20 at 8 45 55 PM
3Dickulus commented 4 years ago

you should see this... Screenshot_20200620_215650

try adding...

<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSHighResolutionCapable</key>
<string>True</string>

...to the file Fragmentarium-2.5.0.app/Contents/Info.plist re:issue #40

iRyanBell commented 4 years ago

I'm not getting any preview in the editor, but a render produces the image. out

3Dickulus commented 4 years ago

if the above suggestion doesn't get the display going then it's probably in the GL buffer init/render routines in FragM source, may need to look at triggering gl_SwapBuffers() manually?

in DisplayWidget.cpp at line 1695 and line 1835 the code waits for GPU to return control calling glFinish(); immediately after those lines add this line... context()->swapBuffers(context()->surface()); ...and recompile the app.

3Dickulus commented 4 years ago

oh... ok that's promising, at least the engine is running... not sure what to do about the display.

the only suggestions I can come up with are

  1. Fragmentarium-2.5.0.app/Contents/Info.plist re:issue #40
  2. call swapbuffers() manually.

in issue #40 user shengsword says he had it running but Mohave not Catalina. that's all I've got to go on for right now.

iRyanBell commented 4 years ago

Hmm, it must be someplace else.

For reference, this is the build command I used for macOS, after pulling in the frameworks (qt + glm) with brew:

cmake -DUSE_OPEN_EXR=ON -DCMAKE_PREFIX_PATH=/usr/local/Cellar/qt/5.15.0/lib/cmake -framework /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/OpenGL.framework -DCMAKE_INSTALL_PREFIX=~/ .. -DCMAKE_CXX_FLAGS=-I\ /usr/local/Cellar/glm/0.9.9.8/include

macOS Build
3Dickulus commented 4 years ago

On the main menu Edit->Preferences->Editor stylesheet->font: 9pt Courier; style sheet instructions are separated by semicolon, change the font to whatever you like ;)

to compile all I've ever done is...

mkdir build
cd build
cmake -DUSE_OPEN_EXR=ON -DUSE_OPENGL_4=1 -DCMAKE_INSTALL_PREFIX=../../ ..
make
make install

this creates the install folder in the topmost level of the FragM project.

edit: after installing the required packages