Ejemplo n.º 1
0
        public void FixtureSetUp()
        {
            try {
                // Support ES tests
                Egl.IsRequired = IsEsTest;

#if GL_LOG_ENABLED
                // Set logging
                Gl.QueryLogContext();
                Wgl.QueryLogContext();
                KhronosApi.RegisterApplicationLogDelegate(delegate(string format, object[] args) {
                    Console.WriteLine(format, args);
                });
#endif

                // Create window on which tests are run
                _Window = new GraphicsWindow(800, 600);

                // Define window buffers
                GraphicsBuffersFormat graphicsBuffersFormat = new GraphicsBuffersFormat(PixelLayout.RGB24);

                //graphicsBuffersFormat.DefineDepthBuffer(24, GraphicsBuffersFormat.BufferPolicy.RequiredAndDegradable);
                //graphicsBuffersFormat.DefineDoubleBuffers(GraphicsBuffersFormat.BufferPolicy.RequiredAndDegradable);

                _Window.Create(graphicsBuffersFormat);
                // Create graphics context
                _Context = new GraphicsContext(_Window.GetDeviceContext(), null, null, GraphicsContextFlags.CompatibilityProfile);
            } catch {
                // Release resources manually
                FixtureTearDown();
                throw;
            }
        }
Ejemplo n.º 2
0
		static void Main()
		{
			string envDebug = Environment.GetEnvironmentVariable("DEBUG");

			if (envDebug == "GL") {
				KhronosApi.RegisterApplicationLogDelegate(delegate (string format, object[] args) {
					Console.WriteLine(format, args);
				});
			}

			try {
				// Gl.CurrentExtensions.FramebufferObject_ARB = false;		// Test P-Buffer
				// Egl.IsRequired = Egl.IsAvailable;						// Test EGL (not yet working)

				if (Gl.CurrentExtensions.FramebufferObject_ARB) {
					using (DeviceContext deviceContext = DeviceContext.Create()) {
						RenderOsdFramebuffer(deviceContext);
					}
				} else {
					// Fallback to old-school pbuffer
					using (INativePBuffer nativeBuffer = DeviceContext.CreatePBuffer(new DevicePixelFormat(24), 800, 600)) {
						using (DeviceContext deviceContext = DeviceContext.Create(nativeBuffer)) {
							RenderOsdPBuffer(deviceContext);
						}
					}
				}
			} catch (Exception exception) {
				Console.WriteLine("Unexpected exception: {0}", exception.ToString());
			}
		}
Ejemplo n.º 3
0
        static void Main()
        {
            try {
                string envDebug = Environment.GetEnvironmentVariable("DEBUG");

                if (envDebug == "GL")
                {
                    KhronosApi.RegisterApplicationLogDelegate(delegate(string format, object[] args) {
                        Console.WriteLine(format, args);
                    });
                }

                // RPi runs on EGL
                Egl.IsRequired = true;

                if (Egl.IsAvailable == false)
                {
                    throw new InvalidOperationException("EGL is not available. Aborting.");
                }

                using (VideoCoreWindow nativeWindow = new VideoCoreWindow()) {
                    using (DeviceContext eglContext = DeviceContext.Create(nativeWindow.Display, nativeWindow.Handle)) {
                        eglContext.ChoosePixelFormat(new DevicePixelFormat(32));

                        IntPtr glContext = eglContext.CreateContext(IntPtr.Zero);

                        eglContext.MakeCurrent(glContext);

                        Initialize();

                        Gl.Viewport(0, 0, 1920, 1080);
                        Gl.ClearColor(0.0f, 0.0f, 0.0f, 1.0f);

                        while (true)
                        {
                            Gl.Clear(ClearBufferMask.ColorBufferBit);
                            Draw();
                            eglContext.SwapBuffers();
                            break;
                        }

                        System.Threading.Thread.Sleep(10000);

                        Terminate();
                        eglContext.DeleteContext(glContext);
                    }
                }
            } catch (Exception exception) {
                Console.WriteLine(exception.ToString());
            }
        }
Ejemplo n.º 4
0
        static void Main()
        {
            try {
                string envDebug = Environment.GetEnvironmentVariable("GL_DEBUG");

                if (envDebug == "YES")
                {
                    KhronosApi.RegisterApplicationLogDelegate(delegate(string format, object[] args) {
                        Console.WriteLine(format, args);
                    });
                }
            } catch (Exception exception) {
                Console.WriteLine(exception.ToString());
            }
        }
