Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial GLES3 (bis) #517

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions project/ToolkitBuild.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
<set name="mac" value="1" if="macos" />
<set name="native_toolkit_sdl_static" value="1" if="static_link" />

<!-- TODO: test ios, mac -->
<set name="NME_NO_GLES3COMPAT" value="1" unless="windows||android||NME_GLES3COMPAT" />

<!-- Require Android 2.3+ -->
<set name="PLATFORM" value="android-9" if="android" />
<set name="PLATFORM" value="android-14" if="HXCPP_X86" />
<set name="PLATFORM" value="android-18" unless="NME_NO_GLES3COMPAT"/>
<set name="PLATFORM" value="android-21" if="HXCPP_ARM64" />
<set name="HXCPP_CPP11" value="1" />

Expand Down Expand Up @@ -199,6 +203,7 @@
<compilerflag value="-I${NME_INC_DIR}"/>
<compilerflag value="-I${INC_DIR}"/>

<compilerflag value="-DNME_NO_GLES3COMPAT" if="NME_NO_GLES3COMPAT" />
<compilerflag value="-DNME_MODPLUG" if="modplug" />
<compilerflag value="-DSTATIC_LINK" if="NME_STATIC_LINK" />
<compilerflag value="-DNME_INTERNAL_CLIPPING" if="NME_INTERNAL_CLIPPING" />
Expand Down Expand Up @@ -497,20 +502,23 @@
<section if="android">
<lib name="-ldl" />
<lib name="-landroid" />
<lib name="-lGLESv2" />
<lib name="-lGLESv2" if="NME_NO_GLES3COMPAT"/>
<lib name="-lGLESv3" unless="NME_NO_GLES3COMPAT"/>
<lib name="-lEGL" />
<lib name="-lz" />
</section>

<section if="rpi" unless="winrpi" >
<lib name="/opt/vc/lib/libGLESv2.so" />
<lib name="/opt/vc/lib/libGLESv2.so" if="NME_NO_GLES3COMPAT"/>
<lib name="/opt/vc/lib/libGLESv3.so" unless="NME_NO_GLES3COMPAT"/>
<lib name="/opt/vc/lib/libEGL.so" />
<lib name="/opt/vc/lib/libbcm_host.so" />
</section>

<section if="rpi winrpi" >
<libpath name="${haxelib:winrpi}/lib" />
<lib name="-lGLESv2" />
<lib name="-lGLESv2" if="NME_NO_GLES3COMPAT"/>
<lib name="-lGLESv3" unless="NME_NO_GLES3COMPAT"/>
<lib name="-lEGL" />
<lib name="-lvcos" />
<lib name="-lvchiq_arm" />
Expand Down
1 change: 1 addition & 0 deletions project/include/Hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class HardwareRenderer : public HardwareContext
virtual void DestroyShader(unsigned int inShader)=0;
virtual void DestroyFramebuffer(unsigned int inBuffer)=0;
virtual void DestroyRenderbuffer(unsigned int inBuffer)=0;
virtual void DestroyVertexarray(unsigned int inBuffer)=0;

#ifdef NME_S3D
virtual void EndS3DRender()=0;
Expand Down
14 changes: 14 additions & 0 deletions project/src/opengl/OGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@
#define NME_GLES
#define GL_GLEXT_PROTOTYPES

#ifndef NME_NO_GLES3COMPAT
#include <GLES3/gl3.h>
#endif
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>

#elif defined(BLACKBERRY) || defined(ANDROID) || defined(WEBOS) || defined(GPH) || defined(RASPBERRYPI) || defined(EMSCRIPTEN)

#define NME_GLES

#ifndef NME_NO_GLES3COMPAT
#include <GLES3/gl3.h>
#define __gl2_h_ //Not needed for Android Platform >= 21
#endif
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>

Expand All @@ -24,13 +31,20 @@

#include <gl2.h>
#include <gl2ext.h>
#ifndef NME_NO_GLES3COMPAT
#include <gl3.h>
#endif

#elif defined(IPHONE)

#include <OpenGLES/ES1/gl.h>
#include <OpenGLES/ES1/glext.h>
#include <OpenGLES/ES2/gl.h>
#include <OpenGLES/ES2/glext.h>
#ifndef NME_NO_GLES3COMPAT
#include <OpenGLES/ES3/gl.h>
#include <OpenGLES/ES3/glext.h>
#endif

