예제 #1
0
        private static string BuildSurfaceFlagsTags(SurfaceFlags flags)
        {
            var tags = new StringBuilder();

            for (int j = 0; j < 32; j++)
            {
                var flag    = ( SurfaceFlags )(1u << j);
                var hasFlag = flags.HasFlagFast(flag);

                if (hasFlag)
                {
                    if (!sTags.TryGetValue(flag, out var tag))
                    {
                        tag = $"B{j}";
                    }

                    tags.Append($"@{tag}");
                }
                else
                {
                    if (flag == SurfaceFlags.Visible)
                    {
                        tags.Append("@H");
                    }
                }
            }

            return(tags.ToString());
        }
예제 #2
0
 private void Read(EndianBinaryReader reader)
 {
     Bounds   = reader.ReadBoundingSphere();
     RootNode = reader.ReadObjectOffset <Node>();
     Field14  = reader.ReadInt32();
     Field18  = reader.ReadInt32();
     Flags    = ( SurfaceFlags )reader.ReadInt32();
 }
예제 #3
0
 void ISerializableObject.Read(EndianBinaryReader reader, object context)
 {
     Bounds   = reader.ReadBoundingSphere();
     Field10  = reader.ReadInt32();
     Field14  = reader.ReadInt32();
     RootNode = reader.ReadObjectOffset <Node>(new NodeReadContext(GeometryFormat.BasicDX));
     Field1C  = reader.ReadInt32();
     Flags    = ( SurfaceFlags )reader.ReadInt32();
 }
예제 #4
0
        public Surface(Device gbmDev, int width, int height, SurfaceFlags flags, SurfaceFormat format = SurfaceFormat.ARGB8888)
        {
            handle = gbm_surface_create(gbmDev.handle, width, height, format, flags);

            if (handle == IntPtr.Zero)
            {
                throw new NotSupportedException("[GBM] Failed to create GBM surface");
            }
        }
예제 #5
0
파일: Surface.cs 프로젝트: XionWin/THeGuID
        public Surface(Device gbmDev, uint width, uint height, SurfaceFormat format, SurfaceFlags flags)
        {
            this.Device        = gbmDev;
            this.surfaceHandle = gbm_surface_create(gbmDev.Handle, width, height, format, flags);

            if (this.surfaceHandle == null)
            {
                throw new NotSupportedException("[GBM] Failed to create GBM surface");
            }
        }
예제 #6
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="rs"></param>
		/// <param name="maxTextures"></param>
		internal MaterialInstance ( RenderSystem rs, ContentManager content, MaterialData parameters, IEnumerable<TextureMapBind> textureBinds, SurfaceFlags surfaceFlags )
		{
			if (rs==null) {
				throw new ArgumentNullException("rs");
			}

			if (textureBinds.Count()<0 || textureBinds.Count()>MaxTextures) {
				throw new ArgumentException("textureCount", "Must be less or equal to " + MaxTextures.ToString() );
			}


			//
			//	Pipeline states :
			//
			var factory	=	rs.SceneRenderer.Factory;

			var gbufferRigid	=	SurfaceFlags.GBUFFER | SurfaceFlags.RIGID	| surfaceFlags ;
			var gbufferSkinned	=	SurfaceFlags.GBUFFER | SurfaceFlags.SKINNED | surfaceFlags ;
			var shadowRigid		=	SurfaceFlags.SHADOW  | SurfaceFlags.RIGID	| surfaceFlags ;
			var shadowSkinned	=	SurfaceFlags.SHADOW  | SurfaceFlags.SKINNED | surfaceFlags ;

			GBufferRigid	=	factory[ (int)gbufferRigid ];
			GBufferSkinned	=	factory[ (int)gbufferSkinned ];

			ShadowRigid		=	factory[ (int)shadowRigid ];
			ShadowSkinned	=	factory[ (int)shadowSkinned ];


			//
			//	Textures :
			//
			var textures = textureBinds
				.Select( texBind => texBind.TextureMap.LoadTexture( content, texBind.FallbackPath ) );

			var uvMods = new Vector4[MaxTextures];

			textureBinds
				.Select( tb => tb.TextureMap )
				.Select( tm => new Vector4( tm.ScaleU, tm.ScaleV, tm.OffsetU, tm.OffsetV ) )
				.ToArray()
				.CopyTo( uvMods, 0 );

			shaderResources		=	textures.Select( tex => tex.Srv ).ToArray();

			//
			//	Constants :
			//
			constBufferParams	=	new ConstantBuffer( rs.Device, typeof(MaterialData) );
			constBufferParams.SetData( parameters );

			constBufferUVMods	=	new ConstantBuffer( rs.Device, typeof(Vector4), MaxTextures );
			constBufferUVMods.SetData( uvMods );
		}
예제 #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="material"></param>
        /// <param name="flags"></param>
        /// <returns></returns>
        SurfaceFlags ApplyFlags(MeshInstance instance, SurfaceFlags flags)
        {
            if (instance.IsSkinned)
            {
                flags |= SurfaceFlags.SKINNED;
            }
            else
            {
                flags |= SurfaceFlags.RIGID;
            }

            return(flags);
        }
예제 #8
0
            public short AllocateSurfaceFlags(int flags)
            {
                var index = Convert.ToInt16(coct.SurfaceFlagsList.Count);

                var ent7 = new SurfaceFlags
                {
                    Flags = flags,
                };

                coct.SurfaceFlagsList.Add(ent7);

                return(index);
            }
예제 #9
0
 public Surface(BinaryReader reader, bool simple = false)
 {
     if (!simple) {
         Material = reader.ReadByte();
         Flags = (SurfaceFlags) reader.ReadByte();
         Brightness = reader.ReadByte();
         Light = reader.ReadByte();
     } else {
         Material = reader.ReadByte();
         Flags = SurfaceFlags.None;
         Brightness = 0;
         Light = reader.ReadByte();
     }
 }
