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

oGLfbGFX - Added full openGL 2D render for fbGFX #40

Merged
merged 3 commits into from Sep 21, 2017
Merged
Diff settings

Always

Just for now

Copy path View file
@@ -6,6 +6,7 @@ Version 1.06.0
[added]
- -noobjinfo option to disable the writing/reading of compile-time library and other linking options from/to .o and .a files. This also disables the use of fbextra.x (the supplemental linker script) for discarding the .fbctinf sections, which is useful when using the gold linker that doesn't support this kind of linker script.
- Linux console Inkey() now recognizes F11 and F12
- 2D render through OpenGL on Windows and Linux via screencontrol (angros47)

[fixed]
- win/d3dx9.bi no longer has a hard-coded #inclib "d3dx9d". d3dx9d.dll is apparently not a generally valid choice. In practice programs have to be linked against d3dx9_33.dll or d3dx9_39.dll, etc.
Copy path View file
@@ -45,7 +45,10 @@ namespace FB
GFX_ACCUMULATION_BUFFER = &h20000 , _
GFX_MULTISAMPLE = &h40000


'Constants for OpenGL 2D render
const as integer OGL_MANUAL_SYNC = 1, _
OGL_AUTO_SYNC = 2

'' Constants accepted by ScreenControl
''
'' Getters:
Copy path View file
@@ -147,7 +147,9 @@
#define SET_GL_ACCUM_GREEN_BITS 114
#define SET_GL_ACCUM_BLUE_BITS 115
#define SET_GL_ACCUM_ALPHA_BITS 116
#define SET_GL_NUM_SAMPLES 117
#define SET_GL_NUM_SAMPLES 117
#define SET_GL_2D_MODE 150
#define SET_GL_SCALE 151

#define POLL_EVENTS 200

Copy path View file
@@ -20,6 +20,8 @@

typedef void (APIENTRY *GLENABLE)(GLenum);
typedef void (APIENTRY *GLDISABLE)(GLenum);
typedef void (APIENTRY *GLENABLECLIENTSTATE)(GLenum);
typedef void (APIENTRY *GLDISABLECLIENTSTATE)(GLenum);
typedef const GLubyte *(APIENTRY *GLGETSTRING)(GLenum);
typedef void (APIENTRY *GLVIEWPORT)(GLint,GLint,GLsizei,GLsizei);
typedef void (APIENTRY *GLMATRIXMODE)(GLenum);
@@ -32,12 +34,28 @@ typedef void (APIENTRY *GLCLEAR)(GLbitfield);
typedef void (APIENTRY *GLGENTEXTURES)(GLsizei,GLuint *);
typedef void (APIENTRY *GLDELETETEXTURES)(GLsizei,GLuint *);
typedef void (APIENTRY *GLBINDTEXTURE)(GLenum,GLuint);
typedef void (APIENTRY *GLTEXPARAMETERI)(GLenum, GLenum, GLint);
typedef void (APIENTRY *GLTEXIMAGE2D)(GLenum,GLint,GLint,GLsizei,GLsizei,GLint,GLenum,GLenum,const GLvoid *);
typedef void (APIENTRY *GLTEXSUBIMAGE2D)(GLenum,GLint,GLint,GLint,GLsizei,GLsizei,GLenum,GLenum,const GLvoid *);
typedef void (APIENTRY *GLVERTEXPOINTER)(GLint,GLenum,GLsizei, const GLvoid *);
typedef void (APIENTRY *GLTEXCOORDPOINTER)(GLint,GLenum,GLsizei,const GLvoid *);
typedef void (APIENTRY *GLDRAWARRAYS)(GLenum,GLint,GLsizei);
typedef void (APIENTRY *GLPUSHMATRIX)(void);
typedef void (APIENTRY *GLPOPMATRIX)(void);
typedef void (APIENTRY *GLPUSHATTRIB)(GLbitfield);
typedef void (APIENTRY *GLPOPATTRIB)(void);
typedef void (APIENTRY *GLPUSHCLIENTATTRIB)(GLbitfield);
typedef void (APIENTRY *GLPOPCLIENTATTRIB)(void);
typedef void (APIENTRY *GLPIXELTRANSFERI)(GLenum, GLint);
typedef void (APIENTRY *GLPIXELMAP)(GLenum, GLsizei, const GLfloat *);



