Beispiel #1
0
void send_set_brush_frag_shader(int i, const char *text)
{
    int n = text ? (strlen(text) + 1) : 0;

    struct brush *b = get_brush(i);

    send_event(EVENT_SET_BRUSH_FRAG_SHADER);
    send_index(i);
    send_index(n);

    fini_brush(i);

    /* Free the old fragment program buffer. */

    if (b->frag_text)
    {
        free(b->frag_text);
        b->frag_text = NULL;
    }

    /* Copy the new fragment program buffer. */

    if (n > 0)
    {
        b->frag_text = memdup(text, n, 1);
        send_array(b->frag_text, n, 1);
    }
}
Beispiel #2
0
void fini_brush(int i)
{
    struct brush *b = get_brush(i);

    if (b->state == 1)
    {
        /* Finalize any vertex and fragment shader objects. */

        if (GL_has_shader_objects)
        {
            if (b->shad_prog) glDeleteObjectARB(b->shad_prog);
            if (b->vert_shad) glDeleteObjectARB(b->vert_shad);
            if (b->frag_shad) glDeleteObjectARB(b->frag_shad);
        }
                
        /* Finalize any vertex and fragment programs. */

        if (GL_has_vertex_program)
            if (glIsProgramARB(b->vert_prog))
                glDeleteProgramsARB(1, &b->vert_prog);

        if (GL_has_fragment_program)
            if (glIsProgramARB(b->frag_prog))
                glDeleteProgramsARB(1, &b->frag_prog);
                
        b->vert_shad = 0;
        b->frag_shad = 0;
        b->shad_prog = 0;

        b->vert_prog = 0;
        b->frag_prog = 0;
        b->state     = 0;
    }
}
Beispiel #3
0
void recv_set_brush_frag_shader(void)
{
    int i = recv_index();
    int n = recv_index();

    struct brush *b = get_brush(i);

    fini_brush(i);

    /* Free the old fragment program buffer. */

    if (b->frag_text)
    {
        free(b->frag_text);
        b->frag_text = NULL;
    }

    /* Receive the new fragment program buffer. */

    if (n > 0)
    {
        b->frag_text = (char *) malloc(n);
        recv_array(b->frag_text, n, 1);
    }
}
Beispiel #4
0
void send_set_brush_vert_prog(int i, const char *text)
{
    int n = text ? (strlen(text) + 1) : 0;

    struct brush *b = get_brush(i);

    send_event(EVENT_SET_BRUSH_VERT_PROG);
    send_index(i);
    send_index(n);

    fini_brush(i);

    /* Free the old vertex program buffer. */

    if (b->vert)
    {
        free(b->vert);
        b->vert = NULL;
    }

    /* Copy the new vertex program buffer. */

    if (n > 0)
    {
        b->vert = memdup(text, n, 1);
        send_array(text, n, 1);
    }
}
Beispiel #5
0
void recv_set_brush_vert_prog(void)
{
    int i = recv_index();
    int n = recv_index();

    struct brush *b = get_brush(i);

    fini_brush(i);

    /* Free the old vertex program buffer. */

    if (b->vert)
    {
        free(b->vert);
        b->vert = NULL;
    }

    /* Receive the new vertex program buffer. */

    if (n > 0)
    {
        b->vert = (char *) malloc(n);
        recv_array(b->vert, n, 1);
    }
}
Beispiel #6
0
void send_set_brush_line_width(int i, float w)
{
    struct brush *b = get_brush(i);

    send_event(EVENT_SET_BRUSH_LINE_WIDTH);
    send_index(i);
    send_float((b->line_width = w));
}
Beispiel #7
0
void recv_set_brush_image(void)
{
    int i = recv_index();
    int j = recv_index();
    int k = recv_index();

    get_brush(i)->image[k] = j;
}
Beispiel #8
0
void fini_brushes(void)
{
    int i, n = vecnum(brush);

    for (i = 0; i < n; ++i)
        if (get_brush(i)->count)
            fini_brush(i);
}
Beispiel #9
0
void nuke_brushes(void)
{
    int i, n = vecnum(brush);

    for (i = 1; i < n; ++i)
        while (get_brush(i)->count)
            send_delete_brush(i);
}
Beispiel #10
0
static int new_brush(void)
{
    int i, n = vecnum(brush);

    for (i = 0; i < n; ++i)
        if (get_brush(i)->count == 0)
            return i;

    return vecadd(brush);
}
Beispiel #11
0
static int free_brush(int i)
{
    struct brush   *b = get_brush(i);
    struct uniform *u;

    if (i > 0)
    {
        if (b->count > 0)
        {
            b->count--;

            if (b->count == 0)
            {
                fini_brush(i);

                /* Release all uniforms. */

                if (b->uniform)
                {
                    for (i = 0; i < vecnum(b->uniform); ++i)
                    {
                        u = (struct uniform *) vecget(b->uniform, i);

                        if (u->name) free(u->name);
                        if (u->vals) free(u->vals);
                    }
                    vecdel(b->uniform);
                }

                /* Release all string buffers. */

                if (b->file) free(b->file);
                if (b->name) free(b->name);
                if (b->frag) free(b->frag);
                if (b->vert) free(b->vert);

                if (b->vert_text) free(b->vert_text);
                if (b->frag_text) free(b->frag_text);

                /* Release all images. */

                if (b->image[0]) send_delete_image(b->image[0]);
                if (b->image[1]) send_delete_image(b->image[1]);
                if (b->image[2]) send_delete_image(b->image[2]);
                if (b->image[3]) send_delete_image(b->image[3]);

                memset(b, 0, sizeof (struct brush));

                return 1;
            }
        }
    }
    return 0;
}
Beispiel #12
0
void send_set_brush_image(int i, int j, int k)
{
    struct brush *b = get_brush(i);

    dupe_create_image(j);
    send_delete_image(b->image[k]);

    send_event(EVENT_SET_BRUSH_IMAGE);
    send_index(i);
    send_index((b->image[k] = j));
    send_index(k);
}
Beispiel #13
0
void init_brush(int i)
{
    struct brush *b = get_brush(i);

    if (b->state == 0)
    {
        int p;

        /* Initialize and vertex and fragment shaders and uniforms. */

        if (GL_has_shader_objects)
        {
            if (b->vert_text)
                b->vert_shad = opengl_shader_object(GL_VERTEX_SHADER_ARB,
                                                    b->vert_text);
            if (b->frag_text)
                b->frag_shad = opengl_shader_object(GL_FRAGMENT_SHADER_ARB,
                                                    b->frag_text);
            if (b->vert_shad || b->frag_shad)
                b->shad_prog = opengl_program_object(b->vert_shad,
                                                     b->frag_shad);

            if (b->shad_prog && b->uniform)
                for (p = 0; p < vecnum(b->uniform); ++p)
                    use_uniform(b, (struct uniform *) vecget(b->uniform, p));
        }

        /* Initialize any vertex program and parameters. */

        if (b->vert && GL_has_vertex_program)
        {
            b->vert_prog = opengl_vert_prog(b->vert);

            for (p = 0; p < MAX_PARAM; ++p)
                glProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB,
                                              p, b->vert_param[p]);
        }

        /* Initialize any fragment program and parameters. */

        if (b->frag && GL_has_fragment_program)
        {
            b->frag_prog = opengl_frag_prog(b->frag);

            for (p = 0; p < MAX_PARAM; ++p)
                glProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB,
                                              p, b->frag_param[p]);
        }

        b->state = 1;
    }
}
Beispiel #14
0
void recv_set_brush_flags(void)
{
    int i     = recv_index();
    int flags = recv_index();
    int state = recv_index();

    struct brush *b = get_brush(i);

    if (state)
        b->flags = b->flags | ( flags);
    else
        b->flags = b->flags & (~flags);
}
Beispiel #15
0
void recv_set_brush_color(void)
{
    int i = recv_index();

    struct brush *b = get_brush(i);

    recv_array(b->d, 4, sizeof (float));
    recv_array(b->s, 4, sizeof (float));
    recv_array(b->a, 4, sizeof (float));
    recv_array(b->x, 1, sizeof (float));

    b->flags = recv_index();
}
Beispiel #16
0
void send_set_brush_flags(int i, int flags, int state)
{
    struct brush *b = get_brush(i);

    send_event(EVENT_SET_BRUSH_FLAGS);
    send_index(i);
    send_index(flags);
    send_index(state);

    if (state)
        b->flags = b->flags | ( flags);
    else
        b->flags = b->flags & (~flags);
}
Beispiel #17
0
void recv_set_brush_vert_param(void)
{
    struct brush *b = get_brush(recv_index());
    int           p = recv_index();

    recv_array(b->vert_param[p], 4, sizeof (float));

    if (b->vert_prog && GL_has_vertex_program)
    {
        glBindProgramARB(GL_VERTEX_PROGRAM_ARB, b->vert_prog);
        glProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB,
                                      p, b->vert_param[p]);
    }
}
Beispiel #18
0
void recv_set_brush_frag_param(void)
{
    struct brush *b = get_brush(recv_index());
    int           p = recv_index();

    recv_array(b->frag_param[p], 4, sizeof (float));

    if (b->frag_prog && GL_has_fragment_program)
    {
        glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, b->frag_prog);
        glProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB,
                                      p, b->frag_param[p]);
    }
}
Beispiel #19
0
void recv_create_brush(void)
{
    struct brush *b = get_brush(new_brush());

    b->flags = recv_index();
    b->count = 1;

    b->line_width = 1;

    recv_array(b->image, 4, sizeof (int));
    recv_array(b->d,     4, sizeof (float));
    recv_array(b->s,     4, sizeof (float));
    recv_array(b->a,     4, sizeof (float));
    recv_array(b->x,     1, sizeof (float));
}
Beispiel #20
0
void send_set_brush_uniform(int i, const char *n,
                            int r, int c, int d, const float *v)
{
    struct brush *b = get_brush(i);

    int l = strlen(n);

    send_event(EVENT_SET_BRUSH_UNIFORM);
    send_index(i);
    send_index(r);
    send_index(c);
    send_index(d);
    send_index(l);
    send_array(n, l,     sizeof (char));
    send_array(v, r * c, sizeof (float));

    set_brush_uniform(b, n, r, c, d, v);
}
Beispiel #21
0
void recv_set_brush_uniform(void)
{
    struct brush *b = get_brush(recv_index());

    int r = recv_index();
    int c = recv_index();
    int d = recv_index();
    int l = recv_index();

    float v[MAX_UNIFORM];
    char  n[MAX_NAME];

    memset(n, 0, MAX_NAME    * sizeof (char));
    memset(v, 0, MAX_UNIFORM * sizeof (float));

    recv_array(n, l,     sizeof (char));
    recv_array(v, r * c, sizeof (float));

    set_brush_uniform(b, n, r, c, d, v);
}
Beispiel #22
0
int startup_brush(void)
{
    if ((brush = vecnew(16, sizeof (struct brush))))
    {
        int i;

        /* Create a default brush. */

        if ((i = new_brush()) >= 0)
        {
            struct brush *b = get_brush(i);

            b->count = 1;
            b->state = 0;
            b->flags = BRUSH_DIFFUSE | BRUSH_SPECULAR |
                       BRUSH_AMBIENT | BRUSH_SHINY;

            b->d[0] = BRUSH_DIFFUSE_R;
            b->d[1] = BRUSH_DIFFUSE_G;
            b->d[2] = BRUSH_DIFFUSE_B;
            b->d[3] = BRUSH_DIFFUSE_A;

            b->s[0] = BRUSH_SPECULAR_R;
            b->s[1] = BRUSH_SPECULAR_G;
            b->s[2] = BRUSH_SPECULAR_B;
            b->s[3] = BRUSH_SPECULAR_A;

            b->a[0] = BRUSH_AMBIENT_R;
            b->a[1] = BRUSH_AMBIENT_G;
            b->a[2] = BRUSH_AMBIENT_B;
            b->a[3] = BRUSH_AMBIENT_A;

            b->x[0] = BRUSH_SHININESS;

            b->line_width = 1.0f;

            return 1;
        }
    }
    return 0;
}
Beispiel #23
0
void send_set_brush_color(int i, const float d[4],
                                 const float s[4],
                                 const float a[4],
                                 const float x[1], int f)
{
    struct brush *b = get_brush(i);

    b->flags |= f;

    if (f & BRUSH_DIFFUSE)
    {
        b->d[0] = d[0];
        b->d[1] = d[1];
        b->d[2] = d[2];
        b->d[3] = d[3];
    }
    if (f & BRUSH_SPECULAR)
    {
        b->s[0] = s[0];
        b->s[1] = s[1];
        b->s[2] = s[2];
        b->s[3] = s[3];
    }
    if (f & BRUSH_AMBIENT)
    {
        b->a[0] = a[0];
        b->a[1] = a[1];
        b->a[2] = a[2];
        b->a[3] = a[3];
    }
    if (f & BRUSH_SHINY)
        b->x[0] = x[0];

    send_event(EVENT_SET_BRUSH_COLOR);
    send_index(i);
    send_array(b->d, 4, sizeof (float));
    send_array(b->s, 4, sizeof (float));
    send_array(b->a, 4, sizeof (float));
    send_array(b->x, 1, sizeof (float));
    send_index(b->flags);
}
Beispiel #24
0
void send_set_brush_vert_param(int i, int p, const float v[4])
{
    struct brush *b = get_brush(i);

    b->vert_param[p][0] = v[0];
    b->vert_param[p][1] = v[1];
    b->vert_param[p][2] = v[2];
    b->vert_param[p][3] = v[3];

    send_event(EVENT_SET_BRUSH_VERT_PARAM);
    send_index(i);
    send_index(p);
    send_array(b->vert_param[p], 4, sizeof (float));

    if (b->vert_prog && GL_has_vertex_program)
    {
        glBindProgramARB(GL_VERTEX_PROGRAM_ARB, b->vert_prog);
        glProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB,
                                      p, b->vert_param[p]);
    }
}
std::set<map_location> brush_drag_mouse_action::affected_hexes(
	editor_display& /*disp*/, const map_location& hex)
{
	return get_brush().project(hex);
}
Beispiel #26
0
 virtual void apply(ptr<dc> pdc) override {
     pdc->set_brush(get_brush(pdc));
 }