//typedef CAEAGLLayer *WinDC;
//typedef EAGLContext *GLCtx;
Expand Down
46 changes: 41 additions & 5 deletions project/src/opengl/OGLExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ enum ResoType
resoProgram, //4
resoFramebuffer, //5
resoRenderbuffer, //6
resoVertexarray, //7 (GLES3)
};

const char *getTypeString(int inType)
Expand All @@ -59,6 +60,7 @@ const char *getTypeString(int inType)
case resoProgram: return "Program";
case resoFramebuffer: return "Framebuffer";
case resoRenderbuffer: return "Renderbuffer";
case resoVertexarray: return "Vertexarray";
}
return "Unknown";
}
Expand Down Expand Up @@ -306,6 +308,9 @@ class NmeResource : public nme::Object
case resoRenderbuffer:
ctx->DestroyRenderbuffer(id);
break;
case resoVertexarray:
ctx->DestroyVertexarray(id);
break;
}
}
type = resoNone;
Expand Down Expand Up @@ -638,7 +643,6 @@ value nme_gl_get_parameter(value pname_val)
case GL_SAMPLE_BUFFERS:
case GL_SAMPLES:
case GL_SCISSOR_TEST:
case GL_SHADING_LANGUAGE_VERSION:
case GL_STENCIL_BACK_FAIL:
case GL_STENCIL_BACK_FUNC:
case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
Expand All @@ -663,6 +667,7 @@ value nme_gl_get_parameter(value pname_val)

case GL_VENDOR:
case GL_VERSION:
case GL_SHADING_LANGUAGE_VERSION:
case GL_RENDERER:
strings = 1;
break;
Expand Down Expand Up @@ -794,6 +799,17 @@ GL_GEN_RESO(buffer,glGenBuffers,resoBuffer)
GL_GEN_RESO(framebuffer,glGenFramebuffers,resoFramebuffer)
GL_GEN_RESO(render_buffer,glGenRenderbuffers,resoRenderbuffer)

//GLES3
#ifdef NME_NO_GLES3COMPAT
value nme_gl_create_vertexarray(value inType)
{
ELOG("Error: NME_NO_GLES3COMPAT is set");
return alloc_int(-1);
}
DEFINE_PRIM(nme_gl_create_vertexarray,0);
#else
GL_GEN_RESO(vertexarray,glGenVertexArrays,resoVertexarray)
#endif

// --- Stencil -------------------------------------------

Expand Down Expand Up @@ -1376,9 +1392,12 @@ value nme_gl_shader_source(value inId,value inSource)
const char *lines = source.c_str();
#ifdef NME_GLES
// TODO - do something better here
std::string buffer;
buffer = std::string("precision mediump float;\n") + hxToStdString(source);
lines = buffer.c_str();
if (lines[0]!='#' && lines[1]!='v')
{
std::string buffer;
buffer = std::string("precision mediump float;\n") + hxToStdString(source);
lines = buffer.c_str();
}
#endif

glShaderSource(id,1,&lines,0);
Expand Down Expand Up @@ -1756,9 +1775,26 @@ value nme_gl_get_render_buffer_parameter(value target, value pname)
}
DEFINE_PRIM(nme_gl_get_render_buffer_parameter,2);

// --- Drawing -------------------------------



// --- GLES3: VertexArray

value nme_gl_bind_vertexarray(value inId )
{
int id = getResourceId(inId,resoVertexarray);
#ifndef NME_NO_GLES3COMPAT
glBindVertexArray(id);
#endif
return alloc_null();
}
DEFINE_PRIM(nme_gl_bind_vertexarray,1);




// --- Drawing -------------------------------

value nme_gl_draw_arrays(value inMode, value inFirst, value inCount)
{
DBGFUNC("drawArrays");
Expand Down
23 changes: 23 additions & 0 deletions project/src/opengl/OpenGLContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,18 @@ class OGLContext : public HardwareRenderer
else
glDeleteRenderbuffers(1,&inBuffer);
}
void DestroyVertexarray(unsigned int inBuffer)
{
if ( !IsMainThread() )
{
mHasZombie = true;
mZombieVertexarrays.push_back(inBuffer);
}
#ifndef NME_NO_GLES3COMPAT
else
glDeleteVertexArrays(1,&inBuffer);
#endif
}


void OnContextLost()
Expand All @@ -164,6 +176,7 @@ class OGLContext : public HardwareRenderer
mZombieShaders.resize(0);
mZombieFramebuffers.resize(0);
mZombieRenderbuffers.resize(0);
mZombieVertexarrays.resize(0);
mHasZombie = false;
}