typedef struct FB_GL {
GLENABLE Enable;
GLDISABLE Disable;
GLENABLECLIENTSTATE EnableClientState;
GLDISABLECLIENTSTATE DisableClientState;
GLGETSTRING GetString;
GLVIEWPORT Viewport;
GLMATRIXMODE MatrixMode;
@@ -50,7 +68,20 @@ typedef struct FB_GL {
GLGENTEXTURES GenTextures;
GLDELETETEXTURES DeleteTextures;
GLBINDTEXTURE BindTexture;
GLTEXPARAMETERI TexParameter;

This comment has been minimized.

Copy link
@dkl

dkl Sep 20, 2017

Collaborator

Since this field is used for glTexParameteri, it should probably have an i appended.

GLTEXIMAGE2D TexImage2D;
GLTEXSUBIMAGE2D TexSubImage2D;
GLVERTEXPOINTER VertexPointer;
GLTEXCOORDPOINTER TexCoordPointer;
GLDRAWARRAYS DrawArrays;
GLPUSHMATRIX PushMatrix;
GLPOPMATRIX PopMatrix;
GLPUSHATTRIB PushAttrib;
GLPOPATTRIB PopAttrib;
GLPUSHCLIENTATTRIB PushClientAttrib;
GLPOPCLIENTATTRIB PopClientAttrib;
GLPIXELTRANSFERI PixelTransferi;
GLPIXELMAP PixelMap;

This comment has been minimized.

Copy link
@dkl

dkl Sep 20, 2017

Collaborator

This field is used for glPixelMapfv, so I think it should be named PixelMapfv (just for better consistency).

int state;
char extensions[FBGL_EXTENSIONS_STRING_SIZE];
} FB_GL;
@@ -69,14 +100,21 @@ typedef struct FB_GL_PARAMS {
int accum_blue_bits;
int accum_alpha_bits;
int num_samples;

int mode_2d;
int scale;
void (*callback)(void);
} FB_GL_PARAMS;

extern FB_GL __fb_gl;
extern FB_GL_PARAMS __fb_gl_params;
extern void fb_hGL_SetPalette(int index, int r, int g, int b);

extern void fb_hGL_NormalizeParameters(int gl_options);
extern int fb_hGL_Init(FB_DYLIB lib, char *os_extensions);
extern int fb_hGL_ExtensionSupported(const char *extension);
extern void *fb_hGL_GetProcAddress(const char *proc);
extern void fb_hGL_SetupProjection(void);
extern void fb_hGL_ScreenCreate(void);

#endif /* not DISABLE_OPENGL */
Copy path View file
@@ -233,6 +233,14 @@ FBCALL void fb_GfxControl_i( int what, ssize_t *param1, ssize_t *param2, ssize_t
case SET_GL_NUM_SAMPLES:
__fb_gl_params.num_samples = *param1;
break;

case SET_GL_2D_MODE:
__fb_gl_params.mode_2d = *param1;
break;

case SET_GL_SCALE:
__fb_gl_params.scale = *param1;
break;
#endif

case POLL_EVENTS:
Copy path View file
@@ -20,8 +20,18 @@ FBCALL void *fb_GfxGetGLProcAddress(const char *proc)
#define GL_BGRA 0x80E1
#endif

#ifndef GL_UNSIGNED_SHORT_5_6_5
#define GL_UNSIGNED_SHORT_5_6_5 0x8363
#endif


FB_GL __fb_gl;
FB_GL_PARAMS __fb_gl_params = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
FB_GL_PARAMS __fb_gl_params = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, NULL };
GLfloat texcoords[8];

This comment has been minimized.

Copy link
@dkl

dkl Sep 20, 2017

Collaborator

About the module-level variables here: They should either be static, or maybe even be part of the __fb_gl context struct (unless that doesn't make sense).

GLuint ScreenTex;

GLfloat map_r[256], map_g[256], map_b[256];


static int next_pow2(int n)
{
@@ -102,6 +112,44 @@ GLuint fb_hGL_ImageCreate(PUT_HEADER *image, unsigned int color)
return id;
}

void fb_hGL_ScreenCreate(void)
{
int w, h;
GLuint id;

w = next_pow2(__fb_gfx->w);
h = next_pow2(__fb_gfx->h);

__fb_gl.GenTextures(1, &id);
__fb_gl.BindTexture(GL_TEXTURE_2D, id);
__fb_gl.TexParameter(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
__fb_gl.TexParameter(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);

switch(__fb_gfx->depth){
case 32:
case 24:
__fb_gl.TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, 0);
break;
case 16:
case 15:
__fb_gl.TexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 0);
break;
case 8:
case 4:
case 2:
case 1:
__fb_gl.TexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, 0);
}

GLfloat ratio_w=(GLfloat)__fb_gfx->w/w, ratio_h=(GLfloat)__fb_gfx->h/h;

This comment has been minimized.

Copy link
@dkl

dkl Sep 20, 2017

Collaborator

It would be nice to use formatting rules like most of rtlib/gfxlib2 code. There should be more spaces, for example:

GLfloat ratio_w = (GLfloat)__fb_gfx->w / w;
GLfloat ratio_h = (GLfloat)__fb_gfx->h / h;

or above:

- switch(__fb_gfx->depth){
+ switch (__fb_gfx->depth) {
texcoords[0]=0 ; texcoords[1]=ratio_h;
texcoords[2]=0 ; texcoords[3]=0;
texcoords[4]=ratio_w ; texcoords[5]=0;
texcoords[6]=ratio_w ; texcoords[7]=ratio_h;

ScreenTex = id;
}

void fb_hGL_ImageDestroy(GLuint id)
{
__fb_gl.DeleteTextures(1, &id);
@@ -167,10 +215,14 @@ void fb_hGL_NormalizeParameters(int gl_options)

int fb_hGL_Init(FB_DYLIB lib, char *os_extensions)
{
const char *gl_funcs[] = { "glEnable", "glDisable", "glGetString", "glViewport", "glMatrixMode",
const char *gl_funcs[] = { "glEnable", "glDisable", "glEnableClientState", "glDisableClientState",
"glGetString", "glViewport", "glMatrixMode",
"glLoadIdentity", "glOrtho", "glShadeModel", "glDepthMask", "glClearColor",
"glClear", "glGenTextures", "glDeleteTextures", "glBindTexture",
"glTexImage2D" };
"glClear", "glGenTextures", "glDeleteTextures", "glBindTexture",
"glTexParameteri", "glTexImage2D", "glTexSubImage2D",
"glVertexPointer", "glTexCoordPointer", "glDrawArrays",
"glPushMatrix", "glPopMatrix", "glPushAttrib", "glPopAttrib",
"glPushClientAttrib", "glPopClientAttrib", "glPixelTransferi", "glPixelMapfv" };
FB_GL *funcs = &__fb_gl;
void **funcs_ptr = (void **)funcs;
int res = 0, size = FBGL_EXTENSIONS_STRING_SIZE - 1;
@@ -191,19 +243,72 @@ int fb_hGL_Init(FB_DYLIB lib, char *os_extensions)
return res;
}



void fb_hGL_SetPalette(int index, int r, int g, int b){
map_r[index]=(float)r/256.0;
map_g[index]=(float)g/256.0;
map_b[index]=(float)b/256.0;
}


void fb_hGL_SetupProjection(void)
{
__fb_gl.Viewport(0, 0, __fb_gfx->w, __fb_gfx->h);
const GLfloat vert[]={-1,-1,-1,1,1,1,1,-1};

__fb_gl.PushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);
__fb_gl.PushAttrib(GL_ALL_ATTRIB_BITS);
__fb_gl.Viewport(0, 0, __fb_gfx->w * __fb_gl_params.scale, __fb_gfx->h * __fb_gl_params.scale);
__fb_gl.MatrixMode(GL_PROJECTION);
__fb_gl.PushMatrix();
__fb_gl.LoadIdentity();
__fb_gl.Ortho(-0.325, __fb_gfx->w - 0.325, __fb_gfx->h - 0.325, -0.325, -1.0, 1.0);

__fb_gl.Ortho(-1, 1, -1, 1, -1, 1);
__fb_gl.MatrixMode(GL_MODELVIEW);
__fb_gl.LoadIdentity();
__fb_gl.ShadeModel(GL_FLAT);
__fb_gl.Disable(GL_DEPTH_TEST);
__fb_gl.DepthMask(GL_FALSE);
__fb_gl.ClearColor(0.0, 0.0, 0.0, 1.0);
__fb_gl.Clear(GL_COLOR_BUFFER_BIT);
__fb_gl.EnableClientState( GL_VERTEX_ARRAY );
__fb_gl.EnableClientState( GL_TEXTURE_COORD_ARRAY );
__fb_gl.DisableClientState(GL_NORMAL_ARRAY);
__fb_gl.DisableClientState(GL_COLOR_ARRAY);

__fb_gl.VertexPointer(2, GL_FLOAT, 0, vert);
__fb_gl.TexCoordPointer(2, GL_FLOAT, 0, texcoords);

//__fb_gl.ActiveTexture(GL_TEXTURE0);
__fb_gl.BindTexture(GL_TEXTURE_2D, ScreenTex);
switch(__fb_gfx->depth){
case 32:
case 24:
__fb_gl.TexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, __fb_gfx->w, __fb_gfx->h, GL_BGRA, GL_UNSIGNED_BYTE, (unsigned char *)__fb_gfx->framebuffer);
break;
case 16:
case 15:
__fb_gl.TexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, __fb_gfx->w, __fb_gfx->h, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, (unsigned char *)__fb_gfx->framebuffer);
break;
case 8:
case 4:
case 2:
case 1:
__fb_gl.PixelTransferi(GL_MAP_COLOR, GL_TRUE );
__fb_gl.PixelMap(GL_PIXEL_MAP_I_TO_R,256, map_r);
__fb_gl.PixelMap(GL_PIXEL_MAP_I_TO_G,256, map_g);
__fb_gl.PixelMap(GL_PIXEL_MAP_I_TO_B,256, map_b);

__fb_gl.TexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, __fb_gfx->w, __fb_gfx->h, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, (unsigned char *)__fb_gfx->framebuffer);

}

