Beispiel #1
0
        /// <summary>
        /// R_RenderBrushPoly
        /// </summary>
        private void RenderBrushPoly(MemorySurface fa)
        {
            _BrushPolys++;

            if ((fa.flags & ( Int32 )Q1SurfaceFlags.Sky) != 0)
            {               // warp texture, no lightmaps
                WarpableTextures.EmitBothSkyLayers(Host.RealTime, Host.RenderContext.Origin, fa);
                return;
            }

            var t = TextureAnimation(fa.texinfo.texture);

            t.texture.Bind( );

            if ((fa.flags & ( Int32 )Q1SurfaceFlags.Turbulence) != 0)
            {               // warp texture, no lightmaps
                WarpableTextures.EmitWaterPolys(Host.RealTime, fa);
                return;
            }

            if ((fa.flags & ( Int32 )Q1SurfaceFlags.Underwater) != 0)
            {
                Host.Video.Device.Graphics.DrawWaterPoly(fa.polys, Host.RealTime);
            }
            else
            {
                Host.Video.Device.Graphics.DrawPoly(fa.polys, t.scaleX, t.scaleY);
            }

            // add the poly to the proper lightmap chain

            fa.polys.chain = _LightMapPolys[fa.lightmaptexturenum];
            _LightMapPolys[fa.lightmaptexturenum] = fa.polys;

            // check for lightmap modification
            var modified = false;

            for (var maps = 0; maps < BspDef.MAXLIGHTMAPS && fa.styles[maps] != 255; maps++)
            {
                if (_LightStyleValue[fa.styles[maps]] != fa.cached_light[maps])
                {
                    modified = true;
                    break;
                }
            }

            if (modified ||
                fa.dlightframe == _FrameCount ||            // dynamic this frame
                fa.cached_dlight)                           // dynamic previously
            {
                if (Host.Cvars.Dynamic.Get <Boolean>( ))
                {
                    LightMapTexture.LightMapModified[fa.lightmaptexturenum] = true;
                    UpdateRect(fa, ref LightMapTexture.LightMapRectChange[fa.lightmaptexturenum]);
                    var offset = fa.lightmaptexturenum * _LightMapBytes * RenderDef.BLOCK_WIDTH * RenderDef.BLOCK_HEIGHT;
                    offset += fa.light_t * RenderDef.BLOCK_WIDTH * _LightMapBytes + fa.light_s * _LightMapBytes;
                    BuildLightMap(fa, new ByteArraySegment(_LightMaps, offset), RenderDef.BLOCK_WIDTH * _LightMapBytes);
                }
            }
        }
Beispiel #2
0
        private Pixbuf ProcessImpl(Pixbuf input, Cms.Profile input_profile, bool fast)
        {
            Pixbuf result;

            using (ImageInfo info = new ImageInfo(input)) {
                MemorySurface surface = new MemorySurface(Format.Argb32,
                                                          input.Width,
                                                          input.Height);

                Context ctx = new Context(surface);
                ctx.Matrix = info.Fill(info.Bounds, angle);
                SurfacePattern p = new SurfacePattern(info.Surface);
                if (fast)
                {
                    p.Filter = Filter.Fast;
                }
                ctx.Source = p;
                ctx.Paint();
                ((IDisposable)ctx).Dispose();
                p.Destroy();
                result = MemorySurface.CreatePixbuf(surface);
                surface.Flush();
            }
            return(result);
        }
		private ImageInfo CreateBlur (ImageInfo source)
		{
			double scale = Math.Max (256 / (double) source.Bounds.Width,
						 256 / (double) source.Bounds.Height);

			Gdk.Rectangle small = new Gdk.Rectangle (0, 0,
								(int) Math.Ceiling (source.Bounds.Width * scale),
								(int) Math.Ceiling (source.Bounds.Height * scale));

			MemorySurface image = new MemorySurface (Format.Argb32,
								 small.Width,
								 small.Height);

			Context ctx = new Context (image);
			//Pattern solid = new SolidPattern (0, 0, 0, 0);
			//ctx.Source = solid;
			//ctx.Paint ();
			//solid.Destroy ();
			ctx.Matrix = source.Fit (small);
			ctx.Operator = Operator.Source;
			Pattern p = new SurfacePattern (source.Surface);
			ctx.Source = p;
			//Log.Debug (small);
			ctx.Paint ();
			p.Destroy ();
			((IDisposable)ctx).Dispose ();
			Gdk.Pixbuf normal = MemorySurface.CreatePixbuf (image);
			Gdk.Pixbuf blur = PixbufUtils.Blur (normal, 3);
			ImageInfo overlay = new ImageInfo (blur);
			blur.Dispose ();
			normal.Dispose ();
			image.Destroy ();
			return overlay;
		}
        public bool Convert(FilterRequest req)
        {
            string source = req.Current.LocalPath;
            Uri    dest   = req.TempUri(Path.GetExtension(source));

            using (ImageFile img = ImageFile.Create(source)) {
                using (Pixbuf pixbuf = img.Load()) {
                    using (ImageInfo info = new ImageInfo(pixbuf)) {
                        MemorySurface surface = new MemorySurface(Format.Argb32,
                                                                  pixbuf.Width,
                                                                  pixbuf.Height);

                        Context ctx = new Context(surface);
                        ctx.Matrix = info.Fill(info.Bounds, angle);
                        Pattern p = new SurfacePattern(info.Surface);
                        ctx.Source = p;
                        ctx.Paint();
                        ((IDisposable)ctx).Dispose();
                        p.Destroy();
                        using (Pixbuf result = CairoUtils.CreatePixbuf(surface)) {
                            using (Stream output = File.OpenWrite(dest.LocalPath)) {
                                img.Save(result, output);
                            }
                        }
                        surface.Flush();
                        info.Dispose();
                        req.Current = dest;
                        return(true);
                    }
                }
            }
        }
