Skip to content

Commit

Permalink
Support multiple TexCoord pointers
Browse files Browse the repository at this point in the history
* partial fix glimpl_push_client_pointers for texcoord
* add SGL_DEBUG_EMIT_FRAMES to help with debugging/tracing
* remove a limitation and add troubleshooting tip to README
  • Loading branch information
dmaivel committed Jun 11, 2024
1 parent e3cb91e commit 48b558f
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 25 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,13 @@ This list describes the amount of functions left from each standard to implement
- Clients may reserve too much memory according to server's allocated memory
- No Vsync
- Resizing is possible, no proper implementation
- Some GLFW applications cant request OpenGL profiles
- New GLX FB configs may cause applications using `freeglut` or `glad` to no longer run
# Troubleshooting
You may encounter weird crashes/faults/errors such as `IOT instruction` or `No provider of glXXX found.`. Although the code base is buggy, these are some tips to try to further attempts to get an application to work:
- Change the GL version (i.e `-g 2.0`)
If you encounter "Entry point retrieval is broken" on applications that use GLFW, use `LD_PRELOAD`.
---
If you encounter weird crashes/faults/errors such as `IOT instruction` or `No provider of glXXX found.`:
- Try changing the GL version (i.e `-g 2.0`)
- Allocate more memory (i.e `-m 256`)
---
Application shows a blank window in the virtual machine?
Expand Down
100 changes: 78 additions & 22 deletions src/client/glimpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#endif

#define GLIMPL_MAX_OBJECTS 256
#define GLIMPL_MAX_TEXTURES 8

// used by glGet*v
#define GL_GET_MEMCPY_RETVAL_EX(name, data, type) \
Expand Down Expand Up @@ -113,10 +114,12 @@ struct gl_map_buffer {
struct gl_vertex_attrib_pointer glimpl_vaps[GLIMPL_MAX_OBJECTS];

struct gl_color_tex_vertex_pointer glimpl_color_ptr,
glimpl_tex_coord_ptr,
glimpl_tex_coord_ptr[GLIMPL_MAX_TEXTURES],
glimpl_vertex_ptr,
glimpl_color2_ptr;

int glimpl_client_active_texture = 0;

struct gl_normal_index_pointer glimpl_normal_ptr,
glimpl_index_pointer,
glimpl_interleaved_pointer,
Expand Down Expand Up @@ -578,7 +581,7 @@ static inline void glimpl_push_client_pointers(int mode, int max_index)
for (int i = 0; i < max_index; i++) {
for (int j = 0; j < glimpl_vertex_ptr.size; j++)
pb_pushf(*fvertices++);
for (int j = 0; j < (glimpl_normal_ptr.stride / 4) - glimpl_vertex_ptr.size; j++)
for (int j = 0; j < (glimpl_normal_ptr.stride / sizeof(float)) - glimpl_vertex_ptr.size; j++)
fvertices++;
}

Expand Down Expand Up @@ -617,22 +620,49 @@ static inline void glimpl_push_client_pointers(int mode, int max_index)
pb_push(0);
}

