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

Handling Complexity with Other Graphic APIs #1701

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 28 additions & 15 deletions project/Build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,6 @@
<section if="windows">

<lib name="gdi32.lib" />
<lib name="opengl32.lib" />
<lib name="user32.lib" />
<lib name="kernel32.lib" />
<lib name="advapi32.lib" />
Expand All @@ -414,6 +413,7 @@
<lib name="usp10.lib" if="LIME_HARFBUZZ" />
<lib name="rpcrt4.lib" if="LIME_HARFBUZZ" />
<lib name="dwrite.lib" if="LIME_HARFBUZZ" />
<lib name="opengl32.lib" if="LIME_OPENGL" />

<lib name="comsuppw.lib" unless="winrt" />

Expand Down Expand Up @@ -449,7 +449,6 @@
<vflag name="-framework" value="CoreAudio" />
<vflag name="-framework" value="CoreVideo" />
<vflag name="-framework" value="Cocoa" />
<vflag name="-framework" value="OpenGL" />
<vflag name="-framework" value="AudioToolbox" />
<vflag name="-framework" value="AudioUnit" />
<vflag name="-framework" value="ForceFeedback" />
Expand All @@ -458,6 +457,8 @@
<vflag name="-framework" value="OpenAL" />
<vflag name="-framework" value="SystemConfiguration" />

<vflag name="-framework" value="OpenGL" if="LIME_OPENGL" />

<lib name="/opt/local/lib/libgc.a" if="LIME_NEKO" />
<lib name="-lm" if="LIME_NEKO" />

Expand All @@ -474,22 +475,28 @@
<lib name="-llog" />
<lib name="-landroid" />
<lib name="-lm" />
<lib name="-lEGL" />
<lib name="-lGLESv2" />
<lib name="-lGLESv1_CM" />
<lib name="-lOpenSLES" />

<section if="LIME_OPENGL">
<lib name="-lEGL" />
<lib name="-lGLESv2" />
<lib name="-lGLESv1_CM" />
</section>

</section>

<section if="rpi">

<lib name="-lbcm_host" />
<lib name="-ldl" />
<lib name="-lm" />
<lib name="-lbrcmGLESv2" />
<lib name="-lbrcmEGL" />
<lib name="-L/opt/vc/lib" />

<section if="LIME_OPENGL">
<lib name="-lbrcmGLESv2" />
<lib name="-lbrcmEGL" />
</section>

</section>

<section if="tvos">
Expand All @@ -498,16 +505,19 @@
<vflag name="-framework" value="Foundation" />
<vflag name="-framework" value="CoreAudio" />
<vflag name="-framework" value="CoreVideo" />
<vflag name="-framework" value="OpenGLES" />
<vflag name="-framework" value="AudioToolbox" />
<vflag name="-framework" value="AudioUnit" />
<vflag name="-framework" value="OpenAL" />
<vflag name="-framework" value="GameController" />
<!-- <vflag name="-framework" value="CoreBluetooth" /> -->

<lib name="-ldl" />
<lib name="-lEGL" />
<lib name="-lGLESv3" />
<vflag name="-framework" value="OpenGLES" if="LIME_OPENGL" />

<section if="LIME_OPENGL">
<lib name="-ldl" />
<lib name="-lEGL" />
<lib name="-lGLESv3" />
</section>

</section>

Expand All @@ -517,17 +527,20 @@
<vflag name="-framework" value="Foundation" />
<vflag name="-framework" value="CoreAudio" />
<vflag name="-framework" value="CoreVideo" />
<vflag name="-framework" value="OpenGLES" />
<vflag name="-framework" value="AudioToolbox" />
<vflag name="-framework" value="AudioUnit" />
<vflag name="-framework" value="OpenAL" />
<vflag name="-framework" value="CoreMotion" />
<vflag name="-framework" value="CoreText" />
<!-- <vflag name="-framework" value="CoreBluetooth" /> -->

<lib name="-ldl" />
<lib name="-lEGL" />
<lib name="-lGLESv3" />
<vflag name="-framework" value="OpenGLES" if="LIME_OPENGL" />

