renderer: drop support for SDL

This commit is contained in:
Ray Strode 2016-01-12 16:35:51 -05:00 committed by Rui Matos
parent 7e8e1dfc8f
commit ed9f3fd50a
19 changed files with 36 additions and 2533 deletions

View File

@ -1,173 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{0B5D144D-1872-42CD-8437-FFDCDD08C03E}</ProjectGuid>
<RootNamespace>coglsdl2hello</RootNamespace>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v100</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v100</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v100</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v100</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="cogl-build-defines.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="cogl-build-defines.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="cogl-build-defines.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="cogl-build-defines.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.40219.1</_ProjectFileVersion>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</LinkIncremental>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;COGL_ENABLE_EXPERIMENTAL_2_0_API;$(BaseBuildDefines);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
</ClCompile>
<Link>
<AdditionalDependencies>SDL2.lib;SDL2main.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;COGL_ENABLE_EXPERIMENTAL_2_0_API;$(BaseBuildDefines);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<CompileAs>CompileAsC</CompileAs>
</ClCompile>
<Link>
<AdditionalDependencies>SDL2.lib;SDL2main.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX64</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>COGL_ENABLE_EXPERIMENTAL_2_0_API;$(BaseBuildDefines);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<AdditionalDependencies>SDL2.lib;SDL2main.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PreprocessorDefinitions>COGL_ENABLE_EXPERIMENTAL_2_0_API;$(BaseBuildDefines);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<CompileAs>CompileAsC</CompileAs>
</ClCompile>
<Link>
<AdditionalDependencies>SDL2.lib;SDL2main.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX64</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\..\examples\cogl-sdl2-hello.c" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="cogl.vcxproj">
<Project>{f3a80987-5411-43db-a23b-06f2076e1206}</Project>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Sources">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\examples\cogl-sdl2-hello.c">
<Filter>Sources</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -1,161 +0,0 @@
<?xml version="1.0" encoding="big5"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="cogl-sdl2-hello"
ProjectGUID="{0B5D144D-1872-42CD-8437-FFDCDD08C03E}"
RootNamespace="coglsdl2hello"
Keyword="Win32Proj"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
<Platform
Name="x64"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
InheritedPropertySheets=".\cogl-build-defines.vsprops"
ConfigurationType="1"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="_DEBUG;COGL_ENABLE_EXPERIMENTAL_2_0_API;$(BaseBuildDefines)"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="4"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="SDL2.lib SDL2main.lib"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="1"
TargetMachine="1"
/>
</Configuration>
<Configuration
Name="Debug|x64"
ConfigurationType="1"
InheritedPropertySheets=".\cogl-build-defines.vsprops"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="_DEBUG;COGL_ENABLE_EXPERIMENTAL_2_0_API;$(BaseBuildDefines)"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
CompileAs="1"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="SDL2.lib SDL2main.lib"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="1"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="17"
/>
</Configuration>
<Configuration
Name="Release|Win32"
InheritedPropertySheets=".\cogl-build-defines.vsprops"
ConfigurationType="1"
CharacterSet="2"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
PreprocessorDefinitions="COGL_ENABLE_EXPERIMENTAL_2_0_API;$(BaseBuildDefines)"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="SDL2.lib SDL2main.lib"
LinkIncremental="1"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
</Configuration>
<Configuration
Name="Release|x64"
ConfigurationType="1"
InheritedPropertySheets=".\cogl-build-defines.vsprops"
CharacterSet="2"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="COGL_ENABLE_EXPERIMENTAL_2_0_API;$(BaseBuildDefines)"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
CompileAs="1"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="SDL2.lib SDL2main.lib"
LinkIncremental="1"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="17"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Sources"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File RelativePath="..\..\..\examples\cogl-sdl2-hello.c" />
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -503,20 +503,6 @@ cogl_sources_c += \
winsys/cogl-winsys-egl-feature-functions.h \
winsys/cogl-winsys-egl-private.h
endif
if SUPPORT_SDL
cogl_experimental_h += $(srcdir)/cogl-sdl.h
cogl_sources_c += \
winsys/cogl-winsys-sdl-private.h \
winsys/cogl-winsys-sdl.c \
cogl-sdl.c
endif
if SUPPORT_SDL2
cogl_experimental_h += $(srcdir)/cogl-sdl.h
cogl_sources_c += \
winsys/cogl-winsys-sdl-private.h \
winsys/cogl-winsys-sdl2.c \
cogl-sdl.c
endif
EXTRA_DIST += stb_image.c
@ -643,8 +629,6 @@ cogl.vsenums_c:
EXTRA_DIST += \
cogl-defines.h.win32.in \
cogl-defines.h.win32 \
cogl-defines.h.win32_SDL.in \
cogl-defines.h.win32_SDL \
cogl-gl-header.h.win32 \
cogl.symbols \
cogl.rc.in \

View File

@ -1,78 +0,0 @@
/*
* Cogl
*
* A Low Level GPU Graphics and Utilities API
*
* Copyright (C) 2007,2008,2009,2010 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*
*/
#if !defined(__COGL_H_INSIDE__) && !defined(COGL_COMPILATION)
#error "Only <cogl/cogl.h> can be included directly."
#endif
#ifndef __COGL_DEFINES_H__
#define __COGL_DEFINES_H__
#include <glib.h>
G_BEGIN_DECLS
#define COGL_HAS_GLIB_SUPPORT 1
#define COGL_HAS_GTYPE_SUPPORT 1
#define COGL_HAS_WGL_SUPPORT 1
#define COGL_HAS_WIN32_SUPPORT 1
#define COGL_HAS_SDL_SUPPORT 1
#define COGL_HAS_COGL_PATH_SUPPORT 1
#define COGL_HAS_GL 1
#define CLUTTER_COGL_HAS_GL 1
#ifdef COGL_HAS_EGL_SUPPORT
#ifdef COGL_HAS_GLES1
#include <GLES/gl.h>
#include <GLES/egl.h>
#else
#include <EGL/egl.h>
#endif
#endif
#ifndef GL_OES_EGL_image
#define GLeglImageOES void *
#endif
#define COGL_SYSDEF_POLLIN 1
#define COGL_SYSDEF_POLLPRI 2
#define COGL_SYSDEF_POLLOUT 4
#define COGL_SYSDEF_POLLERR 8
#define COGL_SYSDEF_POLLHUP 16
#define COGL_SYSDEF_POLLNVAL 32
#define COGL_VERSION_MAJOR_INTERNAL @COGL_MAJOR_VERSION@
#define COGL_VERSION_MINOR_INTERNAL @COGL_MINOR_VERSION@
#define COGL_VERSION_MICRO_INTERNAL @COGL_MICRO_VERSION@
#define COGL_VERSION_STRING_INTERNAL "@COGL_VERSION@"
G_END_DECLS
#endif

View File

@ -100,11 +100,6 @@ struct _CoglRenderer
int kms_fd;
#endif
#ifdef COGL_HAS_SDL_SUPPORT
CoglBool sdl_event_type_set;
uint32_t sdl_event_type;
#endif
/* List of callback functions that will be given every native event */
GSList *event_filters;
void *winsys;

View File

@ -72,9 +72,6 @@
#ifdef COGL_HAS_WGL_SUPPORT
#include "cogl-winsys-wgl-private.h"
#endif
#ifdef COGL_HAS_SDL_SUPPORT
#include "cogl-winsys-sdl-private.h"
#endif
#ifdef COGL_HAS_XLIB_SUPPORT
#include "cogl-xlib-renderer.h"
@ -163,21 +160,6 @@ static CoglDriverDescription _cogl_drivers[] =
&_cogl_texture_driver_gles,
COGL_GLES1_LIBNAME,
},
#endif
#ifdef USING_EMSCRIPTEN
{
COGL_DRIVER_WEBGL,
"webgl",
0,
{ COGL_PRIVATE_FEATURE_ANY_GL,
COGL_PRIVATE_FEATURE_GL_EMBEDDED,
COGL_PRIVATE_FEATURE_GL_PROGRAMMABLE,
COGL_PRIVATE_FEATURE_GL_WEB,
-1 },
&_cogl_driver_gles,
&_cogl_texture_driver_gles,
NULL,
},
#endif
{
COGL_DRIVER_NOP,
@ -212,9 +194,6 @@ static CoglWinsysVtableGetter _cogl_winsys_vtable_getters[] =
#endif
#ifdef COGL_HAS_WGL_SUPPORT
_cogl_winsys_wgl_get_vtable,
#endif
#ifdef COGL_HAS_SDL_SUPPORT
_cogl_winsys_sdl_get_vtable,
#endif
_cogl_winsys_stub_get_vtable,
};

View File

