Exemple #1
0
void NVprPathRendererState::stencilStroke(GLint replace_value, GLuint stencil_write_mask,
                                          GLenum stencil_func,
                                          GLint stencil_ref,
                                          GLuint read_mask)
{
    glPathStencilFuncNV(stencil_func, stencil_ref, read_mask);
    glStencilStrokePathNV(path, replace_value, stencil_write_mask);
}
Exemple #2
0
static void nvpr_render_shape(void *render, LVGShapeCollection *shapecol, LVGColorTransform *cxform, float ratio, int blend_mode)
{
    //render_ctx *ctx = render;
    for (int j = 0; j < shapecol->num_shapes; j++)
    {
        NSVGshape *shape = shapecol->shapes + j;
        NSVGshape *shape2 = shapecol->morph ? shapecol->morph->shapes + j : 0;
        GLuint pathObj = shape->cache;
        if (shape2)
            pathObj = morph_shape(shape, shape2, ratio);

        /*GLfloat object_bbox[4], fill_bbox[4], stroke_bbox[4];
        glGetPathParameterfvNV(pathObj, GL_PATH_OBJECT_BOUNDING_BOX_NV, object_bbox);
        glGetPathParameterfvNV(pathObj, GL_PATH_FILL_BOUNDING_BOX_NV, fill_bbox);
        glGetPathParameterfvNV(pathObj, GL_PATH_STROKE_BOUNDING_BOX_NV, stroke_bbox);*/

        glEnable(GL_BLEND);
        glBlendEquation(GL_FUNC_ADD);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        switch(blend_mode)
        {
        case BLEND_LAYER:     assert(0); break;
        case BLEND_MULTIPLY:  glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA); break;
        case BLEND_SCREEN:    glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR); break;
        case BLEND_LIGHTEN:   glBlendFunc(GL_ONE, GL_ONE); glBlendEquation(GL_MAX); break;
        case BLEND_DARKEN:    glBlendFunc(GL_ONE, GL_ONE); glBlendEquation(GL_MIN); break;
        case BLEND_DIFFERENCE: assert(0); break;
        case BLEND_ADD:       glBlendFunc(GL_ONE, GL_ONE); break;
        case BLEND_SUBTRACT:  glBlendFunc(GL_ONE, GL_ONE); glBlendEquation(GL_FUNC_REVERSE_SUBTRACT); break;
        case BLEND_INVERT:    assert(0); break;
        case BLEND_ALPHA:     assert(0); break;
        case BLEND_ERASE:     assert(0); break;
        case BLEND_OVERLAY:   assert(0); glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA); break;
        case BLEND_HARDLIGHT: assert(0); break;
        }

        glStencilFunc(GL_NOTEQUAL, 0, 0x1F);
        glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);
        glEnable(GL_STENCIL_TEST);
        if (NSVG_PAINT_NONE != shape->fill.type)
        {
            if (NSVG_PAINT_COLOR == shape->fill.type)
            {
                NVGcolor c = transformColor(nvgColorU32(shape->fill.color), cxform);
                glColor4f(c.r, c.g, c.b, c.a);
            } else if (NSVG_PAINT_LINEAR_GRADIENT == shape->fill.type)
                LinearGrad(shape, cxform, 1);
            else if (NSVG_PAINT_RADIAL_GRADIENT == shape->fill.type)
                RadialGrad(shape, cxform, 1);
            else if (NSVG_PAINT_IMAGE == shape->fill.type)
                ImagePaint(shape, cxform, 1);
            glStencilFillPathNV(pathObj, (NSVG_FILLRULE_EVENODD == shape->fillRule) ? GL_INVERT : GL_COUNT_UP_NV, 0x1F);
            glCoverFillPathNV(pathObj, GL_BOUNDING_BOX_NV);

            glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
            glPathTexGenNV(GL_TEXTURE0, GL_NONE, 0, NULL);
            glPathColorGenNV(GL_PRIMARY_COLOR, GL_NONE, 0, NULL);
            glDisable(GL_TEXTURE_2D);
        }
        if (/*NSVG_PAINT_NONE != shape->stroke.type*/NSVG_PAINT_COLOR == shape->stroke.type)
        {
            if (NSVG_PAINT_COLOR == shape->stroke.type)
            {
                NVGcolor c = transformColor(nvgColorU32(shape->stroke.color), cxform);
                glColor4f(c.r, c.g, c.b, c.a);
            }/* else if (NSVG_PAINT_LINEAR_GRADIENT == shape->stroke.type)
                LinearGrad(shape, cxform, 0);
            else if (NSVG_PAINT_RADIAL_GRADIENT == shape->stroke.type)
                RadialGrad(shape, cxform, 0);
            else if (NSVG_PAINT_IMAGE == shape->stroke.type)
                ImagePaint(shape, cxform, 0);*/
            glPathParameterfNV(pathObj, GL_PATH_STROKE_WIDTH_NV, shape->strokeWidth);
            if (NSVG_JOIN_ROUND == shape->strokeLineJoin)
                glPathParameteriNV(pathObj, GL_PATH_JOIN_STYLE_NV, GL_ROUND_NV);
            else if (NSVG_JOIN_BEVEL == shape->strokeLineJoin)
                glPathParameteriNV(pathObj, GL_PATH_JOIN_STYLE_NV, GL_BEVEL_NV);
            else if (NSVG_JOIN_MITER == shape->strokeLineJoin)
                glPathParameteriNV(pathObj, GL_PATH_JOIN_STYLE_NV, GL_MITER_TRUNCATE_NV);
            glPathParameterfNV(pathObj, GL_PATH_MITER_LIMIT_NV, shape->miterLimit);
            if (NSVG_CAP_ROUND == shape->strokeLineCap)
                glPathParameteriNV(pathObj, GL_PATH_END_CAPS_NV, GL_ROUND_NV);
            else if (NSVG_CAP_BUTT == shape->strokeLineCap)
                glPathParameteriNV(pathObj, GL_PATH_END_CAPS_NV, GL_FLAT);
            else if (NSVG_CAP_SQUARE == shape->strokeLineCap)
                glPathParameteriNV(pathObj, GL_PATH_END_CAPS_NV, GL_SQUARE_NV);
            GLint reference = 0x1;
            glStencilStrokePathNV(pathObj, reference, 0x1F);
            glCoverStrokePathNV(pathObj, GL_BOUNDING_BOX_NV);

            glPathColorGenNV(GL_PRIMARY_COLOR, GL_NONE, 0, NULL);
        }
        glDisable(GL_STENCIL_TEST);
        glDisable(GL_BLEND);
        if (shape2)
            glDeletePathsNV(pathObj, 1);
    }
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_NVPathRendering_nglStencilStrokePathNV(JNIEnv *env, jclass clazz, jint path, jint reference, jint mask, jlong function_pointer) {
	glStencilStrokePathNVPROC glStencilStrokePathNV = (glStencilStrokePathNVPROC)((intptr_t)function_pointer);
	glStencilStrokePathNV(path, reference, mask);
}