__fb_gl.Enable(GL_TEXTURE_2D);
__fb_gl.DrawArrays(GL_TRIANGLE_FAN,0,4);

__fb_gl.PopMatrix();
__fb_gl.PopAttrib();
__fb_gl.PopClientAttrib();


}

#endif /* DISABLE_OPENGL */
Copy path View file
@@ -1,6 +1,7 @@
/* screen multiple pages handling */

#include "fb_gfx.h"
#include "fb_gfx_gl.h"

FBCALL int fb_GfxFlip(int from_page, int to_page)
{
@@ -16,7 +17,11 @@ FBCALL int fb_GfxFlip(int from_page, int to_page)
return fb_ErrorSetNum(FB_RTERROR_ILLEGALFUNCTIONCALL);
}

#ifndef DISABLE_OPENGL
if (__fb_gfx->driver->flip && __fb_gl_params.mode_2d!=2) {
#else
if (__fb_gfx->driver->flip) {
#endif
__fb_gfx->driver->flip();
if (__fb_gfx->driver->poll_events)
__fb_gfx->driver->poll_events();
Copy path View file
@@ -240,8 +240,8 @@ static int set_mode
__fb_gfx->w = w;
__fb_gfx->h = h;
__fb_gfx->depth = depth;
if ((flags >= 0) && (flags & DRIVER_OPENGL))
__fb_gfx->depth = MAX(16, __fb_gfx->depth);
/* if ((flags >= 0) && (flags & DRIVER_OPENGL))
__fb_gfx->depth = MAX(16, __fb_gfx->depth);*/
__fb_gfx->default_palette = (palette >= 0) ? &__fb_palette[palette] : NULL;
__fb_gfx->scanline_size = scanline_size;
__fb_gfx->font = (font >= 0) ? &__fb_font[font] : NULL;
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.