예제 #10
0
 public Surface(BinaryReader reader, bool simple = false)
 {
     if (!simple)
     {
         Material   = reader.ReadByte();
         Flags      = (SurfaceFlags)reader.ReadByte();
         Brightness = reader.ReadByte();
         Light      = reader.ReadByte();
     }
     else
     {
         Material   = reader.ReadByte();
         Flags      = SurfaceFlags.None;
         Brightness = 0;
         Light      = reader.ReadByte();
     }
 }
예제 #11
0
파일: Coct.cs 프로젝트: tadanokojin/OpenKh
            public short AllocateSurfaceFlags(int flags)
            {
                var index = coct.SurfaceFlagsList.FindIndex(it => it.Flags == flags);

                if (index < 0)
                {
                    index = coct.SurfaceFlagsList.Count;

                    var ent7 = new SurfaceFlags
                    {
                        Flags = flags,
                    };
                    coct.SurfaceFlagsList.Add(ent7);
                }

                return(Convert.ToInt16(index));
            }
예제 #12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ps"></param>
        /// <param name="flags"></param>
        void Enum(PipelineState ps, SurfaceFlags flags)
        {
            ps.RasterizerState = RasterizerState.CullCW;

            if (flags.HasFlag(SurfaceFlags.SKINNED))
            {
                ps.VertexInputElements = VertexColorTextureTBNSkinned.Elements;
            }

            if (flags.HasFlag(SurfaceFlags.RIGID))
            {
                ps.VertexInputElements = VertexColorTextureTBNRigid.Elements;
            }

            if (flags.HasFlag(SurfaceFlags.SHADOW))
            {
                ps.RasterizerState = RasterizerState.CullNone;
            }
        }
예제 #13
0
        static BufferObject CreateCursor(IntPtr gbm, MouseCursor cursor)
        {
            if (cursor.Width > 64 || cursor.Height > 64)
            {
                Debug.Print("[KMS] Cursor size {0}x{1} unsupported. Maximum is 64x64.",
                            cursor.Width, cursor.Height);
                return(default(BufferObject));
            }

            int           width  = 64;
            int           height = 64;
            SurfaceFormat format = SurfaceFormat.ARGB8888;
            SurfaceFlags  usage  = SurfaceFlags.Cursor64x64 | SurfaceFlags.Write;

            Debug.Print("[KMS] Gbm.CreateBuffer({0:X}, {1}, {2}, {3}, {4}).",
                        gbm, width, height, format, usage);

            BufferObject bo = Gbm.CreateBuffer(
                gbm, width, height, format, usage);

            if (bo == BufferObject.Zero)
            {
                Debug.Print("[KMS] Failed to create buffer.");
                return(bo);
            }

            // Copy cursor.Data into a new buffer of the correct size
            byte[] cursor_data = new byte[width * height * 4];
            for (int y = 0; y < cursor.Height; y++)
            {
                int dst_offset = y * width * 4;
                int src_offset = y * cursor.Width * 4;
                int src_length = cursor.Width * 4;
                Array.Copy(
                    cursor.Data, src_offset,
                    cursor_data, dst_offset,
                    src_length);
            }
            bo.Write(cursor_data);

            return(bo);
        }
        static BrushMesh.Polygon[] CreateBoxPolygons(SurfaceLayers layers, SurfaceFlags surfaceFlags)
        {
            return(new[]
            {
                // left/right
                new BrushMesh.Polygon {
                    surfaceID = 0, firstEdge = 0, edgeCount = 4, description = new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    }, layers = layers
                },
                new BrushMesh.Polygon {
                    surfaceID = 1, firstEdge = 4, edgeCount = 4, description = new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    }, layers = layers
                },

                // front/back
                new BrushMesh.Polygon {
                    surfaceID = 2, firstEdge = 8, edgeCount = 4, description = new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    }, layers = layers
                },
                new BrushMesh.Polygon {
                    surfaceID = 3, firstEdge = 12, edgeCount = 4, description = new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    }, layers = layers
                },

                // top/down
                new BrushMesh.Polygon {
                    surfaceID = 4, firstEdge = 16, edgeCount = 4, description = new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    }, layers = layers
                },
                new BrushMesh.Polygon {
                    surfaceID = 5, firstEdge = 20, edgeCount = 4, description = new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    }, layers = layers
                }
            });
        }
예제 #15
0
파일: Surface.cs 프로젝트: XionWin/THeGuID
 static extern gbm_surface *gbm_surface_create(gbm_device *deviceHandle, uint width, uint height, SurfaceFormat format, SurfaceFlags flags);
예제 #16
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="material"></param>
		/// <param name="flags"></param>
		/// <returns></returns>
		SurfaceFlags ApplyFlags ( MaterialInstance material, MeshInstance instance, SurfaceFlags flags )
		{
			//if (material!=null) {
			//	switch ( material.Options ) {
			//		case MaterialOptions.SingleLayer : flags |= SurfaceFlags.LAYER0; break;	
			//		case MaterialOptions.DoubleLayer : flags |= SurfaceFlags.LAYER0|SurfaceFlags.LAYER1; break;
			//		case MaterialOptions.TripleLayer : flags |= SurfaceFlags.LAYER0|SurfaceFlags.LAYER1|SurfaceFlags.LAYER2; break;
			//		case MaterialOptions.QuadLayer	 : flags |= SurfaceFlags.LAYER0|SurfaceFlags.LAYER1|SurfaceFlags.LAYER2|SurfaceFlags.LAYER3; break;

			//		case MaterialOptions.Terrain : flags |= SurfaceFlags.TERRAIN; break;

			//		case MaterialOptions.TriplanarWorldSingle : flags |= SurfaceFlags.TRIPLANAR_SINGLE; break;
			//		case MaterialOptions.TriplanarWorldDouble : flags |= SurfaceFlags.TRIPLANAR_DOUBLE; break;
			//		case MaterialOptions.TriplanarWorldTriple : flags |= SurfaceFlags.TRIPLANAR_TRIPLE; break;
			//	}
			//}

			if (instance.IsSkinned) {
				flags |= SurfaceFlags.SKINNED;
			} else {
				flags |= SurfaceFlags.RIGID;
			}

			return flags;
		}
