Example #1
0
/*
 *			S T K _ D O S E T U P
 */
static int sh_stk_dosetup(char *cp, struct region *rp, char **dpp, char **mpp, struct rt_i *rtip, struct mfuncs **headp)


    /* udata pointer address */
    /* mfuncs pointer address */


{
    register struct mfuncs *mfp;
#ifdef HAVE_DLOPEN
    register struct mfuncs *mfp_new;
#endif
    struct bu_vls	arg;
    char	matname[32];
    int	ret;
    int	i;

    RT_CK_RTI(rtip);

    if (rdebug&RDEBUG_MATERIAL)
	bu_log( "...starting \"%s\"\n", cp );

    /* skip leading white space */
    while ( *cp == ' ' || *cp == '\t' )
	cp++;

    for ( i = 0; i < 31 && *cp != '\0'; i++, cp++ ) {
	if (*cp == ' ' || *cp == '\t' ) {
	    matname[i++] = '\0';
	    break;
	} else
	    matname[i] = *cp;
    }
    matname[i] = '\0';	/* ensure null termination */

#ifdef HAVE_DLOPEN
 retry:
#endif
    for ( mfp = *headp; mfp != MF_NULL; mfp = mfp->mf_forw )  {
	if (matname[0] != mfp->mf_name[0]  ||
	    strcmp( matname, mfp->mf_name ) != 0 )
	    continue;
	goto found;
    }
#ifdef HAVE_DLOPEN
    /* If we get here, then the shader wasn't found in the list of
     * compiled-in (or previously loaded) shaders.  See if we can
     * dynamically load it.
     */

    bu_log("Shader \"%s\"... ", matname);

    if ((mfp_new = load_dynamic_shader(matname, strlen(matname)))) {
	mlib_add_shader(headp, mfp_new);
	goto retry;
    }
#else
    bu_log("****** dynamic shader loading not available ******\n");
#endif


    bu_log("stack_setup(%s):  material not known\n",
	   matname );
    ret = -1;
    goto out;

 found:
    *mpp = (char *)mfp;
    *dpp = (char *)0;
    bu_vls_init( &arg );
    if (*cp != '\0' )
	bu_vls_strcat( &arg, ++cp );
    if (rdebug&RDEBUG_MATERIAL)
	bu_log("calling %s with %s\n", mfp->mf_name, bu_vls_addr(&arg));
    if (mfp->mf_setup( rp, &arg, dpp, mfp, rtip, headp ) < 0 )  {
	/* Setup has failed */
	bu_vls_free( &arg );
	ret = -1;		/* BAD */
	goto out;
    }
    bu_vls_free( &arg );
    ret = 0;			/* OK */
 out:
    if (rdebug&RDEBUG_MATERIAL)
	bu_log( "...finished \"%s\", ret=%d\n", matname, ret );
    return ret;
}
HIDDEN int
sh_stk_dosetup(char *cp, struct region *rp, void **dpp, struct mfuncs **mpp, struct rt_i *rtip)


/* udata pointer address */
/* mfuncs pointer address */


{
    register struct mfuncs *mfp;
    register struct mfuncs *mfp_new;
    struct bu_vls arg = BU_VLS_INIT_ZERO;
    char matname[32];
    int ret;
    int i;
    struct mfuncs *shaders = MF_NULL;

    RT_CK_RTI(rtip);

    if (rdebug&RDEBUG_MATERIAL)
	bu_log("...starting \"%s\"\n", cp);

    /* skip leading white space */
    while (*cp == ' ' || *cp == '\t')
	cp++;

    for (i = 0; i < 31 && *cp != '\0'; i++, cp++) {
	if (*cp == ' ' || *cp == '\t') {
	    matname[i++] = '\0';
	    break;
	} else
	    matname[i] = *cp;
    }
    matname[i] = '\0';	/* ensure null termination */

retry:
    /* get list of available shaders */
    if (!shaders) {
	optical_shader_init(&shaders);
    }

    for (mfp = shaders; mfp && mfp->mf_name != NULL; mfp = mfp->mf_forw) {
	if (matname[0] != mfp->mf_name[0]  ||
	    !BU_STR_EQUAL(matname, mfp->mf_name))
	    continue;
	goto found;
    }

    /* If we get here, then the shader wasn't found in the list of
     * compiled-in (or previously loaded) shaders.  See if we can
     * dynamically load it.
     */

    bu_log("Shader \"%s\"... ", matname);

    if ((mfp_new = load_dynamic_shader(matname))) {
	mlib_add_shader(&shaders, mfp_new);
	goto retry;
    }

    bu_log("stack_setup(%s):  material not known\n",
	   matname);
    ret = -1;
    goto out;

found:
    *mpp = mfp;
    *dpp = (char *)0;
    if (*cp != '\0')
	bu_vls_strcat(&arg, ++cp);
    if (rdebug&RDEBUG_MATERIAL)
	bu_log("calling %s with %s\n", mfp->mf_name, bu_vls_addr(&arg));
    if (!mfp || !mfp->mf_setup || mfp->mf_setup(rp, &arg, dpp, mfp, rtip) < 0) {
	/* Setup has failed */
	bu_vls_free(&arg);
	ret = -1;		/* BAD */
	goto out;
    }
    bu_vls_free(&arg);
    ret = 0;			/* OK */
out:
    if (rdebug&RDEBUG_MATERIAL)
	bu_log("...finished \"%s\", ret=%d\n", matname, ret);
    return ret;
}