if (glimpl_tex_coord_ptr.in_use) {
pb_push(SGL_CMD_VP_UPLOAD);
pb_push(max_index * glimpl_tex_coord_ptr.size);
const float *fvertices = glimpl_tex_coord_ptr.pointer;
for (int t = 0; t < GLIMPL_MAX_TEXTURES; t++) {
if (glimpl_tex_coord_ptr[t].in_use) {
pb_push(SGL_CMD_VP_UPLOAD);
pb_push(max_index * glimpl_tex_coord_ptr[t].size);
switch (glimpl_tex_coord_ptr[t].type) {
case GL_SHORT: {
const short *svertices = glimpl_tex_coord_ptr[t].pointer;

// assuming size = 2
for (int i = 0; i < max_index; i++) {
for (int j = 0; j < glimpl_tex_coord_ptr[t].size; j += 2) {
pb_push((svertices[0] << 16) | svertices[1]);
svertices++;
svertices++;
}
for (int j = 0; j < (glimpl_tex_coord_ptr[t].stride / sizeof(short)) - glimpl_tex_coord_ptr[t].size; j++)
svertices++;
// svertices += glimpl_tex_coord_ptr[t].stride / sizeof(short);
}
}
default: {
const float *fvertices = glimpl_tex_coord_ptr[t].pointer;

for (int i = 0; i < max_index; i++) {
for (int j = 0; j < glimpl_tex_coord_ptr[t].size; j++)
pb_pushf(*fvertices++);
for (int j = 0; j < (glimpl_tex_coord_ptr[t].stride / sizeof(float)) - glimpl_tex_coord_ptr[t].size; j++)
fvertices++;
}
}
}

for (int i = 0; i < max_index; i++) {
for (int j = 0; j < glimpl_tex_coord_ptr.size; j++)
pb_pushf(*fvertices++);
for (int j = 0; j < (glimpl_tex_coord_ptr.stride / 4) - glimpl_tex_coord_ptr.size; j++)
fvertices++;
}
pb_push(SGL_CMD_CLIENTACTIVETEXTURE);
pb_push(GL_TEXTURE0 + t);

pb_push(SGL_CMD_TEXCOORDPOINTER);
pb_push(glimpl_tex_coord_ptr.size);
pb_push(glimpl_tex_coord_ptr.type);
pb_push(0);
pb_push(SGL_CMD_ENABLECLIENTSTATE);
pb_push(GL_TEXTURE_COORD_ARRAY);

pb_push(SGL_CMD_TEXCOORDPOINTER);
pb_push(glimpl_tex_coord_ptr[t].size);
pb_push(glimpl_tex_coord_ptr[t].type);
pb_push(0);
}
}

if (glimpl_vertex_ptr.in_use) {
Expand All @@ -643,7 +673,7 @@ static inline void glimpl_push_client_pointers(int mode, int max_index)
for (int i = 0; i < max_index; i++) {
for (int j = 0; j < glimpl_vertex_ptr.size; j++)
pb_pushf(*fvertices++);
for (int j = 0; j < (glimpl_vertex_ptr.stride / 4) - glimpl_vertex_ptr.size; j++)
for (int j = 0; j < (glimpl_vertex_ptr.stride / sizeof(float)) - glimpl_vertex_ptr.size; j++)
fvertices++;
}

Expand Down Expand Up @@ -1010,6 +1040,30 @@ void glDrawArrays(GLenum mode, GLint first, GLsizei count)
// glimpl_push_client_pointers(mode, count);
// }

for (int i = 0; i < GLIMPL_MAX_OBJECTS; i++) {
struct gl_vertex_attrib_pointer *vap = &glimpl_vaps[i];
if (vap->client_managed) {
bool is_ptr_offset = is_value_likely_an_offset(vap->ptr);
if (!is_ptr_offset) {
pb_push(SGL_CMD_VP_UPLOAD);
pb_push(vap->size * count);
for (int i = 0; i < vap->size * count; i++)
pb_push(vap->ptr[i]);
}

pb_push(SGL_CMD_VERTEXATTRIBPOINTER);
pb_push(vap->index);
pb_push(vap->size);
pb_push(vap->type);
pb_push(vap->normalized);
pb_push(vap->stride);
pb_push(is_ptr_offset ? (int)(long)vap->ptr : 0xFFFFFFFF); // force server to use upload

pb_push(SGL_CMD_ENABLEVERTEXATTRIBARRAY);
pb_push(vap->index);
}
}

glimpl_push_client_pointers(mode, count);

pb_push(SGL_CMD_DRAWARRAYS);
Expand Down Expand Up @@ -1685,12 +1739,12 @@ void glNormalPointer(GLenum type, GLsizei stride, const void* pointer)

void glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const void* pointer)
{
glimpl_tex_coord_ptr = (struct gl_color_tex_vertex_pointer){
glimpl_tex_coord_ptr[glimpl_client_active_texture] = (struct gl_color_tex_vertex_pointer){
.size = size,
.type = type,
.stride = stride,
.pointer = pointer,
.in_use = glimpl_tex_coord_ptr.in_use
.in_use = glimpl_tex_coord_ptr[glimpl_client_active_texture].in_use
};
}

Expand Down Expand Up @@ -2964,7 +3018,7 @@ void glDisableClientState(GLenum array)
glimpl_normal_ptr.in_use = false;
break;
case GL_TEXTURE_COORD_ARRAY:
glimpl_tex_coord_ptr.in_use = false;
glimpl_tex_coord_ptr[glimpl_client_active_texture].in_use = false;
break;
case GL_VERTEX_ARRAY:
glimpl_vertex_ptr.in_use = false;
Expand All @@ -2985,7 +3039,7 @@ void glEnableClientState(GLenum array)
glimpl_normal_ptr.in_use = true;
break;
case GL_TEXTURE_COORD_ARRAY:
glimpl_tex_coord_ptr.in_use = true;
glimpl_tex_coord_ptr[glimpl_client_active_texture].in_use = true;
break;
case GL_VERTEX_ARRAY:
glimpl_vertex_ptr.in_use = true;
Expand Down Expand Up @@ -3056,6 +3110,8 @@ void glClientActiveTexture(GLenum texture)
{
pb_push(SGL_CMD_CLIENTACTIVETEXTURE);
pb_push(texture);

glimpl_client_active_texture = texture - (GLenum)GL_TEXTURE0;
}

void glMultiTexCoord1d(GLenum target, GLdouble s)
Expand Down Expand Up @@ -6758,7 +6814,7 @@ void glGetPointerv(GLenum pname, GLvoid **params)
*params = (void*)glimpl_color_ptr.pointer;
break;
case GL_TEXTURE_COORD_ARRAY_POINTER:
*params = (void*)glimpl_tex_coord_ptr.pointer;
*params = (void*)glimpl_tex_coord_ptr[glimpl_client_active_texture].pointer;
break;
default:
*params = (void*)0;
Expand Down
14 changes: 14 additions & 0 deletions src/server/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,22 @@ void sgl_context_destroy(struct sgl_host_context *ctx)
free(ctx);
}

#define SGL_DEBUG_EMIT_FRAMES
#ifdef SGL_DEBUG_EMIT_FRAMES
SDL_Window *window;
#endif

void sgl_set_current(struct sgl_host_context *ctx)
{
if (ctx == NULL)
SDL_GL_MakeCurrent(NULL, NULL);
else
SDL_GL_MakeCurrent(ctx->window, ctx->gl_context);

#ifdef SGL_DEBUG_EMIT_FRAMES
if (ctx)
window = ctx->window;
#endif
}

void *sgl_read_pixels(unsigned int width, unsigned int height, void *data, int vflip, int format, size_t mem_usage)
Expand Down Expand Up @@ -107,5 +117,9 @@ void *sgl_read_pixels(unsigned int width, unsigned int height, void *data, int v

overlay_stage2(&overlay_ctx, data, width, mem_usage);

#ifdef SGL_DEBUG_EMIT_FRAMES
SDL_GL_SwapWindow(window);
#endif

return data;
}

0 comments on commit 48b558f

Please sign in to comment.