예제 #17
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="ps"></param>
		/// <param name="flags"></param>
		void Enum ( PipelineState ps, SurfaceFlags flags )
		{
			ps.RasterizerState	=	RasterizerState.CullCW;

			if (flags.HasFlag( SurfaceFlags.SKINNED )) {
				ps.VertexInputElements	=	VertexColorTextureTBNSkinned.Elements;
			}
			
			if (flags.HasFlag( SurfaceFlags.RIGID )) {
				ps.VertexInputElements	=	VertexColorTextureTBNRigid.Elements;
			}

			if (flags.HasFlag( SurfaceFlags.VOXELIZE )) {
				ps.RasterizerState		=	RasterizerState.CullNone;
				ps.DepthStencilState	=	DepthStencilState.None;
			}
		}
예제 #18
0
		public MaterialInfoParameter(string name, bool clearSolid, SurfaceFlags surfaceFlags, ContentFlags contentFlags)
		{
			Name = name;
			ClearSolid = clearSolid;
			SurfaceFlags = surfaceFlags;
			ContentFlags = contentFlags;
		}
예제 #19
0
        /// <summary>
        /// Creates a cube <see cref="RealtimeCSG.Foundation.BrushMesh"/> with bounds defined by <paramref name="min"/> and <paramref name="max"/>, its <paramref name="layers"/> and optional <paramref name="surfaceFlags"/>
        /// </summary>
        /// <remarks><note>These methods are a work in progress and may change somewhat over time</note></remarks>
        /// <param name="min">The corner of the cube with the smallest x,y,z values</param>
        /// <param name="max">The corner of the cube with the largest x,y,z values</param>
        /// <param name="layers">The <see cref="RealtimeCSG.Foundation.SurfaceLayers"/> that define how the surfaces of this cube are rendered or if they need to be part of a collider etc.</param>
        /// <param name="surfaceFlags">Optional flags that modify surface behavior.</param>
        /// <returns>A <see cref="RealtimeCSG.Foundation.BrushMesh"/> on success, null on failure</returns>
        public static BrushMesh CreateCube(UnityEngine.Vector3 min, UnityEngine.Vector3 max, SurfaceLayers layers, SurfaceFlags surfaceFlags = SurfaceFlags.None)
        {
            if (min.x == max.x || min.y == max.y || min.z == max.z)
            {
                return(null);
            }

            if (min.x > max.x)
            {
                float x = min.x; min.x = max.x; max.x = x;
            }
            if (min.y > max.y)
            {
                float y = min.y; min.y = max.y; max.y = y;
            }
            if (min.z > max.z)
            {
                float z = min.z; min.z = max.z; max.z = z;
            }

            var surfaceMatrices = new[]
            {
                // left/right
                new UVMatrix {
                    U = new Vector4(-1, 0, 0, -min.x), V = new Vector4(0, 1, 0, min.y)
                },
                new UVMatrix {
                    U = new Vector4(1, 0, 0, min.x), V = new Vector4(0, 1, 0, min.y)
                },

                // front/back
                new UVMatrix {
                    U = new Vector4(0, 0, 1, min.z), V = new Vector4(0, 1, 0, min.y)
                },
                new UVMatrix {
                    U = new Vector4(0, 0, -1, -min.z), V = new Vector4(0, 1, 0, min.y)
                },

                // top/down
                new UVMatrix {
                    U = new Vector4(-1, 0, 0, -min.x), V = new Vector4(0, 0, -1, -min.z)
                },
                new UVMatrix {
                    U = new Vector4(1, 0, 0, min.x), V = new Vector4(0, 0, -1, -min.z)
                },
            };

            return(new BrushMesh
            {
                polygons = new[]
                {
                    // left/right
                    new BrushMesh.Polygon {
                        polygonID = 0, firstEdge = 0, edgeCount = 4, surface = new SurfaceDescription {
                            UV0 = surfaceMatrices[0], surfaceFlags = surfaceFlags, smoothingGroup = 0
                        }, layers = layers
                    },
                    new BrushMesh.Polygon {
                        polygonID = 1, firstEdge = 4, edgeCount = 4, surface = new SurfaceDescription {
                            UV0 = surfaceMatrices[1], surfaceFlags = surfaceFlags, smoothingGroup = 0
                        }, layers = layers
                    },

                    // front/back
                    new BrushMesh.Polygon {
                        polygonID = 2, firstEdge = 8, edgeCount = 4, surface = new SurfaceDescription {
                            UV0 = surfaceMatrices[2], surfaceFlags = surfaceFlags, smoothingGroup = 0
                        }, layers = layers
                    },
                    new BrushMesh.Polygon {
                        polygonID = 3, firstEdge = 12, edgeCount = 4, surface = new SurfaceDescription {
                            UV0 = surfaceMatrices[3], surfaceFlags = surfaceFlags, smoothingGroup = 0
                        }, layers = layers
                    },

                    // top/down
                    new BrushMesh.Polygon {
                        polygonID = 4, firstEdge = 16, edgeCount = 4, surface = new SurfaceDescription {
                            UV0 = surfaceMatrices[4], surfaceFlags = surfaceFlags, smoothingGroup = 0
                        }, layers = layers
                    },
                    new BrushMesh.Polygon {
                        polygonID = 5, firstEdge = 20, edgeCount = 4, surface = new SurfaceDescription {
                            UV0 = surfaceMatrices[5], surfaceFlags = surfaceFlags, smoothingGroup = 0
                        }, layers = layers
                    }
                },

                halfEdges = new[]
                {
                    // polygon 0
                    new BrushMesh.HalfEdge {
                        twinIndex = 17, vertexIndex = 0
                    },                                                                                  //  0
                    new BrushMesh.HalfEdge {
                        twinIndex = 8, vertexIndex = 1
                    },                                                                                  //  1
                    new BrushMesh.HalfEdge {
                        twinIndex = 20, vertexIndex = 2
                    },                                                                                  //  2
                    new BrushMesh.HalfEdge {
                        twinIndex = 13, vertexIndex = 3
                    },                                                                                  //  3

                    // polygon 1
                    new BrushMesh.HalfEdge {
                        twinIndex = 10, vertexIndex = 4
                    },                                                                                  //  4
                    new BrushMesh.HalfEdge {
                        twinIndex = 19, vertexIndex = 5
                    },                                                                                  //  5
                    new BrushMesh.HalfEdge {
                        twinIndex = 15, vertexIndex = 6
                    },                                                                                  //  6
                    new BrushMesh.HalfEdge {
                        twinIndex = 22, vertexIndex = 7
                    },                                                                                  //  7

                    // polygon 2
                    new BrushMesh.HalfEdge {
                        twinIndex = 1, vertexIndex = 0
                    },                                                                                  //  8
                    new BrushMesh.HalfEdge {
                        twinIndex = 16, vertexIndex = 4
                    },                                                                                  //  9
                    new BrushMesh.HalfEdge {
                        twinIndex = 4, vertexIndex = 7
                    },                                                                                  // 10
                    new BrushMesh.HalfEdge {
                        twinIndex = 21, vertexIndex = 1
                    },                                                                                  // 11

                    // polygon 3
                    new BrushMesh.HalfEdge {
                        twinIndex = 18, vertexIndex = 3
                    },                                                                                  // 16
                    new BrushMesh.HalfEdge {
                        twinIndex = 3, vertexIndex = 2
                    },                                                                                  // 17
                    new BrushMesh.HalfEdge {
                        twinIndex = 23, vertexIndex = 6
                    },                                                                                  // 18
                    new BrushMesh.HalfEdge {
                        twinIndex = 6, vertexIndex = 5
                    },                                                                                  // 19

                    // polygon 4
                    new BrushMesh.HalfEdge {
                        twinIndex = 9, vertexIndex = 0
                    },                                                                                  // 20
                    new BrushMesh.HalfEdge {
                        twinIndex = 0, vertexIndex = 3
                    },                                                                                  // 21
                    new BrushMesh.HalfEdge {
                        twinIndex = 12, vertexIndex = 5
                    },                                                                                  // 22
                    new BrushMesh.HalfEdge {
                        twinIndex = 5, vertexIndex = 4
                    },                                                                                  // 23

                    // polygon 5
                    new BrushMesh.HalfEdge {
                        twinIndex = 2, vertexIndex = 1
                    },                                                                                  // 12
                    new BrushMesh.HalfEdge {
                        twinIndex = 11, vertexIndex = 7
                    },                                                                                  // 13
                    new BrushMesh.HalfEdge {
                        twinIndex = 7, vertexIndex = 6
                    },                                                                                  // 14
                    new BrushMesh.HalfEdge {
                        twinIndex = 14, vertexIndex = 2
                    }                                                                                   // 15
                },

                vertices = new[]
                {
                    new Vector3(min.x, min.y, min.z),                      // 0
                    new Vector3(min.x, max.y, min.z),                      // 1
                    new Vector3(max.x, max.y, min.z),                      // 2
                    new Vector3(max.x, min.y, min.z),                      // 3

                    new Vector3(min.x, min.y, max.z),                      // 4
                    new Vector3(max.x, min.y, max.z),                      // 5
                    new Vector3(max.x, max.y, max.z),                      // 6
                    new Vector3(min.x, max.y, max.z)                       // 7
                }
            });
        }
