]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - clvm_cmds.c
CL_VM_GetLight: allow 2'nd optional parm which sets sampling mask: 1 lightmap (defaul...
[xonotic/darkplaces.git] / clvm_cmds.c
index 64dcdd734afb11f9bc649939516b99431e750745..f816eb35a7f6c1121fed8c2806fb11ee4bb1506a 100644 (file)
@@ -667,24 +667,25 @@ static void VM_CL_ambientsound (void)
        S_StaticSound (s, f, PRVM_G_FLOAT(OFS_PARM2), PRVM_G_FLOAT(OFS_PARM3)*64);
 }
 
-// #92 vector(vector org) getlight (DP_QC_GETLIGHT)
+// #92 vector(vector org[, float lpflag]) getlight (DP_QC_GETLIGHT)
 static void VM_CL_getlight (void)
 {
        vec3_t ambientcolor, diffusecolor, diffusenormal;
        vec_t *p;
 
-       VM_SAFEPARMCOUNT(1, VM_CL_getlight);
+       VM_SAFEPARMCOUNTRANGE(1, 2, VM_CL_getlight);
 
        p = PRVM_G_VECTOR(OFS_PARM0);
        VectorClear(ambientcolor);
        VectorClear(diffusecolor);
        VectorClear(diffusenormal);
-       if (cl.worldmodel && cl.worldmodel->brush.LightPoint)
+       if (prog->argc >= 2)
+               R_CompleteLightPoint(ambientcolor, diffusecolor, diffusenormal, p, PRVM_G_FLOAT(OFS_PARM1));
+       else if (cl.worldmodel && cl.worldmodel->brush.LightPoint)
                cl.worldmodel->brush.LightPoint(cl.worldmodel, p, ambientcolor, diffusecolor, diffusenormal);
        VectorMA(ambientcolor, 0.5, diffusecolor, PRVM_G_VECTOR(OFS_RETURN));
 }
 
-
 //============================================================================
 //[515]: SCENE MANAGER builtins
 extern qboolean CSQC_AddRenderEdict (prvm_edict_t *ed, int edictnum);//csprogs.c
@@ -744,6 +745,8 @@ void VM_CL_R_AddEntities (void)
        prog->globals.client->time = cl.time;
        for(i=1;i<prog->num_edicts;i++)
        {
+               // so we can easily check if CSQC entity #edictnum is currently drawn
+               cl.csqcrenderentities[i].entitynumber = 0;
                ed = &prog->edicts[i];
                if(ed->priv.required->free)
                        continue;
@@ -2986,6 +2989,7 @@ typedef struct vmpolygons_s
        unsigned short  *data_sortedelement3s;
 
        qboolean                begin_active;
+       int     begin_draw2d;
        rtexture_t              *begin_texture;
        int                             begin_drawflag;
        int                             begin_vertices;
@@ -3072,9 +3076,11 @@ static void VM_DrawPolygonCallback (const entity_render_t *ent, const rtlight_t
        vmpolygons_t* polys = vmpolygons + PRVM_GetProgNr();
        if(polys->progstarttime != prog->starttime) // from other progs? won't draw these (this can cause crashes!)
                return;
-       R_Mesh_ResetTextureState();
+//     R_Mesh_ResetTextureState();
        R_EntityMatrix(&identitymatrix);
        GL_CullFace(GL_NONE);
+       GL_DepthTest(true); // polys in 3D space shall always have depth test
+       GL_DepthRange(0, 1);
        R_Mesh_PrepareVertices_Generic_Arrays(polys->num_vertices, polys->data_vertex3f, polys->data_color4f, polys->data_texcoord2f);
 
        for (surfacelistindex = 0;surfacelistindex < numsurfaces;)
@@ -3107,7 +3113,7 @@ void VMPolygons_Store(vmpolygons_t *polys)
                if(polys->begin_color[i][3] < 1)
                        hasalpha = true;
 
-       if (r_refdef.draw2dstage)
+       if (polys->begin_draw2d)
        {
                // draw the polygon as 2D immediately
                drawqueuemesh_t mesh;
@@ -3127,7 +3133,8 @@ void VMPolygons_Store(vmpolygons_t *polys)
                int i;
                if (polys->max_triangles < polys->num_triangles + polys->begin_vertices-2)
                {
-                       polys->max_triangles *= 2;
+                       while (polys->max_triangles < polys->num_triangles + polys->begin_vertices-2)
+                               polys->max_triangles *= 2;
                        VM_ResizePolygons(polys);
                }
                if (polys->num_vertices + polys->begin_vertices <= polys->max_vertices)
@@ -3180,7 +3187,7 @@ void VM_CL_AddPolygonsToMeshQueue (void)
          polys->num_vertices = 0;  // otherwise it's not rendered at all and prints an error message --blub */
 }
 
-//void(string texturename, float flag) R_BeginPolygon
+//void(string texturename, float flag[, float is2d]) R_BeginPolygon
 void VM_CL_R_PolygonBegin (void)
 {
        const char              *picname;
@@ -3192,7 +3199,7 @@ void VM_CL_R_PolygonBegin (void)
        // better management of flags, and is more suited for 3D rendering), what
        // about supporting Q3 shaders?
 
-       VM_SAFEPARMCOUNT(2, VM_CL_R_PolygonBegin);
+       VM_SAFEPARMCOUNTRANGE(2, 3, VM_CL_R_PolygonBegin);
 
        if (!polys->initialized)
                VM_InitPolygons(polys);
@@ -3234,6 +3241,7 @@ void VM_CL_R_PolygonBegin (void)
        polys->begin_drawflag = (int)PRVM_G_FLOAT(OFS_PARM1) & DRAWFLAG_MASK;
        polys->begin_vertices = 0;
        polys->begin_active = true;
+       polys->begin_draw2d = (prog->argc >= 3 ? (int)PRVM_G_FLOAT(OFS_PARM2) : r_refdef.draw2dstage);
 }
 
 //void(vector org, vector texcoords, vector rgb, float alpha) R_PolygonVertex
@@ -4301,7 +4309,7 @@ VM_CL_R_AddEntity,                                // #302 void(entity ent) addentity (EXT_CSQC)
 VM_CL_R_SetView,                               // #303 float(float property, ...) setproperty (EXT_CSQC)
 VM_CL_R_RenderScene,                   // #304 void() renderscene (EXT_CSQC)
 VM_CL_R_AddDynamicLight,               // #305 void(vector org, float radius, vector lightcolours) adddynamiclight (EXT_CSQC)
-VM_CL_R_PolygonBegin,                  // #306 void(string texturename, float flag[, float is2d, float lines]) R_BeginPolygon
+VM_CL_R_PolygonBegin,                  // #306 void(string texturename, float flag, float is2d[NYI: , float lines]) R_BeginPolygon
 VM_CL_R_PolygonVertex,                 // #307 void(vector org, vector texcoords, vector rgb, float alpha) R_PolygonVertex
 VM_CL_R_PolygonEnd,                            // #308 void() R_EndPolygon
 NULL /* R_LoadWorldModel in menu VM, should stay unassigned in client*/, // #309