Skip to content

Commit

Permalink
ecere/gfx/drivers/GL3/GLMultiDraw: Moving GLMultiDraw and GLArrayText…
Browse files Browse the repository at this point in the history
…ure classes to ecere library
  • Loading branch information
jerstlouis committed Apr 28, 2020
1 parent db791fc commit ea1511b
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 93 deletions.
84 changes: 76 additions & 8 deletions butterbur/src/opengl/ButterburShader.ec
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,82 @@ import "VersionedShader"

private: // FIXME: eC bug

define squishFactorAttribute = 7;
define drawIDAttribute = 8;
define posOffsetAttribute = 9;

define transform0Attribute = 10;
define transform1Attribute = 11;
define transform2Attribute = 12;
define transform3Attribute = 13;
define squishFactorAttribute = 100;

Size resetDisplaySize;
Size displaySize;
DisplaySystem displaySystem;
Display glDisplay;

GLCapabilities glCaps;
bool glCaps_nonPow2Textures, glCaps_vertexBuffer, glCaps_quads, glCaps_intAndDouble, glCaps_legacyFormats, glCaps_compatible, glCaps_vertexPointer;
bool glCaps_shaders, glCaps_fixedFunction, glCaps_immediate, glCaps_legacy, glCaps_pointSize, glCaps_frameBuffer, glCaps_vao, glCaps_select;

int glVersion;
int glMinorVersion;

uint defaultVAO;

#ifdef _DEBUG
void checkGLErrors( const char *file, int line )
{
int e, nCount = 0;
while((e = glGetError()) && nCount++ < 10)
PrintLn("GL error ", e, "! (at ", file, ":", line, ")");
}
#endif

bool loadedGLExts;

uint tempTexFBO; // TODO: Free this on termination... glDeleteFramebuffers(1, &tempTexFBO);

// FIXME: This is currently duplicated here from Ecere's OGL display driver because there is no other mechanism to access defualt VAO
class TempOGLDisplay : struct
{
GLCapabilities capabilities, originalCapabilities;
bool compat;
int version;
ColorAlpha * flippingBuffer;
int flipBufH, flipBufW;
bool depthWrite;
int x, y;
uint vao;
int maxTMU;
}

public void setupGL(Display display)
{
GLCapabilities caps = display.glCapabilities;
void * data = display.driverData;

glDisplay = display;
displaySystem = display.displaySystem;

displaySize = { display.width, display.height };
resetDisplaySize = displaySize;

SETCAPS(caps);

defaultVAO = ((TempOGLDisplay)data).vao;
if(!loadedGLExts)
{
#if defined(__LUMIN__)
// TODO: !
loadedGLExts = true;
glVersion = 4;
glMinorVersion = 5;
#elif defined(__ANDROID__)
loadedGLExts = true;
glVersion = 3;
glMinorVersion = 2;
#else
ogl_LoadFunctions();
loadedGLExts = true;
glVersion = ogl_GetMajorVersion();
glMinorVersion = ogl_GetMinorVersion();
#endif
}
}