예제 #20
0
        public static BrushMesh CreateSphere(Vector3 diameterXYZ, float offsetY, bool generateFromCenter, int horzSegments, int vertSegments, SurfaceLayers layers = default, SurfaceFlags surfaceFlags = SurfaceFlags.None)
        {
            var lastVertSegment = vertSegments - 1;

            var triangleCount = horzSegments + horzSegments;      // top & bottom
            var quadCount     = horzSegments * (vertSegments - 2);
            int polygonCount  = triangleCount + quadCount;
            int halfEdgeCount = (triangleCount * 3) + (quadCount * 4);

            Vector3[] vertices = null;
            CreateSphereVertices(diameterXYZ, offsetY, generateFromCenter, horzSegments, vertSegments, ref vertices);

            var polygons  = new Polygon[polygonCount];
            var halfEdges = new HalfEdge[halfEdgeCount];

            var edgeIndex    = 0;
            var polygonIndex = 0;
            var startVertex  = 2;

            for (int v = 0; v < vertSegments; v++)
            {
                var startEdge = edgeIndex;
                for (int h = 0, p = horzSegments - 1; h < horzSegments; p = h, h++)
                {
                    var n = (h + 1) % horzSegments;
                    int polygonEdgeCount;
                    if (v == 0) // top
                    {
                        //          0
                        //          *
                        //         ^ \
                        //     p1 /0 1\ n0
                        //       /  2  v
                        //		*<------*
                        //     2    t    1
                        polygonEdgeCount = 3;
                        var p1 = (p * 3) + 1;
                        var n0 = (n * 3) + 0;
                        var t  = ((vertSegments == 2) ? (startEdge + (horzSegments * 3) + (h * 3) + 1) : (startEdge + (horzSegments * 3) + (h * 4) + 1));
                        halfEdges[edgeIndex + 0] = new HalfEdge {
                            twinIndex = p1, vertexIndex = 0
                        };
                        halfEdges[edgeIndex + 1] = new HalfEdge {
                            twinIndex = n0, vertexIndex = startVertex + (horzSegments - 1) - h
                        };
                        halfEdges[edgeIndex + 2] = new HalfEdge {
                            twinIndex = t, vertexIndex = startVertex + (horzSegments - 1) - p
                        };
                    }
                    else
                    if (v == lastVertSegment)
                    {
                        //     0    t    1
                        //		*------>*
                        //       ^  1  /
                        //     p1 \0 2/ n0
                        //         \ v
                        //          *
                        //          2
                        polygonEdgeCount = 3;
                        var p2 = startEdge + (p * 3) + 2;
                        var n0 = startEdge + (n * 3) + 0;
                        var t  = ((vertSegments == 2) ? (startEdge - (horzSegments * 3) + (h * 3) + 2) : (startEdge - (horzSegments * 4) + (h * 4) + 3));
                        halfEdges[edgeIndex + 0] = new HalfEdge {
                            twinIndex = p2, vertexIndex = startVertex + (horzSegments - 1) - p
                        };
                        halfEdges[edgeIndex + 1] = new HalfEdge {
                            twinIndex = t, vertexIndex = startVertex + (horzSegments - 1) - h
                        };
                        halfEdges[edgeIndex + 2] = new HalfEdge {
                            twinIndex = n0, vertexIndex = 1
                        };
                    }
                    else
                    {
                        //     0    t3   1
                        //		*------>*
                        //      ^   1   |
                        //   p1 |0     2| n0
                        //      |   3   v
                        //		*<------*
                        //     3    t1   2
                        polygonEdgeCount = 4;
                        var p1 = startEdge + (p * 4) + 2;
                        var n0 = startEdge + (n * 4) + 0;
                        var t3 = ((v == 1) ? (startEdge - (horzSegments * 3) + (h * 3) + 2) : (startEdge - (horzSegments * 4) + (h * 4) + 3));
                        var t1 = ((v == lastVertSegment - 1) ? (startEdge + (horzSegments * 4) + (h * 3) + 1) : (startEdge + (horzSegments * 4) + (h * 4) + 1));
                        halfEdges[edgeIndex + 0] = new HalfEdge {
                            twinIndex = p1, vertexIndex = startVertex + (horzSegments - 1) - p
                        };
                        halfEdges[edgeIndex + 1] = new HalfEdge {
                            twinIndex = t3, vertexIndex = startVertex + (horzSegments - 1) - h
                        };
                        halfEdges[edgeIndex + 2] = new HalfEdge {
                            twinIndex = n0, vertexIndex = startVertex + (horzSegments - 1) - h + horzSegments
                        };
                        halfEdges[edgeIndex + 3] = new HalfEdge {
                            twinIndex = t1, vertexIndex = startVertex + (horzSegments - 1) - p + horzSegments
                        };
                    }

                    polygons[polygonIndex] = new Polygon
                    {
                        surfaceID   = polygonIndex,
                        firstEdge   = edgeIndex,
                        edgeCount   = polygonEdgeCount,
                        description = new SurfaceDescription {
                            UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                        },
                        layers = layers
                    };

                    edgeIndex += polygonEdgeCount;
                    polygonIndex++;
                }
                if (v > 0)
                {
                    startVertex += horzSegments;
                }
            }

            return(new BrushMesh
            {
                polygons = polygons,
                halfEdges = halfEdges,
                vertices = vertices
            });
        }
