public static void Main()
 {
     // entry point
     using (OpenTKApp app = new OpenTKApp())
     {
         app.Run(30.0, 0.0);
     }
 }
Пример #2
0
 public static void Main(string[] args)
 {
     // entry point
     using (OpenTKApp app = new OpenTKApp())
     {
         // app.Run();
         app.Run(30.0, 0.0);
     }
 }
Пример #3
0
 public static void Main(string[] args)
 {
     // entry point
     using (OpenTKApp app = new OpenTKApp())
     {
         app.ClientSize = new Size(800, 800);
         app.Run(30.0, 0.0);
     }
 }
Пример #4
0
        public static void Initialize(OpenTKApp app)
        {
            keysDown        = new List <Key>();
            keysDownLast    = new List <Key>();
            buttonsDown     = new List <MouseButton>();
            buttonsDownLast = new List <MouseButton>();

            app.KeyDown   += screen_KeyDown;
            app.KeyUp     += screen_KeyUp;
            app.MouseDown += screen_MouseDown;
            app.MouseUp   += screen_MouseUp;
        }
Пример #5
0
	// tick: renders one frame
	public void Tick()
	{
		// initialize timer
		if (firstFrame)
		{
			timer.Reset();
			timer.Start();
			firstFrame = false;
		}
		// handle keys, only when running time set to -1 (infinite)
		if (runningTime == -1) if (camera.HandleInput())
		{
			// camera moved; restart
			ClearAccumulator();
		}
		// render
		if (false) // if (useGPU)
		{
			// add your CPU + OpenCL path here
			// mind the gpuPlatform parameter! This allows us to specify the platform on our
			// test system.
			// note: it is possible that the automated test tool provides you with a different
			// platform number than required by your hardware. In that case, you can hardcode
			// the platform during testing (ignoring gpuPlatform); do not forget to put back
			// gpuPlatform before submitting!
		}
		else
		{
			// this is your CPU only path
			float scale = 1.0f / (float)++spp;
			for( int y = 0; y < screen.height; y++ )
			{
				for( int x = 0; x < screen.width; x++ )
				{
					// generate primary ray
					Ray ray = camera.Generate( RTTools.GetRNG(), x, y );
					// trace path
					int pixelIdx = x + y * screen.width;
					accumulator[pixelIdx] += Sample( ray, 0 );
					// plot final color
					screen.pixels[pixelIdx] = RTTools.Vector3ToIntegerRGB( scale * accumulator[pixelIdx] );
				}
			}
		}
		// stop and report when max render time elapsed
		int elapsedSeconds = (int)(timer.ElapsedMilliseconds / 1000);
		if (runningTime != -1) if (elapsedSeconds >= runningTime)
		{
			OpenTKApp.Report( (int)timer.ElapsedMilliseconds, spp, screen );
		}
	}
Пример #6
0
 public static void Main(string[] args)
 {
     // parse command line parameters
     if (args.Length == 3)
     {
         if (args[0] == "G")
         {
             useGPU = true;
         }
         else
         {
             useGPU = false;
         }
         gpuPlatform = Int32.Parse(args[1]);
         runningTime = Int32.Parse(args[2]);
     }
     // entry point
     using (OpenTKApp app = new OpenTKApp())
     {
         app.Run(30.0, 0.0);
     }
 }
Пример #7
0
 public static void Main(string[] args)
 {
     // entry point
     Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US");               // thanks Mathijs
     using (OpenTKApp app = new OpenTKApp()) { app.Run(30.0, 0.0); }
 }
Пример #8
0
        // tick: renders one frame
        public void Tick()
        {
            // initialize timer
            if (firstFrame)
            {
                timer.Reset();
                timer.Start();
                firstFrame = false;
            }
            // handle keys, only when running time set to -1 (infinite)
            if (runningTime == -1)
            {
                if (camera.HandleInput())
                {
                    // camera moved; restart
                    ClearAccumulator();
                }
            }
            // render
            if (false)     // if (useGPU)
            {
                // add your CPU + OpenCL path here
                // mind the gpuPlatform parameter! This allows us to specify the platform on our
                // test system.
                // note: it is possible that the automated test tool provides you with a different
                // platform number than required by your hardware. In that case, you can hardcode
                // the platform during testing (ignoring gpuPlatform); do not forget to put back
                // gpuPlatform before submitting!
                long[] workSize  = { screen.width, screen.height };
                long[] localSize = { 16, 2 };
                queue.Execute(kernel, null, workSize, null, null);
                queue.Finish();

                queue.ReadFromBuffer(outputBuffer, ref screen.pixels, true, null);
                Console.WriteLine(screen.pixels[0]);

                Random r = RTTools.GetRNG();
                for (int i = 0; i < 1000; i++)
                {
                    randoms[i] = (float)r.NextDouble();
                }
                rndBuffer    = new ComputeBuffer <float>(context, ComputeMemoryFlags.ReadOnly | ComputeMemoryFlags.UseHostPointer, randoms);
                cameraBuffer = new ComputeBuffer <Vector3>(context, ComputeMemoryFlags.ReadOnly | ComputeMemoryFlags.UseHostPointer, camera.toCL());
                kernel.SetMemoryArgument(6, cameraBuffer);
                kernel.SetMemoryArgument(7, rndBuffer);
            }
            else
            {
                // this is your CPU only path
                float scale = 1.0f / (float)++spp;

                Parallel.For(0, screen.height, y => {
                    for (int x = 0; x < screen.width; x++)
                    {
                        // generate primary ray
                        Ray ray = camera.Generate(RTTools.GetRNG(), x, y);
                        // trace path
                        int pixelIdx           = x + y * screen.width;
                        accumulator[pixelIdx] += Sample(ray, 0, x, y);
                        // plot final color
                        screen.pixels[pixelIdx] = RTTools.Vector3ToIntegerRGB(scale * accumulator[pixelIdx]);
                    }
                });
            }
            // stop and report when max render time elapsed
            int elapsedSeconds = (int)(timer.ElapsedMilliseconds / 1000);

            if (runningTime != -1)
            {
                if (elapsedSeconds >= runningTime)
                {
                    OpenTKApp.Report((int)timer.ElapsedMilliseconds, spp, screen);
                }
            }
        }