Beispiel #27
0
int dupe_create_brush(int i)
{
    get_brush(i)->count++;
    return i;
}
Beispiel #28
0
int send_create_brush(const char *file, const char *name)
{
    int i, n = vecnum(brush);

    /* Scan the current brushes for an existing instance. */

    for (i = 0; i < n; ++i)
    {
        struct brush *b = get_brush(i);

        if (file && b->file && strcmp(b->file, file) == 0 &&
            name && b->name && strcmp(b->name, name) == 0)
            return dupe_create_brush(i);
    }

    /* Didn't find it.  It's new. */

    if ((i = new_brush()) >= 0)
    {
        struct brush *b = get_brush(i);

        /* Note the file and material names. */

        if (file) b->file = memdup(file, strlen(file) + 1, 1);
        if (name) b->name = memdup(name, strlen(name) + 1, 1);

        /* Set some default values. */

        b->count = 1;
        b->state = 0;
        b->flags = BRUSH_DIFFUSE | BRUSH_SPECULAR |
                   BRUSH_AMBIENT | BRUSH_SHINY;

        b->d[0] = BRUSH_DIFFUSE_R;
        b->d[1] = BRUSH_DIFFUSE_G;
        b->d[2] = BRUSH_DIFFUSE_B;
        b->d[3] = BRUSH_DIFFUSE_A;

        b->s[0] = BRUSH_SPECULAR_R;
        b->s[1] = BRUSH_SPECULAR_G;
        b->s[2] = BRUSH_SPECULAR_B;
        b->s[3] = BRUSH_SPECULAR_A;

        b->a[0] = BRUSH_AMBIENT_R;
        b->a[1] = BRUSH_AMBIENT_G;
        b->a[2] = BRUSH_AMBIENT_B;
        b->a[3] = BRUSH_AMBIENT_A;

        b->x[0] = BRUSH_SHININESS;

        b->line_width = 1;

        /* Load and pack the brush. */

        if (file && name)
            load_brush(b, file, name);

        send_event(EVENT_CREATE_BRUSH);
        send_index(b->flags);

        send_array(b->image, 4, sizeof (int));
        send_array(b->d,     4, sizeof (float));
        send_array(b->s,     4, sizeof (float));
        send_array(b->a,     4, sizeof (float));
        send_array(b->x,     1, sizeof (float));

        return i;
    }
    return -1;
}
Beispiel #29
0
void recv_set_brush_line_width(void)
{
    struct brush *b = get_brush(recv_index());

    b->line_width = recv_float();
}
Beispiel #30
0
int get_brush_t(int i)
{
    return ((get_brush(i)->flags & BRUSH_TRANSPARENT) ||
            (get_brush(i)->d[3]  < 1.0));
}