@ -168,7 +168,6 @@ cogl_renderer_new (void);
* @COGL_WINSYS_ID_EGL_ANDROID: Use EGL with the Android platform
* @COGL_WINSYS_ID_EGL_MIR: Use EGL with the Mir server
* @COGL_WINSYS_ID_WGL: Use the Microsoft Windows WGL binding API
* @COGL_WINSYS_ID_SDL: Use the SDL window system
*
* Identifies specific window system backends that Cogl supports.
*
@ -186,7 +185,6 @@ typedef enum
COGL_WINSYS_ID_EGL_ANDROID,
COGL_WINSYS_ID_EGL_MIR,
COGL_WINSYS_ID_WGL,
COGL_WINSYS_ID_SDL
} CoglWinsysID;
/**

View File

@ -1,111 +0,0 @@
/*
* Cogl
*
* A Low Level GPU Graphics and Utilities API
*
* Copyright (C) 2012, 2013 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "cogl-sdl.h"
#include "cogl-context-private.h"
#include "cogl-renderer-private.h"
void
cogl_sdl_renderer_set_event_type (CoglRenderer *renderer, int type)
{
renderer->sdl_event_type_set = TRUE;
renderer->sdl_event_type = type;
}
int
cogl_sdl_renderer_get_event_type (CoglRenderer *renderer)
{
_COGL_RETURN_VAL_IF_FAIL (renderer->sdl_event_type_set, SDL_USEREVENT);
return renderer->sdl_event_type;
}
CoglContext *
cogl_sdl_context_new (int type, CoglError **error)
{
CoglRenderer *renderer = cogl_renderer_new ();
CoglDisplay *display;
cogl_renderer_set_winsys_id (renderer, COGL_WINSYS_ID_SDL);
cogl_sdl_renderer_set_event_type (renderer, type);
if (!cogl_renderer_connect (renderer, error))
return NULL;
display = cogl_display_new (renderer, NULL);
if (!cogl_display_setup (display, error))
return NULL;
return cogl_context_new (display, error);
}
void
cogl_sdl_handle_event (CoglContext *context, SDL_Event *event)
{
CoglRenderer *renderer;
_COGL_RETURN_IF_FAIL (cogl_is_context (context));
renderer = context->display->renderer;
_cogl_renderer_handle_native_event (renderer, event);
}
static void
_cogl_sdl_push_wakeup_event (CoglContext *context)
{
SDL_Event wakeup_event;
wakeup_event.type = context->display->renderer->sdl_event_type;
SDL_PushEvent (&wakeup_event);
}
void
cogl_sdl_idle (CoglContext *context)
{
CoglRenderer *renderer = context->display->renderer;
cogl_poll_renderer_dispatch (renderer, NULL, 0);
/* It is expected that this will be called from the application
* immediately before blocking in SDL_WaitEvent. However,
* dispatching cause more work to be queued. If that happens we need
* to make sure the blocking returns immediately. We'll post our
* dummy event to make sure that happens
*/
if (!_cogl_list_empty (&renderer->idle_closures))
_cogl_sdl_push_wakeup_event (context);
}

View File

@ -1,248 +0,0 @@
/*
* Cogl
*
* A Low Level GPU Graphics and Utilities API
*
* Copyright (C) 2012 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*
*/
#ifndef __COGL_SDL_H__
#define __COGL_SDL_H__
/* NB: this is a top-level header that can be included directly but we
* want to be careful not to define __COGL_H_INSIDE__ when this is
* included internally while building Cogl itself since
* __COGL_H_INSIDE__ is used in headers to guard public vs private api
* definitions
*/
#ifndef COGL_COMPILATION
/* Note: When building Cogl .gir we explicitly define
* __COGL_H_INSIDE__ */
#ifndef __COGL_H_INSIDE__
#define __COGL_H_INSIDE__
#define __COGL_SDL_H_MUST_UNDEF_COGL_H_INSIDE__
#endif
#endif /* COGL_COMPILATION */
#include <cogl/cogl-context.h>
#include <cogl/cogl-onscreen.h>
#include <SDL.h>
COGL_BEGIN_DECLS
/**
* SECTION:cogl-sdl
* @short_description: Integration api for the Simple DirectMedia
* Layer library.
*
* Cogl is a portable graphics api that can either be used standalone
* or alternatively integrated with certain existing frameworks. This
* api enables Cogl to be used in conjunction with the Simple
* DirectMedia Layer library.
*
* Using this API a typical SDL application would look something like
* this:
* |[
* MyAppData data;
* CoglError *error = NULL;
*
* data.ctx = cogl_sdl_context_new (SDL_USEREVENT, &error);
* if (!data.ctx)
* {
* fprintf (stderr, "Failed to create context: %s\n",
* error->message);
* return 1;
* }
*
* my_application_setup (&data);
*
* data.redraw_queued = TRUE;
* while (!data.quit)
* {
* while (!data.quit)
* {
* if (!SDL_PollEvent (&event))
* {
* if (data.redraw_queued)
* break;
*
* cogl_sdl_idle (ctx);
* if (!SDL_WaitEvent (&event))
* {
* fprintf (stderr, "Error waiting for SDL events");
* return 1;
* }
* }
*
* handle_event (&data, &event);
* cogl_sdl_handle_event (ctx, &event);
* }
*
* data.redraw_queued = redraw (&data);
* }
* ]|
*/
/**
* cogl_sdl_context_new:
* @type: An SDL user event type between <constant>SDL_USEREVENT</constant> and
* <constant>SDL_NUMEVENTS</constant> - 1
* @error: A CoglError return location.
*
* This is a convenience function for creating a new #CoglContext for
* use with SDL and specifying what SDL user event type Cogl can use
* as a way to interrupt SDL_WaitEvent().
*
* This function is equivalent to the following code:
* |[
* CoglRenderer *renderer = cogl_renderer_new ();
* CoglDisplay *display;
*
* cogl_renderer_set_winsys_id (renderer, COGL_WINSYS_ID_SDL);
*
* cogl_sdl_renderer_set_event_type (renderer, type);
*
* if (!cogl_renderer_connect (renderer, error))
* return NULL;
*
* display = cogl_display_new (renderer, NULL);
* if (!cogl_display_setup (display, error))
* return NULL;
*
* return cogl_context_new (display, error);
* ]|
*
* <note>SDL applications are required to either use this API or
* to manually create a #CoglRenderer and call
* cogl_sdl_renderer_set_event_type().</note>
*
* Since: 2.0
* Stability: unstable
*/
CoglContext *
cogl_sdl_context_new (int type, CoglError **error);
/**
* cogl_sdl_renderer_set_event_type:
* @renderer: A #CoglRenderer
* @type: An SDL user event type between <constant>SDL_USEREVENT</constant> and
* <constant>SDL_NUMEVENTS</constant> - 1
*
* Tells Cogl what SDL user event type it can use as a way to
* interrupt SDL_WaitEvent() to ensure that cogl_sdl_handle_event()
* will be called in a finite amount of time.
*
* <note>This should only be called on an un-connected
* @renderer.</note>
*
* <note>For convenience most simple applications can use
* cogl_sdl_context_new() if they don't want to manually create
* #CoglRenderer and #CoglDisplay objects during
* initialization.</note>
*
* Since: 2.0
* Stability: unstable
*/
void
cogl_sdl_renderer_set_event_type (CoglRenderer *renderer, int type);
/**
* cogl_sdl_renderer_get_event_type:
* @renderer: A #CoglRenderer
*
* Queries what SDL user event type Cogl is using as a way to
* interrupt SDL_WaitEvent(). This is set either using
* cogl_sdl_context_new or by using
* cogl_sdl_renderer_set_event_type().
*
* Since: 2.0
* Stability: unstable
*/
int
cogl_sdl_renderer_get_event_type (CoglRenderer *renderer);
/**
* cogl_sdl_handle_event:
* @context: A #CoglContext
* @event: An SDL event
*
* Passes control to Cogl so that it may dispatch any internal event
* callbacks in response to the given SDL @event. This function must
* be called for every SDL event.
*
* Since: 2.0
* Stability: unstable
*/
void
cogl_sdl_handle_event (CoglContext *context, SDL_Event *event);
/**
* cogl_sdl_idle:
* @context: A #CoglContext
*
* Notifies Cogl that the application is idle and about to call
* SDL_WaitEvent(). Cogl may use this to run low priority book keeping
* tasks.
*
* Since: 2.0
* Stability: unstable
*/
void
cogl_sdl_idle (CoglContext *context);
#if SDL_MAJOR_VERSION >= 2
/**
* cogl_sdl_onscreen_get_window:
* @onscreen: A #CoglOnscreen
*
* Returns: the underlying SDL_Window associated with an onscreen framebuffer.
*
* Since: 2.0
* Stability: unstable
*/
SDL_Window *
cogl_sdl_onscreen_get_window (CoglOnscreen *onscreen);
#endif /* SDL_MAJOR_VERSION */
COGL_END_DECLS
/* The gobject introspection scanner seems to parse public headers in
* isolation which means we need to be extra careful about how we
* define and undefine __COGL_H_INSIDE__ used to detect when internal
* headers are incorrectly included by developers. In the gobject
* introspection case we have to manually define __COGL_H_INSIDE__ as
* a commandline argument for the scanner which means we must be
* careful not to undefine it in a header...
*/
#ifdef __COGL_SDL_H_MUST_UNDEF_COGL_H_INSIDE__
#undef __COGL_H_INSIDE__
#undef __COGL_SDL_H_MUST_UNDEF_COGL_H_INSIDE__
#endif
#endif /* __COGL_SDL_H__ */

View File

@ -1,37 +0,0 @@
/*
* Cogl
*
* A Low Level GPU Graphics and Utilities API
*
* Copyright (C) 2012 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*
*/
#ifndef __COGL_WINSYS_SDL_PRIVATE_H
#define __COGL_WINSYS_SDL_PRIVATE_H
const CoglWinsysVtable *
_cogl_winsys_sdl_get_vtable (void);
#endif /* __COGL_WINSYS_SDL_PRIVATE_H */

View File