Пример #9
0
 public static void Main(string[] args)
 {
     // entry point -> Framerate stuff set?
     using (OpenTKApp app = new OpenTKApp()) { app.Run(60.0, 60.0); }
 }
Пример #10
0
        // tick: renders one frame
        public void Tick()
        {
            //float t = 21.5f;
            // initialize timer
            if (firstFrame)
            {
                timer.Reset();
                timer.Start();
                firstFrame = false;
            }
            // handle keys, only when running time set to -1 (infinite)
            if (runningTime == -1) 
                if (camera.HandleInput())
                {
                    // camera moved; restart
                    ClearAccumulator();
                }
            // render
            if (useGPU)
            {
                
                // add your CPU + OpenCL path here
                // mind the gpuPlatform parameter! This allows us to specify the platform on our
                // test system.
                // note: it is possible that the automated test tool provides you with a different
                // platform number than required by your hardware. In that case, you can hardcode
                // the platform during testing (ignoring gpuPlatform); do not forget to put back
                // gpuPlatform before submitting!
                GL.Finish();
                // clear the screen
                screen.Clear(0);

                // do opencl stuff
                if (GLInterop)
                {
                    kernel.SetMemoryArgument(0, texBuffer);
                }
                else
                {
                    kernel.SetMemoryArgument(0, buffer);
                }
                
                // execute kernel
                //long[] workSize = { screen.width, screen.height };
                long[] localSize = { 8, 12 };
                long [] workSize = { screen.width , screen.height };
                if (GLInterop)
                {
                    List<ComputeMemory> c = new List<ComputeMemory>() { texBuffer };
                    queue.AcquireGLObjects(c, null);
                    queue.Execute(kernel, null, workSize, localSize, null);
                    queue.Finish();
                    queue.ReleaseGLObjects(c, null);
                }
                else
                {
                    camera.Update();
                    gpuCamera = new GPUCamera(camera.pos, camera.p1, camera.p2, camera.p3, camera.up, camera.right, screen.width, screen.height, camera.lensSize);
                    float scale = 1.0f / (float)++spp;
                    kernel.SetValueArgument(2, gpuCamera);
                    kernel.SetValueArgument(3, scale);
                    queue.Execute(kernel, null, workSize, localSize, null);
                    queue.Finish();
                    // fetch results
                    if (!GLInterop)
                    {
                        queue.ReadFromBuffer(buffer, ref data, true, null);

                        // visualize result
                        for (int y = 0; y < screen.height; y++) 
                            for (int x = 0; x < screen.width; x++)
                            {
                                int temp = x + y * screen.width;
                                screen.pixels[temp] = data[temp];
                            }
                    }
                }
            }
            else
            {
                // this is your CPU only path
                float scale = 1.0f / (float)++spp;
                Parallel.For(0, dataArray.Length, parallelOptions, (id) =>
                {
                    for (int j = dataArray[id].y1; j < dataArray[id].y2 && j < screen.height; j++)
                    {
                        for (int i = dataArray[id].x1; i < dataArray[id].x2 && i < screen.width; i++)
                        {
                            // generate primary ray
                            Ray ray = camera.Generate(RTTools.GetRNG(), i, j);
                            // trace path
                            int pixelIdx = i + j * screen.width;
                            accumulator[pixelIdx] += Sample(ray, 0);
                            // plot final color
                            screen.pixels[pixelIdx] = RTTools.Vector3ToIntegerRGB(scale * accumulator[pixelIdx]);
                        }
                    }
                });
            }

            // stop and report when max render time elapsed
            int elapsedSeconds = (int)(timer.ElapsedMilliseconds / 1000);
            if (runningTime != -1) if (elapsedSeconds >= runningTime)
                {
                    OpenTKApp.Report((int)timer.ElapsedMilliseconds, spp, screen);
                }
        }
Пример #11
0
 public Game(OpenTKApp app)
 {
     this.app = app; //Inherited the app pointer to get the window size
 }
Пример #12
0
		public static void Main( string[] args ) 
		{ 
			// parse command line parameters
			if (args.Length == 3)
			{
				if (args[0] == "G") useGPU = true; else useGPU = false;
				gpuPlatform = Int32.Parse( args[1] );
				runningTime = Int32.Parse( args[2] );
			}
			// entry point
			using (OpenTKApp app = new OpenTKApp()) 
			{ 
				app.Run( 30.0, 0.0 ); 
			}
		}
Пример #13
0
 public static void Main(string[] args)
 {
     // entry point
     using (OpenTKApp app = new OpenTKApp()) { app.Run(30.0, 0.0); }
 }