Ejemplo n.º 5
0
        static void Main()
        {
            string envDebug = Environment.GetEnvironmentVariable("DEBUG");

            if (envDebug == "GL")
            {
                KhronosApi.RegisterApplicationLogDelegate(delegate(string format, object[] args) {
                    Console.WriteLine(format, args);
                });
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new SampleForm());
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Draw this SceneGraph.
        /// </summary>
        /// <param name="ctx">
        /// The <see cref="GraphicsContext"/> used for drawing.
        /// </param>
        /// <param name="programOverride">
        /// A <see cref="ShaderProgram"/> that overrides the default one used for rendering the batch. It can be null.
        /// </param>
        public void Draw(GraphicsContext ctx, ShaderProgram programOverride)
        {
            CheckCurrentContext(ctx);

            // View parameters
            SceneRoot.LocalProjection          = ProjectionMatrix;
            SceneRoot.LocalModel               = new ModelMatrix();
            SceneRoot.LocalModelView           = ViewMatrix;
            SceneRoot.LocalModelViewProjection = new ModelMatrix((Matrix4x4)ProjectionMatrix.Multiply(ViewMatrix));

            using (SceneGraphContext ctxScene = new SceneGraphContext(this)) {
                ObjectBatchContext objectBatchContext = new ObjectBatchContext();

                // Traverse the scene graph
                SceneRoot.TraverseDirect(ctx, ctxScene, _TraverseDrawContext, objectBatchContext);
                // Generate shadow maps
                if ((SceneFlags & SceneGraphFlags.Lighting) != 0 && (SceneFlags & SceneGraphFlags.ShadowMaps) != 0)
                {
                    _LightManager.GenerateShadowMaps(ctx, this);
                }

                // Sort geometries
                List <SceneObjectBatch> sceneObjects = objectBatchContext.Objects;
                if (((SceneFlags & SceneGraphFlags.StateSorting) != 0) && (_SorterRoot != null))
                {
                    sceneObjects = _SorterRoot.Sort(objectBatchContext.Objects);
                }

                // Draw all batches
                KhronosApi.LogComment("*** Draw Graph");
                foreach (SceneObjectBatch objectBatch in sceneObjects)
                {
                    objectBatch.Draw(ctx, programOverride);
                }

                // Debug: shadow maps
                if ((SceneFlags & SceneGraphFlags.Lighting) != 0 && (SceneFlags & SceneGraphFlags.ShadowMaps) != 0)
                {
                    DisplayShadowMaps(ctx);
                }
            }
        }
Ejemplo n.º 7
0
        public void TestIsCompatibleField()
        {
            FieldInfo fi = typeof(KhronosApiTest).GetField("GetPointer", BindingFlags.Static | BindingFlags.Public);

            Gl.Extensions extensions = new Gl.Extensions();

            Assert.IsFalse(KhronosApi.IsCompatibleField(fi, Gl.Version_100, extensions));
            Assert.IsTrue(KhronosApi.IsCompatibleField(fi, Gl.Version_110, extensions));
            Assert.IsTrue(KhronosApi.IsCompatibleField(fi, Gl.Version_150, extensions));
            Assert.IsTrue(KhronosApi.IsCompatibleField(fi, Gl.Version_210, extensions));
            Assert.IsTrue(KhronosApi.IsCompatibleField(fi, Gl.Version_300, extensions));
            Assert.IsTrue(KhronosApi.IsCompatibleField(fi, Gl.Version_310, extensions));

            Assert.IsFalse(KhronosApi.IsCompatibleField(fi, new KhronosVersion(Gl.Version_320, KhronosVersion.ProfileCore), extensions));
            Assert.IsFalse(KhronosApi.IsCompatibleField(fi, new KhronosVersion(Gl.Version_400, KhronosVersion.ProfileCore), extensions));
            Assert.IsFalse(KhronosApi.IsCompatibleField(fi, new KhronosVersion(Gl.Version_410, KhronosVersion.ProfileCore), extensions));
            Assert.IsFalse(KhronosApi.IsCompatibleField(fi, new KhronosVersion(Gl.Version_420, KhronosVersion.ProfileCore), extensions));
            Assert.IsTrue(KhronosApi.IsCompatibleField(fi, new KhronosVersion(Gl.Version_430, KhronosVersion.ProfileCore), extensions));
            Assert.IsTrue(KhronosApi.IsCompatibleField(fi, new KhronosVersion(Gl.Version_440, KhronosVersion.ProfileCore), extensions));

            Assert.IsTrue(KhronosApi.IsCompatibleField(fi, new KhronosVersion(Gl.Version_320, KhronosVersion.ProfileCompatibility), extensions));
            Assert.IsTrue(KhronosApi.IsCompatibleField(fi, new KhronosVersion(Gl.Version_400, KhronosVersion.ProfileCompatibility), extensions));
            Assert.IsTrue(KhronosApi.IsCompatibleField(fi, new KhronosVersion(Gl.Version_410, KhronosVersion.ProfileCompatibility), extensions));
            Assert.IsTrue(KhronosApi.IsCompatibleField(fi, new KhronosVersion(Gl.Version_420, KhronosVersion.ProfileCompatibility), extensions));
            Assert.IsTrue(KhronosApi.IsCompatibleField(fi, new KhronosVersion(Gl.Version_430, KhronosVersion.ProfileCompatibility), extensions));
            Assert.IsTrue(KhronosApi.IsCompatibleField(fi, new KhronosVersion(Gl.Version_440, KhronosVersion.ProfileCompatibility), extensions));

            // Not sure how Profile can affect this...
            Assert.IsTrue(KhronosApi.IsCompatibleField(fi, Gl.Version_100_ES, extensions));
            Assert.IsFalse(KhronosApi.IsCompatibleField(fi, Gl.Version_200_ES, extensions));
            Assert.IsFalse(KhronosApi.IsCompatibleField(fi, Gl.Version_300_ES, extensions));
            Assert.IsFalse(KhronosApi.IsCompatibleField(fi, Gl.Version_310_ES, extensions));
            Assert.IsTrue(KhronosApi.IsCompatibleField(fi, Gl.Version_320_ES, extensions));

            extensions.EnableExtension("GL_EXT_vertex_array");
            Assert.IsTrue(KhronosApi.IsCompatibleField(fi, Gl.Version_100, extensions));

            extensions.EnableExtension("GL_KHR_debug");
            Assert.IsTrue(KhronosApi.IsCompatibleField(fi, Gl.Version_100, extensions));
            Assert.IsTrue(KhronosApi.IsCompatibleField(fi, Gl.Version_200_ES, extensions));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Get the handle relative to the specified library.
        /// </summary>
        /// <param name="libraryPath">
        /// A <see cref="String"/> that specify the path of the library to load.
        /// </param>
        /// <returns>
        /// It returns a <see cref="IntPtr"/> that represents the handle of the library loaded from <paramref name="libraryPath"/>.
        /// </returns>
        private IntPtr GetLibraryHandle(string libraryPath)
        {
            IntPtr libraryHandle;

            if (_LibraryHandles.TryGetValue(libraryPath, out libraryHandle) == false)
            {
                // Load library
                libraryHandle = UnsafeNativeMethods.LoadLibrary(libraryPath);
#if PLATFORM_LOG_ENABLED
                KhronosApi.LogFunction("LoadLibrary({0}) = 0x{1}", libraryPath, libraryHandle.ToString("X8"));
#endif

                _LibraryHandles.Add(libraryPath, libraryHandle);
            }

            if (libraryHandle == IntPtr.Zero)
            {
                throw new InvalidOperationException(String.Format("unable to load library at {0}", libraryPath));
            }

            return(libraryHandle);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Update framebuffer.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ObjectsControl_Render(object sender, GlControlEventArgs e)
        {
            GlControl senderControl     = (GlControl)sender;
            float     senderAspectRatio = (float)senderControl.Width / senderControl.Height;

            KhronosApi.LogEnabled = false;
            KhronosApi.LogComment("--------------------------------------------------");
            KhronosApi.LogComment("*** Draw");

            // Clear
            Gl.Viewport(0, 0, senderControl.Width, senderControl.Height);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            _CubeScene.CurrentView.ProjectionMatrix = new PerspectiveProjectionMatrix(45.0f, senderAspectRatio, 0.1f, 100.0f);
            _CubeScene.CurrentView.LocalModel.SetIdentity();
            _CubeScene.CurrentView.LocalModel.Translate(_ViewStrideLat, _ViewStrideAlt, 0.0f);
            _CubeScene.CurrentView.LocalModel.RotateY(_ViewAzimuth);
            _CubeScene.CurrentView.LocalModel.RotateX(_ViewElevation);
            _CubeScene.CurrentView.LocalModel.Translate(0.0f, 0.0f, _ViewLever);
            _CubeScene.UpdateViewMatrix();

            _CubeScene.Draw(_Context);

            KhronosApi.LogEnabled = false;

            return;

            // Overlay
            ProjectionMatrix overlayProjection = new OrthoProjectionMatrix(0.0f, ClientSize.Width, 0.0f, ClientSize.Height);
            ModelMatrix      overlayModel      = new ModelMatrix();

            overlayModel.Translate(0.375f, 0.375f);

            Gl.Clear(ClearBufferMask.DepthBufferBit);

            ColorRGBAF fpsColor = ColorRGBAF.ColorGreen;
            int        fps      = (int)Math.Floor(1000.0 / senderControl.FrameSwapTime.TotalMilliseconds);

            if (fps >= 59)
            {
                fpsColor = ColorRGBAF.ColorGreen;
            }
            else if (fps >= 29)
            {
                fpsColor = ColorRGBAF.ColorBlue;
            }
            else if (fps >= 24)
            {
                fpsColor = ColorRGBAF.ColorYellow;
            }
            else
            {
                fpsColor = ColorRGBAF.ColorRed;
            }

            fontPatch.DrawString(
                _Context, overlayProjection * overlayModel, fpsColor,
                String.Format("FPS: {0}", fps)
                );

            overlayModel.SetIdentity();
            overlayModel.Translate(0.375f, ClientSize.Height - 64 + 0.375f);
            fontTitle.DrawString(
                _Context, overlayProjection * overlayModel, ColorRGBAF.ColorGreen,
                "Hello Objects example ~(^.^)~"
                );

            overlayModel.SetIdentity();
            overlayModel.Translate(0.375f, ClientSize.Height - 128 + 0.375f);
            fontTitleV.DrawString(_Context, overlayProjection * overlayModel, ColorRGBAF.ColorGreen,
                                  "Hello Objects example ~(^.^)~"
                                  );

            // Release resources
            _Context.DisposeResources();
        }