pemgl

Forum Replies Created

Viewing 17 posts - 1 through 17 (of 17 total)
  • Author
    Posts

  • pemgl
    Participant

    Oops actually I was already doing that and it still doesn’t work:

    CheckReturn(SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES), "A"); // this line
    CheckReturn(SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2), "B");
    CheckReturn(SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0), "C");
    CheckReturn(SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1), "D");
    CheckReturn(SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16), "E");
    CheckReturn(SDL_CreateWindowAndRenderer(g_Width, g_Height, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE, &g_Window, &g_Renderer), "SDL_CreateWindowAndRenderer");
    

    pemgl
    Participant

    Oh here’s something interesting from SDL_cocoaopengl.m:

        if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
            SDL_SetError ("OpenGL ES is not supported on this platform");
            return NULL;
        }
        if ((_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) && !lion_or_later) {
            SDL_SetError ("OpenGL Core Profile is not supported on this platform version");
            return NULL;
        }
    

    I may look more later… for now I’d better log off (it’s 2:10am in my time zone)


    pemgl
    Participant

    If you download the SDL2 source code and grep for GLKView, you get no hits. If you grep for NSView, you get the following:

    ./src/video/cocoa/SDL_cocoakeyboard.m:60:@interface SDLTranslatorResponder : NSView <NSTextInput>
    ./src/video/cocoa/SDL_cocoakeyboard.m:556: NSView *parentView = [[NSApp keyWindow] contentView];
    ./src/video/cocoa/SDL_cocoaopengl.m:40: * AppKite/NSView.h in 10.8 SDK. */
    ./src/video/cocoa/SDL_cocoaopengl.m:41:@interface NSView (Backing)
    ./src/video/cocoa/SDL_cocoaopengl.m:313: NSView *contentView = [windata->nswindow contentView];
    ./src/video/cocoa/SDL_cocoashape.m:60: NSView* view;
    ./src/video/cocoa/SDL_cocoawindow.m:39:@interface NSView (NSOpenGLSurfaceResolution)
    ./src/video/cocoa/SDL_cocoawindow.m:68: NSView *view = [window contentView];
    ./src/video/cocoa/SDL_cocoawindow.m:152: NSView *view = [window contentView];
    ./src/video/cocoa/SDL_cocoawindow.m:574:@interface SDLView : NSView
    ./src/video/cocoa/SDL_cocoawindow.m:748: NSView *contentView = [[SDLView alloc] initWithFrame:rect];

    Here is the relevant open source SDL2 code online:

    https://www.libsdl.org/tmp/SDL/src/video/cocoa/SDL_cocoaopengl.m
    https://www.libsdl.org/tmp/SDL/src/video/cocoa/SDL_cocoawindow.m

    I wonder if there’s an easy way to tell SDL2 (eg with a #define?) to use the iOS version instead of the OSX version…


    pemgl
    Participant

    SDL2 (Simple DirectMedia Layer) and similar cross-platform libraries (eg GLFW, GLUT, SFML, Marmalade, a game engine like Unity, etc) are commonly used to abstract things like creating a window and an OpenGL context. This enables developers to write more cross-platform code (and less platform-specific code such as NSView).

    MetalGL also lets developers write more cross-platform code (and less platform-specific code such as Metal). If a developer wants to write platform-specific code they can use (NSView + Metal + XCode). If they want to write cross-platform code they can instead use (SDL2 + MetalGL + CMake) for example. I suspect a lot of potential MetalGL users will also use cross-platform libraries (such as SDL2) for creating a window and an OpenGL context.

    Since MetalGL is using MGLGLKView, then this must mean it is not expected to work with SDL2 because obviously SDL2 does not implement support for MGLGLKView. To me this seems broken… If MetalGL is able to intercept GLES calls such that developers can reuse GLES code written for other platforms… Then why does MetalGL not do the same sort of thing for NSView? I am surprised that MetalGL exists to enable cross-platform GLES code, but it requires one to use MGLGLKView. Or am I confused?

    As for SDL2’s source code… It’s an open source project, see libsdl.org > download source code.

    I took a quick look (ie grep) and “src/render/SDL_render.c” appears to have the implementation for SDL_CreateWindowAndRenderer():

    int
    SDL_CreateWindowAndRenderer(int width, int height, Uint32 window_flags,
                                SDL_Window **window, SDL_Renderer **renderer)
    {
        *window = SDL_CreateWindow(NULL, SDL_WINDOWPOS_UNDEFINED,
                                         SDL_WINDOWPOS_UNDEFINED,
                                         width, height, window_flags);
        if (!*window) {
            *renderer = NULL;
            return -1;
        }
    
        *renderer = SDL_CreateRenderer(*window, -1, 0);
        if (!*renderer) {
            return -1;
        }
    
        return 0;
    }
    

    I also saw NSView used in “SDL2-2.0.3\src\video\cocoa\SDL_cocoawindow.m”

    Beyond that, grep only got me so far, so to better understand how SDL2 works under-the-hood, I may need to build a debug version of SDL2 and step into it…


    pemgl
    Participant

    I installed OSX 10.11 and verified DrawLoadDemo sample works. Here’s where I am now (on my CMake + SDL2 project):

    void CheckReturn(int retVal, const char* sMsg)
    {
    	if (retVal != 0)
    		SDL_Log("ERROR: %s; %s", sMsg, SDL_GetError());
    }
    int main(int argc, char *argv[])
    {
    	assert(SDL_Init(SDL_INIT_VIDEO) == 0);
    	CheckReturn(SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES), "A");
    	CheckReturn(SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2), "B");
    	CheckReturn(SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0), "C");
    	CheckReturn(SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1), "D");
    	CheckReturn(SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16), "E");
    	CheckReturn(SDL_CreateWindowAndRenderer(g_Width, g_Height, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE, &g_Window, &g_Renderer), "SDL_CreateWindowAndRenderer");
    

    The error I get is:

    SDL_CreateWindowAndRenderer; Couldn’t find matching render driver

    The above code works on all other platforms I’ve tried using GLES2 – Windows desktop (ANGLE), iOS, Android, Linux, Emscripten. My application also works on OSX with desktop OpenGL (not MetalGL) if I make some minor changes.

    in reply to: DrawLoadDemo – dyld: Symbol not found: ___NSDictionary0__ #731

    pemgl
    Participant

    After installing OS 10.11 (which was just publicly released today 9/30), I am now able to build and run the DrawLoadDemo sample application. Good stuff! I look forward to seeing more progress from MetalGL OSX support for GLES2 & GLES3. I’ll try my (CMake, SDL2, GLES2) project next (I have a separate thread on this). thank you & best regards

    in reply to: DrawLoadDemo – dyld: Symbol not found: ___NSDictionary0__ #730

    pemgl
    Participant

    @bill I think what happened is that I was building for 10.11 but I was not running 10.11. I did a software update for XCode which includes 10.11 (MacOSX10.11.sdk), but the public (non-beta) 10.11 release of OSX is not released until tomorrow (9/30). That must be why I got an error message saying “built for Mac OS X 10.11” even though I haven’t installed 10.11 yet. I will install 10.11 tomorrow and see if it works


    pemgl
    Participant

    Probably the next thing I will try is to install OS X 10.11 (El Capitan). Apparently it is “coming September 30” which is in two days, so I can either install the preview, or just wait two days… best regards


    pemgl
    Participant

    Per your suggestion I added the following line to my CMakeLists.txt file:

    # for EGL/egl.h, won’t be needed in future versions of MetalGL
    INCLUDE_DIRECTORIES(“${CMAKE_CURRENT_SOURCE_DIR}/../../MetalGL-0.10.0/SampleProjects/Common/API”)

    I also installed the XCode 7.1 update, which mentions OS X 11.11 El Captain. Although “About This Mac” still says OS X Yosemite 10.10.5.

    Good news – I’m now able to compile and run without link errors.

    I now get the following message from MetalGL:

    [mgl-info] OpenGL functionality using Metal cannot be provided because Metal is not supported on this device. OpenGL functionality provided by native OpenGL framework.

    I’ll see if I can get any farther later tonight or tomorrow… I just wanted to share a quick update on my progress

    thank you and best regards


    pemgl
    Participant

    I’m running CMake inside Qt Creator. Qt Creator lists the cmake Generator as “Unix Generator (Desktop Qt 5.5.0 clang 64bit). My simple cross-platform demo works fine using desktop OpenGL on OSX (and GLES2 for other platforms).


    pemgl
    Participant

    @bill I am using (C++, SDL2, CMake) for all platforms including OSX. I’m using OpenGL ES 2 on all platforms, except on OSX I am using desktop OpenGL (that is, until I get MetalGL working). I’m using pure C++ (not Objective C) on all platforms. I can send more if needed, but here are some snippets of relevant code:

    // includes
    #include “SDL_platform.h”
    #include “SDL_test_common.h”
    #include <OpenGL/gl3.h>
    #define __gl_h_ // block SDL from including OpenGL/gl.h
    #include <SDL.h>

    // globals
    SDL_Window *g_Window = nullptr;
    SDL_Renderer *g_Renderer = nullptr;
    SDL_GLContext g_Context = NULL;

    // setup
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 32);
    SDL_CreateWindowAndRenderer(g_Width, g_Height, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE, &g_Window, &g_Renderer);
    g_Context = SDL_GL_CreateContext(g_Window);
    glViewport(0, 0, g_Width, g_Height);
    glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);

    // render loop
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
    g_Entity->render(g_CameraB.matrix());
    SDL_GL_SwapWindow(g_Window);

    in reply to: DrawLoadDemo – dyld: Symbol not found: ___NSDictionary0__ #722

    pemgl
    Participant

    OS X Yosemite 10.10.5, Macbook Air (11-inch, Mid 2013).

    I’m just trying to build an unmodified version of “MetalGL-0.10.0/SampleProjects/SampleProjectx.xcworkspace” for OSX

    The error seems strange because NSDictionary is found here:

    $ nm -gU /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation | grep NSDict
    00000000003e0488 S _OBJC_CLASS_$_NSDictionary
    00000000003e0550 S _OBJC_METACLASS_$_NSDictionary

    Yet the error message says that’s where it is looking for NSDictionary:

    dyld: Symbol not found: ___NSDictionary0__
    Referenced from: /Users/pem/Library/Developer/Xcode/DerivedData/SampleProjects-fusvntzfbrkzyecavaryepgdovjd/Build/Products/Release/DrawLoadDemo.app/Contents/MacOS/DrawLoadDemo (which was built for Mac OS X 10.11)
    Expected in: /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
    in /Users/pem/Library/Developer/Xcode/DerivedData/SampleProjects-fusvntzfbrkzyecavaryepgdovjd/Build/Products/Release/DrawLoadDemo.app/Contents/MacOS/DrawLoadDemo


    pemgl
    Participant

    Oops, I now see that step 6 of the “install” section says to add (gl.m, glext.m, egl.m, and EAGL.m from the MetalGL/OSX folder). So I added them, but then I got a different error:

    [ 16%] Building C object CMakeFiles/pemDemos.dir/Users/pem/Pem_Code/grfxdemossdl2015/MetalGL-0.10.0/MetalGL/OSX/gl.m.o
    error: invalid argument ‘-std=c++11’ not allowed with ‘C/ObjC’
    make[2]: *** [CMakeFiles/pemDemos.dir/Users/foo/Pem_Code/fooproj/MetalGL-0.10.0/MetalGL/OSX/gl.m.o] Error 1

    So I removed -std=c++11 from my CMakeLists.txt:

    #add_definitions(“-std=c++11 -stdlib=libc++”)
    add_definitions(“-stdlib=libc++”)

    I notice these four files are .m instead of .h or .cpp, but my project is cross-platform so I am not building with -ObjC because building with -ObjC gives errors such as:

    pemDemos/pemDemos/main.cpp:33:10: fatal error: ‘iostream’ file not found
    #include <iostream>

    If I comment out that line, I still get compile errors from GLM ( http://glm.g-truc.net/ ) such as:

    glm/glm/detail/_fixes.hpp:33:10: fatal error: ‘cmath’ file not found
    #include <cmath>

    I don’t think there is any reason why MetalGL needs to require my project to use -ObjC? My (C++, SDL2, CMake, desktop OpenGL on OSX, GLES2 on iOS & Android & Windows ANGLE & Emscripten) project builds and runs as expected without MetalGL and without -ObjC. So requiring -ObjC makes MetalGL incompatible with my project, with GLM, and probably a lot of other cross-platform projects that use <iostream> or <cmath> etc.

    So I’m not using -ObjC, and I now get this error:

    MetalGL-0.10.0/MetalGL/OSX/egl.m:42:10: fatal error: ‘EGL/egl.h’ file not found
    #include <EGL/egl.h>

    RedirectHeaders/include only has OpenGLES/EAGL.h, I don’t see EGL/egl.h. According to this link ( http://www.g-truc.net/post-0457.html ), OSX uses EAGL instead of EGL, so I’m confused why egl.m includes EGL/egl.h.

    thank you


    pemgl
    Participant

    I think the problem is that I’m not linking to an OpenGL Extensions library because OpenGL.framework only has core OpenGL? I’m getting link errors like the following:

    Undefined symbols for architecture x86_64:
    … etc
    “_glActiveShaderProgramEXT”, referenced from:
    _mglActiveShaderProgramEXT in MetalGL(MetalGL-x86_64-master.o)
    “_glBeginQueryEXT”, referenced from:
    _mglBeginQueryEXT in MetalGL(MetalGL-x86_64-master.o)
    “_glBindProgramPipelineEXT”, referenced from:
    _mglBindProgramPipelineEXT in MetalGL(MetalGL-x86_64-master.o)
    “_glBindVertexArrayOES”, referenced from:
    _mglBindVertexArrayOES in MetalGL(MetalGL-x86_64-master.o)
    … etc


    pemgl
    Participant

    Another data point is that I tried adding -ObjC:

    add_definitions(“-std=c++11 -ObjC”)

    However this causes an error:

    error: invalid argument ‘-std=c++11’ not allowed with ‘C/ObjC’

    Doing just -ObjC without -std=c++11 also causes an error:

    main.cpp:33:10: fatal error: ‘iostream’ file not found
    #include <iostream>


    pemgl
    Participant

    I made some progress by copying additional frameworks from the MetalGL XCode sample project DrawLoadDemo:

    INCLUDE_DIRECTORIES(“${CMAKE_CURRENT_SOURCE_DIR}/../../MetalGL-0.10.0/MetalGL/RedirectHeaders/include”)
    LINK_LIBRARIES(“${CMAKE_CURRENT_SOURCE_DIR}/../../MetalGL-0.10.0/MetalGL/OSX/MetalGL.framework”)
    #LINK_LIBRARIES(/Users/foo/Pem_Code/fooproj/MetalGL-0.10.0/MetalGL/OSX/MetalGL.framework)
    LINK_LIBRARIES(“${CMAKE_CURRENT_SOURCE_DIR}/../../MetalGL-0.10.0/MetalGLShaderConverter/OSX/MetalGLShaderConverter.framework”)
    LINK_LIBRARIES(/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/Metal.framework)
    LINK_LIBRARIES(/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/Foundation.framework)
    LINK_LIBRARIES(/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/CoreFoundation.framework)
    LINK_LIBRARIES(/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/CoreGraphics.framework)
    LINK_LIBRARIES(/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/AppKit.framework)
    LINK_LIBRARIES(/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/QuartzCore.framework)

    I’m getting less link errors, but I still have unresolved symbols such as:

    Undefined symbols for architecture x86_64:
    “_OBJC_CLASS_$_CAEAGLLayer”, referenced from:
    objc-class-ref in MetalGL(MetalGL-x86_64-master.o)
    “_OBJC_CLASS_$_EAGLContext”, referenced from:
    objc-class-ref in MetalGL(MetalGL-x86_64-master.o)
    “_glActiveShaderProgramEXT”, referenced from:
    _mglActiveShaderProgramEXT in MetalGL(MetalGL-x86_64-master.o)
    “_glBeginQueryEXT”, referenced from:
    _mglBeginQueryEXT in MetalGL(MetalGL-x86_64-master.o)
    … etc

    in reply to: DrawLoadDemo – dyld: Symbol not found: ___NSDictionary0__ #711

    pemgl
    Participant

    I verified DrawLoadDemo has a shared library link to Foundation, and I verified Foundation has the symbol NSDictionary:

    $ otool -L DrawLoadDemo
    DrawLoadDemo:
    /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1252.0.0)
    /System/Library/Frameworks/CoreGraphics.framework/Versions/A/CoreGraphics (compatibility version 64.0.0, current version 600.0.0)
    /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.1.0)
    /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1404.0.0)
    /System/Library/Frameworks/Metal.framework/Versions/A/Metal (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore (compatibility version 1.2.0, current version 1.11.0)
    /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1225.1.1)
    /System/Library/Frameworks/Foundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1253.0.0)
    /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo (compatibility version 1.2.0, current version 1.5.0)

    $ nm -gu /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation | grep NSDictionary
    _OBJC_CLASS_$_NSDictionary
    _OBJC_METACLASS_$_NSDictionary

    $ nm -gu /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation | grep NSD
    => nothing

    Based on this, I’m confused… DrawLoadDemo links to both CoreFoundation and Foundation. The error message says NSDictionary expected in CoreFoundation, but NSDictionary only exists in Foundation (not CoreFoundation).

Viewing 17 posts - 1 through 17 (of 17 total)