Beispiel #5
0
        private void UpdateRect(MemorySurface fa, ref glRect_t theRect)
        {
            if (fa.light_t < theRect.t)
            {
                if (theRect.h != 0)
                {
                    theRect.h += ( Byte )(theRect.t - fa.light_t);
                }
                theRect.t = ( Byte )fa.light_t;
            }
            if (fa.light_s < theRect.l)
            {
                if (theRect.w != 0)
                {
                    theRect.w += ( Byte )(theRect.l - fa.light_s);
                }
                theRect.l = ( Byte )fa.light_s;
            }
            var smax = (fa.extents[0] >> 4) + 1;
            var tmax = (fa.extents[1] >> 4) + 1;

            if ((theRect.w + theRect.l) < (fa.light_s + smax))
            {
                theRect.w = ( Byte )((fa.light_s - theRect.l) + smax);
            }
            if ((theRect.h + theRect.t) < (fa.light_t + tmax))
            {
                theRect.h = ( Byte )((fa.light_t - theRect.t) + tmax);
            }
        }
		private void HandleApply (object sender, EventArgs args)
		{
			BrowsablePointer item = view.Item;
			EditTarget target = new EditTarget (item);
			try { 
				using (ImageFile img = ImageFile.Create (item.Current.DefaultVersionUri)) {

					Cairo.Format format = view.CompletePixbuf ().HasAlpha ? Cairo.Format.Argb32 : Cairo.Format.Rgb24;

					MemorySurface dest = new MemorySurface (format,
										info.Bounds.Width,
										info.Bounds.Height);

					Context ctx = new Context (dest);
					effect.OnExpose (ctx, info.Bounds);
					((IDisposable)ctx).Dispose ();

					string tmp = ImageFile.TempPath (item.Current.DefaultVersionUri.LocalPath);
					using (Gdk.Pixbuf output = Widgets.CairoUtils.CreatePixbuf (dest)) {
						using (System.IO.Stream stream = System.IO.File.OpenWrite (tmp)) {
							img.Save (output, stream);
						
						}
					}

					dest.Destroy ();

					// FIXME Not this again. I need to imlplement a real version of the transfer
					// function that shows progress in the main window and allows for all the
					// goodies we'll need.
					Gnome.Vfs.Result result = Gnome.Vfs.Result.Ok;
					result = Gnome.Vfs.Xfer.XferUri (new Gnome.Vfs.Uri (UriList.PathToFileUri (tmp).ToString ()),
									 new Gnome.Vfs.Uri (target.Uri.ToString ()),
									 Gnome.Vfs.XferOptions.Default,
									 Gnome.Vfs.XferErrorMode.Abort, 
									 Gnome.Vfs.XferOverwriteMode.Replace, 
									 delegate {
										 System.Console.Write (".");
										 return 1;
									 });

					target.Commit ();
				}
			} catch (System.Exception e) {
				System.Console.WriteLine (e);
				target.Delete ();
				Dialog d = new EditExceptionDialog ((Gtk.Window) view.Toplevel, e, view.Item.Current);
				d.Show ();
				d.Run ();
				d.Destroy ();
			}
			Destroy ();
		}
        private void HandleApply(object sender, EventArgs args)
        {
            BrowsablePointer item   = view.Item;
            EditTarget       target = new EditTarget(item);

            try {
                using (ImageFile img = ImageFile.Create(item.Current.DefaultVersionUri)) {
                    Cairo.Format format = view.CompletePixbuf().HasAlpha ? Cairo.Format.Argb32 : Cairo.Format.Rgb24;

                    MemorySurface dest = new MemorySurface(format,
                                                           info.Bounds.Width,
                                                           info.Bounds.Height);

                    Context ctx = new Context(dest);
                    effect.OnExpose(ctx, info.Bounds);
                    ((IDisposable)ctx).Dispose();

                    string tmp = ImageFile.TempPath(item.Current.DefaultVersionUri.LocalPath);
                    using (Gdk.Pixbuf output = Widgets.CairoUtils.CreatePixbuf(dest)) {
                        using (System.IO.Stream stream = System.IO.File.OpenWrite(tmp)) {
                            img.Save(output, stream);
                        }
                    }

                    dest.Destroy();

                    // FIXME Not this again. I need to imlplement a real version of the transfer
                    // function that shows progress in the main window and allows for all the
                    // goodies we'll need.
                    Gnome.Vfs.Result result = Gnome.Vfs.Result.Ok;
                    result = Gnome.Vfs.Xfer.XferUri(new Gnome.Vfs.Uri(UriList.PathToFileUri(tmp).ToString()),
                                                    new Gnome.Vfs.Uri(target.Uri.ToString()),
                                                    Gnome.Vfs.XferOptions.Default,
                                                    Gnome.Vfs.XferErrorMode.Abort,
                                                    Gnome.Vfs.XferOverwriteMode.Replace,
                                                    delegate {
                        System.Console.Write(".");
                        return(1);
                    });

                    target.Commit();
                }
            } catch (System.Exception e) {
                System.Console.WriteLine(e);
                target.Delete();
                Dialog d = new EditExceptionDialog((Gtk.Window)view.Toplevel, e, view.Item.Current);
                d.Show();
                d.Run();
                d.Destroy();
            }
            Destroy();
        }
        /// <summary>
        /// EmitBothSkyLayers
        /// Does a sky warp on the pre-fragmented glpoly_t chain
        /// This will be called for brushmodels, the world
        /// will have them chained together.
        /// </summary>
        public void EmitBothSkyLayers(Double realTime, Vector3 origin, MemorySurface fa)
        {
            Device.DisableMultitexture( );

            SolidSkyTexture.Bind( );
            SpeedScale  = ( Single )realTime * 8;
            SpeedScale -= ( Int32 )SpeedScale & ~127;

            Device.Graphics.EmitSkyPolys(fa.polys, origin, SpeedScale);

            AlphaSkyTexture.Bind( );
            SpeedScale  = ( Single )realTime * 16;
            SpeedScale -= ( Int32 )SpeedScale & ~127;

            Device.Graphics.EmitSkyPolys(fa.polys, origin, SpeedScale, true);
        }