예제 #21
0
 static extern IntPtr gbm_surface_create(IntPtr gbm, int width, int height, SurfaceFormat format, SurfaceFlags flags);
 public static extern BufferObject CreateBuffer(Device gbm, int width, int height, SurfaceFormat format,
                                                SurfaceFlags flags);
예제 #23
0
 public static CSGBrushMeshAsset CreateBoxAsset(UnityEngine.Vector3 min, UnityEngine.Vector3 max, CSGSurfaceAsset surfaceAsset, SurfaceFlags surfaceFlags = SurfaceFlags.None)
 {
     return(CreateBoxAsset(min, max, new CSGSurfaceAsset[] { surfaceAsset, surfaceAsset, surfaceAsset, surfaceAsset, surfaceAsset, surfaceAsset }, surfaceFlags));
 }
        public static BrushMesh CreateBox(UnityEngine.Vector3 min, UnityEngine.Vector3 max, SurfaceLayers layers, SurfaceFlags surfaceFlags = SurfaceFlags.None)
        {
            if (!BoundsExtensions.IsValid(min, max))
            {
                return(null);
            }

            if (min.x > max.x)
            {
                float x = min.x; min.x = max.x; max.x = x;
            }
            if (min.y > max.y)
            {
                float y = min.y; min.y = max.y; max.y = y;
            }
            if (min.z > max.z)
            {
                float z = min.z; min.z = max.z; max.z = z;
            }

            return(new BrushMesh
            {
                polygons = CreateBoxPolygons(layers, surfaceFlags),
                halfEdges = boxHalfEdges.ToArray(),
                vertices = CreateBoxVertices(min, max)
            });
        }
