From 268a332d3afed1e1e78663c0b3dad26f475a46ef Mon Sep 17 00:00:00 2001 From: Ulrich Schwickerath Date: Sun, 29 Mar 2026 11:46:06 +0200 Subject: [PATCH 1/2] code formatting only --- src/libphigs/css/css_el.c | 1017 ++++++++++++++++++------------------- 1 file changed, 508 insertions(+), 509 deletions(-) diff --git a/src/libphigs/css/css_el.c b/src/libphigs/css/css_el.c index a234a92..3383410 100644 --- a/src/libphigs/css/css_el.c +++ b/src/libphigs/css/css_el.c @@ -28,18 +28,18 @@ Copyright (c) 1989,1990, 1991 by Sun Microsystems, Inc. All Rights Reserved -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in +both that copyright notice and this permission notice appear in supporting documentation, and that the names of Sun Microsystems, -and the X Consortium, not be used in advertising or publicity -pertaining to distribution of the software without specific, written -prior permission. +and the X Consortium, not be used in advertising or publicity +pertaining to distribution of the software without specific, written +prior permission. -SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT -SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL +SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT +SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS @@ -64,12 +64,12 @@ static int css_add_to_refer_sets(Css_handle cssh, Struct_handle exec_struct); /******************* phg_css_add_elem - Create a new element, insert (or replace) it in the - currently open structure, and call the appropriate - function (in el_funcs) to store the element data, - according to its type. If it is an execute structure - element, update the structure refer sets. - Return TRUE if successful, otherwise return FALSE - (malloc failure). + currently open structure, and call the appropriate + function (in el_funcs) to store the element data, + according to its type. If it is an execute structure + element, update the structure refer sets. + Return TRUE if successful, otherwise return FALSE + (malloc failure). *******************/ @@ -78,39 +78,39 @@ int phg_css_add_elem(Css_handle cssh, Phg_args_add_el *args) El_handle elptr; if ( (cssh->edit_mode == PEDIT_INSERT) || (!cssh->el_index) ) { - /* in replace mode, if current element is #0, insert before element #1*/ - CSS_CREATE_EL(cssh, elptr) - CSS_INSERT_EL(cssh, elptr) - elptr->eltype = ARGS_ELMT_TYPE(args); - if (!(*cssh->el_funcs[(int)ARGS_ELMT_TYPE(args)]) (cssh, elptr, - (caddr_t) args, CSS_EL_CREATE)){ - ERR_BUF(cssh->erh, ERR901); - return(FALSE); /* out of memory */ - } + /* in replace mode, if current element is #0, insert before element #1*/ + CSS_CREATE_EL(cssh, elptr) + CSS_INSERT_EL(cssh, elptr) + elptr->eltype = ARGS_ELMT_TYPE(args); + if (!(*cssh->el_funcs[(int)ARGS_ELMT_TYPE(args)]) (cssh, elptr, + (caddr_t) args, CSS_EL_CREATE)){ + ERR_BUF(cssh->erh, ERR901); + return(FALSE); /* out of memory */ + } } else { - /* replace mode, really replacing the current element */ - elptr = cssh->el_ptr; - /* find out if new data is of the same class as the old */ - if (cssh->el_funcs[(int)ARGS_ELMT_TYPE(args)] - != cssh->el_funcs[(int)elptr->eltype]) { - /* 2 different classes of data, so free the old, create the new */ - (void)(*cssh->el_funcs[(int)elptr->eltype]) - (cssh, elptr, (caddr_t)cssh->open_struct, CSS_EL_FREE); - elptr->eltype = ARGS_ELMT_TYPE(args); - if (!(*cssh->el_funcs[(int)ARGS_ELMT_TYPE(args)]) - (cssh, elptr, (caddr_t) args, CSS_EL_CREATE)) { - ERR_BUF(cssh->erh, ERR901); - return(FALSE); /* out of memory */ - } - } else { - /* same class of data, so just replace what is there now */ - elptr->eltype = ARGS_ELMT_TYPE(args); - if (!(*cssh->el_funcs[(int)ARGS_ELMT_TYPE(args)]) - (cssh, elptr, (caddr_t) args, CSS_EL_REPLACE)) { - ERR_BUF(cssh->erh, ERR901); - return(FALSE); /* out of memory */ - } - } + /* replace mode, really replacing the current element */ + elptr = cssh->el_ptr; + /* find out if new data is of the same class as the old */ + if (cssh->el_funcs[(int)ARGS_ELMT_TYPE(args)] + != cssh->el_funcs[(int)elptr->eltype]) { + /* 2 different classes of data, so free the old, create the new */ + (void)(*cssh->el_funcs[(int)elptr->eltype]) + (cssh, elptr, (caddr_t)cssh->open_struct, CSS_EL_FREE); + elptr->eltype = ARGS_ELMT_TYPE(args); + if (!(*cssh->el_funcs[(int)ARGS_ELMT_TYPE(args)]) + (cssh, elptr, (caddr_t) args, CSS_EL_CREATE)) { + ERR_BUF(cssh->erh, ERR901); + return(FALSE); /* out of memory */ + } + } else { + /* same class of data, so just replace what is there now */ + elptr->eltype = ARGS_ELMT_TYPE(args); + if (!(*cssh->el_funcs[(int)ARGS_ELMT_TYPE(args)]) + (cssh, elptr, (caddr_t) args, CSS_EL_REPLACE)) { + ERR_BUF(cssh->erh, ERR901); + return(FALSE); /* out of memory */ + } + } } return(TRUE); } @@ -118,77 +118,77 @@ int phg_css_add_elem(Css_handle cssh, Phg_args_add_el *args) /******************* phg_css_set_ep - Set the element pointer as indicated by opcode. Return - new value of element pointer unless a label was not - found; in that case return NULL. + new value of element pointer unless a label was not + found; in that case return NULL. *******************/ El_handle phg_css_set_ep(Css_handle cssh, Phg_args_set_ep_op opcode, Pint data) { - El_handle elptr; - int i; - - switch (opcode) { - - case PHG_ARGS_SETEP_ABS: - cssh->el_ptr = cssh->open_struct->first_el; - cssh->el_index = 0; - /* fall through to SETEP_REL code */ - - case PHG_ARGS_SETEP_REL: - elptr = cssh->el_ptr; - if (data >= 0) - /* search forward */ - while (data--) { - if (elptr->next == cssh->open_struct->last_el) - break; - elptr = elptr->next; - cssh->el_index++; - } - else - /* search backwards */ - while (data++ && elptr!=cssh->open_struct->first_el) { - elptr = elptr->prev; - cssh->el_index--; - } - break; - - case PHG_ARGS_SETEP_LABEL: - elptr = cssh->el_ptr->next; - i = cssh->el_index + 1; - while ( elptr != cssh->open_struct->last_el ) { - if ( elptr->eltype == PELEM_LABEL - && PHG_INT(elptr) == data ) - break; - elptr = elptr->next; - i++; - } - if (elptr == cssh->open_struct->last_el) { - ERR_BUF(cssh->erh, ERR205); - return(NULL); /* label not found */ - } - cssh->el_index = i; - break; - - default: - /* Default */ + El_handle elptr; + int i; + + switch (opcode) { + + case PHG_ARGS_SETEP_ABS: + cssh->el_ptr = cssh->open_struct->first_el; + cssh->el_index = 0; + /* fall through to SETEP_REL code */ + + case PHG_ARGS_SETEP_REL: + elptr = cssh->el_ptr; + if (data >= 0) + /* search forward */ + while (data--) { + if (elptr->next == cssh->open_struct->last_el) + break; + elptr = elptr->next; + cssh->el_index++; + } + else + /* search backwards */ + while (data++ && elptr!=cssh->open_struct->first_el) { + elptr = elptr->prev; + cssh->el_index--; + } + break; + + case PHG_ARGS_SETEP_LABEL: + elptr = cssh->el_ptr->next; + i = cssh->el_index + 1; + while ( elptr != cssh->open_struct->last_el ) { + if ( elptr->eltype == PELEM_LABEL + && PHG_INT(elptr) == data ) break; + elptr = elptr->next; + i++; + } + if (elptr == cssh->open_struct->last_el) { + ERR_BUF(cssh->erh, ERR205); + return(NULL); /* label not found */ } - return(cssh->el_ptr = elptr); + cssh->el_index = i; + break; + + default: + /* Default */ + break; + } + return(cssh->el_ptr = elptr); } /******************* phg_css_el_delete_list - Return element pointers to the first and last of a list of elements to be deleted, as indicated by - the parameters for deleting a range, between - labels, etc. The pointers will both point to the - same element for DEL_CURRENT. ep1 always points - to the element closest to the beginning of the - structure, so any routine processing the list - of elements delimited by ep1 and ep2 can do so - by following the "next" field of each successive - element. + the parameters for deleting a range, between + labels, etc. The pointers will both point to the + same element for DEL_CURRENT. ep1 always points + to the element closest to the beginning of the + structure, so any routine processing the list + of elements delimited by ep1 and ep2 can do so + by following the "next" field of each successive + element. *******************/ @@ -197,129 +197,129 @@ void phg_css_el_delete_list(Css_handle cssh, Phg_args_del_el_data *data, El_handle *ep1, El_handle *ep2) { - El_handle elptr; - int i1, i2; - Struct_handle structp; - - switch (opcode) { - - case PHG_ARGS_DEL_CURRENT: - if (cssh->el_index) - *ep1 = *ep2 = cssh->el_ptr; - else - *ep1 = NULL; - break; - - case PHG_ARGS_DEL_RANGE: - if (!cssh->open_struct->num_el) { - *ep1 = NULL; - return; /* empty structure */ - } - i1 = data->ep_values.ep1; - /* make sure i1 <= i2 */ - if (i1 > data->ep_values.ep2) { - i2 = i1; - i1 = data->ep_values.ep2; - } else - i2 = data->ep_values.ep2; - if (i1<1 && i2<1) { - /* nothing to delete here, but set ep to element 0 */ - *ep1 = NULL; - cssh->el_ptr = cssh->open_struct->first_el; - cssh->el_index = 0; - return; - } - /* make sure index values are in range */ - if (i1 < 1) - i1 = 1; - else if (i1 > cssh->open_struct->num_el) - i1 = cssh->open_struct->num_el; - if (i2 < 1) - i2 = 1; - else if (i2 > cssh->open_struct->num_el) - i2 = cssh->open_struct->num_el; - /* now get the pointer values */ - i2 = i2 - i1; - *ep1 = cssh->open_struct->first_el; - while (i1--) - *ep1 = (*ep1)->next; - *ep2 = *ep1; - while (i2--) - *ep2 = (*ep2)->next; - break; - - case PHG_ARGS_DEL_LABEL: - *ep1 = *ep2 = NULL; - elptr = cssh->el_ptr->next; - i1 = cssh->el_index + 1; - while ( elptr != cssh->open_struct->last_el ) { - if ( elptr->eltype == PELEM_LABEL - && PHG_INT(elptr) == - data->label_range.label1 ) - break; - elptr = elptr->next; - i1++; - } - if (elptr == cssh->open_struct->last_el) { - ERR_BUF(cssh->erh, ERR206); - return; /* label not found */ - } - *ep1 = elptr; - elptr = elptr->next; - i2 = i1 + 1; - while ( elptr != cssh->open_struct->last_el ) { - if ( elptr->eltype == PELEM_LABEL - && PHG_INT(elptr) == - data->label_range.label2 ) - break; - elptr = elptr->next; - i2++; - } - if (elptr == cssh->open_struct->last_el) { - ERR_BUF(cssh->erh, ERR206); - return; /* label not found */ - } - if (i2-1 == i1) { - /* nothing to delete here, but set ep to label 1 */ - cssh->el_ptr = *ep1; - cssh->el_index = i1; - *ep1 = NULL; - } else { - *ep1 = (*ep1)->next; - *ep2 = elptr->prev; - } - break; - - case PHG_ARGS_EMPTY_STRUCT: - *ep1 = NULL; - /* if structure doesn't exist, create an empty one */ - if ( !(structp = CSS_STRUCT_EXISTS(cssh, data->struct_id)) ) { - if ( !(structp = phg_css_create_struct(data->struct_id)) ) { - ERR_BUF(cssh->erh, ERR901); - return; /* out of memory */ - } - if ( !phg_css_stab_insert(cssh->stab, data->struct_id, structp) ) { - ERR_BUF(cssh->erh, ERR901); - return; /* out of memory */ - } - } else { - if (structp->num_el) { - *ep1 = structp->first_el->next; - *ep2 = structp->last_el->prev; - } - } - break; + El_handle elptr; + int i1, i2; + Struct_handle structp; + + switch (opcode) { + + case PHG_ARGS_DEL_CURRENT: + if (cssh->el_index) + *ep1 = *ep2 = cssh->el_ptr; + else + *ep1 = NULL; + break; + + case PHG_ARGS_DEL_RANGE: + if (!cssh->open_struct->num_el) { + *ep1 = NULL; + return; /* empty structure */ } + i1 = data->ep_values.ep1; + /* make sure i1 <= i2 */ + if (i1 > data->ep_values.ep2) { + i2 = i1; + i1 = data->ep_values.ep2; + } else + i2 = data->ep_values.ep2; + if (i1<1 && i2<1) { + /* nothing to delete here, but set ep to element 0 */ + *ep1 = NULL; + cssh->el_ptr = cssh->open_struct->first_el; + cssh->el_index = 0; + return; + } + /* make sure index values are in range */ + if (i1 < 1) + i1 = 1; + else if (i1 > cssh->open_struct->num_el) + i1 = cssh->open_struct->num_el; + if (i2 < 1) + i2 = 1; + else if (i2 > cssh->open_struct->num_el) + i2 = cssh->open_struct->num_el; + /* now get the pointer values */ + i2 = i2 - i1; + *ep1 = cssh->open_struct->first_el; + while (i1--) + *ep1 = (*ep1)->next; + *ep2 = *ep1; + while (i2--) + *ep2 = (*ep2)->next; + break; + + case PHG_ARGS_DEL_LABEL: + *ep1 = *ep2 = NULL; + elptr = cssh->el_ptr->next; + i1 = cssh->el_index + 1; + while ( elptr != cssh->open_struct->last_el ) { + if ( elptr->eltype == PELEM_LABEL + && PHG_INT(elptr) == + data->label_range.label1 ) + break; + elptr = elptr->next; + i1++; + } + if (elptr == cssh->open_struct->last_el) { + ERR_BUF(cssh->erh, ERR206); + return; /* label not found */ + } + *ep1 = elptr; + elptr = elptr->next; + i2 = i1 + 1; + while ( elptr != cssh->open_struct->last_el ) { + if ( elptr->eltype == PELEM_LABEL + && PHG_INT(elptr) == + data->label_range.label2 ) + break; + elptr = elptr->next; + i2++; + } + if (elptr == cssh->open_struct->last_el) { + ERR_BUF(cssh->erh, ERR206); + return; /* label not found */ + } + if (i2-1 == i1) { + /* nothing to delete here, but set ep to label 1 */ + cssh->el_ptr = *ep1; + cssh->el_index = i1; + *ep1 = NULL; + } else { + *ep1 = (*ep1)->next; + *ep2 = elptr->prev; + } + break; + + case PHG_ARGS_EMPTY_STRUCT: + *ep1 = NULL; + /* if structure doesn't exist, create an empty one */ + if ( !(structp = CSS_STRUCT_EXISTS(cssh, data->struct_id)) ) { + if ( !(structp = phg_css_create_struct(data->struct_id)) ) { + ERR_BUF(cssh->erh, ERR901); + return; /* out of memory */ + } + if ( !phg_css_stab_insert(cssh->stab, data->struct_id, structp) ) { + ERR_BUF(cssh->erh, ERR901); + return; /* out of memory */ + } + } else { + if (structp->num_el) { + *ep1 = structp->first_el->next; + *ep2 = structp->last_el->prev; + } + } + break; + } } /******************* phg_css_delete_el - Delete the list of elements delimited by ep1 and ep2. - This routine assumes ep1 and ep2 were obtained from - phg_css_el_delete_list and therefore doesn't worry - about the possibility of ep1 pointing to element 0. - Set the current element index and pointer appropriately. + This routine assumes ep1 and ep2 were obtained from + phg_css_el_delete_list and therefore doesn't worry + about the possibility of ep1 pointing to element 0. + Set the current element index and pointer appropriately. *******************/ @@ -334,20 +334,20 @@ void phg_css_delete_el(Css_handle cssh, int i; if (opcode != PHG_ARGS_EMPTY_STRUCT) { - /* set new current element pointer and index */ - cssh->el_ptr = ep1->prev; - CSS_UPDATE_EL_INDEX(cssh) - structp = cssh->open_struct; + /* set new current element pointer and index */ + cssh->el_ptr = ep1->prev; + CSS_UPDATE_EL_INDEX(cssh) + structp = cssh->open_struct; } else { - /* only reset element ptr/index if this structure is the open one */ - if (cssh->open_struct && - (data->struct_id == cssh->open_struct->struct_id) ) { - cssh->el_ptr = cssh->open_struct->first_el; - cssh->el_index = 0; - structp = cssh->open_struct; - } else { - structp = CSS_STRUCT_EXISTS(cssh, data->struct_id); - } + /* only reset element ptr/index if this structure is the open one */ + if (cssh->open_struct && + (data->struct_id == cssh->open_struct->struct_id) ) { + cssh->el_ptr = cssh->open_struct->first_el; + cssh->el_index = 0; + structp = cssh->open_struct; + } else { + structp = CSS_STRUCT_EXISTS(cssh, data->struct_id); + } } /* remove group of elements from structure */ @@ -358,12 +358,12 @@ void phg_css_delete_el(Css_handle cssh, i = 0; ep2 = ep2->next; do { - (void) (*cssh->el_funcs[(int)elptr->eltype]) - (cssh, elptr, (caddr_t)structp, CSS_EL_FREE); - ep1 = elptr; - elptr = elptr->next; - free( (char *)ep1 ); - i++; + (void) (*cssh->el_funcs[(int)elptr->eltype]) + (cssh, elptr, (caddr_t)structp, CSS_EL_FREE); + ep1 = elptr; + elptr = elptr->next; + free( (char *)ep1 ); + i++; } while (elptr != ep2); structp->num_el -= i; } @@ -371,14 +371,14 @@ void phg_css_delete_el(Css_handle cssh, /******************* phg_css_struct_ref - Handle element data for execute structure element - This includes creating non_existent structures - and updating ws_appear and refer_to information - as needed. Also includes translating between structure - pointer stored in css and structure id stored in - archive. - Return TRUE(1) if successful, FALSE(0) if malloc - failed; return -1 if successful but an empty - structure had to be created. + This includes creating non_existent structures + and updating ws_appear and refer_to information + as needed. Also includes translating between structure + pointer stored in css and structure id stored in + archive. + Return TRUE(1) if successful, FALSE(0) if malloc + failed; return -1 if successful but an empty + structure had to be created. *******************/ @@ -387,86 +387,86 @@ int phg_css_struct_ref(Css_handle cssh, caddr_t argdata, Css_el_op opcode) { - Struct_handle structp; - int structid; - int retval = TRUE; - - switch (opcode) { - case CSS_EL_REPLACE: - phg_css_rm_from_ws_appear(cssh, (Struct_handle)elptr->eldata.ptr, - cssh->open_struct->ws_appear_on, 1); - css_rm_from_refer_sets(cssh->open_struct, elptr); - /* fall through */ - - case CSS_EL_CREATE: - case CSS_EL_AR_TO_CSS: - structid = opcode == CSS_EL_AR_TO_CSS ? - ((Css_eldata *)argdata)->idata : - *((Pint *) (((Phg_args_add_el *) argdata)->el_data)); - /* if executed structure doesn't exist, create an empty one */ - if ( !(structp = CSS_STRUCT_EXISTS(cssh, structid)) ) { - if ( !(structp = phg_css_create_struct(structid)) ) - return(FALSE); /* out of memory */ - if ( !phg_css_stab_insert(cssh->stab, structid, structp) ) - return(FALSE); /* out of memory */ - retval = -1; - } - elptr->eldata.ptr = (caddr_t)structp; - if ( !css_add_to_refer_sets(cssh, structp) ) - return(FALSE); /* out of memory */ - if ( !phg_css_add_to_ws_appear(cssh, structp, - cssh->open_struct->ws_appear_on, 1)) - return(FALSE); /* out of memory */ - break; - - case CSS_EL_COPY: - elptr->eldata.ptr = ((Css_eldata *)argdata)->ptr; - structp = (Struct_handle)elptr->eldata.ptr; - if ( !css_add_to_refer_sets(cssh, structp) ) - return(FALSE); /* out of memory */ - if ( !phg_css_add_to_ws_appear(cssh, structp, - cssh->open_struct->ws_appear_on, 1)) - return(FALSE); /* out of memory */ - break; - - case CSS_EL_CSS_TO_AR: - elptr->eldata.idata = - ((Struct_handle)(((Css_eldata *)argdata)->ptr))->struct_id; - break; - - case CSS_EL_FREE: - if (argdata && cssh->ssh_type!=SSH_AR) { - /* if no structp passed in argdata, or if ssh is an archive (archive - * maintains no ws_appear or refer_to lists), no need to do this - */ - phg_css_rm_from_ws_appear(cssh, (Struct_handle)elptr->eldata.ptr, - ((Struct_handle)argdata)->ws_appear_on, 1); - css_rm_from_refer_sets((Struct_handle)argdata, elptr); - } - break; - - case CSS_EL_INQ_CONTENT: { - Phg_ret_q_content *ret_data = (Phg_ret_q_content *)argdata; - CSS_MEM_BLOCK(cssh, sizeof(Phg_elmt_info) + sizeof(Pint), - ret_data->el_head, Phg_elmt_info); - ret_data->el_head->elementType = PELEM_EXEC_STRUCT; - ret_data->el_head->length = sizeof(Phg_elmt_info) + sizeof(Pint); - *((Pint *) (&ret_data->el_head[1])) = - ((Struct_handle)elptr->eldata.ptr)->struct_id; - } break; - - case CSS_EL_INQ_TYPE_SIZE: - *((Pint *)argdata) = 0; - break; + Struct_handle structp; + int structid; + int retval = TRUE; + + switch (opcode) { + case CSS_EL_REPLACE: + phg_css_rm_from_ws_appear(cssh, (Struct_handle)elptr->eldata.ptr, + cssh->open_struct->ws_appear_on, 1); + css_rm_from_refer_sets(cssh->open_struct, elptr); + /* fall through */ + + case CSS_EL_CREATE: + case CSS_EL_AR_TO_CSS: + structid = opcode == CSS_EL_AR_TO_CSS ? + ((Css_eldata *)argdata)->idata : + *((Pint *) (((Phg_args_add_el *) argdata)->el_data)); + /* if executed structure doesn't exist, create an empty one */ + if ( !(structp = CSS_STRUCT_EXISTS(cssh, structid)) ) { + if ( !(structp = phg_css_create_struct(structid)) ) + return(FALSE); /* out of memory */ + if ( !phg_css_stab_insert(cssh->stab, structid, structp) ) + return(FALSE); /* out of memory */ + retval = -1; } - return(retval); + elptr->eldata.ptr = (caddr_t)structp; + if ( !css_add_to_refer_sets(cssh, structp) ) + return(FALSE); /* out of memory */ + if ( !phg_css_add_to_ws_appear(cssh, structp, + cssh->open_struct->ws_appear_on, 1)) + return(FALSE); /* out of memory */ + break; + + case CSS_EL_COPY: + elptr->eldata.ptr = ((Css_eldata *)argdata)->ptr; + structp = (Struct_handle)elptr->eldata.ptr; + if ( !css_add_to_refer_sets(cssh, structp) ) + return(FALSE); /* out of memory */ + if ( !phg_css_add_to_ws_appear(cssh, structp, + cssh->open_struct->ws_appear_on, 1)) + return(FALSE); /* out of memory */ + break; + + case CSS_EL_CSS_TO_AR: + elptr->eldata.idata = + ((Struct_handle)(((Css_eldata *)argdata)->ptr))->struct_id; + break; + + case CSS_EL_FREE: + if (argdata && cssh->ssh_type!=SSH_AR) { + /* if no structp passed in argdata, or if ssh is an archive (archive + * maintains no ws_appear or refer_to lists), no need to do this + */ + phg_css_rm_from_ws_appear(cssh, (Struct_handle)elptr->eldata.ptr, + ((Struct_handle)argdata)->ws_appear_on, 1); + css_rm_from_refer_sets((Struct_handle)argdata, elptr); + } + break; + + case CSS_EL_INQ_CONTENT: { + Phg_ret_q_content *ret_data = (Phg_ret_q_content *)argdata; + CSS_MEM_BLOCK(cssh, sizeof(Phg_elmt_info) + sizeof(Pint), + ret_data->el_head, Phg_elmt_info); + ret_data->el_head->elementType = PELEM_EXEC_STRUCT; + ret_data->el_head->length = sizeof(Phg_elmt_info) + sizeof(Pint); + *((Pint *) (&ret_data->el_head[1])) = + ((Struct_handle)elptr->eldata.ptr)->struct_id; + } break; + + case CSS_EL_INQ_TYPE_SIZE: + *((Pint *)argdata) = 0; + break; + } + return(retval); } /******************* phg_css_no_data - Dummy for element types with no associated data. - Only PELEM_NIL now. - Return TRUE. + Only PELEM_NIL now. + Return TRUE. *******************/ @@ -477,138 +477,138 @@ int phg_css_no_data(Css_handle cssh, { Phg_ret_q_content *ret_data = (Phg_ret_q_content *)(&argdata); - switch (opcode) { - case CSS_EL_INQ_CONTENT: - ret_data->op = 0; - ret_data->el_head = NULL; - break; - - case CSS_EL_INQ_TYPE_SIZE: - ARGS_INQ_SIZE(&argdata) = 0; - break; - - default: - /* Default */ - break; - } - return(TRUE); + switch (opcode) { + case CSS_EL_INQ_CONTENT: + ret_data->op = 0; + ret_data->el_head = NULL; + break; + + case CSS_EL_INQ_TYPE_SIZE: + ARGS_INQ_SIZE(&argdata) = 0; + break; + + default: + /* Default */ + break; + } + return(TRUE); } -/* +/* * Structure Sets - a set has a key and data associated with that key. For - * the structure sets the data fields are counts, pointers to other sets or + * the structure sets the data fields are counts, pointers to other sets or * NULL. Counting is used to know when a structure is not referenced by any * structure. - * + * * Notation: { ( , ) } is a set of ordered pairs; {( , {( , )})} is a set * whose data field is another set. - * - * refer_to_me - set of structures that refer to me - * {(struct_ptr, count)} - * - * i_refer_to - structures this structure refers to; associated - * with each referenced structure is a set of element - * ptrs for the EXECUTE_STRUCTURE elements. - * {(struct_ptr, {(el_ptr, NULL)})} - * + * + * refer_to_me - set of structures that refer to me + * {(struct_ptr, count)} + * + * i_refer_to - structures this structure refers to; associated + * with each referenced structure is a set of element + * ptrs for the EXECUTE_STRUCTURE elements. + * {(struct_ptr, {(el_ptr, NULL)})} + * */ /******************* css_add_to_refer_sets - Add the executed structure (named in current - structure element) to the currently open - structure's i_refer_to set, and add the - currently open structure to the executed - structure's refer_to_me set. - Return TRUE if successful, FALSE if malloc - failed. + structure element) to the currently open + structure's i_refer_to set, and add the + currently open structure to the executed + structure's refer_to_me set. + Return TRUE if successful, FALSE if malloc + failed. *******************/ static int css_add_to_refer_sets(Css_handle cssh, Struct_handle exec_struct) -{ - Struct_handle open_struct = cssh->open_struct; - Css_set_ptr el_set; /* set of element pointers */ - int count; /* how many times a structure - * has been referenced */ - - /* see if open structure has previously referenced exec_struct, if not - * then create a set for exec_struct before adding the elptr to the - * EXECUTE STRUCTURE element. - */ - if (!phg_css_set_element_of(open_struct->i_refer_to, - (caddr_t)exec_struct, (caddr_t *)&el_set)){ - if ( !(el_set = phg_css_set_create(SET_DATA_SET)) ) - return(FALSE); /* out of memory */ - if ( !phg_css_set_add(open_struct->i_refer_to, (caddr_t)exec_struct, - (caddr_t)el_set) ) - return(FALSE); /* out of memory */ - } - if ( !phg_css_set_add(el_set, (caddr_t)cssh->el_ptr, (caddr_t)NULL) ) - return(FALSE); /* out of memory */ - - /* add open struct to exec_struct's refer_to_me set */ - if( !phg_css_set_element_of(exec_struct->refer_to_me, - (caddr_t)open_struct, (caddr_t *)&count) ) - count = 0; - count++; - if ( !phg_css_set_add(exec_struct->refer_to_me, (caddr_t)open_struct, - (caddr_t)((long)count)) ) - return(FALSE); /* out of memory */ - - return(TRUE); +{ + Struct_handle open_struct = cssh->open_struct; + Css_set_ptr el_set; /* set of element pointers */ + int count; /* how many times a structure + * has been referenced */ + + /* see if open structure has previously referenced exec_struct, if not + * then create a set for exec_struct before adding the elptr to the + * EXECUTE STRUCTURE element. + */ + if (!phg_css_set_element_of(open_struct->i_refer_to, + (caddr_t)exec_struct, (caddr_t *)&el_set)){ + if ( !(el_set = phg_css_set_create(SET_DATA_SET)) ) + return(FALSE); /* out of memory */ + if ( !phg_css_set_add(open_struct->i_refer_to, (caddr_t)exec_struct, + (caddr_t)el_set) ) + return(FALSE); /* out of memory */ + } + if ( !phg_css_set_add(el_set, (caddr_t)cssh->el_ptr, (caddr_t)NULL) ) + return(FALSE); /* out of memory */ + + /* add open struct to exec_struct's refer_to_me set */ + if( !phg_css_set_element_of(exec_struct->refer_to_me, + (caddr_t)open_struct, (caddr_t *)&count) ) + count = 0; + count++; + if ( !phg_css_set_add(exec_struct->refer_to_me, (caddr_t)open_struct, + (caddr_t)((long)count)) ) + return(FALSE); /* out of memory */ + + return(TRUE); } /******************* - css_rm_from_refer_sets - Remove the executed structure (named in current - structure element) from the currently open - structure's i_refer_to set, and remove the - currently open structure from the executed - structure's refer_to_me set. + css_rm_from_refer_sets - Remove the executed structure (named in current + structure element) from the currently open + structure's i_refer_to set, and remove the + currently open structure from the executed + structure's refer_to_me set. *******************/ static void css_rm_from_refer_sets(Struct_handle edit_struct, El_handle elptr) -{ - Struct_handle exec_struct = /* structure being executed */ - (Struct_handle)elptr->eldata.ptr; - Css_set_ptr el_set; /* set of element pointers */ - int count; /* how many times a structure - * has been referenced */ - - /* remove element ptr from set of references to exec_struct, and remove - * the set of references if there was only the one ptr in it - */ - if (phg_css_set_element_of(edit_struct->i_refer_to, - (caddr_t)exec_struct, (caddr_t *)&el_set)) { - (void) phg_css_set_remove(el_set, (caddr_t)elptr); - if (!el_set->num_elements) { - (void) phg_css_set_remove(edit_struct->i_refer_to, - (caddr_t)exec_struct); - phg_css_set_free(el_set); - } - } - /* if executed struct is no longer referred to by the open structure, - * remove edit_struct from the set, otherwise just decrement the count - */ - if (phg_css_set_element_of(exec_struct->refer_to_me, - (caddr_t)edit_struct, (caddr_t *)&count)) { - if (--count <= 0) - (void) phg_css_set_remove(exec_struct->refer_to_me, - (caddr_t)edit_struct); - else - (void)phg_css_set_add(exec_struct->refer_to_me, - (caddr_t)((long)edit_struct), (caddr_t)((long)count)); +{ + Struct_handle exec_struct = /* structure being executed */ + (Struct_handle)elptr->eldata.ptr; + Css_set_ptr el_set; /* set of element pointers */ + int count; /* how many times a structure + * has been referenced */ + + /* remove element ptr from set of references to exec_struct, and remove + * the set of references if there was only the one ptr in it + */ + if (phg_css_set_element_of(edit_struct->i_refer_to, + (caddr_t)exec_struct, (caddr_t *)&el_set)) { + (void) phg_css_set_remove(el_set, (caddr_t)elptr); + if (!el_set->num_elements) { + (void) phg_css_set_remove(edit_struct->i_refer_to, + (caddr_t)exec_struct); + phg_css_set_free(el_set); } + } + /* if executed struct is no longer referred to by the open structure, + * remove edit_struct from the set, otherwise just decrement the count + */ + if (phg_css_set_element_of(exec_struct->refer_to_me, + (caddr_t)edit_struct, (caddr_t *)&count)) { + if (--count <= 0) + (void) phg_css_set_remove(exec_struct->refer_to_me, + (caddr_t)edit_struct); + else + (void)phg_css_set_add(exec_struct->refer_to_me, + (caddr_t)((long)edit_struct), (caddr_t)((long)count)); + } } /******************* phg_css_el_search - Perform "element search" forward or backward - for an element in the inclusion set, but not - in the exclusion set. + for an element in the inclusion set, but not + in the exclusion set. *******************/ @@ -620,93 +620,92 @@ void phg_css_el_search(Css_handle cssh, Pelem_type_list *excl, Phg_ret *ret) { - Struct_handle structp; - El_handle elptr; - Pint elem_no, count; - char type_array [(int)PELEM_NUM_EL_TYPES]; - char *type_ptr; - Pelem_type sel_type; - - if ( !(structp = CSS_STRUCT_EXISTS(cssh, struct_id)) ) { - ret->err = ERR201; - return; - } else { - ret->err = 0; - ret->data.el_search.status = PSEARCH_STATUS_FAILURE; - ret->data.el_search.found_el = 0; + Struct_handle structp; + El_handle elptr; + Pint elem_no, count; + char type_array [(int)PELEM_NUM_EL_TYPES]; + char *type_ptr; + Pelem_type sel_type; + + if ( !(structp = CSS_STRUCT_EXISTS(cssh, struct_id)) ) { + ret->err = ERR201; + return; + } else { + ret->err = 0; + ret->data.el_search.status = PSEARCH_STATUS_FAILURE; + ret->data.el_search.found_el = 0; + } + + /* Find start_el element, clamping to NIL elements at ends of structure */ + if (start_el <= 0) { + start_el = 0; + elptr = structp->first_el; /* HEAD NIL element */ + + } else if (start_el >= structp->num_el) {/* as far as we ever go */ + start_el = structp->num_el; + elptr = structp->last_el->prev; /* last non-NIL element */ + + } else { /* count forward for start_el */ + El_handle next; + + assert( (1 <= start_el) && (start_el <= structp->num_el) ); + + elptr = structp->first_el; + next = elptr->next; + elem_no = 0; + while (elem_no < start_el) { + elptr = next; + assert(elptr); + next = elptr->next; + assert(next); + elem_no++; } - - /* Find start_el element, clamping to NIL elements at ends of structure */ - if (start_el <= 0) { - start_el = 0; - elptr = structp->first_el; /* HEAD NIL element */ - - } else if (start_el >= structp->num_el) {/* as far as we ever go */ - start_el = structp->num_el; - elptr = structp->last_el->prev; /* last non-NIL element */ - - } else { /* count forward for start_el */ - El_handle next; - - assert( (1 <= start_el) && (start_el <= structp->num_el) ); - - elptr = structp->first_el; - next = elptr->next; - elem_no = 0; - while (elem_no < start_el) { - elptr = next; - assert(elptr); - next = elptr->next; - assert(next); - elem_no++; - } - assert(elem_no == start_el); /* ready to search */ - } - /* elptr points to element numbered start_el in struct_id */ - - /* Load the type_array (of include/exclude info), ready to search */ - if (incl->num_elem_types > 0 && incl->elem_types[0] == PELEM_ALL) -incl_all_true: - for (type_ptr = type_array; - type_ptr < &type_array[(int)PELEM_NUM_EL_TYPES]; type_ptr++) - *type_ptr = TRUE; /* turn them all on */ - else { - for (type_ptr = type_array; - type_ptr < &type_array[(int)PELEM_NUM_EL_TYPES]; type_ptr++) - *type_ptr = FALSE; /* turn them all off */ - for (count = incl->num_elem_types; count--; ) - if ( (sel_type = *incl->elem_types++) == PELEM_ALL) - goto incl_all_true; - else - type_array[(int)sel_type] = TRUE; + assert(elem_no == start_el); /* ready to search */ + } + /* elptr points to element numbered start_el in struct_id */ + + /* Load the type_array (of include/exclude info), ready to search */ + if (incl->num_elem_types > 0 && incl->elem_types[0] == PELEM_ALL) + incl_all_true: + for (type_ptr = type_array; + type_ptr < &type_array[(int)PELEM_NUM_EL_TYPES]; type_ptr++) + *type_ptr = TRUE; /* turn them all on */ + else { + for (type_ptr = type_array; + type_ptr < &type_array[(int)PELEM_NUM_EL_TYPES]; type_ptr++) + *type_ptr = FALSE; /* turn them all off */ + for (count = incl->num_elem_types; count--; ) + if ( (sel_type = *incl->elem_types++) == PELEM_ALL) + goto incl_all_true; + else + type_array[(int)sel_type] = TRUE; + } + + for (count = excl->num_elem_types; count--; ) + if ( (sel_type = *excl->elem_types++) == PELEM_ALL) { + assert(ret->data.el_search.status == PSEARCH_STATUS_FAILURE); + return; + } else + type_array[(int)sel_type] = FALSE; + + /* elptr points to element numbered start_el in struct_id */ + if (dir == PDIR_FORWARD) { + for (elem_no = start_el; elem_no <= structp->num_el; + elptr = elptr->next, elem_no++) { + if( type_array[(int)elptr->eltype] ) { + ret->data.el_search.found_el = elem_no; + ret->data.el_search.status = PSEARCH_STATUS_SUCCESS; + return; + } } - - for (count = excl->num_elem_types; count--; ) - if ( (sel_type = *excl->elem_types++) == PELEM_ALL) { - assert(ret->data.el_search.status == PSEARCH_STATUS_FAILURE); - return; - } else - type_array[(int)sel_type] = FALSE; - - /* elptr points to element numbered start_el in struct_id */ - if (dir == PDIR_FORWARD) { - for (elem_no = start_el; elem_no <= structp->num_el; - elptr = elptr->next, elem_no++) { - if( type_array[(int)elptr->eltype] ) { - ret->data.el_search.found_el = elem_no; - ret->data.el_search.status = PSEARCH_STATUS_SUCCESS; - return; - } - } - } - else { /* (dir == PDIR_BACKWARD) */ - for (elem_no = start_el; elptr; elptr = elptr->prev, elem_no--) { - if( type_array[(int)elptr->eltype] ) { - ret->data.el_search.found_el = elem_no; - ret->data.el_search.status = PSEARCH_STATUS_SUCCESS; - return; - } - } + } + else {/* (dir == PDIR_BACKWARD) */ + for (elem_no = start_el; elptr; elptr = elptr->prev, elem_no--) { + if( type_array[(int)elptr->eltype] ) { + ret->data.el_search.found_el = elem_no; + ret->data.el_search.status = PSEARCH_STATUS_SUCCESS; + return; + } } + } } - From a82c5ab059d8c525dd50be2fdaeef8de8db1cfe6 Mon Sep 17 00:00:00 2001 From: Ulrich Schwickerath Date: Sun, 29 Mar 2026 16:22:04 +0200 Subject: [PATCH 2/2] implement shading model stuff --- src/include/phigs/phigs.h | 14 + src/include/phigs/phigsfunc.h | 365 ++++++++++---------- src/include/phigs/private/wsglP.h | 13 + src/libphigs/c_binding/cb_extel.c | 31 ++ src/libphigs/css/css_ini.c | 29 +- src/libphigs/errors/err_num.c | 4 +- src/libphigs/f_binding/fb_extel.c | 25 +- src/libphigs/wsgl/wsgl.c | 10 +- src/libphigs/wsgl/wsgl_extattr.c | 556 +++++++++++++----------------- src/test_c/test_c6.c | 5 +- src/test_c/test_c8.c | 6 +- 11 files changed, 521 insertions(+), 537 deletions(-) diff --git a/src/include/phigs/phigs.h b/src/include/phigs/phigs.h index c53d928..0c7ddd9 100644 --- a/src/include/phigs/phigs.h +++ b/src/include/phigs/phigs.h @@ -248,6 +248,7 @@ typedef enum { PELEM_GSE, PELEM_ALPHA_CHANNEL, PELEM_TEXT3, + PELEM_INT_REFL_MODEL, PELEM_NUM_EL_TYPES } Pelem_type; @@ -419,6 +420,7 @@ typedef enum { PASPECT_INT_SHAD_METH, PASPECT_REFL_PROPS, PASPECT_INT_REFL_EQN, + PASPECT_INT_REFL_MODEL, PASPECT_BACK_INT_STYLE, PASPECT_BACK_INT_STYLE_IND, PASPECT_BACK_INT_COLR, @@ -683,6 +685,7 @@ typedef struct { Pint style_ind; Pgcolr colr; Pint refl_eqn; + Pint refl_model; Pint shad_meth; Prefl_props refl_props; Pint_style back_style; @@ -2914,6 +2917,17 @@ void pset_back_int_shad_meth( Pint shad_meth ); +/******************************************************************************* + * pset_refl_model + * + * DESCR: Creates a new element - Set reflectance model + * RETURNS: N/A + */ + +void pset_refl_model( + Pint refl_model + ); + /******************************************************************************* * pset_refl_eqn * diff --git a/src/include/phigs/phigsfunc.h b/src/include/phigs/phigsfunc.h index 3f635ad..2b7e28d 100644 --- a/src/include/phigs/phigsfunc.h +++ b/src/include/phigs/phigsfunc.h @@ -55,188 +55,187 @@ SOFTWARE. extern "C" { #endif -#define Pfn_open_phigs (0) -#define Pfn_close_phigs (1) -#define Pfn_open_ws (2) -#define Pfn_close_ws (3) -#define Pfn_redraw_all_structs (4) -#define Pfn_upd_ws (5) -#define Pfn_set_disp_upd_st (6) -#define Pfn_message (7) -#define Pfn_polyline3 (8) -#define Pfn_polyline (9) -#define Pfn_polymarker3 (10) -#define Pfn_polymarker (11) -#define Pfn_text3 (12) -#define Pfn_text (13) -#define Pfn_anno_text_rel3 (14) -#define Pfn_anno_text_rel (15) -#define Pfn_fill_area3 (16) -#define Pfn_fill_area (17) -#define Pfn_fill_area_set3 (18) -#define Pfn_fill_area_set (19) -#define Pfn_cell_array3 (20) -#define Pfn_cell_array (21) -#define Pfn_gdp3 (22) -#define Pfn_gdp (23) -#define Pfn_set_line_ind (24) -#define Pfn_set_marker_ind (25) -#define Pfn_set_text_ind (26) -#define Pfn_set_int_ind (27) -#define Pfn_set_edge_ind (28) -#define Pfn_set_linetype (29) -#define Pfn_set_linewidth (30) -#define Pfn_set_line_colr_ind (31) -#define Pfn_set_marker_type (32) -#define Pfn_set_marker_size (33) -#define Pfn_set_marker_colr_ind (34) -#define Pfn_set_text_font (35) -#define Pfn_set_text_prec (36) -#define Pfn_set_char_expan (37) -#define Pfn_set_char_space (38) -#define Pfn_set_text_colr_ind (39) -#define Pfn_set_char_ht (40) -#define Pfn_set_char_up_vec (41) -#define Pfn_set_text_path (42) -#define Pfn_set_text_align (43) -#define Pfn_set_anno_char_ht (44) -#define Pfn_set_anno_char_up_vec (45) -#define Pfn_set_anno_path (46) -#define Pfn_set_anno_align (47) -#define Pfn_set_anno_style (48) -#define Pfn_set_int_style (49) -#define Pfn_set_int_style_ind (50) -#define Pfn_set_int_colr_ind (51) -#define Pfn_set_edge_flag (52) -#define Pfn_set_edgetype (53) -#define Pfn_set_edgewidth (54) -#define Pfn_set_edge_colr_ind (55) -#define Pfn_set_pat_size (56) -#define Pfn_set_pat_ref_point_vecs (57) -#define Pfn_set_pat_ref_point (58) -#define Pfn_add_names_set (59) -#define Pfn_remove_names_set (60) -#define Pfn_set_indiv_asf (61) -#define Pfn_set_line_rep (62) -#define Pfn_set_marker_rep (63) -#define Pfn_set_text_rep (64) -#define Pfn_set_int_rep (65) -#define Pfn_set_edge_rep (66) -#define Pfn_set_pat_rep (67) -#define Pfn_set_colr_rep (68) -#define Pfn_set_highl_filter (69) -#define Pfn_set_invis_filter (70) -#define Pfn_set_colr_model (71) -#define Pfn_set_hlhsr_id (72) -#define Pfn_set_hlhsr_mode (73) -#define Pfn_set_local_tran3 (74) -#define Pfn_set_local_tran (75) -#define Pfn_set_global_tran3 (76) -#define Pfn_set_global_tran (77) -#define Pfn_set_model_clip_vol3 (78) -#define Pfn_set_model_clip_vol (79) -#define Pfn_set_model_clip_ind (80) -#define Pfn_restore_model_clip_vol (81) -#define Pfn_set_view_ind (82) -#define Pfn_set_view_rep3 (83) -#define Pfn_set_view_rep (84) -#define Pfn_set_view_tran_in_pri (85) -#define Pfn_set_ws_win3 (86) -#define Pfn_set_ws_win (87) -#define Pfn_set_ws_vp3 (88) -#define Pfn_set_ws_vp (89) -#define Pfn_open_struct (90) -#define Pfn_close_struct (91) -#define Pfn_exec_struct (92) -#define Pfn_label (93) -#define Pfn_appl_data (94) -#define Pfn_gse (95) -#define Pfn_set_edit_mode (96) -#define Pfn_copy_all_elems_struct (97) -#define Pfn_set_elem_ptr (98) -#define Pfn_offset_elem_ptr (99) -#define Pfn_set_elem_ptr_label (100) -#define Pfn_del_elem (101) -#define Pfn_del_elem_range (102) -#define Pfn_del_elems_labels (103) -#define Pfn_empty_struct (104) -#define Pfn_del_struct (105) -#define Pfn_del_struct_net (106) -#define Pfn_del_all_struct (107) -#define Pfn_change_struct_id (108) -#define Pfn_change_struct_refs (109) -#define Pfn_change_struct_id_refs (110) -#define Pfn_post_struct (111) -#define Pfn_unpost_struct (112) -#define Pfn_unpost_all_structs (113) -#define Pfn_open_ar_file (114) -#define Pfn_close_ar_file (115) -#define Pfn_ar_structs (116) -#define Pfn_ar_struct_nets (117) -#define Pfn_ar_all_structs (118) -#define Pfn_set_conf_res (119) -#define Pfn_ret_struct_ids (120) -#define Pfn_ret_structs (121) -#define Pfn_ret_struct_nets (122) -#define Pfn_ret_all_structs (123) -#define Pfn_ret_paths_ancest (124) -#define Pfn_ret_paths_descs (125) -#define Pfn_del_structs_ar (126) -#define Pfn_del_struct_nets_ar (127) -#define Pfn_del_all_structs_ar (128) -#define Pfn_set_pick_id (129) -#define Pfn_set_pick_filter (130) -#define Pfn_init_loc3 (131) -#define Pfn_init_loc (132) -#define Pfn_init_stroke3 (133) -#define Pfn_init_stroke (134) -#define Pfn_init_val3 (135) -#define Pfn_init_val (136) -#define Pfn_init_choice3 (137) -#define Pfn_init_choice (138) -#define Pfn_init_pick3 (139) -#define Pfn_init_pick (140) -#define Pfn_init_string3 (141) -#define Pfn_init_string (142) -#define Pfn_set_loc_mode (143) -#define Pfn_set_stroke_mode (144) -#define Pfn_set_val_mode (145) -#define Pfn_set_choice_mode (146) -#define Pfn_set_pick_mode (147) -#define Pfn_set_string_mode (148) -#define Pfn_req_loc3 (149) -#define Pfn_req_loc (150) -#define Pfn_req_stroke3 (151) -#define Pfn_req_stroke (152) -#define Pfn_req_val (153) -#define Pfn_req_choice (154) -#define Pfn_req_pick (155) -#define Pfn_req_string (156) -#define Pfn_sample_loc3 (157) -#define Pfn_sample_loc (158) -#define Pfn_sample_stroke3 (159) -#define Pfn_sample_stroke (160) -#define Pfn_sample_val (161) -#define Pfn_sample_choice (162) -#define Pfn_sample_pick (163) -#define Pfn_sample_string (164) -#define Pfn_await_event (165) -#define Pfn_flush_events (166) -#define Pfn_get_loc3 (167) -#define Pfn_get_loc (168) -#define Pfn_get_stroke3 (169) -#define Pfn_get_stroke (170) -#define Pfn_get_val (171) -#define Pfn_get_choice (172) -#define Pfn_get_pick (173) -#define Pfn_get_string (174) -#define Pfn_write_item (175) -#define Pfn_get_item_type (176) -#define Pfn_read_item (177) -#define Pfn_interpret_item (178) -#define Pfn_set_err_hand_mode (179) -#define Pfn_escape (180) - +#define Pfn_open_phigs (0) +#define Pfn_close_phigs (1) +#define Pfn_open_ws (2) +#define Pfn_close_ws (3) +#define Pfn_redraw_all_structs (4) +#define Pfn_upd_ws (5) +#define Pfn_set_disp_upd_st (6) +#define Pfn_message (7) +#define Pfn_polyline3 (8) +#define Pfn_polyline (9) +#define Pfn_polymarker3 (10) +#define Pfn_polymarker (11) +#define Pfn_text3 (12) +#define Pfn_text (13) +#define Pfn_anno_text_rel3 (14) +#define Pfn_anno_text_rel (15) +#define Pfn_fill_area3 (16) +#define Pfn_fill_area (17) +#define Pfn_fill_area_set3 (18) +#define Pfn_fill_area_set (19) +#define Pfn_cell_array3 (20) +#define Pfn_cell_array (21) +#define Pfn_gdp3 (22) +#define Pfn_gdp (23) +#define Pfn_set_line_ind (24) +#define Pfn_set_marker_ind (25) +#define Pfn_set_text_ind (26) +#define Pfn_set_int_ind (27) +#define Pfn_set_edge_ind (28) +#define Pfn_set_linetype (29) +#define Pfn_set_linewidth (30) +#define Pfn_set_line_colr_ind (31) +#define Pfn_set_marker_type (32) +#define Pfn_set_marker_size (33) +#define Pfn_set_marker_colr_ind (34) +#define Pfn_set_text_font (35) +#define Pfn_set_text_prec (36) +#define Pfn_set_char_expan (37) +#define Pfn_set_char_space (38) +#define Pfn_set_text_colr_ind (39) +#define Pfn_set_char_ht (40) +#define Pfn_set_char_up_vec (41) +#define Pfn_set_text_path (42) +#define Pfn_set_text_align (43) +#define Pfn_set_anno_char_ht (44) +#define Pfn_set_anno_char_up_vec (45) +#define Pfn_set_anno_path (46) +#define Pfn_set_anno_align (47) +#define Pfn_set_anno_style (48) +#define Pfn_set_int_style (49) +#define Pfn_set_int_style_ind (50) +#define Pfn_set_int_colr_ind (51) +#define Pfn_set_edge_flag (52) +#define Pfn_set_edgetype (53) +#define Pfn_set_edgewidth (54) +#define Pfn_set_edge_colr_ind (55) +#define Pfn_set_pat_size (56) +#define Pfn_set_pat_ref_point_vecs (57) +#define Pfn_set_pat_ref_point (58) +#define Pfn_add_names_set (59) +#define Pfn_remove_names_set (60) +#define Pfn_set_indiv_asf (61) +#define Pfn_set_line_rep (62) +#define Pfn_set_marker_rep (63) +#define Pfn_set_text_rep (64) +#define Pfn_set_int_rep (65) +#define Pfn_set_edge_rep (66) +#define Pfn_set_pat_rep (67) +#define Pfn_set_colr_rep (68) +#define Pfn_set_highl_filter (69) +#define Pfn_set_invis_filter (70) +#define Pfn_set_colr_model (71) +#define Pfn_set_hlhsr_id (72) +#define Pfn_set_hlhsr_mode (73) +#define Pfn_set_local_tran3 (74) +#define Pfn_set_local_tran (75) +#define Pfn_set_global_tran3 (76) +#define Pfn_set_global_tran (77) +#define Pfn_set_model_clip_vol3 (78) +#define Pfn_set_model_clip_vol (79) +#define Pfn_set_model_clip_ind (80) +#define Pfn_restore_model_clip_vol (81) +#define Pfn_set_view_ind (82) +#define Pfn_set_view_rep3 (83) +#define Pfn_set_view_rep (84) +#define Pfn_set_view_tran_in_pri (85) +#define Pfn_set_ws_win3 (86) +#define Pfn_set_ws_win (87) +#define Pfn_set_ws_vp3 (88) +#define Pfn_set_ws_vp (89) +#define Pfn_open_struct (90) +#define Pfn_close_struct (91) +#define Pfn_exec_struct (92) +#define Pfn_label (93) +#define Pfn_appl_data (94) +#define Pfn_gse (95) +#define Pfn_set_edit_mode (96) +#define Pfn_copy_all_elems_struct (97) +#define Pfn_set_elem_ptr (98) +#define Pfn_offset_elem_ptr (99) +#define Pfn_set_elem_ptr_label (100) +#define Pfn_del_elem (101) +#define Pfn_del_elem_range (102) +#define Pfn_del_elems_labels (103) +#define Pfn_empty_struct (104) +#define Pfn_del_struct (105) +#define Pfn_del_struct_net (106) +#define Pfn_del_all_struct (107) +#define Pfn_change_struct_id (108) +#define Pfn_change_struct_refs (109) +#define Pfn_change_struct_id_refs (110) +#define Pfn_post_struct (111) +#define Pfn_unpost_struct (112) +#define Pfn_unpost_all_structs (113) +#define Pfn_open_ar_file (114) +#define Pfn_close_ar_file (115) +#define Pfn_ar_structs (116) +#define Pfn_ar_struct_nets (117) +#define Pfn_ar_all_structs (118) +#define Pfn_set_conf_res (119) +#define Pfn_ret_struct_ids (120) +#define Pfn_ret_structs (121) +#define Pfn_ret_struct_nets (122) +#define Pfn_ret_all_structs (123) +#define Pfn_ret_paths_ancest (124) +#define Pfn_ret_paths_descs (125) +#define Pfn_del_structs_ar (126) +#define Pfn_del_struct_nets_ar (127) +#define Pfn_del_all_structs_ar (128) +#define Pfn_set_pick_id (129) +#define Pfn_set_pick_filter (130) +#define Pfn_init_loc3 (131) +#define Pfn_init_loc (132) +#define Pfn_init_stroke3 (133) +#define Pfn_init_stroke (134) +#define Pfn_init_val3 (135) +#define Pfn_init_val (136) +#define Pfn_init_choice3 (137) +#define Pfn_init_choice (138) +#define Pfn_init_pick3 (139) +#define Pfn_init_pick (140) +#define Pfn_init_string3 (141) +#define Pfn_init_string (142) +#define Pfn_set_loc_mode (143) +#define Pfn_set_stroke_mode (144) +#define Pfn_set_val_mode (145) +#define Pfn_set_choice_mode (146) +#define Pfn_set_pick_mode (147) +#define Pfn_set_string_mode (148) +#define Pfn_req_loc3 (149) +#define Pfn_req_loc (150) +#define Pfn_req_stroke3 (151) +#define Pfn_req_stroke (152) +#define Pfn_req_val (153) +#define Pfn_req_choice (154) +#define Pfn_req_pick (155) +#define Pfn_req_string (156) +#define Pfn_sample_loc3 (157) +#define Pfn_sample_loc (158) +#define Pfn_sample_stroke3 (159) +#define Pfn_sample_stroke (160) +#define Pfn_sample_val (161) +#define Pfn_sample_choice (162) +#define Pfn_sample_pick (163) +#define Pfn_sample_string (164) +#define Pfn_await_event (165) +#define Pfn_flush_events (166) +#define Pfn_get_loc3 (167) +#define Pfn_get_loc (168) +#define Pfn_get_stroke3 (169) +#define Pfn_get_stroke (170) +#define Pfn_get_val (171) +#define Pfn_get_choice (172) +#define Pfn_get_pick (173) +#define Pfn_get_string (174) +#define Pfn_write_item (175) +#define Pfn_get_item_type (176) +#define Pfn_read_item (177) +#define Pfn_interpret_item (178) +#define Pfn_set_err_hand_mode (179) +#define Pfn_escape (180) #define Pfn_fill_area_set_data (301) #define Pfn_fill_area_set3_data (302) #define Pfn_set_of_fill_area_set3_data (304) @@ -258,7 +257,7 @@ extern "C" { #define Pfn_set_light_src_state (326) #define Pfn_set_edge_colr (327) #define Pfn_set_light_src_rep (340) - +#define Pfn_set_refl_model (343) #define Pfn_set_alpha_channel (900) #define Pfn_INQUIRY (1000) diff --git a/src/include/phigs/private/wsglP.h b/src/include/phigs/private/wsglP.h index c924091..6338928 100644 --- a/src/include/phigs/private/wsglP.h +++ b/src/include/phigs/private/wsglP.h @@ -618,6 +618,19 @@ void wsgl_setup_back_int_attr_nocol( Ws_attr_st *ast ); +/******************************************************************************* + * wsgl_setup_int_reflectance_model + * + * DESCR: + * RETURNS: N/A + */ + +void wsgl_setup_int_reflectance_model( + Pint colr_type, + Pcoval *colr, + Ws_attr_st *ast +); + /******************************************************************************* * wsgl_setup_int_refl_props * diff --git a/src/libphigs/c_binding/cb_extel.c b/src/libphigs/c_binding/cb_extel.c index a866626..5f715b8 100644 --- a/src/libphigs/c_binding/cb_extel.c +++ b/src/libphigs/c_binding/cb_extel.c @@ -942,6 +942,37 @@ void pset_back_int_shad_meth( } } +/******************************************************************************* + * pset_refl_model + * + * DESCR: Creates a new element - Set surface reflectance equation + * RETURNS: N/A + */ +void pset_refl_model( + Pint refl_model + ) +{ + Phg_args_add_el args; + + if (phg_entry_check(PHG_ERH, ERR5, Pfn_set_refl_model)) { + if (PSL_STRUCT_STATE(PHG_PSL) != PSTRUCT_ST_STOP) { + ERR_REPORT(PHG_ERH, ERR5); + } + else { + args.el_type = PELEM_INT_REFL_MODEL; + args.el_size = sizeof(Pint); + if (!PHG_SCRATCH_SPACE(&PHG_SCRATCH, args.el_size)) { + ERR_REPORT(PHG_ERH, ERR900); + } + else { + args.el_data = PHG_SCRATCH.buf; + memcpy(args.el_data, &refl_model, args.el_size); + phg_add_el(PHG_CSS, &args); + } + } + } +} + /******************************************************************************* * pset_refl_eqn * diff --git a/src/libphigs/css/css_ini.c b/src/libphigs/css/css_ini.c index 160987b..cebcc76 100644 --- a/src/libphigs/css/css_ini.c +++ b/src/libphigs/css/css_ini.c @@ -73,7 +73,7 @@ Css_handle phg_css_init(Err_handle erh, Css_ssh_type ssh_type) Css_func *fptr; if ( !(cssh = (Css_handle) calloc((unsigned)1,sizeof(Css_struct))) ) - return(NULL); /* out of memory */ + return(NULL); /* out of memory */ fptr = cssh->el_funcs; fptr[(int)PELEM_NIL] = phg_css_no_data; fptr[(int)PELEM_ADD_NAMES_SET] = hdl_generic_elmt; @@ -134,6 +134,7 @@ Css_handle phg_css_init(Err_handle erh, Css_ssh_type ssh_type) fptr[(int)PELEM_TEXT_COLR] = hdl_generic_elmt; fptr[(int)PELEM_LIGHT_SRC_STATE] = hdl_generic_elmt; fptr[(int)PELEM_INT_SHAD_METH] = hdl_generic_elmt; + fptr[(int)PELEM_INT_REFL_MODEL] = hdl_generic_elmt; fptr[(int)PELEM_BACK_INT_SHAD_METH] = hdl_generic_elmt; fptr[(int)PELEM_INT_REFL_EQN] = hdl_generic_elmt; fptr[(int)PELEM_BACK_INT_REFL_EQN] = hdl_generic_elmt; @@ -156,8 +157,8 @@ Css_handle phg_css_init(Err_handle erh, Css_ssh_type ssh_type) fptr[(int)PELEM_GSE] = hdl_generic_elmt; if ( !(cssh->stab = phg_css_stab_init(CSS_STAB_SIZE)) ) { - free((char *)cssh); - return(NULL); /* out of memory */ + free((char *)cssh); + return(NULL); /* out of memory */ } cssh->open_struct = NULL; cssh->el_ptr = NULL; @@ -165,12 +166,12 @@ Css_handle phg_css_init(Err_handle erh, Css_ssh_type ssh_type) cssh->edit_mode = PEDIT_INSERT; cssh->erh = erh; if ( !(cssh->ws_list = (Css_ws_list) - malloc((MAX_NO_OPEN_WS+1) * sizeof(Css_ws_on))) ) { - phg_css_stab_free(cssh->stab); - free((char *)cssh); - return(NULL); /* out of memory */ + malloc((MAX_NO_OPEN_WS+1) * sizeof(Css_ws_on))) ) { + phg_css_stab_free(cssh->stab); + free((char *)cssh); + return(NULL); /* out of memory */ } - cssh->mem = NULL; /* don't allocate space until it's needed */ + cssh->mem = NULL; /* don't allocate space until it's needed */ cssh->ssh_type = ssh_type; return(cssh); } @@ -183,10 +184,10 @@ Css_handle phg_css_init(Err_handle erh, Css_ssh_type ssh_type) void phg_css_destroy(Css_handle cssh) { - phg_css_delete_all_structs(cssh); - phg_css_stab_free(cssh->stab); - free((char *)cssh->ws_list); - if (cssh->mem) - free(cssh->mem); - free((char *)cssh); + phg_css_delete_all_structs(cssh); + phg_css_stab_free(cssh->stab); + free((char *)cssh->ws_list); + if (cssh->mem) + free(cssh->mem); + free((char *)cssh); } diff --git a/src/libphigs/errors/err_num.c b/src/libphigs/errors/err_num.c index 1ac6f13..71cc2d0 100644 --- a/src/libphigs/errors/err_num.c +++ b/src/libphigs/errors/err_num.c @@ -261,7 +261,9 @@ static Phg_map fmap[] = { {339, "SET PATTERN REPRESENTATION PLUS"}, {340, "SET LIGHT SOURCE REPRESENTATION"}, {341, "SET DEPTH CUE REPRESENTATION"}, - {342, "SET COLOUR MAPPING REPRESENTATION"} + {342, "SET COLOUR MAPPING REPRESENTATION"}, + {343, "SET REFLECTION MODEL"}, + {900, "SET ALPHA CHANNEL"} }; static Phg_map errmap[] = { diff --git a/src/libphigs/f_binding/fb_extel.c b/src/libphigs/f_binding/fb_extel.c index 0546c75..b5ce861 100644 --- a/src/libphigs/f_binding/fb_extel.c +++ b/src/libphigs/f_binding/fb_extel.c @@ -94,6 +94,19 @@ FTN_SUBROUTINE(psbism)( pset_back_int_shad_meth(ism); } +/******************************************************************************* + * psrfm + * + * DESCR: set reflectance model + * RETURNS: N/A + */ +FTN_SUBROUTINE(psrfm)( + FTN_INTEGER(refl_mod) + ){ + Pint refl_model = FTN_INTEGER_GET(refl_mod); + pset_refl_model(refl_model); +} + /******************************************************************************* * psrfeq * @@ -101,10 +114,10 @@ FTN_SUBROUTINE(psbism)( * RETURNS: N/A */ FTN_SUBROUTINE(psrfeq)( - FTN_INTEGER(refl_model1) + FTN_INTEGER(refl_eq) ){ - Pint refl_model = FTN_INTEGER_GET(refl_model1); - pset_refl_eqn(refl_model); + Pint refl_equation = FTN_INTEGER_GET(refl_eq); + pset_refl_eqn(refl_equation); } /******************************************************************************* @@ -114,10 +127,10 @@ FTN_SUBROUTINE(psrfeq)( * RETURNS: N/A */ FTN_SUBROUTINE(psbrfm)( - FTN_INTEGER(refl_model1) + FTN_INTEGER(refl_eq) ){ - Pint refl_model = FTN_INTEGER_GET(refl_model1); - pset_back_refl_eqn(refl_model); + Pint refl_equation = FTN_INTEGER_GET(refl_eq); + pset_back_refl_eqn(refl_equation); } /******************************************************************************* diff --git a/src/libphigs/wsgl/wsgl.c b/src/libphigs/wsgl/wsgl.c index 4a0e35c..569aca2 100644 --- a/src/libphigs/wsgl/wsgl.c +++ b/src/libphigs/wsgl/wsgl.c @@ -1209,8 +1209,11 @@ void wsgl_render_element( break; case PELEM_BACK_INT_SHAD_METH: - wsgl->cur_struct.ast.indiv_group.int_bundle.back_shad_meth = - PHG_INT(el); + wsgl->cur_struct.ast.indiv_group.int_bundle.back_shad_meth = PHG_INT(el); + break; + + case PELEM_INT_REFL_MODEL: + wsgl->cur_struct.ast.indiv_group.int_bundle.refl_model = PHG_INT(el); break; case PELEM_INT_REFL_EQN: @@ -1218,8 +1221,7 @@ void wsgl_render_element( break; case PELEM_BACK_INT_REFL_EQN: - wsgl->cur_struct.ast.indiv_group.int_bundle.back_refl_eqn = - PHG_INT(el); + wsgl->cur_struct.ast.indiv_group.int_bundle.back_refl_eqn = PHG_INT(el); break; case PELEM_REFL_PROPS: diff --git a/src/libphigs/wsgl/wsgl_extattr.c b/src/libphigs/wsgl/wsgl_extattr.c index 0b0e01c..48421a4 100644 --- a/src/libphigs/wsgl/wsgl_extattr.c +++ b/src/libphigs/wsgl/wsgl_extattr.c @@ -46,19 +46,19 @@ extern GLint vAmbient, vDiffuse, vSpecular; */ Pgcolr* wsgl_get_back_int_colr( - Ws_attr_st *ast - ) + Ws_attr_st *ast + ) { - Pgcolr *gcolr; + Pgcolr *gcolr; - if (phg_nset_name_is_set(&ast->asf_nameset, (Pint) PASPECT_BACK_INT_COLR)) { - gcolr = &ast->indiv_group.int_bundle.back_colr; - } - else { - gcolr = &ast->bundl_group.int_bundle.back_colr; - } + if (phg_nset_name_is_set(&ast->asf_nameset, (Pint) PASPECT_BACK_INT_COLR)) { + gcolr = &ast->indiv_group.int_bundle.back_colr; + } + else { + gcolr = &ast->bundl_group.int_bundle.back_colr; + } - return gcolr; + return gcolr; } /******************************************************************************* @@ -69,91 +69,83 @@ Pgcolr* wsgl_get_back_int_colr( */ void wsgl_setup_back_int_attr_nocol( - Ws *ws, - Ws_attr_st *ast - ) + Ws *ws, + Ws_attr_st *ast + ) { - Pint_style style; - Pint style_ind; - Pint shad_meth; - - Wsgl_handle wsgl = ws->render_context; - - if (phg_nset_name_is_set(&ast->asf_nameset, (Pint) PASPECT_BACK_INT_STYLE)) { - style = ast->indiv_group.int_bundle.back_style; - } - else { - style = ast->bundl_group.int_bundle.back_style; - } - if (style != wsgl->dev_st.int_style) { - wsgl_setup_int_style(style); - wsgl->dev_st.int_style = style; - } - - if (phg_nset_name_is_set(&ast->asf_nameset, - (Pint) PASPECT_BACK_INT_STYLE_IND)) { - style_ind = ast->indiv_group.int_bundle.back_style_ind; - } - else { - style_ind = ast->bundl_group.int_bundle.back_style_ind; - } - - if (style_ind != wsgl->dev_st.int_style_ind) { - glPolygonStipple(wsgl_hatch_tbl[style_ind - 1]); - wsgl->dev_st.int_style_ind = style_ind; - } - - if (phg_nset_name_is_set(&ast->asf_nameset, - (Pint) PASPECT_BACK_INT_SHAD_METH)) { - shad_meth = ast->indiv_group.int_bundle.back_shad_meth; - } - else { - shad_meth = ast->bundl_group.int_bundle.back_shad_meth; - } - - if (shad_meth != wsgl->dev_st.int_shad_meth) { - if (shad_meth == PSD_NONE) { - glShadeModel(GL_FLAT); - } - else { - glShadeModel(GL_SMOOTH); - } - wsgl->dev_st.int_shad_meth = shad_meth; - } - - if (wsgl->cur_struct.lighting) { + Pint_style style; + Pint style_ind; + Pint shad_meth; + + Wsgl_handle wsgl = ws->render_context; + + if (phg_nset_name_is_set(&ast->asf_nameset, (Pint) PASPECT_BACK_INT_STYLE)) { + style = ast->indiv_group.int_bundle.back_style; + } else { + style = ast->bundl_group.int_bundle.back_style; + } + if (style != wsgl->dev_st.int_style) { + wsgl_setup_int_style(style); + wsgl->dev_st.int_style = style; + } + + if (phg_nset_name_is_set(&ast->asf_nameset, + (Pint) PASPECT_BACK_INT_STYLE_IND)) { + style_ind = ast->indiv_group.int_bundle.back_style_ind; + } else { + style_ind = ast->bundl_group.int_bundle.back_style_ind; + } + + if (style_ind != wsgl->dev_st.int_style_ind) { + glPolygonStipple(wsgl_hatch_tbl[style_ind - 1]); + wsgl->dev_st.int_style_ind = style_ind; + } + + if (phg_nset_name_is_set(&ast->asf_nameset, + (Pint) PASPECT_BACK_INT_SHAD_METH)) { + shad_meth = ast->indiv_group.int_bundle.back_shad_meth; + } else { + shad_meth = ast->bundl_group.int_bundle.back_shad_meth; + } + + if (shad_meth != wsgl->dev_st.int_shad_meth) { + if (shad_meth == PSD_NONE) { + glShadeModel(GL_FLAT); + } else { + glShadeModel(GL_SMOOTH); + } + wsgl->dev_st.int_shad_meth = shad_meth; + } + + if (wsgl->cur_struct.lighting) { #ifdef GLEW - if (wsgl_use_shaders && GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader && GLEW_ARB_shader_objects) { + if (wsgl_use_shaders && GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader && GLEW_ARB_shader_objects) { #else - if (wsgl_use_shaders) { + if (wsgl_use_shaders) { #endif - glUniform1i(shading_mode, 1); - } else { - glEnable(GL_LIGHTING); - } - } - else - { + glUniform1i(shading_mode, 1); + } else { + glEnable(GL_LIGHTING); + } + } else { #ifdef GLEW - if (wsgl_use_shaders && GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader && GLEW_ARB_shader_objects) { + if (wsgl_use_shaders && GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader && GLEW_ARB_shader_objects) { #else - if (wsgl_use_shaders) { + if (wsgl_use_shaders) { #endif - glUniform1i(shading_mode, 0); - } else { - glDisable(GL_LIGHTING); - } - } - glCullFace(GL_FRONT); + glUniform1i(shading_mode, 0); + } else { + glDisable(GL_LIGHTING); + } + } + glCullFace(GL_FRONT); } - -#if 0 /******************************************************************************* * wsgl_setup_int_refl_props * - * DESCR: Setup surface reflection and colour properties - * NOTES: Make sure to enable GL_COLOR_MATERIAL before use + * DESCR: Setup surface reflection and colour properties + * NOTES: Make sure to enable GL_COLOR_MATERIAL before use * RETURNS: N/A */ void wsgl_setup_int_refl_props( @@ -165,6 +157,9 @@ void wsgl_setup_int_refl_props( Pint refl_eqn; Prefl_props *refl_props; +#ifdef DEBUGLIGHT + printf("Setup int refl_props called.\n"); +#endif if (phg_nset_name_is_set(&ast->asf_nameset, (Pint) PASPECT_INT_REFL_EQN)) { refl_eqn = ast->indiv_group.int_bundle.refl_eqn; } @@ -182,7 +177,7 @@ void wsgl_setup_int_refl_props( switch (refl_eqn) { case PREFL_AMBIENT: if (colr_type == PMODEL_RGB) { - glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT); + glColorMaterial(GL_FRONT, GL_AMBIENT); glVertexAttrib4f(vCOLOR, colr->direct.rgb.red * refl_props->ambient_coef, colr->direct.rgb.green * refl_props->ambient_coef, @@ -190,23 +185,23 @@ void wsgl_setup_int_refl_props( 1.0); } - glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); + glColorMaterial(GL_FRONT, GL_DIFFUSE); glVertexAttrib4f(vCOLOR, 0.0, 0.0, 0.0, 1.0); - glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR); + glColorMaterial(GL_FRONT, GL_SPECULAR); glVertexAttrib4f(vCOLOR,0.0, 0.0, 0.0, 1.0); break; case PREFL_AMB_DIFF: if (colr_type == PMODEL_RGB) { - glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT); + glColorMaterial(GL_FRONT, GL_AMBIENT); glVertexAttrib4f(vCOLOR, colr->direct.rgb.red * refl_props->ambient_coef, colr->direct.rgb.green * refl_props->ambient_coef, colr->direct.rgb.blue * refl_props->ambient_coef, 1.0); - glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); + glColorMaterial(GL_FRONT, GL_DIFFUSE); glVertexAttrib4f(vCOLOR, colr->direct.rgb.red * refl_props->diffuse_coef, colr->direct.rgb.green * refl_props->diffuse_coef, @@ -214,27 +209,27 @@ void wsgl_setup_int_refl_props( 1.0); } - glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR); + glColorMaterial(GL_FRONT, GL_SPECULAR); glVertexAttrib4f(vCOLOR,0.0, 0.0, 0.0, 1.0); break; case PREFL_AMB_DIFF_SPEC: if (colr_type == PMODEL_RGB) { - glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT); + glColorMaterial(GL_FRONT, GL_AMBIENT); glVertexAttrib4f(vCOLOR, colr->direct.rgb.red * refl_props->ambient_coef, colr->direct.rgb.green * refl_props->ambient_coef, colr->direct.rgb.blue * refl_props->ambient_coef, 1.0); - glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); + glColorMaterial(GL_FRONT, GL_DIFFUSE); glVertexAttrib4f(vCOLOR, colr->direct.rgb.red * refl_props->diffuse_coef, colr->direct.rgb.green * refl_props->diffuse_coef, colr->direct.rgb.blue * refl_props->diffuse_coef, 1.0); - glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR); + glColorMaterial(GL_FRONT, GL_SPECULAR); glVertexAttrib4f(vCOLOR, colr->direct.rgb.red * refl_props->specular_coef, colr->direct.rgb.green * refl_props->specular_coef, @@ -255,138 +250,142 @@ void wsgl_setup_int_refl_props( * NOTES: Make sure to enable GL_COLOR_MATERIAL before use * RETURNS: N/A */ -/* void wsgl_setup_back_int_refl_props( - Pint colr_type, - Pcoval *colr, - Ws_attr_st *ast - ) + Pint colr_type, + Pcoval *colr, + Ws_attr_st *ast + ) { - Pint refl_eqn; - Prefl_props *refl_props; - - if (phg_nset_name_is_set(&ast->asf_nameset, - (Pint) PASPECT_BACK_INT_REFL_EQN)) { - refl_eqn = ast->indiv_group.int_bundle.back_refl_eqn; - } - else { - refl_eqn = ast->bundl_group.int_bundle.back_refl_eqn; - } + Pint refl_eqn; + Prefl_props *refl_props; - if (phg_nset_name_is_set(&ast->asf_nameset, - (Pint) PASPECT_BACK_REFL_PROPS)) { - refl_props = &ast->indiv_group.int_bundle.back_refl_props; - } - else { - refl_props = &ast->bundl_group.int_bundle.back_refl_props; - } - - switch (refl_eqn) { - case PREFL_AMBIENT: - if (colr_type == PMODEL_RGB) { - glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT); - glVertexAttrib4f(vCOLOR, - colr->direct.rgb.red * refl_props->ambient_coef, - colr->direct.rgb.green * refl_props->ambient_coef, - colr->direct.rgb.blue * refl_props->ambient_coef, - 1.0); - } - - glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); - glVertexAttrib4f(vCOLOR,0.0, 0.0, 0.0, 1.0); - - glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR); - glVertexAttrib4f(vCOLOR,0.0, 0.0, 0.0, 1.0); - break; - - case PREFL_AMB_DIFF: - if (colr_type == PMODEL_RGB) { - glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT); - glVertexAttrib4f(vCOLOR, - colr->direct.rgb.red * refl_props->ambient_coef, - colr->direct.rgb.green * refl_props->ambient_coef, - colr->direct.rgb.blue * refl_props->ambient_coef, - 1.0); - - glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); - glVertexAttrib4f(vCOLOR, - colr->direct.rgb.red * refl_props->diffuse_coef, - colr->direct.rgb.green * refl_props->diffuse_coef, - colr->direct.rgb.blue * refl_props->diffuse_coef, - 1.0); - } - - glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR); - glVertexAttrib4f(vCOLOR,0.0, 0.0, 0.0, 1.0); - break; - - case PREFL_AMB_DIFF_SPEC: - if (colr_type == PMODEL_RGB) { - glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT); - glVertexAttrib4f(vCOLOR, - colr->direct.rgb.red * refl_props->ambient_coef, - colr->direct.rgb.green * refl_props->ambient_coef, - colr->direct.rgb.blue * refl_props->ambient_coef, - 1.0); - - glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); - glVertexAttrib4f(vCOLOR, - colr->direct.rgb.red * refl_props->diffuse_coef, - colr->direct.rgb.green * refl_props->diffuse_coef, - colr->direct.rgb.blue * refl_props->diffuse_coef, - 1.0); - - glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR); - glVertexAttrib4f(vCOLOR, - colr->direct.rgb.red * refl_props->specular_coef, - colr->direct.rgb.green * refl_props->specular_coef, - colr->direct.rgb.blue * refl_props->specular_coef, - 1.0); - } - break; - - default: - break; - } -} -*/ +#ifdef DEBUGLIGHT + printf("Setup back int refl_props called.\n"); #endif + if (phg_nset_name_is_set(&ast->asf_nameset, + (Pint) PASPECT_BACK_INT_REFL_EQN)) { + refl_eqn = ast->indiv_group.int_bundle.back_refl_eqn; + } + else { + refl_eqn = ast->bundl_group.int_bundle.back_refl_eqn; + } + + if (phg_nset_name_is_set(&ast->asf_nameset, + (Pint) PASPECT_BACK_REFL_PROPS)) { + refl_props = &ast->indiv_group.int_bundle.back_refl_props; + } + else { + refl_props = &ast->bundl_group.int_bundle.back_refl_props; + } + + switch (refl_eqn) { + case PREFL_AMBIENT: + if (colr_type == PMODEL_RGB) { + glColorMaterial(GL_BACK, GL_AMBIENT); + glVertexAttrib4f(vCOLOR, + colr->direct.rgb.red * refl_props->ambient_coef, + colr->direct.rgb.green * refl_props->ambient_coef, + colr->direct.rgb.blue * refl_props->ambient_coef, + 1.0); + } + + glColorMaterial(GL_BACK, GL_DIFFUSE); + glVertexAttrib4f(vCOLOR,0.0, 0.0, 0.0, 1.0); + + glColorMaterial(GL_BACK, GL_SPECULAR); + glVertexAttrib4f(vCOLOR,0.0, 0.0, 0.0, 1.0); + break; + + case PREFL_AMB_DIFF: + if (colr_type == PMODEL_RGB) { + glColorMaterial(GL_BACK, GL_AMBIENT); + glVertexAttrib4f(vCOLOR, + colr->direct.rgb.red * refl_props->ambient_coef, + colr->direct.rgb.green * refl_props->ambient_coef, + colr->direct.rgb.blue * refl_props->ambient_coef, + 1.0); + + glColorMaterial(GL_BACK, GL_DIFFUSE); + glVertexAttrib4f(vCOLOR, + colr->direct.rgb.red * refl_props->diffuse_coef, + colr->direct.rgb.green * refl_props->diffuse_coef, + colr->direct.rgb.blue * refl_props->diffuse_coef, + 1.0); + } + + glColorMaterial(GL_BACK, GL_SPECULAR); + glVertexAttrib4f(vCOLOR,0.0, 0.0, 0.0, 1.0); + break; + + case PREFL_AMB_DIFF_SPEC: + if (colr_type == PMODEL_RGB) { + glColorMaterial(GL_BACK, GL_AMBIENT); + glVertexAttrib4f(vCOLOR, + colr->direct.rgb.red * refl_props->ambient_coef, + colr->direct.rgb.green * refl_props->ambient_coef, + colr->direct.rgb.blue * refl_props->ambient_coef, + 1.0); + + glColorMaterial(GL_BACK, GL_DIFFUSE); + glVertexAttrib4f(vCOLOR, + colr->direct.rgb.red * refl_props->diffuse_coef, + colr->direct.rgb.green * refl_props->diffuse_coef, + colr->direct.rgb.blue * refl_props->diffuse_coef, + 1.0); + + glColorMaterial(GL_BACK, GL_SPECULAR); + glVertexAttrib4f(vCOLOR, + colr->direct.rgb.red * refl_props->specular_coef, + colr->direct.rgb.green * refl_props->specular_coef, + colr->direct.rgb.blue * refl_props->specular_coef, + 1.0); + } + break; + + default: + break; + } +} /******************************************************************************* - * wsgl_setup_int_refl_props + * wsgl_setup_int_reflectance_model * - * DESCR: Setup surface reflection and colour properties + * DESCR: * RETURNS: N/A */ -void wsgl_setup_int_refl_props( +void wsgl_setup_int_reflectance_model( Pint colr_type, Pcoval *colr, Ws_attr_st *ast ) { - Pint refl_eqn; + Pint refl_model; Prefl_props *refl_props; GLfloat ambient[4]; GLfloat diffuse[4]; GLfloat specular[4]; - if (phg_nset_name_is_set(&ast->asf_nameset, (Pint) PASPECT_INT_REFL_EQN)) { - refl_eqn = ast->indiv_group.int_bundle.refl_eqn; - } - else { - refl_eqn = ast->bundl_group.int_bundle.refl_eqn; - } - - if (phg_nset_name_is_set(&ast->asf_nameset, (Pint) PASPECT_REFL_PROPS)) { - refl_props = &ast->indiv_group.int_bundle.refl_props; + if (phg_nset_name_is_set(&ast->asf_nameset, + (Pint) PASPECT_INT_REFL_MODEL)) { + refl_model = ast->indiv_group.int_bundle.refl_model; } else { - refl_props = &ast->bundl_group.int_bundle.refl_props; + refl_model = ast->bundl_group.int_bundle.refl_model; } + if (phg_nset_name_is_set(&ast->asf_nameset, + (Pint) PASPECT_REFL_PROPS)) { + refl_props = &ast->indiv_group.int_bundle.refl_props; + } + else { + refl_props = &ast->bundl_group.int_bundle.refl_props; + } - switch (refl_eqn) { + switch (refl_model) { case PREFL_AMBIENT: +#ifdef DEBUGLIGHT + printf("Reflectance model, Ambient\n"); +#endif #ifdef GLEW if (wsgl_use_shaders && GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader && GLEW_ARB_shader_objects) glUniform1i(shading_mode, 1); #else @@ -411,6 +410,9 @@ void wsgl_setup_int_refl_props( break; case PREFL_AMB_DIFF: +#ifdef DEBUGLIGHT + printf("Reflectance model, AMB_DIFF\n"); +#endif if (colr_type == PMODEL_RGB) { #ifdef GLEW if (wsgl_use_shaders && GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader && GLEW_ARB_shader_objects) glUniform1i(shading_mode, 1); @@ -435,6 +437,9 @@ void wsgl_setup_int_refl_props( break; case PREFL_AMB_DIFF_SPEC: +#ifdef DEBUGLIGHT + printf("Reflectance model, AMB_DIFF_SPEC\n"); +#endif if (colr_type == PMODEL_RGB) { #ifdef GLEW if (wsgl_use_shaders && GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader && GLEW_ARB_shader_objects) glUniform1i(shading_mode, 1); @@ -456,9 +461,15 @@ void wsgl_setup_int_refl_props( specular[2] = colr->direct.rgb.blue * refl_props->specular_coef; specular[3] = 1.0; } +#ifdef DEBUGLIGHT + else printf("Reflectance model, color type is not RGB %d \n", colr_type); +#endif break; default: +#ifdef DEBUGLIGHT + printf("Reflectance model, DEFAULT\n"); +#endif memset(ambient, 0.0, sizeof(Pfloat) * 3); memset(diffuse, 0.0, sizeof(Pfloat) * 3); memset(specular, 0.0, sizeof(Pfloat) * 3); @@ -484,9 +495,9 @@ void wsgl_setup_int_refl_props( glUniform4fv(vDiffuse, 1, diffuse); glUniform4fv(vSpecular, 1, specular); } else { - glMaterialfv(GL_FRONT, GL_AMBIENT, ambient); - glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse); - glMaterialfv(GL_FRONT, GL_SPECULAR, specular); + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse); + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular); } } @@ -509,8 +520,12 @@ int wsgl_setup_int_colr( Wsgl_handle wsgl = ws->render_context; if (wsgl->cur_struct.lighting) { - wsgl_setup_int_refl_props(colr_type, colr, ast); - lighting = TRUE; +#ifdef DEBUGLIGHT + printf("Setup int color\n"); +#endif + wsgl_setup_int_refl_props(colr_type, colr, ast); + wsgl_setup_int_reflectance_model(colr_type, colr, ast); + lighting = TRUE; } else { wsgl_set_colr(colr_type, colr); @@ -534,130 +549,14 @@ int wsgl_setup_int_attr_plus( { Pcoval colr; +#ifdef DEBUGLIGHT + printf("Setup int color plus\n"); +#endif wsgl_setup_int_attr_nocol(ws, ast); wsgl_colr_from_gcolr(&colr, wsgl_get_int_colr(ast)); return wsgl_setup_int_colr(ws, PMODEL_RGB, &colr, ast); } -/******************************************************************************* - * wsgl_setup_back_int_refl_props - * - * DESCR: Setup back surface reflection and colour properties - * RETURNS: N/A - */ - -void wsgl_setup_back_int_refl_props( - Pint colr_type, - Pcoval *colr, - Ws_attr_st *ast - ) -{ - Pint refl_eqn; - Prefl_props *refl_props; - GLfloat ambient[4]; - GLfloat diffuse[4]; - GLfloat specular[4]; - - if (phg_nset_name_is_set(&ast->asf_nameset, - (Pint) PASPECT_BACK_INT_REFL_EQN)) { - refl_eqn = ast->indiv_group.int_bundle.back_refl_eqn; - } - else { - refl_eqn = ast->bundl_group.int_bundle.back_refl_eqn; - } - - if (phg_nset_name_is_set(&ast->asf_nameset, - (Pint) PASPECT_BACK_REFL_PROPS)) { - refl_props = &ast->indiv_group.int_bundle.back_refl_props; - } - else { - refl_props = &ast->bundl_group.int_bundle.back_refl_props; - } - switch (refl_eqn) { - case PREFL_AMBIENT: - if (colr_type == PMODEL_RGB) { - ambient[0] = colr->direct.rgb.red * refl_props->ambient_coef; - ambient[1] = colr->direct.rgb.green * refl_props->ambient_coef; - ambient[2] = colr->direct.rgb.blue * refl_props->ambient_coef; - ambient[3] = 1.0; - - diffuse[0] = 0.0; - diffuse[1] = 0.0; - diffuse[2] = 0.0; - diffuse[3] = 1.0; - - specular[0] = 0.0; - specular[1] = 0.0; - specular[2] = 0.0; - specular[3] = 1.0; - } - break; - - case PREFL_AMB_DIFF: - if (colr_type == PMODEL_RGB) { - ambient[0] = colr->direct.rgb.red * refl_props->ambient_coef; - ambient[1] = colr->direct.rgb.green * refl_props->ambient_coef; - ambient[2] = colr->direct.rgb.blue * refl_props->ambient_coef; - ambient[3] = 1.0; - - diffuse[0] = colr->direct.rgb.red * refl_props->diffuse_coef; - diffuse[1] = colr->direct.rgb.green * refl_props->diffuse_coef; - diffuse[2] = colr->direct.rgb.blue * refl_props->diffuse_coef; - diffuse[3] = 1.0; - - specular[0] = 0.0; - specular[1] = 0.0; - specular[2] = 0.0; - specular[3] = 1.0; - } - break; - - case PREFL_AMB_DIFF_SPEC: - if (colr_type == PMODEL_RGB) { - ambient[0] = colr->direct.rgb.red * refl_props->ambient_coef; - ambient[1] = colr->direct.rgb.green * refl_props->ambient_coef; - ambient[2] = colr->direct.rgb.blue * refl_props->ambient_coef; - ambient[3] = 1.0; - - diffuse[0] = colr->direct.rgb.red * refl_props->diffuse_coef; - diffuse[1] = colr->direct.rgb.green * refl_props->diffuse_coef; - diffuse[2] = colr->direct.rgb.blue * refl_props->diffuse_coef; - diffuse[3] = 1.0; - - specular[0] = colr->direct.rgb.red * refl_props->specular_coef; - specular[1] = colr->direct.rgb.green * refl_props->specular_coef; - specular[2] = colr->direct.rgb.blue * refl_props->specular_coef; - specular[3] = 1.0; - } - break; - - default: - memset(ambient, 0.0, sizeof(Pfloat) * 3); - memset(diffuse, 0.0, sizeof(Pfloat) * 3); - memset(specular, 0.0, sizeof(Pfloat) * 3); - break; - } - -#ifdef GLEW - if (wsgl_use_shaders && GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader && GLEW_ARB_shader_objects) { -#else - if (wsgl_use_shaders) { -#endif - glVertexAttrib4f(vCOLOR, - colr->direct.rgb.red, - colr->direct.rgb.green, - colr->direct.rgb.blue, - 1.0); - glUniform4fv(vAmbient, 1, ambient); - glUniform4fv(vDiffuse, 1, diffuse); - glUniform4fv(vSpecular, 1, specular); - } else { - glMaterialfv(GL_FRONT, GL_AMBIENT, ambient); - glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse); - glMaterialfv(GL_FRONT, GL_SPECULAR, specular); - } - } - /******************************************************************************* * wsgl_setup_back_int_colr * @@ -677,8 +576,12 @@ int wsgl_setup_back_int_colr( Wsgl_handle wsgl = ws->render_context; if (wsgl->cur_struct.lighting) { - wsgl_setup_back_int_refl_props(colr_type, colr, ast); - lighting = TRUE; +#ifdef DEBUGLIGHT + printf("Setup back int color\n"); +#endif + wsgl_setup_back_int_refl_props(colr_type, colr, ast); + wsgl_setup_int_reflectance_model(colr_type, colr, ast); + lighting = TRUE; } else { wsgl_set_colr(colr_type, colr); @@ -701,6 +604,9 @@ int wsgl_setup_back_int_colr( ) { Pcoval colr; +#ifdef DEBUGLIGHT + printf("Setup back int color plus\n"); +#endif wsgl_setup_back_int_attr_nocol(ws, ast); wsgl_colr_from_gcolr(&colr, wsgl_get_back_int_colr(ast)); diff --git a/src/test_c/test_c6.c b/src/test_c/test_c6.c index d93568c..5312c18 100644 --- a/src/test_c/test_c6.c +++ b/src/test_c/test_c6.c @@ -45,7 +45,7 @@ #define BACK_SHAD_METH PSD_NONE #define REFL_EQN PREFL_AMB_DIFF #define BACK_REFL_EQN PREFL_AMBIENT - +#define REFL_MODEL PREFL_AMB_DIFF_SPEC Pint errnum; Pmatrix3 rot3, rotx, roty; @@ -1510,7 +1510,8 @@ int main(int argc, char *argv[]) pset_back_int_style_ind(BACK_STYLE_IND); pset_light_src_state(&lights_on_list, &lights_off_list); pset_int_shad_meth(PSD_COLOUR); - pset_refl_eqn(PREFL_AMB_DIFF); + pset_refl_model(REFL_MODEL); + pset_refl_eqn(REFL_EQN); pset_refl_props(&refl_props); plabel(LABEL_TRANS); pset_local_tran3(rot3, PTYPE_REPLACE); diff --git a/src/test_c/test_c8.c b/src/test_c/test_c8.c index fb55fdc..07e6054 100644 --- a/src/test_c/test_c8.c +++ b/src/test_c/test_c8.c @@ -44,6 +44,7 @@ #define BACK_STYLE_IND 6 #define SHAD_METH PSD_COLOUR #define BACK_SHAD_METH PSD_NONE +#define REFL_MODEL PREFL_AMB_DIFF_SPEC #define REFL_EQN PREFL_AMB_DIFF #define BACK_REFL_EQN PREFL_AMBIENT @@ -740,8 +741,9 @@ int main(int argc, char *argv[]) pset_light_src_state(&lights_on_list, &lights_off_list); pset_int_shad_meth(SHAD_METH); pset_back_int_shad_meth(BACK_SHAD_METH); - pset_refl_eqn(REFL_EQN); - pset_back_refl_eqn(BACK_REFL_EQN); + pset_refl_model(REFL_MODEL); + //pset_refl_eqn(REFL_EQN); + //pset_back_refl_eqn(BACK_REFL_EQN); pset_refl_props(&refl_props); pset_back_refl_props(&back_refl_props); plabel(LABEL_TRANS);