diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 7cf6cfc..9d22255 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -27,7 +27,7 @@ jobs: # - https://gh.io/supported-runners-and-hardware-resources # - https://gh.io/using-larger-runners (GitHub.com only) # Consider using larger runners or machines with greater resources for possible analysis time improvements. - runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} + runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-22.04' }} permissions: # required for all workflows security-events: write @@ -64,6 +64,8 @@ jobs: # or others). This is typically only required for manual builds. # - name: Setup runtime (example) # uses: actions/setup-example@v1 + - name: dependencies + run: sudo apt install --fix-missing cmake gcc gfortran libx11-dev libglu1-mesa-dev libmotif-dev tcsh libxaw7-dev libglew-dev libdlm-dev libgl2ps-dev libpng-dev # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index ecec4e5..d57d265 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -9,7 +9,7 @@ on: jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 strategy: fail-fast: false @@ -24,7 +24,7 @@ jobs: - uses: actions/checkout@v4 - name: dependencies - run: sudo apt install cmake gcc gfortran libx11-dev libglu1-mesa-dev libmotif-dev tcsh libxaw7-dev libglew-dev libdlm-dev libgl2ps-dev + run: sudo apt install --fix-missing cmake gcc gfortran libx11-dev libglu1-mesa-dev libmotif-dev tcsh libxaw7-dev libglew-dev libdlm-dev libgl2ps-dev libpng-dev - name: clean run: make clean diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f95b285..ed8d681 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,16 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.9...3.31) PROJECT(PHIGS) +SET(CMAKE_MODULE_PATH ${PHIGS_SOURCE_DIR}/cmake) + +FIND_PACKAGE(PNG REQUIRED) +FIND_PACKAGE(OpenGL REQUIRED) +FIND_PACKAGE(X11 REQUIRED) +FIND_PACKAGE(XMU REQUIRED) +FIND_PACKAGE(Motif REQUIRED) +FIND_PACKAGE(GLEW) +FIND_PACKAGE(epoxy) + if (APPLE) set(CMAKE_C_COMPILER gcc) set(CMAKE_C_COMPILER_ID GNU) @@ -28,31 +38,21 @@ if (OPENPHIGS_FORCE_32) message(STATUS "PHIGS: Guess for 32bit: OPENSSL_CRYPTO_LIBRARY=${OPENSSL_CRYPTO_LIBRARY}") endif() -SET(CMAKE_MODULE_PATH ${PHIGS_SOURCE_DIR}/cmake) set(GLEW_VERBOSE ON) # for debugging add_definitions(-g) # add_definitions(-DTEST) # add_definitions(-DDEBUG) +# add_definitions(-DDEBUGL) # add_definitions(-DDEBUGINP) # # use Motif widgets rather than Xaw add_definitions(-DMOTIF) -FIND_PACKAGE(PNG REQUIRED) -FIND_PACKAGE(OpenGL REQUIRED) -FIND_PACKAGE(X11 REQUIRED) -FIND_PACKAGE(XMU REQUIRED) -FIND_PACKAGE(Motif REQUIRED) - # use GLEW or epoxy if (USE_GLEW) - if (APPLE) - set (GLEW_USE_STATIC_LIBS "ON") - endif() - FIND_PACKAGE(GLEW) add_definitions(-DGLEW) set (GL_INCLUDES ${GLEW_INCLUDE_DIR}) else() @@ -112,7 +112,6 @@ if (USE_GLEW) m ) else() - FIND_PACKAGE(epoxy) SET(PHIGS_LIBRARIES phigs ${XLIBS} diff --git a/src/cmake/FindGLEW.cmake b/src/cmake/FindGLEW.cmake new file mode 100644 index 0000000..73ecd50 --- /dev/null +++ b/src/cmake/FindGLEW.cmake @@ -0,0 +1,16 @@ +FIND_LIBRARY(GLEW_LIBRARIES + NAMES GLEW + PATHS /usr/lib + PATHS /usr/X11/lib + PATHS /usr/openwin/lib + PATHS /opt/homebrew/lib) + +IF (GLEW_LIBRARIES) + SET (GLEW_FOUND TRUE) +ENDIF (GLEW_LIBRARIES) + +IF (GLEW_FOUND) + MESSAGE (STATUS "Found GLEW:" ${GLEW_LIBRARIES}) +ELSE (GLEW_FOUND) + MESSAGE (FATAL ERROR "Cannot find GLEW") +ENDIF (GLEW_FOUND) diff --git a/src/cmake/FindXMU.cmake b/src/cmake/FindXMU.cmake index d9a7924..a7c1e76 100644 --- a/src/cmake/FindXMU.cmake +++ b/src/cmake/FindXMU.cmake @@ -2,14 +2,15 @@ FIND_LIBRARY(XMU_LIBRARY NAMES Xmu PATHS /usr/lib PATHS /usr/X11/lib - PATHS /usr/openwin/lib) + PATHS /usr/openwin/lib + PATHS /opt/homebrew/lib) IF (XMU_LIBRARY) SET (XMU_FOUND TRUE) ENDIF (XMU_LIBRARY) IF (XMU_FOUND) - MESSAGE (STATUS "Found Xmu:") + MESSAGE (STATUS "Found Xmu:" ${XMU_LIBRARY}) ELSE (XMU_FOUND) MESSAGE (FATAL ERROR "Cannot find Xmu") ENDIF (XMU_FOUND) diff --git a/src/libphigs/c_binding/cb_extel.c b/src/libphigs/c_binding/cb_extel.c index 7f01c77..a866626 100644 --- a/src/libphigs/c_binding/cb_extel.c +++ b/src/libphigs/c_binding/cb_extel.c @@ -1149,6 +1149,9 @@ void pset_model_clip_ind( else if (clipi < 0) { ERR_REPORT(PHG_ERH, ERR112); } + else if (clipi > 2) { + ERR_REPORT(PHG_ERH, ERR112); + } else { args.el_type = PELEM_MODEL_CLIP_IND; args.el_size = sizeof(Pint); @@ -1183,7 +1186,7 @@ void pset_model_clip_vol3 ( if (PSL_STRUCT_STATE(PHG_PSL) != PSTRUCT_ST_STOP) { ERR_REPORT(PHG_ERH, ERR5); } - else if ( op < 0) { + else if ( op < 0 || op > 2) { /* the value of op is not important as this is anyway not used */ ERR_REPORT(PHG_ERH, ERR112); } diff --git a/src/libphigs/f_binding/fb_el.c b/src/libphigs/f_binding/fb_el.c index 892ded2..51f3d8b 100644 --- a/src/libphigs/f_binding/fb_el.c +++ b/src/libphigs/f_binding/fb_el.c @@ -751,51 +751,6 @@ FTN_SUBROUTINE(psiasf)( pset_indiv_asf(attrid, asfval); } -/******************************************************************************* - * psmcli - * - * DESCR: set modelling clipping indicator - * RETURNS: N/A - */ -FTN_SUBROUTINE(psmcli)( - FTN_INTEGER(mclipi) - ) -{ - Pint clipi = FTN_INTEGER_GET(mclipi); - pset_model_clip_ind(clipi); -} - -/******************************************************************************* - * psmcv3 - * - * DESCR: set modelling clipping volume 3 - * RETURNS: N/A - */ -FTN_SUBROUTINE(psmcv3)( - FTN_INTEGER(op), - FTN_INTEGER(nhalfs), - FTN_REAL_ARRAY(halfsp) - ) -{ - Pint iop = FTN_INTEGER_GET(op); - Pint num = FTN_INTEGER_GET(nhalfs); - Phalf_space_list3 spacelist; - Phalf_space3 list[num]; - int i; - - spacelist.num_half_spaces = num; - for (i=0; icur_struct.offset = 0; phg_mat_copy(wsgl->cur_struct.global_tran, wsgl->composite_tran); phg_mat_identity(wsgl->cur_struct.local_tran); - wsgl_set_clip_ind(ws, 0); // FIXME - wsgl_set_alpha_channel(ws, 1.0); // FIXME + wsgl_set_clip_ind(ws, 0); + wsgl_set_alpha_channel(ws, 1.0); wsgl_update_modelview(ws); if (wsgl->render_mode == WS_RENDER_MODE_SELECT) { diff --git a/src/libphigs/wsgl/wsgl_attr.c b/src/libphigs/wsgl/wsgl_attr.c index d56b6b3..49b97ea 100644 --- a/src/libphigs/wsgl/wsgl_attr.c +++ b/src/libphigs/wsgl/wsgl_attr.c @@ -35,7 +35,9 @@ #include "ws.h" #include "private/wsglP.h" -extern GLint clipping_ind, num_clip_planes, plane0, point0; +extern GLint clipping_ind, num_clip_planes; +extern GLint plane0, point0; +extern GLint plane1, point1; extern GLint shading_mode; extern GLint ModelViewMatrix, ProjectionMatrix; extern GLint alpha_channel; @@ -242,8 +244,13 @@ void wsgl_set_clip_ind( glUniform1i(clipping_ind, ind); if (ind == 1) { glEnable(GL_CLIP_PLANE0); + glDisable(GL_CLIP_PLANE1); + } else if (ind == 2) { + glEnable(GL_CLIP_PLANE0); + glEnable(GL_CLIP_PLANE1); } else { glDisable(GL_CLIP_PLANE0); + glDisable(GL_CLIP_PLANE1); } } } @@ -283,8 +290,10 @@ void wsgl_set_clip_vol3( int op, num; int * int_data = (int*) el_data; Phalf_space3 * list; - Phalf_space3 volume0; - Ppoint3 tmp1, tmp2, vol3, point3, pwc; + Phalf_space3 volume0, volume1; + Ppoint3 nn0, pt0; /* first plane */ + Ppoint3 nn1, pt1; /* second plane if any */ + Ppoint3 vol3, point3, pwc; Pmatrix3 vrc2wc, unity; #ifdef GLEW @@ -297,21 +306,43 @@ void wsgl_set_clip_vol3( op = int_data[0]; num = int_data[1]; list = (Phalf_space3 *)(&int_data[2]); - volume0 = list[0]; - /* take a local copy of the data */ - tmp1.x = volume0.norm.delta_x; - tmp1.y = volume0.norm.delta_y; - tmp1.z = volume0.norm.delta_z; - - tmp2.x = volume0.point.x; - tmp2.y = volume0.point.y; - tmp2.z = volume0.point.z; - - glUniform1i(num_clip_planes, num); - glUniform4f(plane0, tmp1.x, tmp1.y, tmp1.z, 0.); - GLdouble eqn0[4] = {tmp1.x, tmp1.y, tmp1.z, 0.}; - glClipPlane(GL_CLIP_PLANE0, eqn0); - glUniform4f(point0, tmp2.x, tmp2.y, tmp2.z, 0.); + if (1 == num || 2 ==num){ + glUniform1i(num_clip_planes, num); + /* first plane */ + volume0 = list[0]; + /* take a local copy of the data */ + nn0.x = volume0.norm.delta_x; + nn0.y = volume0.norm.delta_y; + nn0.z = volume0.norm.delta_z; + + pt0.x = volume0.point.x; + pt0.y = volume0.point.y; + pt0.z = volume0.point.z; + + glUniform4f(plane0, nn0.x, nn0.y, nn0.z, 0.); + GLdouble eqn0[4] = {nn0.x, nn0.y, nn0.z, 0.}; + glClipPlane(GL_CLIP_PLANE0, eqn0); + glUniform4f(point0, pt0.x, pt0.y, pt0.z, 0.); + if (2 ==num){ + /* first plane */ + volume1 = list[1]; + /* take a local copy of the data */ + nn1.x = volume1.norm.delta_x; + nn1.y = volume1.norm.delta_y; + nn1.z = volume1.norm.delta_z; + + pt1.x = volume1.point.x; + pt1.y = volume1.point.y; + pt1.z = volume1.point.z; + + glUniform4f(plane1, nn1.x, nn1.y, nn1.z, 0.); + GLdouble eqn1[4] = {nn1.x, nn1.y, nn1.z, 0.}; + glClipPlane(GL_CLIP_PLANE1, eqn1); + glUniform4f(point1, pt1.x, pt1.y, pt1.z, 0.); + } + } else { + glUniform1i(num_clip_planes, 0); /* ignore the call */ + } } } diff --git a/src/libphigs/wsgl/wsgl_light.c b/src/libphigs/wsgl/wsgl_light.c index 222a4eb..b844995 100644 --- a/src/libphigs/wsgl/wsgl_light.c +++ b/src/libphigs/wsgl/wsgl_light.c @@ -58,7 +58,6 @@ static GLuint get_light_id( ) { GLuint id; - switch (ind) { case 1: id = GL_LIGHT1; break; case 2: id = GL_LIGHT2; break; @@ -93,13 +92,16 @@ static void setup_ambient_light( amb[2] = rec->colr.val.general.z; amb[3] = 1.0; -#ifdef DEBUG +#ifdef DEBUGL printf("Ambient light: %f %f %f\n", amb[0], amb[1], amb[2]); #endif #ifdef GLEW if (wsgl_use_shaders && GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader && GLEW_ARB_shader_objects){ #else if (wsgl_use_shaders){ +#endif +#ifdef DEBUGL + printf("Ambient light Using shaders %d\n", ind); #endif switch (ind){ case 0: @@ -176,7 +178,7 @@ static void setup_directional_light( pos[2] = rec->dir.delta_z; pos[3] = 1.0; -#ifdef DEBUG +#ifdef DEBUGL printf("Directional light: %f %f %f @(%f, %f %f)\n", dif[0], dif[1], dif[2], pos[0], pos[1], pos[2]); @@ -185,6 +187,9 @@ static void setup_directional_light( if (wsgl_use_shaders && GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader && GLEW_ARB_shader_objects){ #else if (wsgl_use_shaders){ +#endif +#ifdef DEBUGL + printf("Directional light Using shaders %d\n", ind); #endif switch (ind){ case 0: @@ -275,7 +280,7 @@ static void setup_positional_light( coef[2] = 0.0; coef[3] = 0.0; -#ifdef DEBUG +#ifdef DEBUGL printf("Positional light: %f %f %f @(%f, %f %f) with %f %f\n", dif[0], dif[1], dif[2], pos[0], pos[1], pos[2], @@ -285,6 +290,9 @@ static void setup_positional_light( if (wsgl_use_shaders && GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader && GLEW_ARB_shader_objects){ #else if (wsgl_use_shaders){ +#endif +#ifdef DEBUGL + printf("Positional light Using shaders %d\n", ind); #endif switch (ind){ case 0: @@ -358,83 +366,92 @@ static void setup_positional_light( */ void wsgl_update_light_src_state( - Ws *ws - ) + Ws *ws + ) { - Pint i; - Phg_ret ret; - Wsgl *wsgl = ws->render_context; - - glPushMatrix(); - glLoadIdentity(); - - /* Activate light sources */ - for (i = 0; i < WS_MAX_LIGHT_SRC; i++) { - if (phg_nset_name_is_set(&wsgl->cur_struct.lightstat, i)) { -#ifdef DEBUG - printf("Setup light source: %d\n", i); + Pint i; + Phg_ret ret; + Wsgl *wsgl = ws->render_context; + + glPushMatrix(); + glLoadIdentity(); + + /* Activate light sources */ + for (i = 0; i < WS_MAX_LIGHT_SRC; i++) { + if (phg_nset_name_is_set(&wsgl->cur_struct.lightstat, i)) { +#ifdef DEBUGL + printf("Setup light source: %d\n", i); #endif - (*ws->inq_representation)(ws, - i, - PINQ_REALIZED, - PHG_ARGS_LIGHTSRCREP, - &ret); - if (ret.err == 0) { - switch (ret.data.rep.lightsrcrep.type) { - case PLIGHT_AMBIENT: - setup_ambient_light(i, &ret.data.rep.lightsrcrep.rec.ambient); - break; - - case PLIGHT_DIRECTIONAL: - setup_directional_light(i, &ret.data.rep.lightsrcrep.rec.directional); - break; - - case PLIGHT_POSITIONAL: - setup_positional_light(i, &ret.data.rep.lightsrcrep.rec.positional); - break; - /* FIXME - case PLIGHT_SPOT: - setup_spot_light(i, &ret.data.rep.lightsrcrep.rec.spot); - break; - */ - default: - break; - } - } - } else { + (*ws->inq_representation)(ws, + i, + PINQ_REALIZED, + PHG_ARGS_LIGHTSRCREP, + &ret); + if (ret.err == 0) { + switch (ret.data.rep.lightsrcrep.type) { + case PLIGHT_AMBIENT: +#ifdef DEBUGL + printf("Configure abient light\n"); +#endif + setup_ambient_light(i, &ret.data.rep.lightsrcrep.rec.ambient); + break; + + case PLIGHT_DIRECTIONAL: +#ifdef DEBUGL + printf("Configure directional light\n"); +#endif + setup_directional_light(i, &ret.data.rep.lightsrcrep.rec.directional); + break; + + case PLIGHT_POSITIONAL: +#ifdef DEBUGL + printf("Configure positional light\n"); +#endif + setup_positional_light(i, &ret.data.rep.lightsrcrep.rec.positional); + break; + /* FIXME + case PLIGHT_SPOT: + setup_spot_light(i, &ret.data.rep.lightsrcrep.rec.spot); + break; + */ + default: + break; + } + } + } 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 - switch (i){ - case 1: - glUniform1i(lightSource0, 0); - break; - case 2: - glUniform1i(lightSource1, 0); - break; - case 3: - glUniform1i(lightSource2, 0); - break; - case 4: - glUniform1i(lightSource3, 0); - break; - case 5: - glUniform1i(lightSource4, 0); - break; - case 6: - glUniform1i(lightSource5, 0); - break; - case 7: - glUniform1i(lightSource6, 0); - break; - } - } else { - glDisable(get_light_id(i)); - } + switch (i){ + case 1: + glUniform1i(lightSource0, 0); + break; + case 2: + glUniform1i(lightSource1, 0); + break; + case 3: + glUniform1i(lightSource2, 0); + break; + case 4: + glUniform1i(lightSource3, 0); + break; + case 5: + glUniform1i(lightSource4, 0); + break; + case 6: + glUniform1i(lightSource5, 0); + break; + case 7: + glUniform1i(lightSource6, 0); + break; + } + } else { + glDisable(get_light_id(i)); } - } + } + } #ifdef GLEW if (!wsgl_use_shaders || !GLEW_ARB_vertex_shader || !GLEW_ARB_fragment_shader || !GLEW_ARB_shader_objects) glPopMatrix(); #else @@ -480,7 +497,7 @@ void wsgl_set_light_src_state( wsgl->cur_struct.lighting = TRUE; } -#ifdef DEBUG +#ifdef DEBUGL printf("Lighting nameset: "); phg_nset_print(&wsgl->cur_struct.lightstat); printf("Lighting is %s\n", (wsgl->cur_struct.lighting) ? "On" : "Off"); diff --git a/src/libphigs/wsgl/wsgl_shaders.c b/src/libphigs/wsgl/wsgl_shaders.c index cefebc8..7e1c5ea 100644 --- a/src/libphigs/wsgl/wsgl_shaders.c +++ b/src/libphigs/wsgl/wsgl_shaders.c @@ -36,7 +36,9 @@ #include "private/wsglP.h" GLint vertex_shader, fragment_shader; -GLint clipping_ind, num_clip_planes, plane0, point0; +GLint clipping_ind, num_clip_planes; +GLint plane0, point0; +GLint plane1, point1; GLint shading_mode; GLint vAmbient, vDiffuse, vSpecular, vPositional; GLint ModelViewMatrix, ProjectionMatrix; @@ -61,18 +63,28 @@ static const char* vertex_shader_text_130 = "uniform int clipping_ind;\n" "uniform vec4 plane0;\n" "uniform vec4 point0;\n" +"uniform vec4 plane1;\n" +"uniform vec4 point1;\n" "float distance;\n" "void main()\n" "{\n" -" Color = vColor;\n" -" Normal = normalize(ModelViewMatrix * vec4(gl_Normal, 1));\n" -" gl_Position = ProjectionMatrix * ModelViewMatrix * gl_Vertex;\n" -" if ((num_clip_planes == 1) && (clipping_ind > 0)) {\n" -" distance = dot(gl_Vertex-point0, plane0);\n" +" Color = vColor;\n" +" Normal = normalize(ModelViewMatrix * vec4(gl_Normal, 1));\n" +" gl_Position = ProjectionMatrix * ModelViewMatrix * gl_Vertex;\n" +" if (clipping_ind > 0) {\n" +" if (num_clip_planes == 1) {\n" +" gl_ClipDistance[0] = dot(gl_Vertex-point0, plane0);\n" +" } else if (num_clip_planes == 2) {\n" +" gl_ClipDistance[0] = dot(gl_Vertex-point0, plane0);\n" +" gl_ClipDistance[1] = -dot(gl_Vertex-point1, plane1);\n" " } else {\n" -" distance = 1.0;\n" -" };\n" -" gl_ClipDistance[0] = distance;\n" +" gl_ClipDistance[0] = 1.0;\n" +" gl_ClipDistance[1] = 1.0;\n" +" }\n" +" } else {\n" +" gl_ClipDistance[0] = 1.0;\n" +" gl_ClipDistance[1] = 1.0;\n" +" }\n" "}\n"; static const char* fragment_shader_text_130 = @@ -208,12 +220,14 @@ static const char* vertex_shader_text_120 = "uniform int clipping_ind;\n" "uniform vec4 plane0;\n" "uniform vec4 point0;\n" +"uniform vec4 plane1;\n" +"uniform vec4 point1;\n" "void main()\n" "{\n" " Color = vColor;\n" " Normal = normalize(ModelViewMatrix * vec4(gl_Normal, 1));\n" " gl_Position = ProjectionMatrix * ModelViewMatrix * gl_Vertex;\n" -" if ((num_clip_planes == 1) && (clipping_ind > 0)) {\n" +" if ((num_clip_planes >0 ) && (clipping_ind > 0)) {\n" " gl_ClipVertex = transpose(ModelViewMatrix) * gl_Vertex;\n" " };\n" "}\n"; @@ -436,10 +450,13 @@ void wsgl_shaders(Ws * ws){ num_clip_planes = glGetUniformLocation(ws->program, "num_clip_planes"); clipping_ind = glGetUniformLocation(ws->program, "clipping_ind"); glDisable(GL_CLIP_PLANE0); + glDisable(GL_CLIP_PLANE1); glUniform1i(clipping_ind, 0); - glUniform1i(num_clip_planes, 1); + glUniform1i(num_clip_planes, 2); plane0 = glGetUniformLocation(ws->program, "plane0"); point0 = glGetUniformLocation(ws->program, "point0"); + plane1 = glGetUniformLocation(ws->program, "plane1"); + point1 = glGetUniformLocation(ws->program, "point1"); // shading mode shading_mode = glGetUniformLocation(ws->program, "ShadingMode"); // light sources