Beispiel #9
0
        /// <summary>
        /// GL_CreateSurfaceLightmap
        /// </summary>
        private void CreateSurfaceLightmap(ref Int32[,] tempBuffer, MemorySurface surf)
        {
            if ((surf.flags & (( Int32 )Q1SurfaceFlags.Sky | ( Int32 )Q1SurfaceFlags.Turbulence)) != 0)
            {
                return;
            }

            var smax = (surf.extents[0] >> 4) + 1;
            var tmax = (surf.extents[1] >> 4) + 1;

            surf.lightmaptexturenum = AllocBlock(ref tempBuffer, smax, tmax, ref surf.light_s, ref surf.light_t);
            var offset = surf.lightmaptexturenum * _LightMapBytes * RenderDef.BLOCK_WIDTH * RenderDef.BLOCK_HEIGHT;

            offset += (surf.light_t * RenderDef.BLOCK_WIDTH + surf.light_s) * _LightMapBytes;
            BuildLightMap(surf, new ByteArraySegment(_LightMaps, offset), RenderDef.BLOCK_WIDTH * _LightMapBytes);
        }
        /// <summary>
        /// EmitBothSkyLayers
        /// Does a sky warp on the pre-fragmented glpoly_t chain
        /// This will be called for brushmodels, the world
        /// will have them chained together.
        /// </summary>
        public void EmitBothSkyLayers(double realTime, Vector3 origin, MemorySurface fa)
        {
            this.Device.DisableMultitexture( );

            this.SolidSkyTexture.Bind( );
            this.SpeedScale  = ( float )realTime * 8;
            this.SpeedScale -= ( int )this.SpeedScale & ~127;

            this.Device.Graphics.EmitSkyPolys(fa.polys, origin, this.SpeedScale);

            this.AlphaSkyTexture.Bind( );
            this.SpeedScale  = ( float )realTime * 16;
            this.SpeedScale -= ( int )this.SpeedScale & ~127;

            this.Device.Graphics.EmitSkyPolys(fa.polys, origin, this.SpeedScale, true);
        }
		private Pixbuf ProcessImpl (Pixbuf input, Cms.Profile input_profile, bool fast) {
			Pixbuf result;
			using (ImageInfo info = new ImageInfo (input)) {
				Widgets.SoftFocus soft = new Widgets.SoftFocus (info);
				soft.Radius = radius;

				MemorySurface surface = new MemorySurface (Format.Argb32,
									   input.Width,
									   input.Height);

				Context ctx = new Context (surface);
				soft.Apply (ctx, info.Bounds);
				((IDisposable)ctx).Dispose ();

				result = MemorySurface.CreatePixbuf (surface);
				surface.Flush ();
			}
			return result;
		}