<section if="LIME_OPENGL">
<lib name="-ldl" />
<lib name="-lEGL" />
<lib name="-lGLESv3" />
</section>

</section>

Expand Down
25 changes: 25 additions & 0 deletions project/src/backend/Definitions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef DEFINITIONS_H
#define DEFINITIONS_H


#ifdef LIME_OPENGL


#define CreateContext SDL_GL_CreateContext
#define DeleteContext SDL_GL_DeleteContext
#define GetDrawableSize SDL_GL_GetDrawableSize
#define Context SDL_GLContext
#define WINDOW_GRAPHICS SDL_WINDOW_OPENGL
#define SetAttribute SDL_GL_SetAttribute
#define MakeCurrent SDL_GL_MakeCurrent
#define SwapWindow SDL_GL_SwapWindow
#define SetSwapInterval SDL_GL_SetSwapInterval


#endif


#define EMPTY(...) (0)


#endif
76 changes: 40 additions & 36 deletions project/src/backend/sdl/SDLWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ namespace lime {

if (flags & WINDOW_FLAG_HARDWARE) {

sdlWindowFlags |= SDL_WINDOW_OPENGL;
sdlWindowFlags |= WINDOW_GRAPHICS;

if (flags & WINDOW_FLAG_ALLOW_HIGHDPI) {

Expand All @@ -88,16 +88,16 @@ namespace lime {
}

#if defined (HX_WINDOWS) && defined (NATIVE_TOOLKIT_SDL_ANGLE)
SDL_GL_SetAttribute (SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
SDL_GL_SetAttribute (SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute (SDL_GL_CONTEXT_MINOR_VERSION, 0);
SetAttribute (SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
SetAttribute (SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SetAttribute (SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_SetHint (SDL_HINT_VIDEO_WIN_D3DCOMPILER, "d3dcompiler_47.dll");
#endif

#if defined (RASPBERRYPI)
SDL_GL_SetAttribute (SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
SDL_GL_SetAttribute (SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute (SDL_GL_CONTEXT_MINOR_VERSION, 0);
#if defined (RASPBERRYPI) && defined (LIME_OPENGL)
SetAttribute (SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
SetAttribute (SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SetAttribute (SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_SetHint (SDL_HINT_RENDER_DRIVER, "opengles2");
#endif

Expand All @@ -108,40 +108,40 @@ namespace lime {

if (flags & WINDOW_FLAG_DEPTH_BUFFER) {

SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 32 - (flags & WINDOW_FLAG_STENCIL_BUFFER) ? 8 : 0);
SetAttribute (SDL_GL_DEPTH_SIZE, 32 - (flags & WINDOW_FLAG_STENCIL_BUFFER) ? 8 : 0);

}

if (flags & WINDOW_FLAG_STENCIL_BUFFER) {

SDL_GL_SetAttribute (SDL_GL_STENCIL_SIZE, 8);
SetAttribute (SDL_GL_STENCIL_SIZE, 8);

}

if (flags & WINDOW_FLAG_HW_AA_HIRES) {

SDL_GL_SetAttribute (SDL_GL_MULTISAMPLEBUFFERS, true);
SDL_GL_SetAttribute (SDL_GL_MULTISAMPLESAMPLES, 4);
SetAttribute (SDL_GL_MULTISAMPLEBUFFERS, true);
SetAttribute (SDL_GL_MULTISAMPLESAMPLES, 4);

} else if (flags & WINDOW_FLAG_HW_AA) {

SDL_GL_SetAttribute (SDL_GL_MULTISAMPLEBUFFERS, true);
SDL_GL_SetAttribute (SDL_GL_MULTISAMPLESAMPLES, 2);
SetAttribute (SDL_GL_MULTISAMPLEBUFFERS, true);
SetAttribute (SDL_GL_MULTISAMPLESAMPLES, 2);

}

if (flags & WINDOW_FLAG_COLOR_DEPTH_32_BIT) {

SDL_GL_SetAttribute (SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute (SDL_GL_ALPHA_SIZE, 8);
SetAttribute (SDL_GL_RED_SIZE, 8);
SetAttribute (SDL_GL_GREEN_SIZE, 8);
SetAttribute (SDL_GL_BLUE_SIZE, 8);
SetAttribute (SDL_GL_ALPHA_SIZE, 8);

} else {

SDL_GL_SetAttribute (SDL_GL_RED_SIZE, 5);
SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 6);
SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, 5);
SetAttribute (SDL_GL_RED_SIZE, 5);
SetAttribute (SDL_GL_GREEN_SIZE, 6);
SetAttribute (SDL_GL_BLUE_SIZE, 5);

}

Expand All @@ -150,10 +150,10 @@ namespace lime {
sdlWindow = SDL_CreateWindow (title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, sdlWindowFlags);

#if defined (IPHONE) || defined (APPLETV)
if (sdlWindow && !SDL_GL_CreateContext (sdlWindow)) {
if (sdlWindow && !CreateContext (sdlWindow)) {

SDL_DestroyWindow (sdlWindow);
SDL_GL_SetAttribute (SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SetAttribute (SDL_GL_CONTEXT_MAJOR_VERSION, 2);

sdlWindow = SDL_CreateWindow (title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, sdlWindowFlags);

Expand Down Expand Up @@ -211,27 +211,31 @@ namespace lime {

// if (sdlRenderer) {

// context = SDL_GL_GetCurrentContext ();
// context = GetCurrentContext ();

// }

context = SDL_GL_CreateContext (sdlWindow);
context = CreateContext (sdlWindow);

if (context && SDL_GL_MakeCurrent (sdlWindow, context) == 0) {
if (context && MakeCurrent (sdlWindow, context) == 0) {

if (flags & WINDOW_FLAG_VSYNC) {

SDL_GL_SetSwapInterval (1);
SetSwapInterval (1);

} else {

SDL_GL_SetSwapInterval (0);
SetSwapInterval (0);

}

#if defined (LIME_OPENGL)

OpenGLBindings::Init ();

#ifndef LIME_GLES
#endif

#if !defined (LIME_GLES) && defined (LIME_OPENGL)

int version = 0;
glGetIntegerv (GL_MAJOR_VERSION, &version);
Expand All @@ -246,12 +250,12 @@ namespace lime {

if (version < 2 && !strstr ((const char*)glGetString (GL_VERSION), "OpenGL ES")) {

SDL_GL_DeleteContext (context);
DeleteContext (context);
context = 0;

}

#elif defined(IPHONE) || defined(APPLETV)
#elif (defined (IPHONE) || defined (APPLETV)) && defined (LIME_OPENGL)

// SDL_SysWMinfo windowInfo;
// SDL_GetWindowWMInfo (sdlWindow, &windowInfo);
Expand All @@ -264,7 +268,7 @@ namespace lime {

} else {

SDL_GL_DeleteContext (context);
DeleteContext (context);
context = NULL;

}
Expand Down Expand Up @@ -310,7 +314,7 @@ namespace lime {

} else if (context) {

SDL_GL_DeleteContext (context);
DeleteContext (context);

}

Expand Down Expand Up @@ -381,7 +385,7 @@ namespace lime {

if (context && !sdlRenderer) {

SDL_GL_SwapWindow (sdlWindow);
SwapWindow (sdlWindow);

} else if (sdlRenderer) {

Expand Down Expand Up @@ -481,7 +485,7 @@ namespace lime {

if (sdlWindow && context) {

SDL_GL_MakeCurrent (sdlWindow, context);
MakeCurrent (sdlWindow, context);

}

Expand Down Expand Up @@ -641,7 +645,7 @@ namespace lime {
int outputWidth;
int outputHeight;

SDL_GL_GetDrawableSize (sdlWindow, &outputWidth, &outputHeight);
GetDrawableSize (sdlWindow, &outputWidth, &outputHeight);

int width;
int height;
Expand Down
5 changes: 4 additions & 1 deletion project/src/backend/sdl/SDLWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#define LIME_SDL_WINDOW_H


#include "../Definitions.h"


#include <SDL.h>
#include <graphics/ImageBuffer.h>
#include <ui/Cursor.h>
Expand Down Expand Up @@ -65,7 +68,7 @@ namespace lime {

private:

SDL_GLContext context;
Context context;
int contextHeight;
int contextWidth;

Expand Down