@ -1,490 +0,0 @@
/*
* Cogl
*
* A Low Level GPU Graphics and Utilities API
*
* Copyright (C) 2011,2013 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*
* Authors:
* Neil Roberts <neil@linux.intel.com>
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <SDL.h>
#include "cogl-renderer-private.h"
#include "cogl-display-private.h"
#include "cogl-framebuffer-private.h"
#include "cogl-swap-chain-private.h"
#include "cogl-onscreen-template-private.h"
#include "cogl-context-private.h"
#include "cogl-onscreen-private.h"
#include "cogl-winsys-sdl-private.h"
#include "cogl-error-private.h"
#include "cogl-poll-private.h"
typedef struct _CoglRendererSdl
{
CoglClosure *resize_notify_idle;
} CoglRendererSdl;
typedef struct _CoglDisplaySdl
{
SDL_Surface *surface;
CoglOnscreen *onscreen;
Uint32 video_mode_flags;
} CoglDisplaySdl;
static CoglFuncPtr
_cogl_winsys_renderer_get_proc_address (CoglRenderer *renderer,
const char *name,
CoglBool in_core)
{
CoglFuncPtr ptr;
/* XXX: It's not totally clear whether it's safe to call this for
* core functions. From the code it looks like the implementations
* will fall back to using some form of dlsym if the winsys
* GetProcAddress function returns NULL. Presumably this will work
* in most cases apart from EGL platforms that return invalid
* pointers for core functions. It's awkward for this code to get a
* handle to the GL module that SDL has chosen to load so just
* calling SDL_GL_GetProcAddress is probably the best we can do
* here. */
#ifdef COGL_HAS_SDL_GLES_SUPPORT
if (renderer->driver != COGL_DRIVER_GL)
return SDL_GLES_GetProcAddress (name);
#endif
return SDL_GL_GetProcAddress (name);
}
static void
_cogl_winsys_renderer_disconnect (CoglRenderer *renderer)
{
SDL_Quit ();
g_slice_free (CoglRendererSdl, renderer->winsys);
}
static CoglBool
_cogl_winsys_renderer_connect (CoglRenderer *renderer,
CoglError **error)
{
#ifdef USING_EMSCRIPTEN
if (renderer->driver != COGL_DRIVER_GLES2)
{
_cogl_set_error (error, COGL_WINSYS_ERROR,
COGL_WINSYS_ERROR_INIT,
"The SDL winsys with emscripten only supports "
"the GLES2 driver");
return FALSE;
}
#elif !defined (COGL_HAS_SDL_GLES_SUPPORT)
if (renderer->driver != COGL_DRIVER_GL)
{
_cogl_set_error (error, COGL_WINSYS_ERROR,
COGL_WINSYS_ERROR_INIT,
"The SDL winsys only supports the GL driver");
return FALSE;
}
#endif
if (SDL_Init (SDL_INIT_VIDEO) == -1)
{
_cogl_set_error (error, COGL_WINSYS_ERROR,
COGL_WINSYS_ERROR_INIT,
"SDL_Init failed: %s",
SDL_GetError ());
return FALSE;
}
renderer->winsys = g_slice_new0 (CoglRendererSdl);
return TRUE;
}
static void
_cogl_winsys_display_destroy (CoglDisplay *display)
{
CoglDisplaySdl *sdl_display = display->winsys;
_COGL_RETURN_IF_FAIL (sdl_display != NULL);
/* No need to destroy the surface - it is freed by SDL_Quit */
g_slice_free (CoglDisplaySdl, display->winsys);
display->winsys = NULL;
}
static void
set_gl_attribs_from_framebuffer_config (CoglFramebufferConfig *config)
{
SDL_GL_SetAttribute (SDL_GL_RED_SIZE, 1);
SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 1);
SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, 1);
SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 1);
SDL_GL_SetAttribute (SDL_GL_STENCIL_SIZE,
config->need_stencil ? 1 : 0);
if (config->swap_chain->length >= 0)
SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER,
config->swap_chain->length > 1 ? 1 : 0);
SDL_GL_SetAttribute (SDL_GL_ALPHA_SIZE,
config->swap_chain->has_alpha ? 1 : 0);
}
static CoglBool
_cogl_winsys_display_setup (CoglDisplay *display,
CoglError **error)
{
CoglDisplaySdl *sdl_display;
_COGL_RETURN_VAL_IF_FAIL (display->winsys == NULL, FALSE);
sdl_display = g_slice_new0 (CoglDisplaySdl);
display->winsys = sdl_display;
set_gl_attribs_from_framebuffer_config (&display->onscreen_template->config);
switch (display->renderer->driver)
{
case COGL_DRIVER_GL:
sdl_display->video_mode_flags = SDL_OPENGL;
break;
case COGL_DRIVER_GL3:
_cogl_set_error (error, COGL_WINSYS_ERROR,
COGL_WINSYS_ERROR_INIT,
"The SDL winsys does not support GL 3");
goto error;
#ifdef COGL_HAS_SDL_GLES_SUPPORT
case COGL_DRIVER_GLES2:
sdl_display->video_mode_flags = SDL_OPENGLES;
SDL_GL_SetAttribute (SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute (SDL_GL_CONTEXT_MINOR_VERSION, 0);
break;
case COGL_DRIVER_GLES1:
sdl_display->video_mode_flags = SDL_OPENGLES;
SDL_GL_SetAttribute (SDL_GL_CONTEXT_MAJOR_VERSION, 1);
SDL_GL_SetAttribute (SDL_GL_CONTEXT_MINOR_VERSION, 1);
break;
#elif defined (USING_EMSCRIPTEN)
case COGL_DRIVER_GLES2:
sdl_display->video_mode_flags = SDL_OPENGL;
break;
#endif
default:
g_assert_not_reached ();
}
/* There's no way to know what size the application will need until
it creates the first onscreen but we need to set the video mode
now so that we can get a GL context. We'll have to just guess at
a size an resize it later */
sdl_display->surface = SDL_SetVideoMode (640, 480, /* width/height */
0, /* bitsperpixel */
sdl_display->video_mode_flags);
if (sdl_display->surface == NULL)
{
_cogl_set_error (error, COGL_WINSYS_ERROR,
COGL_WINSYS_ERROR_INIT,
"SDL_SetVideoMode failed: %s",
SDL_GetError ());
goto error;
}
return TRUE;
error:
_cogl_winsys_display_destroy (display);
return FALSE;
}
static void
flush_pending_resize_notification_idle (void *user_data)
{
CoglContext *context = user_data;
CoglRenderer *renderer = context->display->renderer;
CoglRendererSdl *sdl_renderer = renderer->winsys;
CoglDisplaySdl *sdl_display = context->display->winsys;
CoglOnscreen *onscreen = sdl_display->onscreen;
/* This needs to be disconnected before invoking the callbacks in
* case the callbacks cause it to be queued again */
_cogl_closure_disconnect (sdl_renderer->resize_notify_idle);
sdl_renderer->resize_notify_idle = NULL;
_cogl_onscreen_notify_resize (onscreen);
}
static CoglFilterReturn
sdl_event_filter_cb (SDL_Event *event, void *data)
{
CoglContext *context = data;
CoglDisplay *display = context->display;
CoglDisplaySdl *sdl_display = display->winsys;
CoglFramebuffer *framebuffer;
if (!sdl_display->onscreen)
return COGL_FILTER_CONTINUE;
framebuffer = COGL_FRAMEBUFFER (sdl_display->onscreen);
if (event->type == SDL_VIDEORESIZE)
{
CoglRenderer *renderer = display->renderer;
CoglRendererSdl *sdl_renderer = renderer->winsys;
float width = event->resize.w;
float height = event->resize.h;
sdl_display->surface = SDL_SetVideoMode (width, height,
0, /* bitsperpixel */
sdl_display->video_mode_flags);
_cogl_framebuffer_winsys_update_size (framebuffer, width, height);
/* We only want to notify that a resize happened when the
* application calls cogl_context_dispatch so instead of
* immediately notifying we queue an idle callback */
if (!sdl_renderer->resize_notify_idle)
{
sdl_renderer->resize_notify_idle =
_cogl_poll_renderer_add_idle (renderer,
flush_pending_resize_notification_idle,
context,
NULL);
}
return COGL_FILTER_CONTINUE;
}
else if (event->type == SDL_VIDEOEXPOSE)
{
CoglOnscreenDirtyInfo info;
/* Sadly SDL doesn't seem to report the rectangle of the expose
* event so we'll just queue the whole window */
info.x = 0;
info.y = 0;
info.width = framebuffer->width;
info.height = framebuffer->height;
_cogl_onscreen_queue_dirty (COGL_ONSCREEN (framebuffer), &info);
}
return COGL_FILTER_CONTINUE;
}
static CoglBool
_cogl_winsys_context_init (CoglContext *context, CoglError **error)
{
CoglRenderer *renderer = context->display->renderer;
if (G_UNLIKELY (renderer->sdl_event_type_set == FALSE))
g_error ("cogl_sdl_renderer_set_event_type() or cogl_sdl_context_new() "
"must be called during initialization");
_cogl_renderer_add_native_filter (renderer,
(CoglNativeFilterFunc)sdl_event_filter_cb,
context);
/* We'll manually handle queueing dirty events in response to
* SDL_VIDEOEXPOSE events */
COGL_FLAGS_SET (context->private_features,
COGL_PRIVATE_FEATURE_DIRTY_EVENTS,
TRUE);
return _cogl_context_update_features (context, error);
}
static void
_cogl_winsys_context_deinit (CoglContext *context)
{
}
static void
_cogl_winsys_onscreen_bind (CoglOnscreen *onscreen)
{
}
static void
_cogl_winsys_onscreen_deinit (CoglOnscreen *onscreen)
{
CoglContext *context = COGL_FRAMEBUFFER (onscreen)->context;
CoglDisplay *display = context->display;
CoglDisplaySdl *sdl_display = display->winsys;
sdl_display->onscreen = NULL;
}
static CoglBool
_cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
CoglError **error)
{
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
CoglContext *context = framebuffer->context;
CoglDisplay *display = context->display;
CoglDisplaySdl *sdl_display = display->winsys;
CoglBool flags_changed = FALSE;
int width, height;
if (sdl_display->onscreen)
{
_cogl_set_error (error, COGL_WINSYS_ERROR,
COGL_WINSYS_ERROR_CREATE_ONSCREEN,
"SDL winsys only supports a single onscreen window");
return FALSE;
}
width = cogl_framebuffer_get_width (framebuffer);
height = cogl_framebuffer_get_height (framebuffer);
if (cogl_onscreen_get_resizable (onscreen))
{
sdl_display->video_mode_flags |= SDL_RESIZABLE;
flags_changed = TRUE;
}
/* Try to update the video size using the onscreen size */
if (width != sdl_display->surface->w ||
height != sdl_display->surface->h ||
flags_changed)
{
sdl_display->surface = SDL_SetVideoMode (width, height,
0, /* bitsperpixel */
sdl_display->video_mode_flags);
if (sdl_display->surface == NULL)
{
_cogl_set_error (error, COGL_WINSYS_ERROR,
COGL_WINSYS_ERROR_CREATE_ONSCREEN,
"SDL_SetVideoMode failed: %s",
SDL_GetError ());
return FALSE;
}
}
_cogl_framebuffer_winsys_update_size (framebuffer,
sdl_display->surface->w,
sdl_display->surface->h);
sdl_display->onscreen = onscreen;
return TRUE;
}
static void
_cogl_winsys_onscreen_swap_buffers_with_damage (CoglOnscreen *onscreen,
const int *rectangles,
int n_rectangles)
{
SDL_GL_SwapBuffers ();
}
static void
_cogl_winsys_onscreen_update_swap_throttled (CoglOnscreen *onscreen)
{
/* SDL doesn't appear to provide a way to set this */
}
static void
_cogl_winsys_onscreen_set_visibility (CoglOnscreen *onscreen,
CoglBool visibility)
{
/* SDL doesn't appear to provide a way to set this */
}
static void
_cogl_winsys_onscreen_set_resizable (CoglOnscreen *onscreen,
CoglBool resizable)
{
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
CoglContext *context = framebuffer->context;
CoglDisplay *display = context->display;
CoglDisplaySdl *sdl_display = display->winsys;
int width, height;
width = cogl_framebuffer_get_width (framebuffer);
height = cogl_framebuffer_get_height (framebuffer);
if (resizable)
sdl_display->video_mode_flags |= SDL_RESIZABLE;
else
sdl_display->video_mode_flags &= ~SDL_RESIZABLE;
sdl_display->surface = SDL_SetVideoMode (width, height,
0, /* bitsperpixel */
sdl_display->video_mode_flags);
}
const CoglWinsysVtable *
_cogl_winsys_sdl_get_vtable (void)
{
static CoglBool vtable_inited = FALSE;
static CoglWinsysVtable vtable;
/* It would be nice if we could use C99 struct initializers here
like the GLX backend does. However this code is more likely to be
compiled using Visual Studio which (still!) doesn't support them
so we initialize it in code instead */
if (!vtable_inited)
{
memset (&vtable, 0, sizeof (vtable));
vtable.id = COGL_WINSYS_ID_SDL;
vtable.name = "SDL";
vtable.renderer_get_proc_address = _cogl_winsys_renderer_get_proc_address;
vtable.renderer_connect = _cogl_winsys_renderer_connect;
vtable.renderer_disconnect = _cogl_winsys_renderer_disconnect;
vtable.display_setup = _cogl_winsys_display_setup;
vtable.display_destroy = _cogl_winsys_display_destroy;
vtable.context_init = _cogl_winsys_context_init;
vtable.context_deinit = _cogl_winsys_context_deinit;
vtable.onscreen_init = _cogl_winsys_onscreen_init;
vtable.onscreen_deinit = _cogl_winsys_onscreen_deinit;
vtable.onscreen_bind = _cogl_winsys_onscreen_bind;
vtable.onscreen_swap_buffers_with_damage =
_cogl_winsys_onscreen_swap_buffers_with_damage;
vtable.onscreen_update_swap_throttled =
_cogl_winsys_onscreen_update_swap_throttled;
vtable.onscreen_set_visibility = _cogl_winsys_onscreen_set_visibility;
vtable.onscreen_set_resizable = _cogl_winsys_onscreen_set_resizable;
vtable_inited = TRUE;
}
return &vtable;
}

