unsafe static void Main() { Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var window = new Form1(); var device = Dawn.createDevice(window.Handle); var queue = WebGPUNative.wgpuDeviceGetDefaultQueue(device); var swapChain = Dawn.createSwapChain(device, WGPUTextureUsage.WGPUTextureUsage_OutputAttachment, 800, 450, WGPUPresentMode.WGPUPresentMode_Mailbox); Triangle.Device = device; Triangle.Queue = queue; Triangle.SwapChain = swapChain; TriangleCPP.initialize(device, queue, swapChain); Triangle.CreatePipelineAndBuffers(); //TriangleCPP.initializePipelineAndBuffers(Triangle.pipeline, Triangle.vertBuf, Triangle.indxBuf, Triangle.uRotBuf, Triangle.bindGroup); //TriangleCPP.createPipelineAndBuffers(); window.Show(); while (true) { System.Windows.Forms.Application.DoEvents(); Triangle.redraw(); //TriangleCPP.redraw(); } }
public static IntPtr CreatePipeline(IntPtr bindGroupLayout) { // Load shaders var vertMod = CreateShader(triangleVert); //var vertMod = TriangleCPP.createVertShader(); var fragMod = CreateShader(triangleFrag); //var fragMod = TriangleCPP.createFragShader(); WGPUPipelineLayoutDescriptor layoutDesc = new WGPUPipelineLayoutDescriptor { bindGroupLayoutCount = 1, bindGroupLayouts = &bindGroupLayout }; IntPtr pipelineLayout = WebGPUNative.wgpuDeviceCreatePipelineLayout(Device, &layoutDesc); // begin pipeline set-up WGPURenderPipelineDescriptor desc = new WGPURenderPipelineDescriptor { layout = pipelineLayout, vertexStage = new WGPUProgrammableStageDescriptor() { module = vertMod, entryPoint = str_entrypoint } }; WGPUProgrammableStageDescriptor fragStage = new WGPUProgrammableStageDescriptor { module = fragMod, entryPoint = str_entrypoint }; desc.fragmentStage = &fragStage; // describe buffer layouts var vertAttrs = stackalloc WGPUVertexAttributeDescriptor[2]; vertAttrs[0] = new WGPUVertexAttributeDescriptor { format = WGPUVertexFormat.WGPUVertexFormat_Float2, offset = 0, shaderLocation = 0 }; vertAttrs[1] = new WGPUVertexAttributeDescriptor { format = WGPUVertexFormat.WGPUVertexFormat_Float3, offset = 2 * sizeof(float), shaderLocation = 1 }; WGPUVertexBufferLayoutDescriptor vertDesc = new WGPUVertexBufferLayoutDescriptor { arrayStride = 5 * sizeof(float), attributeCount = 2, attributes = vertAttrs }; WGPUVertexStateDescriptor vertState = new WGPUVertexStateDescriptor { ////indexFormat = WGPUIndexFormat.WGPUIndexFormat_Uint16, vertexBufferCount = 1, vertexBuffers = &vertDesc }; desc.vertexState = &vertState; desc.primitiveTopology = WGPUPrimitiveTopology.WGPUPrimitiveTopology_TriangleList; desc.sampleCount = 1; // describe blend WGPUBlendDescriptor blendDesc = new WGPUBlendDescriptor { operation = WGPUBlendOperation.WGPUBlendOperation_Add, srcFactor = WGPUBlendFactor.WGPUBlendFactor_SrcAlpha, dstFactor = WGPUBlendFactor.WGPUBlendFactor_OneMinusSrcAlpha }; WGPUColorStateDescriptor colorDesc = new WGPUColorStateDescriptor { format = Dawn.getSwapChainFormat(Device), alphaBlend = blendDesc, colorBlend = blendDesc, writeMask = WGPUColorWriteMask.WGPUColorWriteMask_All }; desc.colorStateCount = 1; desc.colorStates = &colorDesc; desc.sampleMask = 0xFFFFFFFF; // <-- Note: this currently causes Emscripten to fail (sampleMask ends up as -1, which trips an assert) IntPtr _pipeline = WebGPUNative.wgpuDeviceCreateRenderPipeline(Device, ref desc); // partial clean-up (just move to the end, no?) WebGPUNative.wgpuPipelineLayoutRelease(pipelineLayout); WebGPUNative.wgpuShaderModuleRelease(fragMod); WebGPUNative.wgpuShaderModuleRelease(vertMod); return(_pipeline); }
public Sun(DateTime date, double latitude, double longitude, TimeZoneInfo timezone) { //Date = new DateTime(date.Year,date.Month,date.Day) + GetTimeEquation(date); Date = date; EclipLon = -1; double[] rises = new double[] { 0, 0, 0, 0 }; double[] sets = new double[] { 0, 0, 0, 0 }; bool[] isrises = new bool[] { false, false, false, false }; bool[] issets = new bool[] { false, false, false, false }; double[] h_correct = new double[] { Astro.Rad(-50 / 60.0), Astro.Rad(-6), Astro.Rad(-12), Astro.Rad(-18) }; double hour = 1.0; double y_minus, y_0, y_plus; double xe = 0, ye = 0, root1 = 0, root2 = 0; int nRoot = 0; double MJD0h = Astro.Mjd(date) - timezone.GetUtcOffset(date).TotalHours / 24.0; for (int i = 0; i < 4; i++) { hour = 1.0; y_minus = SinAlt(MJD0h, hour - 1.0, latitude, longitude) - Math.Sin(h_correct[i]); // loop over search intervals from [0h-2h] to [22h-24h] do { y_0 = SinAlt(MJD0h, hour, latitude, longitude) - Math.Sin(h_correct[i]); y_plus = SinAlt(MJD0h, hour + 1.0, latitude, longitude) - Math.Sin(h_correct[i]); // find parabola through three values y_minus,y_0,y_plus Astro.Quad(y_minus, y_0, y_plus, out xe, out ye, out root1, out root2, out nRoot); if (nRoot == 1) { if (y_minus < 0.0) { rises[i] = hour + root1; isrises[i] = true; } else { sets[i] = hour + root1; issets[i] = true; } } if (nRoot == 2) { if (ye < 0.0) { rises[i] = hour + root2; sets[i] = hour + root1; } else { rises[i] = hour + root1; sets[i] = hour + root2; } isrises[i] = true; issets[i] = true; } y_minus = y_plus; // prepare for next interval hour += 2.0; }while (!((hour == 25.0) || (isrises[i] && issets[i]))); } Dawn = Date.AddHours(rises[0]); Dusk = Date.AddHours(sets[0]); Noon = Dawn.AddHours((sets[0] - rises[0]) / 2); if (Dusk.Day != Dawn.Day) { Noon = Noon.AddHours(12); } CivilDawn = Date.AddHours(rises[1]); CivilDusk = Date.AddHours(sets[1]); NauticalDawn = Date.AddHours(rises[2]); NauticalDusk = Date.AddHours(sets[2]); AstronomicalDawn = Date.AddHours(rises[3]); AstronomicalDusk = Date.AddHours(sets[3]); Result = new SunResult { NoDawnDusk = !isrises[0] || !issets[0], NoCivil = !isrises[1] || !issets[1], NoNautical = !isrises[2] | !issets[2], NoAstronomical = !isrises[3] | !issets[3], }; }