Expand Down Expand Up @@ -277,6 +290,14 @@ class OGLContext : public HardwareRenderer
glDeleteRenderbuffers(mZombieRenderbuffers.size(),&mZombieRenderbuffers[0]);
mZombieRenderbuffers.resize(0);
}

if (mZombieVertexarrays.size())
{
#ifndef NME_NO_GLES3COMPAT
glDeleteVertexArrays(mZombieVertexarrays.size(),&mZombieVertexarrays[0]);
#endif
mZombieVertexarrays.resize(0);
}
}


Expand Down Expand Up @@ -316,6 +337,7 @@ class OGLContext : public HardwareRenderer
mZombieShaders.resize(0);
mZombieFramebuffers.resize(0);
mZombieRenderbuffers.resize(0);
mZombieVertexarrays.resize(0);

ReloadExtentions();
}
Expand Down Expand Up @@ -771,6 +793,7 @@ class OGLContext : public HardwareRenderer
QuickVec<GLuint> mZombieShaders;
QuickVec<GLuint> mZombieFramebuffers;
QuickVec<GLuint> mZombieRenderbuffers;
QuickVec<GLuint> mZombieVertexarrays;

GPUProg *mProg[PROG_COUNT];

Expand Down
17 changes: 15 additions & 2 deletions project/src/sdl2/SDL2Stage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ static int sgDesktopWidth = 0;
static int sgDesktopHeight = 0;
static Rect sgWindowRect = Rect(0, 0, 0, 0);
static bool sgInitCalled = false;
//static bool sgJoystickEnabled = false;
static bool sgGameControllerEnabled = false;
static bool sgIsOGL2 = false;
const int sgJoystickDeadZone = 1000;
Expand Down Expand Up @@ -1806,9 +1805,13 @@ void CreateMainFrame(FrameCreationCallback inOnFrame, int inWidth, int inHeight,
if (fullscreen) requestWindowFlags |= FullscreenMode; //SDL_WINDOW_FULLSCREEN_DESKTOP;

#ifdef NME_ANGLE
int major = 3;
#ifdef NME_NO_GLES3COMPAT
major = 2;
#endif
SDL_GL_SetAttribute(SDL_GL_CONTEXT_EGL, 1);
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_MAJOR_VERSION, major);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
#endif

Expand Down Expand Up @@ -1938,6 +1941,16 @@ void CreateMainFrame(FrameCreationCallback inOnFrame, int inWidth, int inHeight,
sgIsOGL2 = false;
}

#ifdef NME_ANGLE
if (!renderer && opengl && major>2)
{
fprintf(stderr, "GLES3 is not available. Retrying with GLES2. (%s)\n", SDL_GetError());
major = 2;
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, major);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
}
else
#endif
if (!renderer && (inFlags & wfHW_AA_HIRES || inFlags & wfHW_AA)) {
// if no window was created and AA was enabled, disable AA and try again
fprintf(stderr, "Multisampling is not available. Retrying without. (%s)\n", SDL_GetError());
Expand Down
41 changes: 41 additions & 0 deletions src/nme/gl/GL3.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package nme.gl;

import nme.display.BitmapData;
import nme.utils.ArrayBuffer;
import nme.utils.ByteArray;
import nme.utils.IMemoryRange;
import nme.utils.ArrayBufferView;
import nme.geom.Matrix3D;
import nme.Lib;
import nme.Loader;

#if (neko||cpp)
import nme.utils.Float32Array;
import nme.utils.Int32Array;
#end


@:nativeProperty
class GL3
{

#if (neko||cpp)

public static inline function bindVertexArray(vertexarray:GLVertexArray):Void
{
nme_gl_bind_vertexarray(vertexarray);
}

public static inline function createVertexArray():GLVertexArray
{
return new GLVertexArray(GL.version, nme_gl_create_vertexarray());
}


// Native Methods
private static var nme_gl_create_vertexarray = GL.load("nme_gl_create_vertexarray", 0);
private static var nme_gl_bind_vertexarray = GL.load("nme_gl_bind_vertexarray", 1);

#end
}

18 changes: 18 additions & 0 deletions src/nme/gl/GLVertexArray.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package nme.gl;
#if (!flash)

@:nativeProperty
class GLVertexArray extends GLObject
{
public function new(inVersion:Int, inId:Dynamic)
{
super(inVersion, inId);
}

override function getType():String
{
return "VertexArray";
}
}

#end
Loading