View File

@ -1,638 +0,0 @@
/*
* Cogl
*
* A Low Level GPU Graphics and Utilities API
*
* Copyright (C) 2011, 2012, 2013 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*
* Authors:
* Neil Roberts <neil@linux.intel.com>
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <SDL.h>
#include "cogl-renderer-private.h"
#include "cogl-display-private.h"
#include "cogl-framebuffer-private.h"
#include "cogl-swap-chain-private.h"
#include "cogl-onscreen-template-private.h"
#include "cogl-context-private.h"
#include "cogl-onscreen-private.h"
#include "cogl-winsys-sdl-private.h"
#include "cogl-error-private.h"
#include "cogl-poll-private.h"
#include "cogl-sdl.h"
typedef struct _CoglContextSdl2
{
SDL_Window *current_window;
} CoglContextSdl2;
typedef struct _CoglRendererSdl2
{
CoglClosure *resize_notify_idle;
} CoglRendererSdl2;
typedef struct _CoglDisplaySdl2
{
SDL_Window *dummy_window;
SDL_GLContext *context;
} CoglDisplaySdl2;
typedef struct _CoglOnscreenSdl2
{
SDL_Window *window;
CoglBool pending_resize_notify;
} CoglOnscreenSdl2;
/* The key used to store a pointer to the CoglOnscreen in an
* SDL_Window */
#define COGL_SDL_WINDOW_DATA_KEY "cogl-onscreen"
static CoglFuncPtr
_cogl_winsys_renderer_get_proc_address (CoglRenderer *renderer,
const char *name,
CoglBool in_core)
{
/* XXX: It's not totally clear whether it's safe to call this for
* core functions. From the code it looks like the implementations
* will fall back to using some form of dlsym if the winsys
* GetProcAddress function returns NULL. Presumably this will work
* in most cases apart from EGL platforms that return invalid
* pointers for core functions. It's awkward for this code to get a
* handle to the GL module that SDL has chosen to load so just
* calling SDL_GL_GetProcAddress is probably the best we can do
* here. */
return SDL_GL_GetProcAddress (name);
}
static void
_cogl_winsys_renderer_disconnect (CoglRenderer *renderer)
{
SDL_VideoQuit ();
g_slice_free (CoglRendererSdl2, renderer->winsys);
}
static CoglBool
_cogl_winsys_renderer_connect (CoglRenderer *renderer,
CoglError **error)
{
if (SDL_VideoInit (NULL) < 0)
{
_cogl_set_error (error, COGL_WINSYS_ERROR,
COGL_WINSYS_ERROR_INIT,
"SDL_Init failed: %s",
SDL_GetError ());
return FALSE;
}
renderer->winsys = g_slice_new0 (CoglRendererSdl2);
return TRUE;
}
static void
_cogl_winsys_display_destroy (CoglDisplay *display)
{
CoglDisplaySdl2 *sdl_display = display->winsys;
_COGL_RETURN_IF_FAIL (sdl_display != NULL);
if (sdl_display->context)
SDL_GL_DeleteContext (sdl_display->context);
if (sdl_display->dummy_window)
SDL_DestroyWindow (sdl_display->dummy_window);
g_slice_free (CoglDisplaySdl2, display->winsys);
display->winsys = NULL;
}
static void
set_gl_attribs_from_framebuffer_config (CoglFramebufferConfig *config)
{
SDL_GL_SetAttribute (SDL_GL_RED_SIZE, 1);
SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 1);
SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, 1);
SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 1);
SDL_GL_SetAttribute (SDL_GL_STENCIL_SIZE,
config->need_stencil ? 1 : 0);
if (config->swap_chain->length >= 0)
SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER,
config->swap_chain->length > 1 ? 1 : 0);
SDL_GL_SetAttribute (SDL_GL_ALPHA_SIZE,
config->swap_chain->has_alpha ? 1 : 0);
}
static CoglBool
_cogl_winsys_display_setup (CoglDisplay *display,
CoglError **error)
{
CoglDisplaySdl2 *sdl_display;
const char * (* get_string_func) (GLenum name);
const char *gl_version;
_COGL_RETURN_VAL_IF_FAIL (display->winsys == NULL, FALSE);
sdl_display = g_slice_new0 (CoglDisplaySdl2);
display->winsys = sdl_display;
set_gl_attribs_from_framebuffer_config (&display->onscreen_template->config);
if (display->renderer->driver == COGL_DRIVER_GLES1)
{
SDL_GL_SetAttribute (SDL_GL_CONTEXT_PROFILE_MASK,
SDL_GL_CONTEXT_PROFILE_ES);
SDL_GL_SetAttribute (SDL_GL_CONTEXT_MAJOR_VERSION, 1);
SDL_GL_SetAttribute (SDL_GL_CONTEXT_MINOR_VERSION, 1);
}
else if (display->renderer->driver == COGL_DRIVER_GLES2)
{
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);
}
else if (display->renderer->driver == COGL_DRIVER_GL3)
{
SDL_GL_SetAttribute (SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute (SDL_GL_CONTEXT_MINOR_VERSION, 1);
SDL_GL_SetAttribute (SDL_GL_CONTEXT_PROFILE_MASK,
SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute (SDL_GL_CONTEXT_FLAGS,
SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG);
}
/* Create a dummy 1x1 window that never gets display so that we can
* create a GL context */
sdl_display->dummy_window = SDL_CreateWindow ("",
0, 0, /* x/y */
1, 1, /* w/h */
SDL_WINDOW_OPENGL |
SDL_WINDOW_HIDDEN);
if (sdl_display->dummy_window == NULL)
{
_cogl_set_error (error, COGL_WINSYS_ERROR,
COGL_WINSYS_ERROR_INIT,
"SDL_CreateWindow failed: %s",
SDL_GetError ());
goto error;
}
sdl_display->context = SDL_GL_CreateContext (sdl_display->dummy_window);
if (sdl_display->context == NULL)
{
_cogl_set_error (error, COGL_WINSYS_ERROR,
COGL_WINSYS_ERROR_INIT,
"SDL_GL_CreateContext failed: %s",
SDL_GetError ());
goto error;
}
/* SDL doesn't seem to provide a way to select between GL and GLES
* and instead it will just pick one itself. We can at least try to
* verify that it picked the one we were expecting by looking at the
* GL version string */
get_string_func = SDL_GL_GetProcAddress ("glGetString");
gl_version = get_string_func (GL_VERSION);
switch (display->renderer->driver)
{
case COGL_DRIVER_GL:
case COGL_DRIVER_GL3:
/* The first character of the version string will be a digit if
* it's normal GL */
if (!g_ascii_isdigit (gl_version[0]))
{
_cogl_set_error (error, COGL_WINSYS_ERROR,
COGL_WINSYS_ERROR_INIT,
"The GL driver was requested but SDL is using GLES");
goto error;
}
if (display->renderer->driver == COGL_DRIVER_GL3 &&
gl_version[0] < '3')
{
_cogl_set_error (error, COGL_WINSYS_ERROR,
COGL_WINSYS_ERROR_INIT,
"The GL3 driver was requested but SDL is using "
"GL %c", gl_version[0]);
goto error;
}
break;
case COGL_DRIVER_GLES2:
if (!g_str_has_prefix (gl_version, "OpenGL ES 2") &&
!g_str_has_prefix (gl_version, "OpenGL ES 3"))
{
_cogl_set_error (error, COGL_WINSYS_ERROR,
COGL_WINSYS_ERROR_INIT,
"The GLES2 driver was requested but SDL is "
"not using GLES2 or GLES3");
goto error;
}
break;
case COGL_DRIVER_GLES1:
if (!g_str_has_prefix (gl_version, "OpenGL ES 1"))
{
_cogl_set_error (error, COGL_WINSYS_ERROR,
COGL_WINSYS_ERROR_INIT,
"The GLES1 driver was requested but SDL is "
"not using GLES1");
goto error;
}
break;
default:
g_assert_not_reached ();
}
return TRUE;
error:
_cogl_winsys_display_destroy (display);
return FALSE;
}
static void
flush_pending_notifications_cb (void *data,
void *user_data)
{
CoglFramebuffer *framebuffer = data;
if (framebuffer->type == COGL_FRAMEBUFFER_TYPE_ONSCREEN)
{
CoglOnscreen *onscreen = COGL_ONSCREEN (framebuffer);
CoglOnscreenSdl2 *sdl_onscreen = onscreen->winsys;
if (sdl_onscreen->pending_resize_notify)
{
_cogl_onscreen_notify_resize (onscreen);
sdl_onscreen->pending_resize_notify = FALSE;
}
}
}
static void
flush_pending_resize_notifications_idle (void *user_data)
{
CoglContext *context = user_data;
CoglRenderer *renderer = context->display->renderer;
CoglRendererSdl2 *sdl_renderer = renderer->winsys;
/* This needs to be disconnected before invoking the callbacks in
* case the callbacks cause it to be queued again */
_cogl_closure_disconnect (sdl_renderer->resize_notify_idle);
sdl_renderer->resize_notify_idle = NULL;
g_list_foreach (context->framebuffers,
flush_pending_notifications_cb,
NULL);
}
static CoglFilterReturn
sdl_window_event_filter (SDL_WindowEvent *event,
CoglContext *context)
{
SDL_Window *window;
CoglFramebuffer *framebuffer;
window = SDL_GetWindowFromID (event->windowID);
if (window == NULL)
return COGL_FILTER_CONTINUE;
framebuffer = SDL_GetWindowData (window, COGL_SDL_WINDOW_DATA_KEY);
if (framebuffer == NULL || framebuffer->context != context)
return COGL_FILTER_CONTINUE;
if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED)
{
CoglDisplay *display = context->display;
CoglRenderer *renderer = display->renderer;
CoglRendererSdl2 *sdl_renderer = renderer->winsys;
float width = event->data1;
float height = event->data2;
CoglOnscreenSdl2 *sdl_onscreen;
_cogl_framebuffer_winsys_update_size (framebuffer, width, height);
/* We only want to notify that a resize happened when the
* application calls cogl_context_dispatch so instead of
* immediately notifying we queue an idle callback */
if (!sdl_renderer->resize_notify_idle)
{
sdl_renderer->resize_notify_idle =
_cogl_poll_renderer_add_idle (renderer,
flush_pending_resize_notifications_idle,
context,
NULL);
}
sdl_onscreen = COGL_ONSCREEN (framebuffer)->winsys;
sdl_onscreen->pending_resize_notify = TRUE;
}
else if (event->event == SDL_WINDOWEVENT_EXPOSED)
{
CoglOnscreenDirtyInfo info;
/* Sadly SDL doesn't seem to report the rectangle of the expose
* event so we'll just queue the whole window */
info.x = 0;
info.y = 0;
info.width = framebuffer->width;
info.height = framebuffer->height;
_cogl_onscreen_queue_dirty (COGL_ONSCREEN (framebuffer), &info);
}
return COGL_FILTER_CONTINUE;
}
static CoglFilterReturn
sdl_event_filter_cb (SDL_Event *event, void *data)
{
CoglContext *context = data;
switch (event->type)
{
case SDL_WINDOWEVENT:
return sdl_window_event_filter (&event->window, context);
default:
return COGL_FILTER_CONTINUE;
}
}
static CoglBool
_cogl_winsys_context_init (CoglContext *context, CoglError **error)
{
CoglRenderer *renderer = context->display->renderer;
context->winsys = g_new0 (CoglContextSdl2, 1);
if (G_UNLIKELY (renderer->sdl_event_type_set == FALSE))
g_error ("cogl_sdl_renderer_set_event_type() or cogl_sdl_context_new() "
"must be called during initialization");
if (!_cogl_context_update_features (context, error))
return FALSE;
if (SDL_GL_GetSwapInterval () != -1)
COGL_FLAGS_SET (context->winsys_features,
COGL_WINSYS_FEATURE_SWAP_REGION_THROTTLE,
TRUE);
/* We'll manually handle queueing dirty events in response to
* SDL_WINDOWEVENT_EXPOSED events */
COGL_FLAGS_SET (context->private_features,
COGL_PRIVATE_FEATURE_DIRTY_EVENTS,
TRUE);
_cogl_renderer_add_native_filter (renderer,
(CoglNativeFilterFunc) sdl_event_filter_cb,
context);
return TRUE;
}
static void
_cogl_winsys_context_deinit (CoglContext *context)
{
CoglRenderer *renderer = context->display->renderer;
_cogl_renderer_remove_native_filter (renderer,
(CoglNativeFilterFunc)
sdl_event_filter_cb,
context);
g_free (context->winsys);
}
static void
_cogl_winsys_onscreen_bind (CoglOnscreen *onscreen)
{
CoglFramebuffer *fb = COGL_FRAMEBUFFER (onscreen);
CoglContext *context = fb->context;
CoglContextSdl2 *sdl_context = context->winsys;
CoglDisplaySdl2 *sdl_display = context->display->winsys;
CoglOnscreenSdl2 *sdl_onscreen = onscreen->winsys;
if (sdl_context->current_window == sdl_onscreen->window)
return;
SDL_GL_MakeCurrent (sdl_onscreen->window, sdl_display->context);
sdl_context->current_window = sdl_onscreen->window;
/* It looks like SDL just directly calls a glXSwapInterval function
* when this is called. This may be provided by either the EXT
* extension, the SGI extension or the Mesa extension. The SGI
* extension is per context so we can't just do this once when the
* framebuffer is allocated. See the comments in the GLX winsys for
* more info. */
if (COGL_FLAGS_GET (context->winsys_features,
COGL_WINSYS_FEATURE_SWAP_REGION_THROTTLE))
{
CoglFramebuffer *fb = COGL_FRAMEBUFFER (onscreen);
SDL_GL_SetSwapInterval (fb->config.swap_throttled ? 1 : 0);
}
}
static void
_cogl_winsys_onscreen_deinit (CoglOnscreen *onscreen)
{
CoglOnscreenSdl2 *sdl_onscreen = onscreen->winsys;
if (sdl_onscreen->window != NULL)
{
CoglContext *context = COGL_FRAMEBUFFER (onscreen)->context;
CoglContextSdl2 *sdl_context = context->winsys;
if (sdl_context->current_window == sdl_onscreen->window)
{
CoglDisplaySdl2 *sdl_display = context->display->winsys;
/* SDL explicitly unbinds the context when the currently
* bound window is destroyed. Cogl always needs a context
* bound so that for example it can create texture resources
* at any time even without flushing a framebuffer.
* Therefore we'll bind the dummy window. */
SDL_GL_MakeCurrent (sdl_display->dummy_window,
sdl_display->context);
sdl_context->current_window = sdl_display->dummy_window;
}
SDL_DestroyWindow (sdl_onscreen->window);
sdl_onscreen->window = NULL;
}
g_slice_free (CoglOnscreenSdl2, sdl_onscreen);
onscreen->winsys = NULL;
}
static CoglBool
_cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
CoglError **error)
{
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
CoglOnscreenSdl2 *sdl_onscreen;
SDL_Window *window;
int width, height;
SDL_WindowFlags flags;
width = cogl_framebuffer_get_width (framebuffer);
height = cogl_framebuffer_get_height (framebuffer);
flags = SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN;
/* The resizable property on SDL window apparently can only be set
* on creation */
if (onscreen->resizable)
flags |= SDL_WINDOW_RESIZABLE;
window = SDL_CreateWindow ("" /* title */,
0, 0, /* x/y */
width, height,
flags);
if (window == NULL)
{
_cogl_set_error (error, COGL_WINSYS_ERROR,
COGL_WINSYS_ERROR_CREATE_ONSCREEN,
"SDL_CreateWindow failed: %s",
SDL_GetError ());
return FALSE;
}
SDL_SetWindowData (window, COGL_SDL_WINDOW_DATA_KEY, onscreen);
onscreen->winsys = g_slice_new (CoglOnscreenSdl2);
sdl_onscreen = onscreen->winsys;
sdl_onscreen->window = window;
return TRUE;
}
static void
_cogl_winsys_onscreen_swap_buffers_with_damage (CoglOnscreen *onscreen,
const int *rectangles,
int n_rectangles)
{
CoglOnscreenSdl2 *sdl_onscreen = onscreen->winsys;
SDL_GL_SwapWindow (sdl_onscreen->window);
}
static void
_cogl_winsys_onscreen_update_swap_throttled (CoglOnscreen *onscreen)
{
CoglContext *context = COGL_FRAMEBUFFER (onscreen)->context;
CoglContextSdl2 *sdl_context = context->winsys;
CoglOnscreenSdl2 *sdl_onscreen = onscreen->winsys;
if (sdl_context->current_window != sdl_onscreen->window)
return;
sdl_context->current_window = NULL;
_cogl_winsys_onscreen_bind (onscreen);
}
static void
_cogl_winsys_onscreen_set_visibility (CoglOnscreen *onscreen,
CoglBool visibility)
{
CoglOnscreenSdl2 *sdl_onscreen = onscreen->winsys;
if (visibility)
SDL_ShowWindow (sdl_onscreen->window);
else
SDL_HideWindow (sdl_onscreen->window);
}
SDL_Window *
cogl_sdl_onscreen_get_window (CoglOnscreen *onscreen)
{
CoglOnscreenSdl2 *sdl_onscreen;
_COGL_RETURN_VAL_IF_FAIL (cogl_is_onscreen (onscreen), NULL);
if (!cogl_framebuffer_allocate (COGL_FRAMEBUFFER (onscreen), NULL))
return NULL;
sdl_onscreen = onscreen->winsys;
return sdl_onscreen->window;
}
const CoglWinsysVtable *
_cogl_winsys_sdl_get_vtable (void)
{
static CoglBool vtable_inited = FALSE;
static CoglWinsysVtable vtable;
/* It would be nice if we could use C99 struct initializers here
like the GLX backend does. However this code is more likely to be
compiled using Visual Studio which (still!) doesn't support them
so we initialize it in code instead */
if (!vtable_inited)
{
memset (&vtable, 0, sizeof (vtable));
vtable.id = COGL_WINSYS_ID_SDL;
vtable.name = "SDL";
vtable.renderer_get_proc_address = _cogl_winsys_renderer_get_proc_address;
vtable.renderer_connect = _cogl_winsys_renderer_connect;
vtable.renderer_disconnect = _cogl_winsys_renderer_disconnect;
vtable.display_setup = _cogl_winsys_display_setup;
vtable.display_destroy = _cogl_winsys_display_destroy;
vtable.context_init = _cogl_winsys_context_init;
vtable.context_deinit = _cogl_winsys_context_deinit;
vtable.onscreen_init = _cogl_winsys_onscreen_init;
vtable.onscreen_deinit = _cogl_winsys_onscreen_deinit;
vtable.onscreen_bind = _cogl_winsys_onscreen_bind;
vtable.onscreen_swap_buffers_with_damage =
_cogl_winsys_onscreen_swap_buffers_with_damage;
vtable.onscreen_update_swap_throttled =
_cogl_winsys_onscreen_update_swap_throttled;
vtable.onscreen_set_visibility = _cogl_winsys_onscreen_set_visibility;
vtable_inited = TRUE;
}
return &vtable;
}

