Merge pull request #5248 from Mailaender/sdl2-opentk

Ported Tao.OpenAL/OpenGL to SDL2/OpenTK
This commit is contained in:
Paul Chote
2014-05-09 20:24:40 +12:00
21 changed files with 279 additions and 299 deletions

View File

@@ -100,8 +100,8 @@ distributed under the MIT license.
Using SharpFont created by Robert Rouhani and
distributed under the MIT license.
Using the Tao framework and distributed under
the MIT license.
Using the Open Toolkit distributed under the
MIT license.
Using SDL2# created by Ethan Lee and released
under the zlib license.

View File

@@ -80,7 +80,7 @@ VERSION = $(shell git name-rev --name-only --tags --no-undefined HEAD 2>/dev
game_SRCS := $(shell find OpenRA.Game/ -iname '*.cs')
game_TARGET = OpenRA.Game.exe
game_KIND = winexe
game_LIBS = $(COMMON_LIBS) $(game_DEPS) thirdparty/Tao/Tao.OpenAl.dll thirdparty/SharpFont.dll
game_LIBS = $(COMMON_LIBS) $(game_DEPS) thirdparty/SDL2-CS.dll thirdparty/SharpFont.dll
game_FLAGS = -win32icon:OpenRA.Game/OpenRA.ico
PROGRAMS += game
game: $(game_TARGET)
@@ -98,7 +98,7 @@ rsdl2_SRCS := $(shell find OpenRA.Renderer.Sdl2/ -iname '*.cs')
rsdl2_TARGET = OpenRA.Renderer.Sdl2.dll
rsdl2_KIND = library
rsdl2_DEPS = $(game_TARGET)
rsdl2_LIBS = $(COMMON_LIBS) thirdparty/Tao/Tao.OpenGl.dll thirdparty/SDL2-CS.dll $(rsdl2_DEPS)
rsdl2_LIBS = $(COMMON_LIBS) thirdparty/SDL2-CS.dll $(rsdl2_DEPS)
rnull_SRCS := $(shell find OpenRA.Renderer.Null/ -iname '*.cs')
rnull_TARGET = OpenRA.Renderer.Null.dll
@@ -276,7 +276,6 @@ endif
dependencies:
@ $(CP_R) thirdparty/*.dl* .
@ $(CP_R) thirdparty/Tao/* .
@ $(CP_R) thirdparty/${platformdeps}/* .
version: mods/ra/mod.yaml mods/cnc/mod.yaml mods/d2k/mod.yaml mods/modchooser/mod.yaml
@@ -315,7 +314,6 @@ install-core: default
@$(CP_R) glsl "$(DATA_INSTALL_DIR)"
@$(CP_R) lua "$(DATA_INSTALL_DIR)"
@$(CP) *.ttf "$(DATA_INSTALL_DIR)"
@$(CP) thirdparty/Tao/* "$(DATA_INSTALL_DIR)"
@$(CP) thirdparty/SDL2-CS* "$(DATA_INSTALL_DIR)"
@$(CP) thirdparty/Eluant* "$(DATA_INSTALL_DIR)"
@$(INSTALL_PROGRAM) thirdparty/ICSharpCode.SharpZipLib.dll "$(DATA_INSTALL_DIR)"

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
@@ -14,33 +14,33 @@ using OpenRA.Graphics;
namespace OpenRA
{
[AttributeUsage( AttributeTargets.Assembly )]
[AttributeUsage(AttributeTargets.Assembly)]
public class RendererAttribute : Attribute
{
public readonly Type Type;
public RendererAttribute( Type graphicsDeviceType )
public RendererAttribute(Type graphicsDeviceType)
{
if( !typeof( IDeviceFactory ).IsAssignableFrom( graphicsDeviceType ) )
throw new InvalidOperationException( "Incorrect type in RendererAttribute" );
if (!typeof(IDeviceFactory).IsAssignableFrom(graphicsDeviceType))
throw new InvalidOperationException("Incorrect type in RendererAttribute");
Type = graphicsDeviceType;
}
}
public interface IDeviceFactory
{
IGraphicsDevice Create( Size size, WindowMode windowMode );
IGraphicsDevice Create(Size size, WindowMode windowMode);
}
public enum BlendMode { None, Alpha, Additive, Subtractive, Multiply }
public interface IGraphicsDevice
{
IVertexBuffer<Vertex> CreateVertexBuffer( int length );
ITexture CreateTexture( Bitmap bitmap );
IVertexBuffer<Vertex> CreateVertexBuffer(int length);
ITexture CreateTexture(Bitmap bitmap);
ITexture CreateTexture();
IFrameBuffer CreateFrameBuffer(Size s);
IShader CreateShader( string name );
IShader CreateShader(string name);
Size WindowSize { get; }
@@ -48,10 +48,10 @@ namespace OpenRA
void Present();
void PumpInput(IInputHandler inputHandler);
void DrawPrimitives( PrimitiveType type, int firstVertex, int numVertices );
void DrawPrimitives(PrimitiveType type, int firstVertex, int numVertices);
void SetLineWidth( float width );
void EnableScissor( int left, int top, int width, int height );
void SetLineWidth(float width);
void EnableScissor(int left, int top, int width, int height);
void DisableScissor();
void EnableDepthBuffer();
@@ -65,7 +65,7 @@ namespace OpenRA
public interface IVertexBuffer<T>
{
void Bind();
void SetData( T[] vertices, int length );
void SetData(T[] vertices, int length);
}
public interface IShader
@@ -105,7 +105,7 @@ namespace OpenRA
public struct Range<T>
{
public readonly T Start, End;
public Range( T start, T end ) { Start = start; End = end; }
public Range(T start, T end) { Start = start; End = end; }
}
public enum WindowMode

View File

@@ -76,10 +76,6 @@
<Reference Include="Eluant">
<HintPath>..\thirdparty\Eluant.dll</HintPath>
</Reference>
<Reference Include="Tao.OpenAl, Version=1.1.0.1, Culture=neutral, PublicKeyToken=a7579dda88828311">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\thirdparty\Tao\Tao.OpenAl.dll</HintPath>
</Reference>
<Reference Include="ICSharpCode.SharpZipLib">
<HintPath>..\thirdparty\ICSharpCode.SharpZipLib.dll</HintPath>
</Reference>
@@ -89,6 +85,9 @@
<Reference Include="MaxMind.Db">
<HintPath>..\thirdparty\MaxMind.Db.dll</HintPath>
</Reference>
<Reference Include="SDL2-CS">
<HintPath>..\thirdparty\SDL2-CS.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Actor.cs" />

View File

@@ -16,7 +16,8 @@ using OpenRA.FileSystem;
using OpenRA.GameRules;
using OpenRA.Primitives;
using OpenRA.Traits;
using Tao.OpenAl;
using OpenTK;
using OpenTK.Audio.OpenAL;
namespace OpenRA
{
@@ -449,13 +450,13 @@ namespace OpenRA
float volume = 1f;
Dictionary<int, PoolSlot> sourcePool = new Dictionary<int, PoolSlot>();
static string[] QueryDevices(string label, int type)
static string[] QueryDevices(string label, AlcGetStringList type)
{
// Clear error bit
Al.alGetError();
AL.GetError();
var devices = Alc.alcGetStringv(IntPtr.Zero, type);
if (Al.alGetError() != Al.AL_NO_ERROR)
var devices = Alc.GetString(IntPtr.Zero, type).ToArray();
if (AL.GetError() != ALError.NoError)
{
Log.Write("sound", "Failed to query OpenAL device list using {0}", label);
return new string[] { };
@@ -466,12 +467,12 @@ namespace OpenRA
public static string[] AvailableDevices()
{
// Returns all devices under windows vista and newer
if (Alc.alcIsExtensionPresent(IntPtr.Zero, "ALC_ENUMERATE_ALL_EXT") == Alc.ALC_TRUE)
return QueryDevices("ALC_ENUMERATE_ALL_EXT", Alc.ALC_ALL_DEVICES_SPECIFIER);
// Returns all devices under Windows Vista and newer
if (Alc.IsExtensionPresent(IntPtr.Zero, "ALC_ENUMERATE_ALL_EXT"))
return QueryDevices("ALC_ENUMERATE_ALL_EXT", AlcGetStringList.AllDevicesSpecifier);
if (Alc.alcIsExtensionPresent(IntPtr.Zero, "ALC_ENUMERATION_EXT") == Alc.ALC_TRUE)
return QueryDevices("ALC_ENUMERATION_EXT", Alc.ALC_DEVICE_SPECIFIER);
if (Alc.IsExtensionPresent(IntPtr.Zero, "ALC_ENUMERATION_EXT"))
return QueryDevices("ALC_ENUMERATION_EXT", AlcGetStringList.DeviceSpecifier);
return new string[] { };
}
@@ -485,25 +486,25 @@ namespace OpenRA
else
Console.WriteLine("Using default device");
var dev = Alc.alcOpenDevice(Game.Settings.Sound.Device);
var dev = Alc.OpenDevice(Game.Settings.Sound.Device);
if (dev == IntPtr.Zero)
{
Console.WriteLine("Failed to open device. Falling back to default");
dev = Alc.alcOpenDevice(null);
dev = Alc.OpenDevice(null);
if (dev == IntPtr.Zero)
throw new InvalidOperationException("Can't create OpenAL device");
}
var ctx = Alc.alcCreateContext(dev, IntPtr.Zero);
if (ctx == IntPtr.Zero)
var ctx = Alc.CreateContext(dev, (int[])null);
if (ctx == ContextHandle.Zero)
throw new InvalidOperationException("Can't create OpenAL context");
Alc.alcMakeContextCurrent(ctx);
Alc.MakeContextCurrent(ctx);
for (var i = 0; i < PoolSize; i++)
{
var source = 0;
Al.alGenSources(1, out source);
if (0 != Al.alGetError())
AL.GenSources(1, out source);
if (0 != AL.GetError())
{
Log.Write("sound", "Failed generating OpenAL source {0}", i);
return;
@@ -528,8 +529,8 @@ namespace OpenRA
foreach (int key in sourcePool.Keys)
{
int state;
Al.alGetSourcei(key, Al.AL_SOURCE_STATE, out state);
if (state != Al.AL_PLAYING && state != Al.AL_PAUSED)
AL.GetSource(key, ALGetSourcei.SourceState, out state);
if (state != (int)ALSourceState.Playing && state != (int)ALSourceState.Paused)
freeSources.Add(key);
}
@@ -606,7 +607,7 @@ namespace OpenRA
public float Volume
{
get { return volume; }
set { Al.alListenerf(Al.AL_GAIN, volume = value); }
set { AL.Listener(ALListenerf.Gain, volume = value); }
}
public void PauseSound(ISound sound, bool paused)
@@ -616,11 +617,11 @@ namespace OpenRA
var key = ((OpenAlSound)sound).Source;
int state;
Al.alGetSourcei(key, Al.AL_SOURCE_STATE, out state);
if (state == Al.AL_PLAYING && paused)
Al.alSourcePause(key);
else if (state == Al.AL_PAUSED && !paused)
Al.alSourcePlay(key);
AL.GetSource(key, ALGetSourcei.SourceState, out state);
if (state == (int)ALSourceState.Playing && paused)
AL.SourcePause(key);
else if (state == (int)ALSourceState.Paused && !paused)
AL.SourcePlay(key);
}
public void SetAllSoundsPaused(bool paused)
@@ -628,11 +629,11 @@ namespace OpenRA
foreach (var key in sourcePool.Keys)
{
int state;
Al.alGetSourcei(key, Al.AL_SOURCE_STATE, out state);
if (state == Al.AL_PLAYING && paused)
Al.alSourcePause(key);
else if (state == Al.AL_PAUSED && !paused)
Al.alSourcePlay(key);
AL.GetSource(key, ALGetSourcei.SourceState, out state);
if (state == (int)ALSourceState.Playing && paused)
AL.SourcePause(key);
else if (state == (int)ALSourceState.Paused && !paused)
AL.SourcePlay(key);
}
}
@@ -641,14 +642,14 @@ namespace OpenRA
var sounds = sourcePool.Select(s => s.Key).Where(b =>
{
int state;
Al.alGetSourcei(b, Al.AL_SOURCE_STATE, out state);
return (state == Al.AL_PLAYING || state == Al.AL_PAUSED) &&
AL.GetSource(b, ALGetSourcei.SourceState, out state);
return (state == (int)ALSourceState.Playing || state == (int)ALSourceState.Paused) &&
(music == null || b != ((OpenAlSound)music).Source) &&
(video == null || b != ((OpenAlSound)video).Source);
});
foreach (var s in sounds)
Al.alSourcef(s, Al.AL_GAIN, volume);
AL.Source(s, ALSourcef.Gain, volume);
}
public void StopSound(ISound sound)
@@ -658,9 +659,9 @@ namespace OpenRA
var key = ((OpenAlSound)sound).Source;
int state;
Al.alGetSourcei(key, Al.AL_SOURCE_STATE, out state);
if (state == Al.AL_PLAYING || state == Al.AL_PAUSED)
Al.alSourceStop(key);
AL.GetSource(key, ALGetSourcei.SourceState, out state);
if (state == (int)ALSourceState.Playing || state == (int)ALSourceState.Paused)
AL.SourceStop(key);
}
public void StopAllSounds()
@@ -668,20 +669,20 @@ namespace OpenRA
foreach (var key in sourcePool.Keys)
{
int state;
Al.alGetSourcei(key, Al.AL_SOURCE_STATE, out state);
if (state == Al.AL_PLAYING || state == Al.AL_PAUSED)
Al.alSourceStop(key);
AL.GetSource(key, ALGetSourcei.SourceState, out state);
if (state == (int)ALSourceState.Playing || state == (int)ALSourceState.Paused)
AL.SourceStop(key);
}
}
public void SetListenerPosition(WPos position)
{
// Move the listener out of the plane so that sounds near the middle of the screen aren't too positional
Al.alListener3f(Al.AL_POSITION, position.X, position.Y, position.Z + 2133);
AL.Listener(ALListener3f.Position, position.X, position.Y, position.Z + 2133);
var orientation = new[] { 0f, 0f, 1f, 0f, -1f, 0f };
Al.alListenerfv(Al.AL_ORIENTATION, ref orientation[0]);
Al.alListenerf(Al.AL_METERS_PER_UNIT, .01f);
AL.Listener(ALListenerfv.Orientation, ref orientation);
AL.Listener(ALListenerf.EfxMetersPerUnit, .01f);
}
}
@@ -689,18 +690,18 @@ namespace OpenRA
{
public readonly int Buffer;
static int MakeALFormat(int channels, int bits)
static ALFormat MakeALFormat(int channels, int bits)
{
if (channels == 1)
return bits == 16 ? Al.AL_FORMAT_MONO16 : Al.AL_FORMAT_MONO8;
return bits == 16 ? ALFormat.Mono16 : ALFormat.Mono8;
else
return bits == 16 ? Al.AL_FORMAT_STEREO16 : Al.AL_FORMAT_STEREO8;
return bits == 16 ? ALFormat.Stereo16 : ALFormat.Stereo8;
}
public OpenAlSoundSource(byte[] data, int channels, int sampleBits, int sampleRate)
{
Al.alGenBuffers(1, out Buffer);
Al.alBufferData(Buffer, MakeALFormat(channels, sampleBits), data, data.Length, sampleRate);
AL.GenBuffers(1, out Buffer);
AL.BufferData(Buffer, MakeALFormat(channels, sampleBits), data, data.Length, sampleRate);
}
}
@@ -717,16 +718,16 @@ namespace OpenRA
Source = source;
Volume = volume;
Al.alSourcef(source, Al.AL_PITCH, 1f);
Al.alSource3f(source, Al.AL_POSITION, pos.X, pos.Y, pos.Z);
Al.alSource3f(source, Al.AL_VELOCITY, 0f, 0f, 0f);
Al.alSourcei(source, Al.AL_BUFFER, buffer);
Al.alSourcei(source, Al.AL_LOOPING, looping ? Al.AL_TRUE : Al.AL_FALSE);
Al.alSourcei(source, Al.AL_SOURCE_RELATIVE, relative ? 1 : 0);
AL.Source(source, ALSourcef.Pitch, 1f);
AL.Source(source, ALSource3f.Position, pos.X, pos.Y, pos.Z);
AL.Source(source, ALSource3f.Velocity, 0f, 0f, 0f);
AL.Source(source, ALSourcei.Buffer, buffer);
AL.Source(source, ALSourceb.Looping, looping);
AL.Source(source, ALSourceb.SourceRelative, relative);
Al.alSourcef(source, Al.AL_REFERENCE_DISTANCE, 6826);
Al.alSourcef(source, Al.AL_MAX_DISTANCE, 136533);
Al.alSourcePlay(source);
AL.Source(source, ALSourcef.ReferenceDistance, 6826);
AL.Source(source, ALSourcef.MaxDistance, 136533);
AL.SourcePlay(source);
}
public float Volume
@@ -739,7 +740,7 @@ namespace OpenRA
set
{
if (Source != -1)
Al.alSourcef(Source, Al.AL_GAIN, volume = value);
AL.Source(Source, ALSourcef.Gain, volume = value);
}
}
@@ -747,8 +748,8 @@ namespace OpenRA
{
get
{
float pos;
Al.alGetSourcef(Source, Al.AL_SAMPLE_OFFSET, out pos);
int pos;
AL.GetSource(Source, ALGetSourcei.SampleOffset, out pos);
return pos / 22050f;
}
}
@@ -758,8 +759,8 @@ namespace OpenRA
get
{
int state;
Al.alGetSourcei(Source, Al.AL_SOURCE_STATE, out state);
return state == Al.AL_PLAYING;
AL.GetSource(Source, ALGetSourcei.SourceState, out state);
return state == (int)ALSourceState.Playing;
}
}
}

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
@@ -10,37 +10,36 @@
using System;
using System.Diagnostics;
using Tao.OpenGl;
using OpenTK.Graphics.OpenGL;
namespace OpenRA.Renderer.Sdl2
{
public static class ErrorHandler
{
public enum GlError
{
GL_NO_ERROR = Gl.GL_NO_ERROR,
GL_INVALID_ENUM = Gl.GL_INVALID_ENUM,
GL_INVALID_VALUE = Gl.GL_INVALID_VALUE,
GL_STACK_OVERFLOW = Gl.GL_STACK_OVERFLOW,
GL_STACK_UNDERFLOW = Gl.GL_STACK_UNDERFLOW,
GL_OUT_OF_MEMORY = Gl.GL_OUT_OF_MEMORY,
GL_TABLE_TOO_LARGE = Gl.GL_TABLE_TOO_LARGE,
GL_INVALID_OPERATION = Gl.GL_INVALID_OPERATION,
static Version OpenGLversion;
// Framebuffer errors
GL_FRAMEBUFFER_COMPLETE_EXT = Gl.GL_FRAMEBUFFER_COMPLETE_EXT,
GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT = Gl.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT,
GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT = Gl.GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT,
GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT = Gl.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT,
GL_FRAMEBUFFER_UNSUPPORTED_EXT = Gl.GL_FRAMEBUFFER_UNSUPPORTED_EXT,
public static void CheckGlVersion()
{
var version = GL.GetString(StringName.Version).Split(' ')[0].Split('.');
int major;
int.TryParse(version[0], out major);
int minor;
int.TryParse(version[1], out minor);
Console.WriteLine("Detected OpenGL version: {0}.{1}".F(major, minor));
OpenGLversion = new Version(major, minor);
if (major < 2)
{
WriteGraphicsLog("OpenRA requires OpenGL version 2.0 or greater.");
throw new InvalidProgramException("OpenGL Version Error: See graphics.log for details.");
}
}
public static void CheckGlError()
{
var n = Gl.glGetError();
if (n != Gl.GL_NO_ERROR)
var n = GL.GetError();
if (n != ErrorCode.NoError)
{
var error = "GL Error: {0}\n{1}".F((GlError)n, new StackTrace());
var error = "GL Error: {0}\n{1}".F(n, new StackTrace());
WriteGraphicsLog(error);
throw new InvalidOperationException("OpenGL Error: See graphics.log for details.");
}
@@ -51,12 +50,22 @@ namespace OpenRA.Renderer.Sdl2
Log.Write("graphics", message);
Log.Write("graphics", "");
Log.Write("graphics", "OpenGL Information:");
Log.Write("graphics", "Vendor: {0}", Gl.glGetString(Gl.GL_VENDOR));
Log.Write("graphics", "Renderer: {0}", Gl.glGetString(Gl.GL_RENDERER));
Log.Write("graphics", "GL Version: {0}", Gl.glGetString(Gl.GL_VERSION));
Log.Write("graphics", "Shader Version: {0}", Gl.glGetString(Gl.GL_SHADING_LANGUAGE_VERSION));
Log.Write("graphics", "Vendor: {0}", GL.GetString(StringName.Vendor));
if (GL.GetString(StringName.Vendor).Contains("Microsoft"))
{
Log.Write("graphics", "Note: The default driver provided by Microsoft does not include full OpenGL support.\n"
+ "Please install the latest drivers from your graphics card manufacturer's website.\n");
}
Log.Write("graphics", "Renderer: {0}", GL.GetString(StringName.Renderer));
Log.Write("graphics", "GL Version: {0}", GL.GetString(StringName.Version));
if (OpenGLversion.Major < 2)
{
Log.Write("graphics", "Note: OpenRA requires OpenGL version 2.0+.\n"
+"Please update your graphics card drivers to the latest version.\n");
}
Log.Write("graphics", "Shader Version: {0}", GL.GetString(StringName.ShadingLanguageVersion));
Log.Write("graphics", "Available extensions:");
Log.Write("graphics", Gl.glGetString(Gl.GL_EXTENSIONS));
Log.Write("graphics", GL.GetString(StringName.Extensions));
}
}
}

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
@@ -13,7 +13,7 @@ using System.Diagnostics;
using System.Drawing;
using System.IO;
using OpenRA.Graphics;
using Tao.OpenGl;
using OpenTK.Graphics.OpenGL;
namespace OpenRA.Renderer.Sdl2
{
@@ -29,41 +29,41 @@ namespace OpenRA.Renderer.Sdl2
if (!Exts.IsPowerOf2(size.Width) || !Exts.IsPowerOf2(size.Height))
throw new InvalidDataException("Frame buffer size ({0}x{1}) must be a power of two".F(size.Width, size.Height));
Gl.glGenFramebuffersEXT(1, out framebuffer);
GL.Ext.GenFramebuffers(1, out framebuffer);
ErrorHandler.CheckGlError();
Gl.glBindFramebufferEXT(Gl.GL_FRAMEBUFFER_EXT, framebuffer);
GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, framebuffer);
ErrorHandler.CheckGlError();
// Color
texture = new Texture();
texture.SetEmpty(size.Width, size.Height);
Gl.glFramebufferTexture2DEXT(Gl.GL_FRAMEBUFFER_EXT, Gl.GL_COLOR_ATTACHMENT0_EXT, Gl.GL_TEXTURE_2D, texture.ID, 0);
GL.Ext.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment0Ext, TextureTarget.Texture2D, texture.ID, 0);
ErrorHandler.CheckGlError();
// Depth
Gl.glGenRenderbuffersEXT(1, out depth);
GL.Ext.GenRenderbuffers(1, out depth);
ErrorHandler.CheckGlError();
Gl.glBindRenderbufferEXT(Gl.GL_RENDERBUFFER_EXT, depth);
GL.Ext.BindRenderbuffer(RenderbufferTarget.RenderbufferExt, depth);
ErrorHandler.CheckGlError();
Gl.glRenderbufferStorageEXT(Gl.GL_RENDERBUFFER_EXT, Gl.GL_DEPTH_COMPONENT, size.Width, size.Height);
GL.Ext.RenderbufferStorage(RenderbufferTarget.RenderbufferExt, (RenderbufferStorage)All.DepthComponent, size.Width, size.Height);
ErrorHandler.CheckGlError();
Gl.glFramebufferRenderbufferEXT(Gl.GL_FRAMEBUFFER_EXT, Gl.GL_DEPTH_ATTACHMENT_EXT, Gl.GL_RENDERBUFFER_EXT, depth);
GL.Ext.FramebufferRenderbuffer(FramebufferTarget.FramebufferExt, FramebufferAttachment.DepthAttachmentExt, RenderbufferTarget.RenderbufferExt, depth);
ErrorHandler.CheckGlError();
// Test for completeness
var status = Gl.glCheckFramebufferStatusEXT(Gl.GL_FRAMEBUFFER_EXT);
if (status != Gl.GL_FRAMEBUFFER_COMPLETE_EXT)
var status = GL.Ext.CheckFramebufferStatus(FramebufferTarget.FramebufferExt);
if (status != FramebufferErrorCode.FramebufferCompleteExt)
{
var error = "Error creating framebuffer: {0}\n{1}".F((ErrorHandler.GlError)status, new StackTrace());
var error = "Error creating framebuffer: {0}\n{1}".F(status, new StackTrace());
ErrorHandler.WriteGraphicsLog(error);
throw new InvalidOperationException("OpenGL Error: See graphics.log for details.");
}
// Restore default buffer
Gl.glBindFramebufferEXT(Gl.GL_FRAMEBUFFER_EXT, 0);
GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, 0);
ErrorHandler.CheckGlError();
}
@@ -74,8 +74,7 @@ namespace OpenRA.Renderer.Sdl2
{
fixed (int* ptr = &v[0])
{
IntPtr intPtr = new IntPtr((void*)ptr);
Gl.glGetIntegerv(Gl.GL_VIEWPORT, intPtr);
GL.GetInteger(GetPName.Viewport, ptr);
}
}
@@ -85,9 +84,9 @@ namespace OpenRA.Renderer.Sdl2
void FinalizeInner()
{
Gl.glDeleteFramebuffersEXT(1, ref framebuffer);
GL.Ext.DeleteFramebuffers(1, ref framebuffer);
ErrorHandler.CheckGlError();
Gl.glDeleteRenderbuffersEXT(1, ref depth);
GL.Ext.DeleteRenderbuffers(1, ref depth);
ErrorHandler.CheckGlError();
}
@@ -99,25 +98,25 @@ namespace OpenRA.Renderer.Sdl2
// Cache viewport rect to restore when unbinding
cv = ViewportRectangle();
Gl.glFlush();
GL.Flush();
ErrorHandler.CheckGlError();
Gl.glBindFramebufferEXT(Gl.GL_FRAMEBUFFER_EXT, framebuffer);
GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, framebuffer);
ErrorHandler.CheckGlError();
Gl.glViewport(0, 0, size.Width, size.Height);
GL.Viewport(0, 0, size.Width, size.Height);
ErrorHandler.CheckGlError();
Gl.glClearColor(0, 0, 0, 0);
GL.ClearColor(0, 0, 0, 0);
ErrorHandler.CheckGlError();
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
ErrorHandler.CheckGlError();
}
public void Unbind()
{
Gl.glFlush();
GL.Flush();
ErrorHandler.CheckGlError();
Gl.glBindFramebufferEXT(Gl.GL_FRAMEBUFFER_EXT, 0);
GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, 0);
ErrorHandler.CheckGlError();
Gl.glViewport(cv[0], cv[1], cv[2], cv[3]);
GL.Viewport(cv[0], cv[1], cv[2], cv[3]);
ErrorHandler.CheckGlError();
}

View File

@@ -33,9 +33,6 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="Tao.OpenGl">
<HintPath>..\thirdparty\Tao\Tao.OpenGl.dll</HintPath>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="SDL2-CS">
<HintPath>..\thirdparty\SDL2-CS.dll</HintPath>

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2013 The OpenRA Developers (see AUTHORS)
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
@@ -14,7 +14,7 @@ using System.Linq;
using OpenRA;
using OpenRA.Graphics;
using SDL2;
using Tao.OpenGl;
using OpenTK.Graphics.OpenGL;
[assembly: Renderer(typeof(OpenRA.Renderer.Sdl2.DeviceFactory))]
@@ -31,17 +31,9 @@ namespace OpenRA.Renderer.Sdl2
public class Sdl2GraphicsDevice : IGraphicsDevice
{
static string[] requiredExtensions =
{
"GL_ARB_vertex_shader",
"GL_ARB_fragment_shader",
"GL_ARB_vertex_buffer_object",
"GL_EXT_framebuffer_object"
};
Size size;
Sdl2Input input;
IntPtr window;
IntPtr context, window;
public Size WindowSize { get { return size; } }
@@ -84,23 +76,22 @@ namespace OpenRA.Renderer.Sdl2
}
SDL.SDL_ShowCursor(0);
SDL.SDL_GL_CreateContext(window);
context = SDL.SDL_GL_CreateContext(window);
SDL.SDL_GL_MakeCurrent(window, context);
GL.LoadAll();
ErrorHandler.CheckGlVersion();
ErrorHandler.CheckGlError();
var extensions = Gl.glGetString(Gl.GL_EXTENSIONS);
if (extensions == null)
Console.WriteLine("Failed to fetch GL_EXTENSIONS, this is bad.");
var missingExtensions = requiredExtensions.Where(r => !extensions.Contains(r)).ToArray();
if (missingExtensions.Any())
if (SDL.SDL_GL_ExtensionSupported("GL_EXT_framebuffer_object") == SDL.SDL_bool.SDL_FALSE)
{
ErrorHandler.WriteGraphicsLog("Unsupported GPU: Missing extensions: {0}".F(missingExtensions.JoinWith(",")));
throw new InvalidProgramException("Unsupported GPU. See graphics.log for details.");
ErrorHandler.WriteGraphicsLog("OpenRA requires the OpenGL extension GL_EXT_framebuffer_object.\n"
+"Please try updating your GPU driver to the latest version provided by the manufacturer.");
throw new InvalidProgramException("Missing OpenGL extension GL_EXT_framebuffer_object. See graphics.log for details.");
}
Gl.glEnableClientState(Gl.GL_VERTEX_ARRAY);
GL.EnableClientState(ArrayCap.VertexArray);
ErrorHandler.CheckGlError();
Gl.glEnableClientState(Gl.GL_TEXTURE_COORD_ARRAY);
GL.EnableClientState(ArrayCap.TextureCoordArray);
ErrorHandler.CheckGlError();
SDL.SDL_SetModState(0);
@@ -109,17 +100,19 @@ namespace OpenRA.Renderer.Sdl2
public virtual void Quit()
{
SDL.SDL_GL_DeleteContext(context);
SDL.SDL_DestroyWindow(window);
SDL.SDL_Quit();
}
int ModeFromPrimitiveType(PrimitiveType pt)
BeginMode ModeFromPrimitiveType(PrimitiveType pt)
{
switch (pt)
{
case PrimitiveType.PointList: return Gl.GL_POINTS;
case PrimitiveType.LineList: return Gl.GL_LINES;
case PrimitiveType.TriangleList: return Gl.GL_TRIANGLES;
case PrimitiveType.QuadList: return Gl.GL_QUADS;
case PrimitiveType.PointList: return BeginMode.Points;
case PrimitiveType.LineList: return BeginMode.Lines;
case PrimitiveType.TriangleList: return BeginMode.Triangles;
case PrimitiveType.QuadList: return BeginMode.Quads;
}
throw new NotImplementedException();
@@ -127,63 +120,63 @@ namespace OpenRA.Renderer.Sdl2
public void DrawPrimitives(PrimitiveType pt, int firstVertex, int numVertices)
{
Gl.glDrawArrays(ModeFromPrimitiveType(pt), firstVertex, numVertices);
GL.DrawArrays(ModeFromPrimitiveType(pt), firstVertex, numVertices);
ErrorHandler.CheckGlError();
}
public void Clear()
{
Gl.glClearColor(0, 0, 0, 0);
GL.ClearColor(0, 0, 0, 0);
ErrorHandler.CheckGlError();
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
GL.Clear(ClearBufferMask.ColorBufferBit);
ErrorHandler.CheckGlError();
}
public void EnableDepthBuffer()
{
Gl.glClear(Gl.GL_DEPTH_BUFFER_BIT);
GL.Clear(ClearBufferMask.DepthBufferBit);
ErrorHandler.CheckGlError();
Gl.glEnable(Gl.GL_DEPTH_TEST);
GL.Enable(EnableCap.DepthTest);
ErrorHandler.CheckGlError();
}
public void DisableDepthBuffer()
{
Gl.glDisable(Gl.GL_DEPTH_TEST);
GL.Disable(EnableCap.DepthTest);
ErrorHandler.CheckGlError();
}
public void SetBlendMode(BlendMode mode)
{
Gl.glBlendEquation(Gl.GL_FUNC_ADD);
GL.BlendEquation(BlendEquationMode.FuncAdd);
ErrorHandler.CheckGlError();
switch (mode)
{
case BlendMode.None:
Gl.glDisable(Gl.GL_BLEND);
GL.Disable(EnableCap.Blend);
break;
case BlendMode.Alpha:
Gl.glEnable(Gl.GL_BLEND);
GL.Enable(EnableCap.Blend);
ErrorHandler.CheckGlError();
Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA);
GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
break;
case BlendMode.Additive:
Gl.glEnable(Gl.GL_BLEND);
GL.Enable(EnableCap.Blend);
ErrorHandler.CheckGlError();
Gl.glBlendFunc(Gl.GL_ONE, Gl.GL_ONE);
GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.One);
break;
case BlendMode.Subtractive:
Gl.glEnable(Gl.GL_BLEND);
GL.Enable(EnableCap.Blend);
ErrorHandler.CheckGlError();
Gl.glBlendFunc(Gl.GL_ONE, Gl.GL_ONE);
GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.One);
ErrorHandler.CheckGlError();
Gl.glBlendEquation(Gl.GL_FUNC_REVERSE_SUBTRACT);
GL.BlendEquation(BlendEquationMode.FuncReverseSubtract);
break;
case BlendMode.Multiply:
Gl.glEnable(Gl.GL_BLEND);
GL.Enable(EnableCap.Blend);
ErrorHandler.CheckGlError();
Gl.glBlendFuncSeparate(Gl.GL_DST_COLOR, Gl.GL_ZERO, Gl.GL_ONE, Gl.GL_ONE_MINUS_SRC_ALPHA);
GL.BlendFuncSeparate(BlendingFactorSrc.DstColor, BlendingFactorDest.Zero, BlendingFactorSrc.One, BlendingFactorDest.OneMinusSrcAlpha);
ErrorHandler.CheckGlError();
break;
}
@@ -199,21 +192,21 @@ namespace OpenRA.Renderer.Sdl2
if (height < 0)
height = 0;
Gl.glScissor(left, size.Height - (top + height), width, height);
GL.Scissor(left, size.Height - (top + height), width, height);
ErrorHandler.CheckGlError();
Gl.glEnable(Gl.GL_SCISSOR_TEST);
GL.Enable(EnableCap.ScissorTest);
ErrorHandler.CheckGlError();
}
public void DisableScissor()
{
Gl.glDisable(Gl.GL_SCISSOR_TEST);
GL.Disable(EnableCap.ScissorTest);
ErrorHandler.CheckGlError();
}
public void SetLineWidth(float width)
{
Gl.glLineWidth(width);
GL.LineWidth(width);
ErrorHandler.CheckGlError();
}

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
@@ -14,7 +14,8 @@ using System.IO;
using System.Text;
using OpenRA.FileSystem;
using OpenRA.Graphics;
using Tao.OpenGl;
using OpenTK;
using OpenTK.Graphics.OpenGL;
namespace OpenRA.Renderer.Sdl2
{
@@ -31,76 +32,73 @@ namespace OpenRA.Renderer.Sdl2
using (var file = new StreamReader(GlobalFileSystem.Open("glsl{0}{1}.vert".F(Path.DirectorySeparatorChar, name))))
vertexCode = file.ReadToEnd();
var v = Gl.glCreateShaderObjectARB(Gl.GL_VERTEX_SHADER_ARB);
var vertexShader = GL.CreateShader(ShaderType.VertexShader);
ErrorHandler.CheckGlError();
Gl.glShaderSourceARB(v, 1, new string[] { vertexCode }, null);
GL.ShaderSource(vertexShader, vertexCode);
ErrorHandler.CheckGlError();
Gl.glCompileShaderARB(v);
GL.CompileShader(vertexShader);
ErrorHandler.CheckGlError();
int success;
Gl.glGetObjectParameterivARB(v, Gl.GL_OBJECT_COMPILE_STATUS_ARB, out success);
GL.GetShader(vertexShader, ShaderParameter.CompileStatus, out success);
ErrorHandler.CheckGlError();
if (success == 0)
throw new InvalidProgramException("Compile error in {0}{1}.vert".F(Path.DirectorySeparatorChar, name));
if (success == (int)All.False)
throw new InvalidProgramException("Compile error in glsl{0}{1}.vert".F(Path.DirectorySeparatorChar, name));
// Fragment shader
string fragmentCode;
using (var file = new StreamReader(GlobalFileSystem.Open("glsl{0}{1}.frag".F(Path.DirectorySeparatorChar, name))))
fragmentCode = file.ReadToEnd();
var f = Gl.glCreateShaderObjectARB(Gl.GL_FRAGMENT_SHADER_ARB);
var fragmentShader = GL.CreateShader(ShaderType.FragmentShader);
ErrorHandler.CheckGlError();
Gl.glShaderSourceARB(f, 1, new string[] { fragmentCode }, null);
GL.ShaderSource(fragmentShader, fragmentCode);
ErrorHandler.CheckGlError();
Gl.glCompileShaderARB(f);
GL.CompileShader(fragmentShader);
ErrorHandler.CheckGlError();
Gl.glGetObjectParameterivARB(f, Gl.GL_OBJECT_COMPILE_STATUS_ARB, out success);
GL.GetShader(vertexShader, ShaderParameter.CompileStatus, out success);
ErrorHandler.CheckGlError();
if (success == 0)
if (success == (int)All.False)
throw new InvalidProgramException("Compile error in glsl{0}{1}.frag".F(Path.DirectorySeparatorChar, name));
// Assemble program
program = Gl.glCreateProgramObjectARB();
program = GL.CreateProgram();
ErrorHandler.CheckGlError();
Gl.glAttachObjectARB(program, v);
GL.AttachShader(program, vertexShader);
ErrorHandler.CheckGlError();
Gl.glAttachObjectARB(program, f);
GL.AttachShader(program, fragmentShader);
ErrorHandler.CheckGlError();
Gl.glLinkProgramARB(program);
GL.LinkProgram(program);
ErrorHandler.CheckGlError();
Gl.glGetObjectParameterivARB(program, Gl.GL_OBJECT_LINK_STATUS_ARB, out success);
GL.GetProgram(program, ProgramParameter.LinkStatus, out success);
ErrorHandler.CheckGlError();
if (success == 0)
if (success == (int)All.False)
throw new InvalidProgramException("Linking error in {0} shader".F(name));
Gl.glUseProgramObjectARB(program);
GL.UseProgram(program);
ErrorHandler.CheckGlError();
int numUniforms;
Gl.glGetObjectParameterivARB(program, Gl.GL_ACTIVE_UNIFORMS, out numUniforms);
GL.GetProgram(program, ProgramParameter.ActiveUniforms, out numUniforms);
ErrorHandler.CheckGlError();
int nextTexUnit = 0;
for (var i = 0; i < numUniforms; i++)
{
int length, size, type;
int length, size;
ActiveUniformType type;
var sb = new StringBuilder(128);
Gl.glGetActiveUniformARB(program, i, 128, out length, out size, out type, sb);
GL.GetActiveUniform(program, i, 128, out length, out size, out type, sb);
var sampler = sb.ToString();
ErrorHandler.CheckGlError();
if (type == Gl.GL_SAMPLER_2D_ARB)
if (type == ActiveUniformType.Sampler2D)
{
samplers.Add(sampler, nextTexUnit);
var loc = Gl.glGetUniformLocationARB(program, sampler);
var loc = GL.GetUniformLocation(program, sampler);
ErrorHandler.CheckGlError();
Gl.glUniform1iARB(loc, nextTexUnit);
GL.Uniform1(loc, nextTexUnit);
ErrorHandler.CheckGlError();
nextTexUnit++;
@@ -110,13 +108,13 @@ namespace OpenRA.Renderer.Sdl2
public void Render(Action a)
{
Gl.glUseProgramObjectARB(program);
GL.UseProgram(program);
// bind the textures
foreach (var kv in textures)
{
Gl.glActiveTextureARB(Gl.GL_TEXTURE0_ARB + kv.Key);
Gl.glBindTexture(Gl.GL_TEXTURE_2D, ((Texture)kv.Value).ID);
GL.ActiveTexture(TextureUnit.Texture0 + kv.Key);
GL.BindTexture(TextureTarget.Texture2D, ((Texture)kv.Value).ID);
}
ErrorHandler.CheckGlError();
@@ -136,34 +134,34 @@ namespace OpenRA.Renderer.Sdl2
public void SetVec(string name, float x)
{
Gl.glUseProgramObjectARB(program);
GL.UseProgram(program);
ErrorHandler.CheckGlError();
var param = Gl.glGetUniformLocationARB(program, name);
var param = GL.GetUniformLocation(program, name);
ErrorHandler.CheckGlError();
Gl.glUniform1fARB(param, x);
GL.Uniform1(param, x);
ErrorHandler.CheckGlError();
}
public void SetVec(string name, float x, float y)
{
Gl.glUseProgramObjectARB(program);
GL.UseProgram(program);
ErrorHandler.CheckGlError();
var param = Gl.glGetUniformLocationARB(program, name);
var param = GL.GetUniformLocation(program, name);
ErrorHandler.CheckGlError();
Gl.glUniform2fARB(param, x, y);
GL.Uniform2(param, x, y);
ErrorHandler.CheckGlError();
}
public void SetVec(string name, float[] vec, int length)
{
var param = Gl.glGetUniformLocationARB(program, name);
var param = GL.GetUniformLocation(program, name);
ErrorHandler.CheckGlError();
switch (length)
{
case 1: Gl.glUniform1fv(param, 1, vec); break;
case 2: Gl.glUniform2fv(param, 1, vec); break;
case 3: Gl.glUniform3fv(param, 1, vec); break;
case 4: Gl.glUniform4fv(param, 1, vec); break;
case 1: GL.Uniform1(param, 1, vec); break;
case 2: GL.Uniform2(param, 1, vec); break;
case 3: GL.Uniform3(param, 1, vec); break;
case 4: GL.Uniform4(param, 1, vec); break;
default: throw new InvalidDataException("Invalid vector length");
}
@@ -175,11 +173,11 @@ namespace OpenRA.Renderer.Sdl2
if (mtx.Length != 16)
throw new InvalidDataException("Invalid 4x4 matrix");
Gl.glUseProgramObjectARB(program);
GL.UseProgram(program);
ErrorHandler.CheckGlError();
var param = Gl.glGetUniformLocationARB(program, name);
var param = GL.GetUniformLocation(program, name);
ErrorHandler.CheckGlError();
Gl.glUniformMatrix4fv(param, 1, Gl.GL_FALSE, mtx);
GL.UniformMatrix4(param, 1, false, mtx);
ErrorHandler.CheckGlError();
}
}

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
@@ -13,7 +13,7 @@ using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using OpenRA.Graphics;
using Tao.OpenGl;
using OpenTK.Graphics.OpenGL;
namespace OpenRA.Renderer.Sdl2
{
@@ -27,38 +27,38 @@ namespace OpenRA.Renderer.Sdl2
public Texture()
{
Gl.glGenTextures(1, out texture);
GL.GenTextures(1, out texture);
ErrorHandler.CheckGlError();
}
public Texture(Bitmap bitmap)
{
Gl.glGenTextures(1, out texture);
GL.GenTextures(1, out texture);
ErrorHandler.CheckGlError();
SetData(bitmap);
}
void FinalizeInner() { Gl.glDeleteTextures(1, ref texture); }
void FinalizeInner() { GL.DeleteTextures(1, ref texture); }
~Texture() { Game.RunAfterTick(FinalizeInner); }
void PrepareTexture()
{
ErrorHandler.CheckGlError();
Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture);
GL.BindTexture(TextureTarget.Texture2D, texture);
ErrorHandler.CheckGlError();
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_NEAREST);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMinFilter.Nearest);
ErrorHandler.CheckGlError();
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_NEAREST);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
ErrorHandler.CheckGlError();
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_CLAMP_TO_EDGE);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (float)TextureWrapMode.ClampToEdge);
ErrorHandler.CheckGlError();
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_CLAMP_TO_EDGE);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (float)TextureWrapMode.ClampToEdge);
ErrorHandler.CheckGlError();
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_BASE_LEVEL, 0);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureBaseLevel, 0);
ErrorHandler.CheckGlError();
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAX_LEVEL, 0);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMaxLevel, 0);
ErrorHandler.CheckGlError();
}
@@ -74,8 +74,8 @@ namespace OpenRA.Renderer.Sdl2
{
IntPtr intPtr = new IntPtr((void*)ptr);
PrepareTexture();
Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGBA8, width, height,
0, Gl.GL_BGRA, Gl.GL_UNSIGNED_BYTE, intPtr);
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8, width, height,
0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, intPtr);
ErrorHandler.CheckGlError();
}
}
@@ -97,8 +97,8 @@ namespace OpenRA.Renderer.Sdl2
{
IntPtr intPtr = new IntPtr((void*)ptr);
PrepareTexture();
Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGBA8, width, height,
0, Gl.GL_BGRA, Gl.GL_UNSIGNED_BYTE, intPtr);
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8, width, height,
0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, intPtr);
ErrorHandler.CheckGlError();
}
}
@@ -111,11 +111,11 @@ namespace OpenRA.Renderer.Sdl2
size = new Size(bitmap.Width, bitmap.Height);
var bits = bitmap.LockBits(bitmap.Bounds(),
ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
PrepareTexture();
Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGBA8, bits.Width, bits.Height,
0, Gl.GL_BGRA, Gl.GL_UNSIGNED_BYTE, bits.Scan0); // todo: weird strides
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8, bits.Width, bits.Height,
0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bits.Scan0); // TODO: weird strides
ErrorHandler.CheckGlError();
bitmap.UnlockBits(bits);
}
@@ -125,13 +125,13 @@ namespace OpenRA.Renderer.Sdl2
var data = new byte[4 * size.Width * size.Height];
ErrorHandler.CheckGlError();
Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture);
GL.BindTexture(TextureTarget.Texture2D, texture);
unsafe
{
fixed (byte* ptr = &data[0])
{
IntPtr intPtr = new IntPtr((void*)ptr);
Gl.glGetTexImage(Gl.GL_TEXTURE_2D, 0, Gl.GL_BGRA, Gl.GL_UNSIGNED_BYTE, intPtr);
GL.GetTexImage(TextureTarget.Texture2D, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, intPtr);
}
}
@@ -146,8 +146,8 @@ namespace OpenRA.Renderer.Sdl2
size = new Size(width, height);
PrepareTexture();
Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGBA8, width, height,
0, Gl.GL_BGRA, Gl.GL_UNSIGNED_BYTE, null);
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8, width, height,
0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero);
ErrorHandler.CheckGlError();
}
}

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
@@ -11,7 +11,7 @@
using System;
using System.Runtime.InteropServices;
using OpenRA.Graphics;
using Tao.OpenGl;
using OpenTK.Graphics.OpenGL;
namespace OpenRA.Renderer.Sdl2
{
@@ -23,20 +23,21 @@ namespace OpenRA.Renderer.Sdl2
public VertexBuffer(int size)
{
Gl.glGenBuffersARB(1, out buffer);
GL.GenBuffers(1, out buffer);
ErrorHandler.CheckGlError();
Bind();
Gl.glBufferDataARB(Gl.GL_ARRAY_BUFFER_ARB,
GL.BufferData(BufferTarget.ArrayBuffer,
new IntPtr(VertexSize * size),
new T[size],
Gl.GL_DYNAMIC_DRAW_ARB);
BufferUsageHint.DynamicDraw
);
ErrorHandler.CheckGlError();
}
public void SetData(T[] data, int length)
{
Bind();
Gl.glBufferSubDataARB(Gl.GL_ARRAY_BUFFER_ARB,
GL.BufferSubData(BufferTarget.ArrayBuffer,
IntPtr.Zero,
new IntPtr(VertexSize * length),
data);
@@ -45,15 +46,15 @@ namespace OpenRA.Renderer.Sdl2
public void Bind()
{
Gl.glBindBufferARB(Gl.GL_ARRAY_BUFFER_ARB, buffer);
GL.BindBuffer(BufferTarget.ArrayBuffer, buffer);
ErrorHandler.CheckGlError();
Gl.glVertexPointer(3, Gl.GL_FLOAT, VertexSize, IntPtr.Zero);
GL.VertexPointer(3, VertexPointerType.Float, VertexSize, IntPtr.Zero);
ErrorHandler.CheckGlError();
Gl.glTexCoordPointer(4, Gl.GL_FLOAT, VertexSize, new IntPtr(12));
GL.TexCoordPointer(4, TexCoordPointerType.Float, VertexSize, new IntPtr(12));
ErrorHandler.CheckGlError();
}
void FinalizeInner() { Gl.glDeleteBuffersARB(1, ref buffer); }
void FinalizeInner() { GL.DeleteBuffers(1, ref buffer); }
~VertexBuffer() { Game.RunAfterTick(FinalizeInner); }
}
}

View File

@@ -76,7 +76,6 @@ elseif ($command -eq "version")
elseif ($command -eq "dependencies")
{
cp thirdparty/*.dll .
cp thirdparty/Tao/*.dll .
cp thirdparty/windows/*.dll .
echo "Dependencies copied."
}

View File

@@ -41,9 +41,6 @@ for i in "${FILES[@]}"; do
cp -R "${i}" "packaging/built/${i}" || exit 3
done
# Copy Tao
cp thirdparty/Tao/* packaging/built
# SharpZipLib for zip file support
cp thirdparty/ICSharpCode.SharpZipLib.dll packaging/built

View File

@@ -81,7 +81,6 @@ Section "Game" GAME
File "${SRCDIR}\DOCUMENTATION.html"
File "${SRCDIR}\*.ttf"
File "${SRCDIR}\OpenRA.ico"
File "${SRCDIR}\Tao.*.dll"
File "${SRCDIR}\SharpFont.dll"
File "${SRCDIR}\SDL2-CS.dll"
File "${SRCDIR}\global mix database.dat"
@@ -93,7 +92,7 @@ Section "Game" GAME
File "${SRCDIR}\KopiLua.dll"
File "${SRCDIR}\NLua.dll"
File "${SRCDIR}\eluant.dll"
File "${DEPSDIR}\OpenAL32.dll"
File "${DEPSDIR}\soft_oal.dll"
File "${DEPSDIR}\SDL2.dll"
File "${DEPSDIR}\freetype6.dll"
File "${DEPSDIR}\zlib1.dll"
@@ -195,7 +194,6 @@ Function ${UN}Clean
Delete $INSTDIR\ICSharpCode.SharpZipLib.dll
Delete $INSTDIR\FuzzyLogicLibrary.dll
Delete $INSTDIR\Mono.Nat.dll
Delete $INSTDIR\Tao.*.dll
Delete $INSTDIR\SharpFont.dll
Delete $INSTDIR\AUTHORS
Delete $INSTDIR\COPYING
@@ -214,7 +212,7 @@ Function ${UN}Clean
Delete $INSTDIR\KopiLua.dll
Delete $INSTDIR\NLua.dll
Delete $INSTDIR\SDL2-CS.dll
Delete $INSTDIR\OpenAL32.dll
Delete $INSTDIR\soft_oal.dll
Delete $INSTDIR\SDL2.dll
Delete $INSTDIR\lua51.dll
Delete $INSTDIR\eluant.dll

View File

@@ -3,4 +3,19 @@
<dllmap os="osx" dll="SDL2.dll" target="libSDL2.dylib"/>
<dllmap os="linux" dll="SDL2.dll" cpu="x86" target="libSDL232.2.0.2.so" />
<dllmap os="linux" dll="SDL2.dll" cpu="x86-64" target="libSDL264.2.0.2.so" />
<dllmap dll="soft_oal.dll" os="osx" target="/System/Library/Frameworks/OpenAL.framework/OpenAL"/>
<dllmap dll="soft_oal.dll" os="linux" target="libopenal.so.1"/>
<dllmap dll="opengl32.dll">
<dllentry os="linux" dll="libGL.so.1" />
<dllentry os="windows" dll="opengl32.dll" />
<dllentry os="osx" dll="/System/Library/Frameworks/OpenGL.framework/OpenGL" />
</dllmap>
<dllmap dll="glu32.dll">
<dllentry os="linux" dll="libGLU.so.1" />
<dllentry os="windows" dll="opengl32.dll" />
<dllentry os="osx" dll="/System/Library/Frameworks/OpenGL.framework/Libraries/libGLU.dylib" />
</dllmap>
</configuration>

Binary file not shown.

View File

@@ -1,12 +0,0 @@
<configuration>
<dllmap dll="OpenAL32.dll">
<dllentry os="linux" dll="libopenal.so.1" />
<dllentry os="windows" dll="OpenAL32.dll" />
<dllentry os="osx" dll="/System/Library/Frameworks/OpenAL.framework/OpenAL" />
</dllmap>
<dllmap dll="alut.dll">
<dllentry os="linux" dll="libalut.so.1" />
<dllentry os="windows" dll="alut.dll" />
<dllentry os="osx" dll="libalut.so.0" />
</dllmap>
</configuration>

Binary file not shown.

View File

@@ -1,12 +0,0 @@
<configuration>
<dllmap dll="opengl32.dll">
<dllentry os="linux" dll="libGL.so.1" />
<dllentry os="windows" dll="opengl32.dll" />
<dllentry os="osx" dll="/System/Library/Frameworks/OpenGL.framework/OpenGL" />
</dllmap>
<dllmap dll="glu32.dll">
<dllentry os="linux" dll="libGLU.so.1" />
<dllentry os="windows" dll="opengl32.dll" />
<dllentry os="osx" dll="/System/Library/Frameworks/OpenGL.framework/Libraries/libGLU.dylib" />
</dllmap>
</configuration>