Beispiel #12
0
        private Pixbuf ProcessImpl(Pixbuf input, Cms.Profile input_profile, bool fast)
        {
            Pixbuf result;

            using (ImageInfo info = new ImageInfo(input)) {
                Widgets.SoftFocus soft = new Widgets.SoftFocus(info);
                soft.Radius = radius;

                MemorySurface surface = new MemorySurface(Format.Argb32,
                                                          input.Width,
                                                          input.Height);

                Context ctx = new Context(surface);
                soft.Apply(ctx, info.Bounds);
                ((IDisposable)ctx).Dispose();

                result = MemorySurface.CreatePixbuf(surface);
                surface.Flush();
            }
            return(result);
        }
Beispiel #13
0
 private Pixbuf ProcessImpl(Pixbuf input, Cms.Profile input_profile, bool fast)
 {
     Pixbuf result;
     using (ImageInfo info = new ImageInfo (input)) {
         using (MemorySurface surface = new MemorySurface (Format.Argb32,
                                input.Width,
                                input.Height)) {
             using (Context ctx = new Context (surface)) {
                 ctx.Matrix = info.Fill (info.Bounds, angle);
                 using (SurfacePattern p = new SurfacePattern (info.Surface)) {
                     if (fast)
                         p.Filter =  Filter.Fast;
                     ctx.Source = p;
                     ctx.Paint ();
                 }
                 result = MemorySurface.CreatePixbuf (surface);
                 surface.Flush ();
             }
         }
     }
     return result;
 }
		private Pixbuf ProcessImpl (Pixbuf input, Cms.Profile input_profile, bool fast) {
			Pixbuf result;
			using (ImageInfo info = new ImageInfo (input)) {
				MemorySurface surface = new MemorySurface (Format.Argb32,
									   input.Width,
									   input.Height);

				Context ctx = new Context (surface);
				ctx.Matrix = info.Fill (info.Bounds, angle);
				SurfacePattern p = new SurfacePattern (info.Surface);
				if (fast) {
					p.Filter =  Filter.Fast;
				}
				ctx.Source = p;
				ctx.Paint ();
				((IDisposable)ctx).Dispose ();
				p.Destroy ();
				result = MemorySurface.CreatePixbuf (surface);
				surface.Flush ();
			}
			return result;
		}