예제 #25
0
		/// <summary>
		/// Parses the material, if there are any errors during parsing the defaultShader will be set.
		/// </summary>
		/// <param name="lexer"></param>
		private void ParseMaterial(idLexer lexer)
		{
			_registerCount = PredefinedRegisterCount; // leave space for the parms to be copied in.

			for(int i = 0; i < _registerCount; i++)
			{
				_parsingData.RegisterIsTemporary[i] = true; // they aren't constants that can be folded.
			}

			TextureRepeat textureRepeatDefault = TextureRepeat.Repeat; // allow a global setting for repeat.
			idToken token = null;

			string tokenValue;
			string tokenLower;
			int count;

			while(true)
			{
				if(TestMaterialFlag(Renderer.MaterialFlags.Defaulted) == true)
				{
					// we have a parse error.
					return;
				}

				if((token = lexer.ExpectAnyToken()) == null)
				{
					this.MaterialFlag = MaterialFlags.Defaulted;
					return;
				}

				tokenValue = token.ToString();
				tokenLower = tokenValue.ToLower();

				// end of material definition
				if(tokenLower == "}")
				{
					break;
				}
				else if(tokenLower == "qer_editorimage")
				{
					token = lexer.ReadTokenOnLine();
					_editorImageName = (token != null) ? token.ToString() : string.Empty;

					lexer.SkipRestOfLine();
				}
				else if(tokenLower == "description")
				{
					token = lexer.ReadTokenOnLine();
					_description = (token != null) ? token.ToString() : string.Empty;
				}
				// check for the surface / content bit flags.
				else if(CheckSurfaceParameter(token) == true)
				{

				}
				else if(tokenLower == "polygonoffset")
				{
					this.MaterialFlag = Renderer.MaterialFlags.PolygonOffset;

					if((token = lexer.ReadTokenOnLine()) == null)
					{
						_polygonOffset = 1;
					}
					else
					{
						_polygonOffset = token.ToFloat();
					}
				}
				// noshadow.
				else if(tokenLower == "noshadows")
				{
					this.MaterialFlag = MaterialFlags.NoShadows;
				}
				else if(tokenLower == "suppressinsubview")
				{
					_suppressInSubview = true;
				}
				else if(tokenLower == "portalsky")
				{
					_portalSky = true;
				}
				else if(tokenLower == "noselfshadow")
				{
					this.MaterialFlag = Renderer.MaterialFlags.NoSelfShadow;
				}
				else if(tokenLower == "noportalfog")
				{
					this.MaterialFlag = Renderer.MaterialFlags.NoPortalFog;
				}
				// forceShadows allows nodraw surfaces to cast shadows.
				else if(tokenLower == "forceshadows")
				{
					this.MaterialFlag = Renderer.MaterialFlags.ForceShadows;
				}
				// overlay / decal suppression.
				else if(tokenLower == "nooverlays")
				{
					_allowOverlays = false;
				}
				// moster blood overlay forcing for alpha tested or translucent surfaces.
				else if(tokenLower == "forceoverlays")
				{
					_parsingData.ForceOverlays = true;
				}
				else if(tokenLower == "translucent")
				{
					_coverage = MaterialCoverage.Translucent;
				}
				// global zero clamp.
				else if(tokenLower == "zeroclamp")
				{
					textureRepeatDefault = TextureRepeat.ClampToZero;
				}
				// global clamp.
				else if(tokenLower == "clamp")
				{
					textureRepeatDefault = TextureRepeat.Clamp;
				}
				// global clamp.
				else if(tokenLower == "alphazeroclamp")
				{
					textureRepeatDefault = TextureRepeat.ClampToZero;
				}
				// forceOpaque is used for skies-behind-windows.
				else if(tokenLower == "forceopaque")
				{
					_coverage = MaterialCoverage.Opaque;
				}
				else if(tokenLower == "twosided")
				{
					_cullType = CullType.TwoSided;

					// twoSided implies no-shadows, because the shadow
					// volume would be coplanar with the surface, giving depth fighting
					// we could make this no-self-shadows, but it may be more important
					// to receive shadows from no-self-shadow monsters.
					this.MaterialFlag = Renderer.MaterialFlags.NoShadows;
				}
				else if(tokenLower == "backsided")
				{
					_cullType = CullType.Back;

					// the shadow code doesn't handle this, so just disable shadows.
					// We could fix this in the future if there was a need.
					this.MaterialFlag = Renderer.MaterialFlags.NoShadows;
				}
				else if(tokenLower == "foglight")
				{
					_fogLight = true;
				}
				else if(tokenLower == "blendlight")
				{
					_blendLight = true;
				}
				else if(tokenLower == "ambientlight")
				{
					_ambientLight = true;
				}
				else if(tokenLower == "mirror")
				{
					_sort = (float) MaterialSort.Subview;
					_coverage = MaterialCoverage.Opaque;
				}
				else if(tokenLower == "nofog")
				{
					_noFog = true;
				}
				else if(tokenLower == "unsmoothedtangents")
				{
					_unsmoothedTangents = true;
				}
				// lightFallofImage <imageprogram>
				// specifies the image to use for the third axis of projected
				// light volumes.
				else if(tokenLower == "lightfalloffimage")
				{
					_lightFalloffImage = idE.ImageManager.ImageFromFile(ParsePastImageProgram(lexer), TextureFilter.Default, false, TextureRepeat.Clamp, TextureDepth.Default);
				}
				// guisurf <guifile> | guisurf entity
				// an entity guisurf must have an idUserInterface
				// specified in the renderEntity.
				else if(tokenLower == "guisurf")
				{
					token = lexer.ReadTokenOnLine();
					tokenLower = token.ToString().ToLower();

					if(tokenLower == "entity")
					{
						_entityGui = 1;
					}
					else if(tokenLower == "entity2")
					{
						_entityGui = 2;
					}
					else if(tokenLower == "entity3")
					{
						_entityGui = 3;
					}
					else
					{
						_userInterface = idE.UIManager.FindInterface(token.ToString(), true);
					}
				}
				// sort.
				else if(tokenLower == "sort")
				{
					ParseSort(lexer);
				}
				// spectrum <integer>.
				else if(tokenLower == "spectrum")
				{
					int.TryParse(lexer.ReadTokenOnLine().ToString(), out _spectrum);
				}
				// deform < sprite | tube | flare >.
				else if(tokenLower == "deform")
				{
					ParseDeform(lexer);
				}
				// decalInfo <staySeconds> <fadeSeconds> (<start rgb>) (<end rgb>).
				else if(tokenLower == "decalinfo")
				{
					ParseDecalInfo(lexer);
				}
				// renderbump <args...>.
				else if(tokenLower == "renderbump")
				{
					_renderBump = lexer.ParseRestOfLine();
				}
				// diffusemap for stage shortcut.
				else if(tokenLower == "diffusemap")
				{
					idLexer newLexer = new idLexer(LexerOptions.NoFatalErrors | LexerOptions.NoStringConcatination | LexerOptions.NoStringEscapeCharacters | LexerOptions.AllowPathNames);
					newLexer.LoadMemory(string.Format("blend diffusemap\nmap {0}\n}}\n", ParsePastImageProgram(lexer)), "diffusemap");

					ParseStage(newLexer, textureRepeatDefault);
				}
				// specularmap for stage shortcut.
				else if(tokenLower == "specularmap")
				{
					idLexer newLexer = new idLexer(LexerOptions.NoFatalErrors | LexerOptions.NoStringConcatination | LexerOptions.NoStringEscapeCharacters | LexerOptions.AllowPathNames);
					newLexer.LoadMemory(string.Format("blend specularmap\nmap {0}\n}}\n", ParsePastImageProgram(lexer)), "specularmap");

					ParseStage(newLexer, textureRepeatDefault);
				}
				// normalmap for stage shortcut.
				else if(tokenLower == "bumpmap")
				{
					idLexer newLexer = new idLexer(LexerOptions.NoFatalErrors | LexerOptions.NoStringConcatination | LexerOptions.NoStringEscapeCharacters | LexerOptions.AllowPathNames);
					newLexer.LoadMemory(string.Format("blend bumpmap\nmap {0}\n}}\n", ParsePastImageProgram(lexer)), "bumpmap");

					ParseStage(newLexer, textureRepeatDefault);
				}
				// DECAL_MACRO for backwards compatibility with the preprocessor macros.
				else if(tokenLower == "decal_macro")
				{
					// polygonOffset
					this.MaterialFlag = Renderer.MaterialFlags.PolygonOffset;
					_polygonOffset = -1;

					// discrete
					_surfaceFlags |= SurfaceFlags.Discrete;
					_contentFlags &= ~ContentFlags.Solid;

					// sort decal.
					_sort = (float) MaterialSort.Decal;

					// noShadows
					this.MaterialFlag = Renderer.MaterialFlags.NoShadows;
				}
				else if(tokenValue == "{")
				{
					// create the new stage.
					ParseStage(lexer, textureRepeatDefault);
				}
				else
				{
					idConsole.WriteLine("unknown general material parameter '{0}' in '{1}'", tokenValue, this.Name);
					return;
				}
			}

			// add _flat or _white stages if needed.
			AddImplicitStages();

			// order the diffuse / bump / specular stages properly.
			SortInteractionStages();

			// if we need to do anything with normals (lighting or environment mapping)
			// and two sided lighting was asked for, flag
			// shouldCreateBackSides() and change culling back to single sided,
			// so we get proper tangent vectors on both sides.

			// we can't just call ReceivesLighting(), because the stages are still
			// in temporary form.
			if(_cullType == CullType.TwoSided)
			{
				count = _parsingData.Stages.Count;

				for(int i = 0; i < count; i++)
				{
					if((_parsingData.Stages[i].Lighting != StageLighting.Ambient) || (_parsingData.Stages[i].Texture.TextureCoordinates != TextureCoordinateGeneration.Explicit))
					{
						if(_cullType == CullType.TwoSided)
						{
							_cullType = CullType.Front;
							_shouldCreateBackSides = true;
						}

						break;
					}
				}
			}

			// currently a surface can only have one unique texgen for all the stages on old hardware.
			TextureCoordinateGeneration firstGen = TextureCoordinateGeneration.Explicit;

			count = _parsingData.Stages.Count;

			for(int i = 0; i < count; i++)
			{
				if(_parsingData.Stages[i].Texture.TextureCoordinates != TextureCoordinateGeneration.Explicit)
				{
					if(firstGen == TextureCoordinateGeneration.Explicit)
					{
						firstGen = _parsingData.Stages[i].Texture.TextureCoordinates;
					}
					else if(firstGen != _parsingData.Stages[i].Texture.TextureCoordinates)
					{
						idConsole.Warning("material '{0}' has multiple stages with a texgen", this.Name);
						break;
					}
				}
			}
		}
