<commit_before>#include "../remote.h"
#include "./glpack.h"
#include "./remote.h"
#include "gl_helpers.h"

int remote_local_pre(GlouijaCall *c, packed_call_t *call) {
    switch (call->index) {
        case glDeleteTextures_INDEX:
        {
            glDeleteTextures_PACKED *n = (glDeleteTextures_PACKED *)call;
            glouija_add_block(c, n->args.textures, n->args.n * sizeof(GLuint), true);
            break;
        }
        case glTexImage2D_INDEX:
        {
            glTexImage2D_PACKED *n = (glTexImage2D_PACKED *)call;
            size_t size = n->args.width * n->args.height * gl_pixel_sizeof(n->args.format, n->args.type);
            glouija_add_block(c, n->args.pixels, size, true);
            break;
        }
        case glLoadMatrixf_INDEX:
        {
            glLoadMatrixf_PACKED *n = (glLoadMatrixf_PACKED *)call;
            glouija_add_block(c, n->args.m, 16 * sizeof(GLfloat), true);
            break;
        }
#if 0
        // this is disabled to remove the X dependency for now
        // it looks like glXChooseVisual returns don't matter anyway
        case glXChooseVisual_INDEX:
        {
            glXChooseVisual_PACKED *n = (glXChooseVisual_PACKED *)call;
            int *attribList = n->args.attribList;
            int size = 0;
            while (attribList[size++]) {}
            glouija_add_block(c, attribList, size, true);
            return 1;
        }
#endif
    }
    return 0;
}

void remote_local_post(GlouijaCall *c, GlouijaCall *ret, packed_call_t *call, void *ret_v, size_t ret_size) {
    switch (call->index) {
#if 0
        // see above
        case glXChooseVisual_INDEX:
        {
            glXChooseVisual_PACKED *n = (glXChooseVisual_PACKED *)call;
            XVisualInfo **ret_vis = (XVisualInfo **)ret_v;
            if (*ret_vis) {
                XVisualInfo *visual = ret->arg[1].data.block.data;
                int count;
                XVisualInfo tmp;
                XMatchVisualInfo(n->args.dpy, visual->screen, visual->depth, visual->class, &tmp);
                memcpy(visual, &tmp, sizeof(XVisualInfo));
                *ret_vis = visual;
            }
            break;
        }
#endif
    }
}

void remote_target_process(GlouijaCall *c, GlouijaCall *response, packed_call_t *call, void *ret) {
    if (call->index >= 0) {
        printf("remote call: ");
        glIndexedPrint(call);
    }
    switch (call->index) {
        case REMOTE_BLOCK_DRAW:
        {
            block_t *block = remote_deserialize_block((void *)call);
            bl_draw(block);
            return;
        }
        case REMOTE_GL_GET:
        {
            return;
        }
        case REMOTE_RENDER_RASTER:
        {
            return;
        }
        case glDeleteTextures_INDEX:
            ((glDeleteTextures_PACKED *)call)->args.textures = c->arg[2].data.block.data;
            break;
        case glTexImage2D_INDEX:
            ((glTexImage2D_PACKED *)call)->args.pixels = c->arg[2].data.block.data;
            break;
        case glLoadMatrixf_INDEX:
            ((glLoadMatrixf_PACKED *)call)->args.m = c->arg[2].data.block.data;
            break;
#if 0
        // see above
        case glXChooseVisual_INDEX:
        {
            PACKED_glXChooseVisual *n = (PACKED_glXChooseVisual *)call;
            n->args.attribList = c->arg[2].data.block.data;
            int *attribList = n->args.attribList;
            XVisualInfo *info = NULL;
            glIndexedCall(call, (void *)&info);
            if (info) {
                glouija_add_block(response, info, sizeof(XVisualInfo), true);
            }
            return;
        }
#endif
    }
    glIndexedCall(call, (void *)ret);
}
<commit_msg>cleanup, add glLightfv and glMaterialfv remote<commit_after>#include "../remote.h"
#include "./glpack.h"
#include "./remote.h"
#include "gl_helpers.h"