Beispiel #15
0
        /// <summary>
        /// R_RenderDynamicLightmaps
        /// Multitexture
        /// </summary>
        private void RenderDynamicLightmaps(MemorySurface fa)
        {
            _BrushPolys++;

            if ((fa.flags & (( Int32 )Q1SurfaceFlags.Sky | ( Int32 )Q1SurfaceFlags.Turbulence)) != 0)
            {
                return;
            }

            fa.polys.chain = _LightMapPolys[fa.lightmaptexturenum];
            _LightMapPolys[fa.lightmaptexturenum] = fa.polys;

            // check for lightmap modification
            var flag = false;

            for (var maps = 0; maps < BspDef.MAXLIGHTMAPS && fa.styles[maps] != 255; maps++)
            {
                if (_LightStyleValue[fa.styles[maps]] != fa.cached_light[maps])
                {
                    flag = true;
                    break;
                }
            }

            if (flag ||
                fa.dlightframe == _FrameCount ||    // dynamic this frame
                fa.cached_dlight)                   // dynamic previously
            {
                if (Host.Cvars.Dynamic.Get <Boolean>( ))
                {
                    LightMapTexture.LightMapModified[fa.lightmaptexturenum] = true;
                    UpdateRect(fa, ref LightMapTexture.LightMapRectChange[fa.lightmaptexturenum]);
                    var offset = fa.lightmaptexturenum * _LightMapBytes * RenderDef.BLOCK_WIDTH * RenderDef.BLOCK_HEIGHT +
                                 fa.light_t * RenderDef.BLOCK_WIDTH * _LightMapBytes + fa.light_s * _LightMapBytes;
                    BuildLightMap(fa, new ByteArraySegment(_LightMaps, offset), RenderDef.BLOCK_WIDTH * _LightMapBytes);
                }
            }
        }
        private ImageInfo CreateBlur(ImageInfo source)
        {
            double scale = Math.Max(256 / (double)source.Bounds.Width,
                                    256 / (double)source.Bounds.Height);

            Gdk.Rectangle small = new Gdk.Rectangle(0, 0,
                                                    (int)Math.Ceiling(source.Bounds.Width * scale),
                                                    (int)Math.Ceiling(source.Bounds.Height * scale));

            MemorySurface image = new MemorySurface(Format.Argb32,
                                                    small.Width,
                                                    small.Height);

            Context ctx = new Context(image);

            //Pattern solid = new SolidPattern (0, 0, 0, 0);
            //ctx.Source = solid;
            //ctx.Paint ();
            //solid.Destroy ();
            ctx.Matrix   = source.Fit(small);
            ctx.Operator = Operator.Source;
            Pattern p = new SurfacePattern(source.Surface);

            ctx.Source = p;
            Console.WriteLine(small);
            ctx.Paint();
            p.Destroy();
            ((IDisposable)ctx).Dispose();
            Gdk.Pixbuf normal  = CairoUtils.CreatePixbuf(image);
            Gdk.Pixbuf blur    = PixbufUtils.Blur(normal, 3);
            ImageInfo  overlay = new ImageInfo(blur);

            blur.Dispose();
            normal.Dispose();
            image.Destroy();
            return(overlay);
        }
        /// <summary>
        /// R_DrawSkyChain
        /// </summary>
        public void DrawSkyChain(double realTime, Vector3 origin, MemorySurface s)
        {
            this.Device.DisableMultitexture( );

            this.SolidSkyTexture.Bind( );

            // used when gl_texsort is on
            this.SpeedScale  = ( float )realTime * 8;
            this.SpeedScale -= ( int )this.SpeedScale & ~127;

            for (var fa = s; fa != null; fa = fa.texturechain)
            {
                this.Device.Graphics.EmitSkyPolys(fa.polys, origin, this.SpeedScale);
            }

            this.AlphaSkyTexture.Bind( );
            this.SpeedScale  = ( float )realTime * 16;
            this.SpeedScale -= ( int )this.SpeedScale & ~127;

            for (var fa = s; fa != null; fa = fa.texturechain)
            {
                this.Device.Graphics.EmitSkyPolys(fa.polys, origin, this.SpeedScale, true);
            }
        }
        /// <summary>
        /// R_DrawSkyChain
        /// </summary>
        public void DrawSkyChain(Double realTime, Vector3 origin, MemorySurface s)
        {
            Device.DisableMultitexture( );

            SolidSkyTexture.Bind( );

            // used when gl_texsort is on
            SpeedScale  = ( Single )realTime * 8;
            SpeedScale -= ( Int32 )SpeedScale & ~127;

            for (var fa = s; fa != null; fa = fa.texturechain)
            {
                Device.Graphics.EmitSkyPolys(fa.polys, origin, SpeedScale);
            }

            AlphaSkyTexture.Bind( );
            SpeedScale  = ( Single )realTime * 16;
            SpeedScale -= ( Int32 )SpeedScale & ~127;

            for (var fa = s; fa != null; fa = fa.texturechain)
            {
                Device.Graphics.EmitSkyPolys(fa.polys, origin, SpeedScale, true);
            }
        }
 /// <summary>
 /// EmitWaterPolys
 /// Does a water warp on the pre-fragmented glpoly_t chain
 /// </summary>
 public void EmitWaterPolys(double realTime, MemorySurface fa)
 {
     this.Device.Graphics.EmitWaterPolys(ref WarpDef._TurbSin, realTime, WarpDef.TURBSCALE, fa.polys);
 }
