Skip to content
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
7 changes: 6 additions & 1 deletion project/ToolkitBuild.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
<set name="mac" value="1" if="macos" />
<set name="native_toolkit_sdl_static" value="1" if="static_link" />

<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 @@ -191,6 +194,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 @@ -484,7 +488,8 @@
<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>
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
16 changes: 16 additions & 0 deletions project/src/opengl/OGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,41 @@
#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>
#if defined(ANDROID)
#define __gl2_h_ //For Android Platform < 21
#endif
#endif
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>

#elif defined(TIZEN)

#define NME_GLES

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

#elif defined(IPHONE)

#ifndef NME_NO_GLES3COMPAT
#include <OpenGLES/ES3/gl.h>
#include <OpenGLES/ES3/glext.h>
#endif
#include <OpenGLES/ES1/gl.h>
#include <OpenGLES/ES1/glext.h>
#include <OpenGLES/ES2/gl.h>
Expand Down
47 changes: 42 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)
{
DBGFUNC("create vertex array needs NME_GLES3COMPAT");
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,27 @@ 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 )
{
DBGFUNC("bindVertexArray");
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
23 changes: 22 additions & 1 deletion project/src/sdl2/SDL2Stage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1550,8 +1550,13 @@ void CreateMainFrame(FrameCreationCallback inOnFrame, int inWidth, int inHeight,
#ifdef NME_ANGLE
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);
int major = 3;
#ifdef NME_NO_GLES3COMPAT
major = 2;
#endif
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, major);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
DLOG("1 ");
#endif

if (opengl)
Expand Down Expand Up @@ -1642,6 +1647,12 @@ void CreateMainFrame(FrameCreationCallback inOnFrame, int inWidth, int inHeight,
if (opengl) renderFlags |= SDL_RENDERER_ACCELERATED;
if (opengl && vsync) renderFlags |= SDL_RENDERER_PRESENTVSYNC;

#ifdef NME_ANGLE
//needs to be just before SDL_CreateRenderer because SDL_GetWindowFlags resets it
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, major);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
#endif

renderer = SDL_CreateRenderer (window, -1, renderFlags);

if (opengl)
Expand All @@ -1653,6 +1664,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
14 changes: 14 additions & 0 deletions src/nme/gl/GL.hx
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,11 @@ class GL
nme_gl_bind_texture(target, texture);
}

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

public static inline function blendColor(red:Float, green:Float, blue:Float, alpha:Float):Void
{
nme_gl_blend_color(red, green, blue, alpha);
Expand Down Expand Up @@ -621,6 +626,11 @@ class GL
return new GLTexture(version, nme_gl_create_texture());
}

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

public static inline function cullFace(mode:Int):Void
{
nme_gl_cull_face(mode);
Expand Down Expand Up @@ -1310,6 +1320,10 @@ class GL
private static var nme_gl_vertex_attrib4fv = load("nme_gl_vertex_attrib4fv", 2);
private static var nme_gl_vertex_attrib_pointer = load("nme_gl_vertex_attrib_pointer", -1);
private static var nme_gl_viewport = load("nme_gl_viewport", 4);

//gles3
private static var nme_gl_create_vertexarray = load("nme_gl_create_vertexarray", 0);
private static var nme_gl_bind_vertexarray = load("nme_gl_bind_vertexarray", 1);
#else // not (neko||cpp)

// Stub to get flixel to compile
Expand Down
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