예제 #26
0
		private void Clear()
		{
			_description = "<none>";
			_renderBump = string.Empty;

			_contentFlags = ContentFlags.Solid;
			_surfaceFlags = SurfaceFlags.None;
			_materialFlags = 0;

			_sort = (float) MaterialSort.Bad;
			_coverage = MaterialCoverage.Bad;
			_cullType = CullType.Front;

			_deformType = DeformType.None;
			_deformRegisters = new int[4];

			_ops = null;
			_expressionRegisters = null;
			_constantRegisters = null;
			_stages = new MaterialStage[] { };

			_stageCount = 0;
			_ambientStageCount = 0;
			_registerCount = 0;
			
			_lightFalloffImage = null;
			_entityGui = 0;
			_shouldCreateBackSides = false;
			_editorImageName = null;

			_fogLight = false;
			_blendLight = false;
			_ambientLight = false;
			_noFog = false;
			_hasSubview = false;
			_allowOverlays = true;
			_unsmoothedTangents = false;

			_userInterface = null;
			_referenceCount = 0;
			
			/*editorAlpha = 1.0;*/
			_spectrum = 0;

			_polygonOffset = 0;
			_suppressInSubview = false;
			_portalSky = false;

			_decalInfo.StayTime = 10000;
			_decalInfo.FadeTime = 4000;
			_decalInfo.Start = new float[] { 1, 1, 1, 1 };
			_decalInfo.End = new float[] { 0, 0, 0, 0 };
		}
예제 #27
0
        static CSGBrushSubMesh.Polygon[] CreateBoxAssetPolygons(CSGSurfaceAsset[] surfaces, SurfaceFlags surfaceFlags)
        {
            return(new[]
            {
                // left/right
                new CSGBrushSubMesh.Polygon {
                    surfaceID = 0, firstEdge = 0, edgeCount = 4, description = new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    }, surfaceAsset = surfaces[0]
                },
                new CSGBrushSubMesh.Polygon {
                    surfaceID = 1, firstEdge = 4, edgeCount = 4, description = new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    }, surfaceAsset = surfaces[1]
                },

                // front/back
                new CSGBrushSubMesh.Polygon {
                    surfaceID = 2, firstEdge = 8, edgeCount = 4, description = new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    }, surfaceAsset = surfaces[2]
                },
                new CSGBrushSubMesh.Polygon {
                    surfaceID = 3, firstEdge = 12, edgeCount = 4, description = new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    }, surfaceAsset = surfaces[3]
                },

                // top/down
                new CSGBrushSubMesh.Polygon {
                    surfaceID = 4, firstEdge = 16, edgeCount = 4, description = new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    }, surfaceAsset = surfaces[4]
                },
                new CSGBrushSubMesh.Polygon {
                    surfaceID = 5, firstEdge = 20, edgeCount = 4, description = new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    }, surfaceAsset = surfaces[5]
                }
            });
        }
 public static extern Surface CreateSurface(Device gbm, int width, int height, SurfaceFormat format,
                                            SurfaceFlags flags);