Beispiel #20
0
        /// <summary>
        /// BuildSurfaceDisplayList
        /// </summary>
        private void BuildSurfaceDisplayList(MemorySurface fa)
        {
            var BrushModelData = ( BrushModelData )_CurrentModel;
            // reconstruct the polygon
            var pedges    = BrushModelData.Edges;
            var lnumverts = fa.numedges;

            //
            // draw texture
            //
            var poly = new GLPoly( );

            poly.AllocVerts(lnumverts);
            poly.next  = fa.polys;
            poly.flags = fa.flags;
            fa.polys   = poly;

            UInt16[] r_pedge_v;
            Vector3  vec;

            for (var i = 0; i < lnumverts; i++)
            {
                var lindex = BrushModelData.SurfEdges[fa.firstedge + i];
                if (lindex > 0)
                {
                    r_pedge_v = pedges[lindex].v;
                    vec       = _CurrentVertBase[r_pedge_v[0]].position;
                }
                else
                {
                    r_pedge_v = pedges[-lindex].v;
                    vec       = _CurrentVertBase[r_pedge_v[1]].position;
                }
                var s = MathLib.DotProduct(ref vec, ref fa.texinfo.vecs[0]) + fa.texinfo.vecs[0].W;
                s /= fa.texinfo.texture.width;

                var t = MathLib.DotProduct(ref vec, ref fa.texinfo.vecs[1]) + fa.texinfo.vecs[1].W;
                t /= fa.texinfo.texture.height;

                poly.verts[i][0] = vec.X;
                poly.verts[i][1] = vec.Y;
                poly.verts[i][2] = vec.Z;
                poly.verts[i][3] = s;
                poly.verts[i][4] = t;

                //
                // lightmap texture coordinates
                //
                s  = MathLib.DotProduct(ref vec, ref fa.texinfo.vecs[0]) + fa.texinfo.vecs[0].W;
                s -= fa.texturemins[0];
                s += fa.light_s * 16;
                s += 8;
                s /= RenderDef.BLOCK_WIDTH * 16;

                t  = MathLib.DotProduct(ref vec, ref fa.texinfo.vecs[1]) + fa.texinfo.vecs[1].W;
                t -= fa.texturemins[1];
                t += fa.light_t * 16;
                t += 8;
                t /= RenderDef.BLOCK_HEIGHT * 16;

                poly.verts[i][5] = s;
                poly.verts[i][6] = t;
            }

            //
            // remove co-linear points - Ed
            //
            if (!Host.Cvars.glKeepTJunctions.Get <Boolean>( ) && (fa.flags & ( Int32 )Q1SurfaceFlags.Underwater) == 0)
            {
                for (var i = 0; i < lnumverts; ++i)
                {
                    if (Utilities.IsCollinear(poly.verts[(i + lnumverts - 1) % lnumverts],
                                              poly.verts[i],
                                              poly.verts[(i + 1) % lnumverts]))
                    {
                        Int32 j;
                        for (j = i + 1; j < lnumverts; ++j)
                        {
                            //int k;
                            for (var k = 0; k < ModelDef.VERTEXSIZE; ++k)
                            {
                                poly.verts[j - 1][k] = poly.verts[j][k];
                            }
                        }
                        --lnumverts;
                        ++_ColinElim;
                        // retry next vertex next time, which is now current vertex
                        --i;
                    }
                }
            }
            poly.numverts = lnumverts;
        }
		/*
		public static Gdk.Pixbuf CreatePixbuf (Surface s)
		{
			
			IntPtr result = f_pixbuf_from_cairo_surface (s.Handle);
			return (Gdk.Pixbuf) GLib.Object.GetObject (result, true);
		}
		*/

		public static Gdk.Pixbuf CreatePixbuf (MemorySurface mem)
		{
			IntPtr result = f_pixbuf_from_cairo_surface (mem.Handle);
			return (Gdk.Pixbuf) GLib.Object.GetObject (result, true);
		}