public class ButterburShaderBits : uint64
{
Expand Down
1 change: 0 additions & 1 deletion butterbur/src/presentation/DrawingManager.ec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ public import IMPORT_STATIC "ecere"
#include "gl123es.h"

import "Presentation"
import "GLMultiDraw"
import "ButterburShader"
import "TIManager"

Expand Down
10 changes: 10 additions & 0 deletions ecere/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ _ECSOURCES1 = \
src/gfx/drivers/LFBDisplayDriver.ec \
$(if $(or $(LINUX_TARGET),$(OSX_TARGET)),src/gfx/drivers/NCursesDisplayDriver.ec,) \
$(if $(DISABLE_GL),,src/gfx/drivers/OpenGLDisplayDriver.ec) \
$(if $(DISABLE_GL),,src/gfx/drivers/gl3/GLMultiDraw.ec) \
$(if $(WINDOWS_TARGET),src/gfx/drivers/Win32BitmapPrinterDisplayDriver.ec,)
_ECSOURCES2 = \
$(if ,src/gfx/drivers/CocoaOpenGLDisplayDriver.ec,) \
Expand Down Expand Up @@ -798,6 +799,9 @@ $(OBJ)ETC2Format.sym: src/gfx/bitmaps/ETC2Format.ec
$(OBJ)glab.sym: src/gfx/drivers/gl3/glab.ec
$(ECP) $(CFLAGS) $(CECFLAGS) $(ECFLAGS) $(PRJ_CFLAGS) -c src/gfx/drivers/gl3/glab.ec -o $(OBJ)glab.sym

$(OBJ)GLMultiDraw.sym: src/gfx/drivers/gl3/GLMultiDraw.ec
$(ECP) $(CFLAGS) $(CECFLAGS) $(ECFLAGS) $(PRJ_CFLAGS) -c src/gfx/drivers/gl3/GLMultiDraw.ec -o $(OBJ)GLMultiDraw.sym

$(OBJ)immediate.sym: src/gfx/drivers/gl3/immediate.ec
$(ECP) $(CFLAGS) $(CECFLAGS) $(ECFLAGS) $(PRJ_CFLAGS) -c src/gfx/drivers/gl3/immediate.ec -o $(OBJ)immediate.sym

Expand Down Expand Up @@ -1258,6 +1262,9 @@ $(OBJ)ETC2Format.c: src/gfx/bitmaps/ETC2Format.ec $(OBJ)ETC2Format.sym | $(SYMBO
$(OBJ)glab.c: src/gfx/drivers/gl3/glab.ec $(OBJ)glab.sym | $(SYMBOLS)
$(ECC) $(CFLAGS) $(CECFLAGS) $(ECFLAGS) $(PRJ_CFLAGS) -c src/gfx/drivers/gl3/glab.ec -o $(OBJ)glab.c -symbols $(OBJ)

$(OBJ)GLMultiDraw.c: src/gfx/drivers/gl3/GLMultiDraw.ec $(OBJ)GLMultiDraw.sym | $(SYMBOLS)
$(ECC) $(CFLAGS) $(CECFLAGS) $(ECFLAGS) $(PRJ_CFLAGS) -c src/gfx/drivers/gl3/GLMultiDraw.ec -o $(OBJ)GLMultiDraw.c -symbols $(OBJ)

$(OBJ)immediate.c: src/gfx/drivers/gl3/immediate.ec $(OBJ)immediate.sym | $(SYMBOLS)
$(ECC) $(CFLAGS) $(CECFLAGS) $(ECFLAGS) $(PRJ_CFLAGS) -c src/gfx/drivers/gl3/immediate.ec -o $(OBJ)immediate.c -symbols $(OBJ)

Expand Down Expand Up @@ -2063,6 +2070,9 @@ $(OBJ)gl_compat_4_4.o: src/gfx/drivers/gl3/gl_compat_4_4.c
$(OBJ)glab.o: $(OBJ)glab.c
$(CC) $(CFLAGS) $(PRJ_CFLAGS) -c $(OBJ)glab.c -o $(OBJ)glab.o

$(OBJ)GLMultiDraw.o: $(OBJ)GLMultiDraw.c
$(CC) $(CFLAGS) $(PRJ_CFLAGS) -c $(OBJ)GLMultiDraw.c -o $(OBJ)GLMultiDraw.o

$(OBJ)immediate.o: $(OBJ)immediate.c
$(CC) $(CFLAGS) $(PRJ_CFLAGS) -c $(OBJ)immediate.c -o $(OBJ)immediate.o

Expand Down
6 changes: 6 additions & 0 deletions ecere/ecere.epj
Original file line number Diff line number Diff line change
Expand Up @@ -1329,6 +1329,12 @@
}
}
]
},
{
"FileName" : "GLMultiDraw.ec",
"Options" : {
"ExcludeFromBuild" : false
}
}
],
"Configurations" : [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
public import IMPORT_STATIC "ecere"
#if defined(__WIN32__) || defined(__unix__) || defined(__APPLE__)

import "OpenGLDisplayDriver"

#include "gl123es.h"

Expand All @@ -8,83 +10,18 @@ public import IMPORT_STATIC "ecere"
#define GL_R16 GL_LUMINANCE
#endif

import "ButterburShader"
public define drawIDAttribute = 7;
public define posOffsetAttribute = 8;

public define transform0Attribute = 9;
public define transform1Attribute = 10;
public define transform2Attribute = 11;
public define transform3Attribute = 12;

private:

// #define CLIENT_MEM_COMMANDS // Defined as a work-around for Intel driver that does not seem to support indirect commands buffers?

GLCapabilities glCaps;
bool glCaps_nonPow2Textures, glCaps_vertexBuffer, glCaps_quads, glCaps_intAndDouble, glCaps_legacyFormats, glCaps_compatible, glCaps_vertexPointer;
bool glCaps_shaders, glCaps_fixedFunction, glCaps_immediate, glCaps_legacy, glCaps_pointSize, glCaps_frameBuffer, glCaps_vao, glCaps_select;

int glVersion;
int glMinorVersion;

uint defaultVAO;

#ifdef _DEBUG
void checkGLErrors( const char *file, int line )
{
int e, nCount = 0;
while((e = glGetError()) && nCount++ < 10)
PrintLn("GL error ", e, "! (at ", file, ":", line, ")");
}
#endif

// FIXME: This is currently duplicated here from Ecere's OGL display driver because there is no other mechanism to access defualt VAO
class TempOGLDisplay : struct
{
GLCapabilities capabilities, originalCapabilities;
bool compat;
int version;
ColorAlpha * flippingBuffer;
int flipBufH, flipBufW;
bool depthWrite;
int x, y;
uint vao;
int maxTMU;
}

Size resetDisplaySize;
Size displaySize;
DisplaySystem displaySystem;
Display glDisplay;

public void setupGL(Display display)
{
GLCapabilities caps = display.glCapabilities;
void * data = display.driverData;

glDisplay = display;
displaySystem = display.displaySystem;

displaySize = { display.width, display.height };
resetDisplaySize = displaySize;

SETCAPS(caps);

defaultVAO = ((TempOGLDisplay)data).vao;
if(!loadedGLExts)
{
#if defined(__LUMIN__)
// TODO: !
loadedGLExts = true;
glVersion = 4;
glMinorVersion = 5;
#elif defined(__ANDROID__)
loadedGLExts = true;
glVersion = 3;
glMinorVersion = 2;
#else
ogl_LoadFunctions();
loadedGLExts = true;
glVersion = ogl_GetMajorVersion();
glMinorVersion = ogl_GetMinorVersion();
#endif
}
}

#define GL_CLAMP_TO_EDGE 0x812F

#if defined _GLES1
Expand All @@ -95,11 +32,7 @@ public void setupGL(Display display)
#define glClampFunction(version) (version >= 2 ? GL_CLAMP_TO_EDGE : GL_CLAMP)
#endif

bool loadedGLExts;

uint tempTexFBO; // TODO: Free this on termination... glDeleteFramebuffers(1, &tempTexFBO);

struct FreeSpots
public struct FreeSpots
{
uint size;
int * spots;
Expand Down Expand Up @@ -159,17 +92,28 @@ struct FreeSpots
size = count;
}
}
}
};