예제 #29
0
 public static bool HasFlagFast(this SurfaceFlags value, SurfaceFlags flag)
 {
     return((value & flag) != 0);
 }
예제 #30
0
        public LinuxNativeWindow(IntPtr display, IntPtr gbm, int fd,
                                 int x, int y, int width, int height, string title,
                                 GraphicsMode mode, GameWindowFlags options,
                                 DisplayDevice display_device)
        {
            Debug.Print("[KMS] Creating window on display {0:x}", display);

            Title = title;

            display_device = display_device ?? DisplayDevice.Default;
            if (display_device == null)
            {
                throw new NotSupportedException("[KMS] Driver does not currently support headless systems");
            }

            window = new LinuxWindowInfo(display, fd, gbm, display_device.Id as LinuxDisplay);

            // Note: we only support fullscreen windows on KMS.
            // We implicitly override the requested width and height
            // by the width and height of the DisplayDevice, if any.
            width       = display_device.Width;
            height      = display_device.Height;
            bounds      = new Rectangle(0, 0, width, height);
            client_size = bounds.Size;

            if (!mode.Index.HasValue)
            {
                mode = new EglGraphicsMode().SelectGraphicsMode(window, mode, 0);
            }
            Debug.Print("[KMS] Selected EGL mode {0}", mode);

            SurfaceFormat format = GetSurfaceFormat(display, mode);
            SurfaceFlags  usage  = SurfaceFlags.Rendering | SurfaceFlags.Scanout;

            if (!Gbm.IsFormatSupported(gbm, format, usage))
            {
                Debug.Print("[KMS] Failed to find suitable surface format, using XRGB8888");
                format = SurfaceFormat.XRGB8888;
            }

            Debug.Print("[KMS] Creating GBM surface on {0:x} with {1}x{2} {3} [{4}]",
                        gbm, width, height, format, usage);
            IntPtr gbm_surface = Gbm.CreateSurface(gbm,
                                                   width, height, format, usage);

            if (gbm_surface == IntPtr.Zero)
            {
                throw new NotSupportedException("[KMS] Failed to create GBM surface for rendering");
            }

            window.Handle = gbm_surface;
            Debug.Print("[KMS] Created GBM surface {0:x}", window.Handle);

            window.CreateWindowSurface(mode.Index.Value);
            Debug.Print("[KMS] Created EGL surface {0:x}", window.Surface);

            cursor_default = CreateCursor(gbm, Cursors.Default);
            cursor_empty   = CreateCursor(gbm, Cursors.Empty);
            Cursor         = MouseCursor.Default;
            exists         = true;
        }
예제 #31
0
파일: Device.cs 프로젝트: jpbruyere/DRI.net
 static extern bool IsFormatSupported(IntPtr gbm, SurfaceFormat format, SurfaceFlags usage);
예제 #32
0
파일: Device.cs 프로젝트: XionWin/THeGuID
 public bool IsSupportedFormat(SurfaceFormat format, SurfaceFlags flags) => gbm_device_is_format_supported(this.handle, format, flags);
예제 #33
0
        /// <summary>
        /// Creates a cube <see cref="RealtimeCSG.Foundation.BrushMesh"/> with <paramref name="size"/> and <paramref name="layers"/> and optional <paramref name="surfaceFlags"/>
        /// </summary>
        /// <remarks><note>These methods are a work in progress and may change somewhat over time</note></remarks>
        /// <param name="size">The size of the cube</param>
        /// <param name="layers">The <see cref="RealtimeCSG.Foundation.SurfaceLayers"/> that define how the surfaces of this cube are rendered or if they need to be part of a collider etc.</param>
        /// <param name="surfaceFlags">Optional flags that modify surface behavior.</param>
        /// <returns>A <see cref="RealtimeCSG.Foundation.BrushMesh"/> on success, null on failure</returns>
        public static BrushMesh CreateCube(UnityEngine.Vector3 size, SurfaceLayers layers, SurfaceFlags surfaceFlags = SurfaceFlags.None)
        {
            var halfSize = size * 0.5f;

            return(CreateCube(-halfSize, halfSize, layers, surfaceFlags));
        }
예제 #34
0
 public BufferObject(Device dev, uint _width, uint _height, SurfaceFormat format, SurfaceFlags flags)
 {
     handle = gbm_bo_create(dev.Handle, _width, _height, format, flags);
     if (handle == null)
     {
         throw new NotSupportedException("[GBM] BO creation failed.");
     }
 }
 public static extern bool IsFormatSupported(Device gbm, SurfaceFormat format, SurfaceFlags usage);
예제 #36
0
		/// <summary>
		/// See if the current token matches one of the surface parameter bit flags.
		/// </summary>
		/// <param name="token"></param>
		/// <returns></returns>
		private bool CheckSurfaceParameter(idToken token)
		{
			string tokenLower = token.ToString().ToLower();

			foreach(MaterialInfoParameter infoParameter in InfoParameters)
			{
				if(tokenLower == infoParameter.Name)
				{
					if((infoParameter.SurfaceFlags & Renderer.SurfaceFlags.TypeMask) == Renderer.SurfaceFlags.TypeMask)
					{
						// ensure we only have one surface type set
						_surfaceFlags &= ~SurfaceFlags.TypeMask;
					}

					_surfaceFlags |= infoParameter.SurfaceFlags;
					_contentFlags |= infoParameter.ContentFlags;

					if(infoParameter.ClearSolid == true)
					{
						_contentFlags &= ~ContentFlags.Solid;
					}

					return true;
				}
			}

			return false;
		}
예제 #37
0
        public static CSGBrushMeshAsset CreateBoxAsset(UnityEngine.Vector3 size, CSGSurfaceAsset surfaceAsset, SurfaceFlags surfaceFlags = SurfaceFlags.None)
        {
            var halfSize = size * 0.5f;

            return(CreateBoxAsset(-halfSize, halfSize, surfaceAsset, surfaceFlags));
        }
예제 #38
0
파일: Device.cs 프로젝트: XionWin/THeGuID
 static extern bool gbm_device_is_format_supported(gbm_device *handle, SurfaceFormat format, SurfaceFlags flags);