Beispiel #22
0
        /// <summary>
        /// R_BuildLightMap
        /// Combine and scale multiple lightmaps into the 8.8 format in blocklights
        /// </summary>
        private void BuildLightMap(MemorySurface surf, ByteArraySegment dest, Int32 stride)
        {
            surf.cached_dlight = (surf.dlightframe == _FrameCount);

            var smax = (surf.extents[0] >> 4) + 1;
            var tmax = (surf.extents[1] >> 4) + 1;
            var size = smax * tmax;

            var srcOffset = surf.sampleofs;
            var lightmap  = surf.sample_base;           // surf.samples;

            // set to full bright if no light data
            if (Host.Cvars.FullBright.Get <Boolean>( ) || Host.Client.cl.worldmodel.LightData == null)
            {
                for (var i = 0; i < size; i++)
                {
                    _BlockLights[i] = 255 * 256;
                }
            }
            else
            {
                // clear to no light
                for (var i = 0; i < size; i++)
                {
                    _BlockLights[i] = 0;
                }

                // add all the lightmaps
                if (lightmap != null)
                {
                    for (var maps = 0; maps < BspDef.MAXLIGHTMAPS && surf.styles[maps] != 255; maps++)
                    {
                        var scale = _LightStyleValue[surf.styles[maps]];
                        surf.cached_light[maps] = scale;                            // 8.8 fraction
                        for (var i = 0; i < size; i++)
                        {
                            _BlockLights[i] += ( UInt32 )(lightmap[srcOffset + i] * scale);
                        }
                        srcOffset += size;                         // lightmap += size;	// skip to next lightmap
                    }
                }

                // add all the dynamic lights
                if (surf.dlightframe == _FrameCount)
                {
                    AddDynamicLights(surf);
                }
            }
            // bound, invert, and shift
            //store:
            var blOffset   = 0;
            var destOffset = dest.StartIndex;
            var data       = dest.Data;

            switch (Host.DrawingContext.LightMapFormat)
            {
            case "GL_RGBA":
                stride -= (smax << 2);
                for (var i = 0; i < tmax; i++, destOffset += stride)                           // dest += stride
                {
                    for (var j = 0; j < smax; j++)
                    {
                        var t = _BlockLights[blOffset++];                                // *bl++;
                        t >>= 7;
                        if (t > 255)
                        {
                            t = 255;
                        }
                        data[destOffset + 3] = ( Byte )(255 - t);                                    //dest[3] = 255 - t;
                        destOffset          += 4;
                    }
                }
                break;

            case "GL_ALPHA":
            case "GL_LUMINANCE":
                //case GL_INTENSITY:
                for (var i = 0; i < tmax; i++, destOffset += stride)
                {
                    for (var j = 0; j < smax; j++)
                    {
                        var t = _BlockLights[blOffset++];                                // *bl++;
                        t >>= 7;
                        if (t > 255)
                        {
                            t = 255;
                        }
                        data[destOffset + j] = ( Byte )(255 - t);                                    // dest[j] = 255 - t;
                    }
                }
                break;

            default:
                Utilities.Error("Bad lightmap format");
                break;
            }
        }
Beispiel #23
0
        /// <summary>
        /// R_AddDynamicLights
        /// </summary>
        private void AddDynamicLights(MemorySurface surf)
        {
            var smax    = (surf.extents[0] >> 4) + 1;
            var tmax    = (surf.extents[1] >> 4) + 1;
            var tex     = surf.texinfo;
            var dlights = Host.Client.DLights;

            for (var lnum = 0; lnum < ClientDef.MAX_DLIGHTS; lnum++)
            {
                if ((surf.dlightbits & (1 << lnum)) == 0)
                {
                    continue;                           // not lit by this light
                }
                var rad  = dlights[lnum].radius;
                var dist = Vector3.Dot(dlights[lnum].origin, surf.plane.normal) - surf.plane.dist;
                rad -= Math.Abs(dist);
                var minlight = dlights[lnum].minlight;
                if (rad < minlight)
                {
                    continue;
                }
                minlight = rad - minlight;

                var impact = dlights[lnum].origin - surf.plane.normal * dist;

                var local0 = Vector3.Dot(impact, tex.vecs[0].Xyz) + tex.vecs[0].W;
                var local1 = Vector3.Dot(impact, tex.vecs[1].Xyz) + tex.vecs[1].W;

                local0 -= surf.texturemins[0];
                local1 -= surf.texturemins[1];

                for (var t = 0; t < tmax; t++)
                {
                    var td = ( Int32 )(local1 - t * 16);
                    if (td < 0)
                    {
                        td = -td;
                    }
                    for (var s = 0; s < smax; s++)
                    {
                        var sd = ( Int32 )(local0 - s * 16);
                        if (sd < 0)
                        {
                            sd = -sd;
                        }
                        if (sd > td)
                        {
                            dist = sd + (td >> 1);
                        }
                        else
                        {
                            dist = td + (sd >> 1);
                        }
                        if (dist < minlight)
                        {
                            _BlockLights[t * smax + s] += ( UInt32 )((rad - dist) * 256);
                        }
                    }
                }
            }
        }