default:
#if defined(_GLES3)
int glVersion = 3;
#elif defined(_GLES2)
int glVersion = 2;
#elif defined(_GLES)
int glVersion = 1;
#else
int glVersion = 0;
#endif
private:

struct GLArrayTexture
public struct GLArrayTexture
{
uint texture;
uint width, height, numLayers;
uint numLevels;
bool maxLevel;
int format;
private FreeSpots spots;
/*private */FreeSpots spots;

void free()
{
Expand Down Expand Up @@ -203,6 +147,12 @@ struct GLArrayTexture
glDeleteTextures(1, &texture);
texture = 0;
}*/

#if !defined(_GLES) && !defined(_GLES2) && !defined(_GLES3)
if(!glVersion)
glVersion = ogl_GetMajorVersion();
#endif

if(!texture)
glGenTextures(1, &texture);

Expand Down Expand Up @@ -354,7 +304,7 @@ struct GLArrayTexture
}
};

struct GLDrawCommand
public struct GLDrawCommand
{
uint count;
uint instanceCount;
Expand All @@ -363,7 +313,7 @@ struct GLDrawCommand
uint baseInstance;
};

struct GLMultiDraw
public struct GLMultiDraw
{
GLMB indexGLMB;
GLMB vertexGLMB;
Expand Down Expand Up @@ -598,9 +548,11 @@ struct GLMultiDraw
}
};

void GLMultisampling(bool value)
public void GLMultisampling(bool value)
{
#if !defined(_GLES) && !defined(_GLES2)
(value ? glEnable : glDisable)(GL_MULTISAMPLE);
#endif
}

#endif

0 comments on commit ea1511b

Please sign in to comment.