View File

@ -225,29 +225,6 @@ AC_ARG_ENABLE(installed_tests,
AM_CONDITIONAL(ENABLE_INSTALLED_TESTS, test x$enable_installed_tests = xyes)
dnl ============================================================
dnl Emscripten support
dnl ============================================================
AC_ARG_ENABLE(
[emscripten],
[AC_HELP_STRING([--enable-emscripten=@<:@no/yes@:>@], [Support building for emscripten])],
[],
enable_emscripten=no
)
AS_IF([test "x$enable_emscripten" = "xyes"],
[
enable_standalone=yes
enable_sdl=yes
enable_gles2=yes
enable_gl=no
AC_DEFINE([USING_EMSCRIPTEN], 1, [Cogl is being compiled with emscripten])
COGL_DEFINES_SYMBOLS="$COGL_DEFINES_SYMBOLS COGL_HAS_EMSCRIPTEN_SUPPORT"
]
)
AM_CONDITIONAL(USING_EMSCRIPTEN, [test "$enable_emscripten" = "yes"])
dnl ============================================================
dnl Standalone cogl
dnl ============================================================
@ -732,33 +709,24 @@ AS_IF([test "x$enable_gles2" = "xyes"],
COGL_DEFINES_SYMBOLS="$COGL_DEFINES_SYMBOLS COGL_HAS_GLES2"
HAVE_GLES2=1
AS_IF([test "x$enable_emscripten" = "xyes"],
[
GL_LIBRARY_DIRECTLY_LINKED=yes
COGL_GLES2_LIBNAME=""
AC_DEFINE([HAVE_COGL_WEBGL], 1, [Have WebGL for rendering])
],
PKG_CHECK_EXISTS([glesv2],
[COGL_PKG_REQUIRES_GL="$COGL_PKG_REQUIRES_GL glesv2"
COGL_GLES2_LIBNAME="libGLESv2.so"
],
[
# We have to check the two headers independently as GLES2/gl2ext.h
# needs to include GLES2/gl2.h to have the GL types defined (eg.
# GLenum).
AC_CHECK_HEADER([GLES2/gl2.h],
[],
[AC_MSG_ERROR([Unable to locate GLES2/gl2.h])])
AC_CHECK_HEADER([GLES2/gl2ext.h],
[],
[AC_MSG_ERROR([Unable to locate GLES2/gl2ext.h])],
[#include <GLES2/gl2.h>])
[
PKG_CHECK_EXISTS([glesv2],
[COGL_PKG_REQUIRES_GL="$COGL_PKG_REQUIRES_GL glesv2"
COGL_GLES2_LIBNAME="libGLESv2.so"
],
[
# We have to check the two headers independently as GLES2/gl2ext.h
# needs to include GLES2/gl2.h to have the GL types defined (eg.
# GLenum).
AC_CHECK_HEADER([GLES2/gl2.h],
[],
[AC_MSG_ERROR([Unable to locate GLES2/gl2.h])])
AC_CHECK_HEADER([GLES2/gl2ext.h],
[],
[AC_MSG_ERROR([Unable to locate GLES2/gl2ext.h])],
[#include <GLES2/gl2.h>])
COGL_GLES2_LIBNAME="libGLESv2.so"
])
])
COGL_GLES2_LIBNAME="libGLESv2.so"
])
])
HAVE_GL=0
@ -919,93 +887,6 @@ AS_IF([test "x$enable_wgl" = "xyes"],
])
AM_CONDITIONAL(SUPPORT_WGL, [test "x$SUPPORT_WGL" = "xyes"])
AC_ARG_ENABLE(
[sdl],
[AC_HELP_STRING([--enable-sdl=@<:@no/yes@:>@], [Enable support SDL @<:@default=no@:>@])],
[],
[enable_sdl=no])
AS_IF([test "x$enable_sdl" = "xyes"],
[
AS_IF([test "x$enable_emscripten" = "xno"],
[
PKG_CHECK_MODULES([SDL],
[sdl],
[
COGL_PKG_REQUIRES="$COGL_PKG_REQUIRES sdl"
],
[
AC_CHECK_HEADER([SDL/SDL.h],
[],
[AC_MSG_ERROR([SDL support requested but SDL not found])])
])
])
SUPPORT_SDL=yes
GL_WINSYS_APIS="$GL_WINSYS_APIS sdl"
COGL_DEFINES_SYMBOLS="$COGL_DEFINES_SYMBOLS COGL_HAS_SDL_SUPPORT"
dnl If we are building with emscripten then that simply implies we are
dnl using SDL in conjunction with WebGL (GLES2)
AS_IF([test "x$enable_emscripten" = "xyes"],
[
SUPPORTED_SDL_GL_APIS="webgl"
SUPPORT_SDL_WEBGL=yes
SUPPORT_SDL_GLES=no
COGL_DEFINES_SYMBOLS="$COGL_DEFINES_SYMBOLS COGL_HAS_SDL_WEBGL_SUPPORT"
],
[
dnl WebOS has a specially patched version of SDL to add
dnl support for creating a GLES1/2 context. This tries to
dnl detect that patch so we can use it if the GLES2 driver is
dnl selected.
cogl_save_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $SDL_CFLAGS"
AC_CHECK_DECL([SDL_OPENGLES],
[SUPPORT_SDL_GLES=yes],
[SUPPORT_SDL_GLES=no],
[#include <SDL.h>])
AC_CHECK_DECL([SDL_GL_CONTEXT_MAJOR_VERSION], [], [SUPPORT_SDL_GLES=no],
[#include <SDL.h>])
AC_CHECK_DECL([SDL_GL_CONTEXT_MINOR_VERSION], [], [SUPPORT_SDL_GLES=no],
[#include <SDL.h>])
CPPFLAGS="$cogl_save_CPPFLAGS"
AS_IF([test "x$SUPPORT_SDL_GLES" = "xyes"],
[
SUPPORTED_SDL_GL_APIS="gles1 gles2"
COGL_DEFINES_SYMBOLS="$COGL_DEFINES_SYMBOLS COGL_HAS_SDL_GLES_SUPPORT"
],
[ SUPPORTED_SDL_GL_APIS="gl" ])
])
],
[SUPPORT_SDL=no])
AM_CONDITIONAL(SUPPORT_SDL, [test "x$SUPPORT_SDL" = "xyes"])
AC_ARG_ENABLE(
[sdl2],
[AC_HELP_STRING([--enable-sdl2=@<:@no/yes@:>@], [Enable SDL2 support @<:@default=no@:>@])],
[],
[enable_sdl2=no])
AS_IF([test "x$enable_sdl2" = "xyes"],
[
PKG_CHECK_MODULES([SDL2],
[sdl2],
[],
[AC_MSG_ERROR([SDL2 support requested but SDL2 not found])])
SUPPORT_SDL2=yes
GL_WINSYS_APIS="$GL_WINSYS_APIS sdl2"
COGL_PKG_REQUIRES="$COGL_PKG_REQUIRES sdl2"
COGL_DEFINES_SYMBOLS="$COGL_DEFINES_SYMBOLS COGL_HAS_SDL_SUPPORT"
],
[SUPPORT_SDL2=no])
AM_CONDITIONAL(SUPPORT_SDL2, [test "x$SUPPORT_SDL2" = "xyes"])
AS_IF([test "x$SUPPORT_SDL2" = "xyes" -a "x$SUPPORT_SDL" = "xyes"],
[AC_MSG_ERROR([The SDL1 and SDL2 winsyses are currently mutually exclusive])])
EGL_PLATFORM_COUNT=0
AC_ARG_ENABLE(
@ -1136,9 +1017,6 @@ AC_ARG_ENABLE(
[],
AS_IF([test "x$enable_gles1" = "xyes" -o \
"x$enable_gles2" = "xyes" && \
test "x$SUPPORT_SDL_GLES" != "xyes" && \
test "x$SUPPORT_SDL_WEBGL" != "xyes" && \
test "x$SUPPORT_SDL2" != "xyes" && \
test $EGL_PLATFORM_COUNT -eq 0],
[enable_xlib_egl_platform=yes], [enable_xlib_egl_platform=no])
)
@ -1315,11 +1193,7 @@ dnl ================================================================
dnl The 'ffs' function is part of C99 so it isn't always
dnl available. Cogl has a fallback if needed.
dnl
dnl XXX: ffs isnt available with the emscripten toolchain currently
dnl but the check passes so we manually skip the check in this case
AS_IF([test "x$enable_emscripten" = "xno"],
[AC_CHECK_FUNCS([ffs])])
AC_CHECK_FUNCS([ffs])
dnl 'memmem' is a GNU extension but we have a simple fallback
AC_CHECK_FUNCS([memmem])
@ -1336,31 +1210,24 @@ dnl ================================================================
dnl These are values from system headers that we want to copy into the
dnl public Cogl headers without having to include the system header
dnl
dnl XXX: poll(2) can't currently be used with emscripten even though
dnl poll.h is in the toolchain headers so we manually skip the check
dnl in this case
have_poll_h=no
AS_IF([test "x$enable_emscripten" = "xno"],
[
AC_CHECK_HEADER(poll.h,
[
AC_COMPUTE_INT(COGL_SYSDEF_POLLIN, POLLIN, [#include <poll.h>],
AC_MSG_ERROR([Unable to get value of POLLIN]))
AC_COMPUTE_INT(COGL_SYSDEF_POLLPRI, POLLPRI, [#include <poll.h>],
AC_MSG_ERROR([Unable to get value of POLLPRI]))
AC_COMPUTE_INT(COGL_SYSDEF_POLLOUT, POLLOUT, [#include <poll.h>],
AC_MSG_ERROR([Unable to get value of POLLOUT]))
AC_COMPUTE_INT(COGL_SYSDEF_POLLERR, POLLERR, [#include <poll.h>],
AC_MSG_ERROR([Unable to get value of POLLERR]))
AC_COMPUTE_INT(COGL_SYSDEF_POLLHUP, POLLHUP, [#include <poll.h>],
AC_MSG_ERROR([Unable to get value of POLLHUP]))
AC_COMPUTE_INT(COGL_SYSDEF_POLLNVAL, POLLNVAL, [#include <poll.h>],
AC_MSG_ERROR([Unable to get value of POLLNVAL]))
COGL_DEFINES_SYMBOLS="$COGL_DEFINES_SYMBOLS COGL_HAS_POLL_SUPPORT"
have_poll_h=yes
])
])
AC_CHECK_HEADER(poll.h,
[
AC_COMPUTE_INT(COGL_SYSDEF_POLLIN, POLLIN, [#include <poll.h>],
AC_MSG_ERROR([Unable to get value of POLLIN]))
AC_COMPUTE_INT(COGL_SYSDEF_POLLPRI, POLLPRI, [#include <poll.h>],
AC_MSG_ERROR([Unable to get value of POLLPRI]))
AC_COMPUTE_INT(COGL_SYSDEF_POLLOUT, POLLOUT, [#include <poll.h>],
AC_MSG_ERROR([Unable to get value of POLLOUT]))
AC_COMPUTE_INT(COGL_SYSDEF_POLLERR, POLLERR, [#include <poll.h>],
AC_MSG_ERROR([Unable to get value of POLLERR]))
AC_COMPUTE_INT(COGL_SYSDEF_POLLHUP, POLLHUP, [#include <poll.h>],
AC_MSG_ERROR([Unable to get value of POLLHUP]))
AC_COMPUTE_INT(COGL_SYSDEF_POLLNVAL, POLLNVAL, [#include <poll.h>],
AC_MSG_ERROR([Unable to get value of POLLNVAL]))
COGL_DEFINES_SYMBOLS="$COGL_DEFINES_SYMBOLS COGL_HAS_POLL_SUPPORT"
have_poll_h=yes
])
AS_IF([test "x$have_poll_h" = "xno"],
[
@ -1441,7 +1308,6 @@ cogl/cogl-1.0.pc
cogl/cogl-2.0-experimental.pc
cogl/cogl-defines.h
cogl/cogl-defines.h.win32
cogl/cogl-defines.h.win32_SDL
cogl/cogl-gl-header.h
cogl/cogl-egl-defines.h
cogl/cogl.rc
@ -1505,10 +1371,6 @@ if test "x$SUPPORT_EGL" = "xyes"; then
echo " EGL Platforms:${EGL_PLATFORMS}"
echo " Wayland compositor support: ${enable_wayland_egl_server}"
fi
if test "x$SUPPORT_SDL" = "xyes"; then
echo " Supported SDL GL APIs: ${SUPPORTED_SDL_GL_APIS}"
fi
echo " Building for emscripten environment: $enable_emscripten"
echo " Build libcogl-gles2 GLES 2.0 frontend api: ${enable_cogl_gles2}"
echo " Image backend: ${COGL_IMAGE_BACKEND}"
echo " Cogl Pango: ${enable_cogl_pango}"

View File

@ -88,39 +88,6 @@ endif
endif #USE_GLIB
# XXX although emscripten "supports sdl" we can't build cogl-sdl-hello
# un-modified for emscripten since emscripten doesn't support
# SDL_WaitEvent() and we need to use some special emscripten apis
# to create a mainloop....
if USING_EMSCRIPTEN
programs += cogl-emscripten-hello
cogl_emscripten_hello_SOURCES = cogl-emscripten-hello.c
cogl_emscripten_hello_LDADD = $(common_ldadd)
else # USING_EMSCRIPTEN
if SUPPORT_SDL
programs += cogl-sdl-hello
cogl_sdl_hello_SOURCES = cogl-sdl-hello.c
cogl_sdl_hello_LDADD = $(common_ldadd)
endif
endif # USING_EMSCRIPTEN
if SUPPORT_SDL2
programs += cogl-sdl2-hello
cogl_sdl2_hello_SOURCES = cogl-sdl2-hello.c
cogl_sdl2_hello_LDADD = $(common_ldadd)
endif
if USING_EMSCRIPTEN
%.html: %.o $(top_builddir)/cogl/.libs/libcogl2.so $(top_builddir)/deps/glib/.libs/libglib.a
$(CC) $(AM_CFLAGS) $(CFLAGS) --js-library $(top_srcdir)/examples/emscripten-example-js-library.js -o $@ $^
all-local: $(addsuffix .html, $(programs))
endif
if INSTALL_EXAMPLES
bin_PROGRAMS = $(programs)
else

View File

@ -147,8 +147,6 @@ get_winsys_name_for_id (CoglWinsysID winsys_id)
return "EGL + Mir platform";
case COGL_WINSYS_ID_WGL:
return "EGL + Windows WGL platform";
case COGL_WINSYS_ID_SDL:
return "EGL + SDL platform";
}
g_return_val_if_reached ("Unknown");
}

View File

@ -1,156 +0,0 @@
#include <cogl/cogl.h>
#include <cogl/cogl-sdl.h>
#include <stdio.h>
#include <SDL.h>
/* This short example is just to demonstrate mixing SDL with Cogl as a
simple way to get portable support for events */
typedef struct Data
{
CoglPrimitive *triangle;
CoglPipeline *pipeline;
float center_x, center_y;
CoglFramebuffer *fb;
CoglBool quit;
CoglBool redraw_queued;
CoglBool ready_to_draw;
} Data;
static void
redraw (Data *data)
{
CoglFramebuffer *fb = data->fb;
cogl_framebuffer_clear4f (fb, COGL_BUFFER_BIT_COLOR, 0, 0, 0, 1);
cogl_framebuffer_push_matrix (fb);
cogl_framebuffer_translate (fb, data->center_x, -data->center_y, 0.0f);
cogl_primitive_draw (data->triangle, fb, data->pipeline);
cogl_framebuffer_pop_matrix (fb);
cogl_onscreen_swap_buffers (COGL_ONSCREEN (fb));
}
static void
dirty_cb (CoglOnscreen *onscreen,
const CoglOnscreenDirtyInfo *info,
void *user_data)
{
Data *data = user_data;
data->redraw_queued = TRUE;
}
static void
handle_event (Data *data, SDL_Event *event)
{
switch (event->type)
{
case SDL_MOUSEMOTION:
{
int width =
cogl_framebuffer_get_width (COGL_FRAMEBUFFER (data->fb));
int height =
cogl_framebuffer_get_height (COGL_FRAMEBUFFER (data->fb));
data->center_x = event->motion.x * 2.0f / width - 1.0f;
data->center_y = event->motion.y * 2.0f / height - 1.0f;
data->redraw_queued = TRUE;
}
break;
case SDL_QUIT:
data->quit = TRUE;
break;
}
}
static void
frame_cb (CoglOnscreen *onscreen,
CoglFrameEvent event,
CoglFrameInfo *info,
void *user_data)
{
Data *data = user_data;
if (event == COGL_FRAME_EVENT_SYNC)
data->ready_to_draw = TRUE;
}
int
main (int argc, char **argv)
{
CoglContext *ctx;
CoglOnscreen *onscreen;
CoglError *error = NULL;
CoglVertexP2C4 triangle_vertices[] = {
{0, 0.7, 0xff, 0x00, 0x00, 0xff},
{-0.7, -0.7, 0x00, 0xff, 0x00, 0xff},
{0.7, -0.7, 0x00, 0x00, 0xff, 0xff}
};
Data data;
SDL_Event event;
ctx = cogl_sdl_context_new (SDL_USEREVENT, &error);
if (!ctx)
{
fprintf (stderr, "Failed to create context: %s\n", error->message);
return 1;
}
onscreen = cogl_onscreen_new (ctx, 800, 600);
data.fb = COGL_FRAMEBUFFER (onscreen);
cogl_onscreen_add_frame_callback (onscreen,
frame_cb,
&data,
NULL /* destroy callback */);
cogl_onscreen_add_dirty_callback (onscreen,
dirty_cb,
&data,
NULL /* destroy callback */);
data.center_x = 0.0f;
data.center_y = 0.0f;
data.quit = FALSE;
cogl_onscreen_show (onscreen);
data.triangle = cogl_primitive_new_p2c4 (ctx, COGL_VERTICES_MODE_TRIANGLES,
3, triangle_vertices);
data.pipeline = cogl_pipeline_new (ctx);
data.redraw_queued = FALSE;
data.ready_to_draw = TRUE;
while (!data.quit)
{
if (!SDL_PollEvent (&event))
{
if (data.redraw_queued && data.ready_to_draw)
{
redraw (&data);
data.redraw_queued = FALSE;
data.ready_to_draw = FALSE;
continue;
}
cogl_sdl_idle (ctx);
if (!SDL_WaitEvent (&event))
{
fprintf (stderr, "Error waiting for SDL events");
return 1;
}
}
handle_event (&data, &event);
cogl_sdl_handle_event (ctx, &event);
}
cogl_object_unref (ctx);
return 0;
}

View File

@ -1,169 +0,0 @@
#include <cogl/cogl.h>
#include <cogl/cogl-sdl.h>
#include <stdio.h>
#include <SDL.h>
/* This short example is just to demonstrate mixing SDL with Cogl as a
simple way to get portable support for events */
typedef struct Data
{
CoglPrimitive *triangle;
CoglPipeline *pipeline;
float center_x, center_y;
CoglFramebuffer *fb;
CoglBool quit;
CoglBool redraw_queued;
CoglBool ready_to_draw;
} Data;
static void
redraw (Data *data)
{
CoglFramebuffer *fb = data->fb;
cogl_framebuffer_clear4f (fb, COGL_BUFFER_BIT_COLOR, 0, 0, 0, 1);
cogl_framebuffer_push_matrix (fb);
cogl_framebuffer_translate (fb, data->center_x, -data->center_y, 0.0f);
cogl_primitive_draw (data->triangle, fb, data->pipeline);
cogl_framebuffer_pop_matrix (fb);
cogl_onscreen_swap_buffers (COGL_ONSCREEN (fb));
}
static void
dirty_cb (CoglOnscreen *onscreen,
const CoglOnscreenDirtyInfo *info,
void *user_data)
{
Data *data = user_data;
data->redraw_queued = TRUE;
}
static void
handle_event (Data *data, SDL_Event *event)
{
switch (event->type)
{
case SDL_WINDOWEVENT:
switch (event->window.event)
{
case SDL_WINDOWEVENT_CLOSE:
data->quit = TRUE;
break;
}
break;
case SDL_MOUSEMOTION:
{
int width =
cogl_framebuffer_get_width (data->fb);
int height =
cogl_framebuffer_get_height (data->fb);
data->center_x = event->motion.x * 2.0f / width - 1.0f;
data->center_y = event->motion.y * 2.0f / height - 1.0f;
data->redraw_queued = TRUE;
}
break;
case SDL_QUIT:
data->quit = TRUE;
break;
}
}
static void
frame_cb (CoglOnscreen *onscreen,
CoglFrameEvent event,
CoglFrameInfo *info,
void *user_data)
{
Data *data = user_data;
if (event == COGL_FRAME_EVENT_SYNC)
data->ready_to_draw = TRUE;
}
int
main (int argc, char **argv)
{
CoglContext *ctx;
CoglOnscreen *onscreen;
CoglError *error = NULL;
CoglVertexP2C4 triangle_vertices[] = {
{0, 0.7, 0xff, 0x00, 0x00, 0xff},
{-0.7, -0.7, 0x00, 0xff, 0x00, 0xff},
{0.7, -0.7, 0x00, 0x00, 0xff, 0xff}
};
Data data;
SDL_Event event;
ctx = cogl_sdl_context_new (SDL_USEREVENT, &error);
if (!ctx)
{
fprintf (stderr, "Failed to create context: %s\n", error->message);
return 1;
}
onscreen = cogl_onscreen_new (ctx, 800, 600);
data.fb = onscreen;
cogl_onscreen_add_frame_callback (onscreen,
frame_cb,
&data,
NULL /* destroy callback */);
cogl_onscreen_add_dirty_callback (onscreen,
dirty_cb,
&data,
NULL /* destroy callback */);
data.center_x = 0.0f;
data.center_y = 0.0f;
data.quit = FALSE;
/* In SDL2, setting resizable only works before allocating the
* onscreen */
cogl_onscreen_set_resizable (onscreen, TRUE);
cogl_onscreen_show (onscreen);
data.triangle = cogl_primitive_new_p2c4 (ctx, COGL_VERTICES_MODE_TRIANGLES,
3, triangle_vertices);
data.pipeline = cogl_pipeline_new (ctx);
data.redraw_queued = FALSE;
data.ready_to_draw = TRUE;
while (!data.quit)
{
if (!SDL_PollEvent (&event))
{
if (data.redraw_queued && data.ready_to_draw)
{
redraw (&data);
data.redraw_queued = FALSE;
data.ready_to_draw = FALSE;
continue;
}
cogl_sdl_idle (ctx);
if (!SDL_WaitEvent (&event))
{
fprintf (stderr, "Error waiting for SDL events");
return 1;
}
}
handle_event (&data, &event);
cogl_sdl_handle_event (ctx, &event);
}
cogl_object_unref (ctx);
return 0;
}

View File

@ -68,14 +68,9 @@ test_sources = \
test-texture-no-allocate.c \
test-pipeline-shader-state.c \
test-texture-rg.c \
test-fence.c \
$(NULL)
if !USING_EMSCRIPTEN
# test-fence depends on the glib mainloop so it won't compile if using
# emscripten which builds in standalone mode.
test_sources += test-fence.c
endif
if BUILD_COGL_PATH
test_sources += \
test-path.c \