Beispiel #24
0
        /// <summary>
        /// R_DrawSequentialPoly
        /// Systems that have fast state and texture changes can
        /// just do everything as it passes with no need to sort
        /// </summary>
        private void DrawSequentialPoly(MemorySurface s)
        {
            //
            // normal lightmaped poly
            //
            if ((s.flags & (( Int32 )Q1SurfaceFlags.Sky | ( Int32 )Q1SurfaceFlags.Turbulence | ( Int32 )Q1SurfaceFlags.Underwater)) == 0)
            {
                RenderDynamicLightmaps(s);
                var p = s.polys;
                var t = TextureAnimation(s.texinfo.texture);
                if (Host.Video.Device.Desc.SupportsMultiTexture)
                {
                    Host.Video.Device.Graphics.DrawSequentialPolyMultiTexture(t.texture, LightMapTexture, _LightMaps, p, s.lightmaptexturenum);
                    return;
                }
                else
                {
                    Host.Video.Device.Graphics.DrawSequentialPoly(t.texture, LightMapTexture, p, s.lightmaptexturenum);
                }

                return;
            }

            //
            // subdivided water surface warp
            //

            if ((s.flags & ( Int32 )Q1SurfaceFlags.Turbulence) != 0)
            {
                Host.Video.Device.DisableMultitexture( );
                s.texinfo.texture.texture.Bind( );
                WarpableTextures.EmitWaterPolys(Host.RealTime, s);
                return;
            }

            //
            // subdivided sky warp
            //
            if ((s.flags & ( Int32 )Q1SurfaceFlags.Sky) != 0)
            {
                WarpableTextures.EmitBothSkyLayers(Host.RealTime, Host.RenderContext.Origin, s);
                return;
            }

            //
            // underwater warped with lightmap
            //
            RenderDynamicLightmaps(s);
            if (Host.Video.Device.Desc.SupportsMultiTexture)
            {
                var t = TextureAnimation(s.texinfo.texture);

                Host.DrawingContext.SelectTexture(MTexTarget.TEXTURE0_SGIS);

                Host.Video.Device.Graphics.DrawWaterPolyMultiTexture(_LightMaps, t.texture, LightMapTexture, s.lightmaptexturenum, s.polys, Host.RealTime);
            }
            else
            {
                var p = s.polys;

                var t = TextureAnimation(s.texinfo.texture);
                t.texture.Bind( );
                Host.Video.Device.Graphics.DrawWaterPoly(p, Host.RealTime);

                LightMapTexture.BindLightmap((( GLTextureDesc )LightMapTexture.Desc).TextureNumber + s.lightmaptexturenum);
                Host.Video.Device.Graphics.DrawWaterPolyLightmap(p, Host.RealTime, true);
            }
        }
        /*
         * public static Gdk.Pixbuf CreatePixbuf (Surface s)
         * {
         *
         *      IntPtr result = f_pixbuf_from_cairo_surface (s.Handle);
         *      return (Gdk.Pixbuf) GLib.Object.GetObject (result, true);
         * }
         */

        public static Gdk.Pixbuf CreatePixbuf(MemorySurface mem)
        {
            IntPtr result = f_pixbuf_from_cairo_surface(mem.Handle);

            return((Gdk.Pixbuf)GLib.Object.GetObject(result, true));
        }
Beispiel #26
0
 private void SetPixbuf(Pixbuf pixbuf)
 {
     Surface       = MemorySurface.CreateSurface(pixbuf);
     Bounds.Width  = pixbuf.Width;
     Bounds.Height = pixbuf.Height;
 }