int remote_local_pre(GlouijaCall *c, packed_call_t *call) {
    switch (call->index) {
        case glDeleteTextures_INDEX:
        {
            glDeleteTextures_PACKED *n = (glDeleteTextures_PACKED *)call;
            glouija_add_block(c, n->args.textures, n->args.n * sizeof(GLuint), true);
            break;
        }
        case glTexImage2D_INDEX:
        {
            glTexImage2D_PACKED *n = (glTexImage2D_PACKED *)call;
            size_t size = n->args.width * n->args.height * gl_pixel_sizeof(n->args.format, n->args.type);
            glouija_add_block(c, n->args.pixels, size, true);
            break;
        }
        case glLoadMatrixf_INDEX:
        {
            glLoadMatrixf_PACKED *n = (glLoadMatrixf_PACKED *)call;
            glouija_add_block(c, n->args.m, 16 * sizeof(GLfloat), true);
            break;
        }
        case glLightfv_INDEX:
        {
            glLightfv_PACKED *n = (glLightfv_PACKED *)call;
            int count = 1;
            switch (n->args.pname) {
                case GL_AMBIENT:
                case GL_DIFFUSE:
                case GL_SPECULAR:
                case GL_POSITION:
                    count = 4;
                    break;
                case GL_SPOT_DIRECTION:
                    count = 3;
                    break;
            }
            glouija_add_block(c, n->args.params, count * sizeof(GLfloat), true);
            break;
        }
        case glMaterialfv_INDEX:
        {
            glMaterialfv_PACKED *n = (glMaterialfv_PACKED *)call;
            int count = 4;
            switch (n->args.pname) {
                case GL_SHININESS:
                    count = 1;
                    break;
                case GL_COLOR_INDEXES:
                    count = 3;
                    break;
            }
            glouija_add_block(c, n->args.params, count * sizeof(GLfloat), true);
        }
#if 0
        // this is disabled to remove the X dependency for now
        // it looks like glXChooseVisual returns don't matter anyway
        case glXChooseVisual_INDEX:
        {
            glXChooseVisual_PACKED *n = (glXChooseVisual_PACKED *)call;
            int *attribList = n->args.attribList;
            int size = 0;
            while (attribList[size++]) {}
            glouija_add_block(c, attribList, size, true);
            return 1;
        }
#endif
    }
    return 0;
}

void remote_local_post(GlouijaCall *c, GlouijaCall *ret, packed_call_t *call, void *ret_v, size_t ret_size) {
    switch (call->index) {
#if 0
        // see above
        case glXChooseVisual_INDEX:
        {
            glXChooseVisual_PACKED *n = (glXChooseVisual_PACKED *)call;
            XVisualInfo **ret_vis = (XVisualInfo **)ret_v;
            if (*ret_vis) {
                XVisualInfo *visual = ret->arg[1].data.block.data;
                int count;
                XVisualInfo tmp;
                XMatchVisualInfo(n->args.dpy, visual->screen, visual->depth, visual->class, &tmp);
                memcpy(visual, &tmp, sizeof(XVisualInfo));
                *ret_vis = visual;
            }
            break;
        }
#endif
    }
}

void remote_target_process(GlouijaCall *c, GlouijaCall *response, packed_call_t *call, void *ret) {
    if (call->index >= 0) {
        printf("remote call: ");
        glIndexedPrint(call);
    }
    void *first = c->arg[2].data.block.data;
    switch (call->index) {
        case REMOTE_BLOCK_DRAW:
        {
            block_t *block = remote_deserialize_block((void *)call);
            bl_draw(block);
            return;
        }
        case REMOTE_GL_GET:
        {
            return;
        }
        case REMOTE_RENDER_RASTER:
        {
            return;
        }
        case glDeleteTextures_INDEX:
            ((glDeleteTextures_PACKED *)call)->args.textures = first;
            break;
        case glTexImage2D_INDEX:
            ((glTexImage2D_PACKED *)call)->args.pixels = first;
            break;
        case glLoadMatrixf_INDEX:
            ((glLoadMatrixf_PACKED *)call)->args.m = first;
            break;
        case glLightfv_INDEX:
            ((glLightfv_PACKED *)call)->args.params = first;
            break;
        case glMaterialfv_INDEX:
            ((glMaterialfv_PACKED *)call)->args.params = first;
            break;
#if 0
        // see above
        case glXChooseVisual_INDEX:
        {
            PACKED_glXChooseVisual *n = (PACKED_glXChooseVisual *)call;
            n->args.attribList = c->arg[2].data.block.data;
            int *attribList = n->args.attribList;
            XVisualInfo *info = NULL;
            glIndexedCall(call, (void *)&info);
            if (info) {
                glouija_add_block(response, info, sizeof(XVisualInfo), true);
            }
            return;
        }
#endif
    }
    glIndexedCall(call, (void *)ret);
}

{'fraction_non_alphanumeric': 0.10875576036866359, 'fraction_numerical': 0.004838709677419355, 'mean_word_length': 1.7035191529118654, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7420916', 'n_tokens_mistral': 2787, 'n_tokens_neox': 2685, 'n_words': 535}