/// <summary> /// Attachs this rendering target to the graphics driver, so that all rendering /// is done to it. /// </summary> bool IRenderTarget.Attach() { if (GraphicsManager.Driver != _driver) { ((Control)_graphicsCanvas).Dispose(); _graphicsCanvas = GraphicsManager.Driver.CreateCanvas(_renderControl, _graphicsCanvas.Flags); _driver = GraphicsManager.Driver; } return(_graphicsCanvas.Attach()); }
public Window CreateWindow(WindowSettings settings, IGraphicsDriver graphicDriver) { if (graphicDriver.GraphicsApi == GraphicsApi.OpenGL) { return(new GlfwWindow(settings)); } else { throw new NotSupportedException(); } }
/// <summary> /// Sets up a new instance of this class with the given values. /// </summary> /// <param name="renderControl">Control to render to.</param> /// <param name="flags">Flags to setup this control with.</param> public GraphicsCanvas(Control renderControl, GraphicsFlags flags, CanvasRenderHandler handler) { _renderControl = renderControl; _graphicsCanvas = GraphicsManager.Driver.CreateCanvas(renderControl, flags); if (handler != null) { _renderDelegate += handler; // Fix this so its removed when canvas is destroyed!. } _driver = GraphicsManager.Driver; GraphicsManager.RenderTarget = this; }
public static DriverConfiguration Initialise(params string[] assemblyNames) { foreach (var asmName in assemblyNames) { AppDomain.CurrentDomain.Load(asmName); } IMonitorDriver monitorDriver = null; IWindowDriver windowDriver = null; IImageDriver imageDriver = null; IFontDriver fontDriver = null; IGraphicsDriver graphicsDriver = null; IAudioDriver audioDriver = null; foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { var jwdriver = assembly.GetCustomAttribute <JankWorksDriver>(); if (jwdriver != null) { var driverInstance = Activator.CreateInstance(jwdriver.DriverType); SetDriverApi(ref monitorDriver, driverInstance); SetDriverApi(ref windowDriver, driverInstance); SetDriverApi(ref imageDriver, driverInstance); SetDriverApi(ref fontDriver, driverInstance); SetDriverApi(ref graphicsDriver, driverInstance); SetDriverApi(ref audioDriver, driverInstance); } } var config = new DriverConfiguration ( monitorDriver, windowDriver, imageDriver, fontDriver, graphicsDriver, audioDriver ); DriverConfiguration.Drivers = config; return(config); void SetDriverApi <T>(ref T api, object driver) { if (api == null && driver is T driverApi) { api = driverApi; } } }
/// <summary> /// Recreates the driver dependent shader. /// </summary> private void CreateShader() { if (_shader != null) { _shader = null; //GC.Collect(); } if (!_shaderCode.ContainsKey(GraphicsManager.Driver.ToString())) { return; } _shader = GraphicsManager.Driver.CreateShader(_shaderCode[GraphicsManager.Driver.ToString()] as string); _driver = GraphicsManager.Driver; }
public DriverConfiguration ( IMonitorDriver monitorDriver = null, IWindowDriver windowDriver = null, IImageDriver imageDriver = null, IFontDriver fontDriver = null, IGraphicsDriver graphicsDriver = null, IAudioDriver audioDriver = null ) { this.monitorApi = monitorDriver ?? DriverUnitialisedException.driver; this.windowApi = windowDriver ?? DriverUnitialisedException.driver; this.imageApi = imageDriver ?? DriverUnitialisedException.driver; this.fontApi = fontDriver ?? DriverUnitialisedException.driver; this.graphicsApi = graphicsDriver ?? DriverUnitialisedException.driver; this.audioApi = audioDriver ?? DriverUnitialisedException.driver; }
public Window(string title, Window parent = null, Size size = null, Point position = null) { _graphicsDriver = new GraphicsDriver(); Title = title; Parent = parent; Position = position; if (position == null) { //SetDefaultSizeAndPosition(); Position = new Point(0, 0); } if (size == null) { Size = new Size(800, 600); } State = WindowState.Active; }
/// <summary> /// Sets up a new instance of this class with the given values. /// </summary> /// <param name="renderControl">Control to render to.</param> /// <param name="flags">Flags to setup this control with.</param> public GraphicsCanvas(Control renderControl, GraphicsFlags flags, CanvasRenderHandler handler) { _renderControl = renderControl; _graphicsCanvas = GraphicsManager.Driver.CreateCanvas(renderControl, flags); if (handler != null) _renderDelegate += handler; // Fix this so its removed when canvas is destroyed!. _driver = GraphicsManager.Driver; GraphicsManager.RenderTarget = this; }
/// <summary> /// Recreates the driver dependent shader. /// </summary> private void CreateShader() { if (_shader != null) { _shader = null; //GC.Collect(); } if (!_shaderCode.ContainsKey(GraphicsManager.Driver.ToString())) return; _shader = GraphicsManager.Driver.CreateShader(_shaderCode[GraphicsManager.Driver.ToString()] as string); _driver = GraphicsManager.Driver; }
/// <summary> /// Tiles this frame at the given position. /// </summary> /// <param name="x">Position on the x-axis to tile this frame.</param> /// <param name="y">Position on the y-axis to tile this frame.</param> /// <param name="z">Position on the z-axis to tile this frame.</param> void IImageFrame.Tile(float x, float y, float z) { IGraphicsDriver graphicsDriver = (IGraphicsDriver)_dx9Driver; // Can we do it as a single quad? bool singleQuad = false; if (_dx9Driver.DX9Device.DeviceCaps.TextureCaps.SupportsSquareOnly == true || _dx9Driver.DX9Device.DeviceCaps.TextureCaps.SupportsPower2 == true) { singleQuad = (_textureWidth == _pixelMap.Width && _textureHeight == _pixelMap.Height); } else { singleQuad = true; } // Yippe! if (singleQuad == true) { // Work out the scale. float rsx = GraphicsManager.Driver.ResolutionScale[0]; float rsy = GraphicsManager.Driver.ResolutionScale[1]; float sx = Math.Abs(GraphicsManager.Driver.ResolutionScale[0] + (Math.Abs(GraphicsManager.Driver.ScaleFactor[0]) - 1.0f)); float sy = Math.Abs(GraphicsManager.Driver.ResolutionScale[1] + (Math.Abs(GraphicsManager.Driver.ScaleFactor[1]) - 1.0f)); float ox = (((graphicsDriver.Viewport.X - x) % (_pixelMap.Width * sx)) * rsx) + (_pixelMap.Width * sx); float oy = (((graphicsDriver.Viewport.Y - y) % (_pixelMap.Height * sy)) * rsy) + (_pixelMap.Height * sy); float qx = ((graphicsDriver.Viewport.X * rsx) + graphicsDriver.ResolutionOffset[0]) - ox; float qy = ((graphicsDriver.Viewport.Y * rsx) + graphicsDriver.ResolutionOffset[1]) - oy; float qw = (graphicsDriver.Viewport.Width * rsx) + ox; float qh = (graphicsDriver.Viewport.Height * rsy) + oy; // If we are flipping the image we need to compensate. if (graphicsDriver.ScaleFactor[0] < 0.0f && qx + qw > graphicsDriver.Resolution[0]) { int hCount = Math.Max(1, (int)Math.Round(((float)graphicsDriver.Viewport.Width * rsx) / ((float)_pixelMap.Width * sx))) + 1; qw = (hCount * (_pixelMap.Width * sx)) + ox; } if (graphicsDriver.ScaleFactor[1] < 0.0f && qy + qh > graphicsDriver.Resolution[1]) { int vCount = Math.Max(1, (int)Math.Round(((float)graphicsDriver.Viewport.Height * rsy) / ((float)_pixelMap.Height * sy))) + 1; qh = (vCount * (_pixelMap.Height * sy)) + oy; } float tw = qw / (_pixelMap.Width * sx); float th = qh / (_pixelMap.Height * sy); // Work out vertex positions. _vertexArray[0].X = qx; _vertexArray[0].Y = qy; _vertexArray[0].Z = z; _vertexArray[0].Tu = GraphicsManager.Driver.ScaleFactor[0] >= 0 ? 0 : tw; _vertexArray[0].Tv = GraphicsManager.Driver.ScaleFactor[1] >= 0 ? 0 : th; _vertexArray[0].Color = graphicsDriver.VertexColors[0]; _vertexArray[1].X = qx + qw; _vertexArray[1].Y = qy; _vertexArray[1].Z = z; _vertexArray[1].Tu = GraphicsManager.Driver.ScaleFactor[0] >= 0 ? tw : 0; _vertexArray[1].Tv = GraphicsManager.Driver.ScaleFactor[1] >= 0 ? 0 : th; _vertexArray[1].Color = graphicsDriver.VertexColors[1]; _vertexArray[2].X = qx + qw; _vertexArray[2].Y = qy + qh; _vertexArray[2].Z = z; _vertexArray[2].Tu = GraphicsManager.Driver.ScaleFactor[0] >= 0 ? tw : 0; _vertexArray[2].Tv = GraphicsManager.Driver.ScaleFactor[1] >= 0 ? th : 0; _vertexArray[2].Color = graphicsDriver.VertexColors[2]; _vertexArray[3].X = qx; _vertexArray[3].Y = qy + qh; _vertexArray[3].Z = z; _vertexArray[3].Tu = GraphicsManager.Driver.ScaleFactor[0] >= 0 ? 0 : tw; _vertexArray[3].Tv = GraphicsManager.Driver.ScaleFactor[1] >= 0 ? th : 0; _vertexArray[3].Color = graphicsDriver.VertexColors[3]; // Render the image using a 2 part triangle fan. _dx9Driver.UploadTextureAndBuffer(_texture, null); if (graphicsDriver.Shader != null) { int passes = graphicsDriver.Shader.Begin(); for (int i = 0; i < passes; i++) { graphicsDriver.Shader.BeginPass(i); _dx9Driver.DX9Device.DrawUserPrimitives(PrimitiveType.TriangleFan, 2, _vertexArray); graphicsDriver.Shader.FinishPass(); } graphicsDriver.Shader.Finish(); } else { _dx9Driver.DX9Device.DrawUserPrimitives(PrimitiveType.TriangleFan, 2, _vertexArray); } // Reset vertex texture positions. _vertexArray[0].Tu = 0; _vertexArray[0].Tv = 0; _vertexArray[1].Tu = 1; _vertexArray[1].Tv = 0; _vertexArray[2].Tu = 1; _vertexArray[2].Tv = 1; _vertexArray[3].Tu = 0; _vertexArray[3].Tv = 1; } // Nuts, we will have to do them seperately. else { float sx = Math.Abs(graphicsDriver.ScaleFactor[0]); float sy = Math.Abs(graphicsDriver.ScaleFactor[1]); float ox = graphicsDriver.Viewport.X - ((graphicsDriver.Viewport.X - x) % (_pixelMap.Width * sx)); float oy = graphicsDriver.Viewport.Y - ((graphicsDriver.Viewport.Y - y) % (_pixelMap.Height * sy)); int hCount = (int)Math.Ceiling(graphicsDriver.Viewport.Width / (_pixelMap.Width * sx)) + 1; int vCount = (int)Math.Ceiling(graphicsDriver.Viewport.Height / (_pixelMap.Height * sy)) + 1; for (int xr = 0; xr < hCount; xr++) { for (int yr = 0; yr < vCount; yr++) { ((IImageFrame)this).Render(ox + (xr * (_pixelMap.Width * sx)), oy + (yr * (_pixelMap.Height * sy)), z); } } } }
/// <summary> /// Renders this frame at the given position. /// </summary> /// <param name="x">Position on the x-axis to render this frame.</param> /// <param name="y">Position on the y-axis to render this frame.</param> /// <param name="z">Position on the z-axis to render this frame.</param> void IImageFrame.Render(float x, float y, float z) { // Set the world matrix to transform our image. IGraphicsDriver graphicsDriver = (IGraphicsDriver)_dx9Driver; // Add origin to position. x += _origin.X; y += _origin.Y; // Work out where we should draw. float sx = graphicsDriver.ResolutionScale[0] + (Math.Abs(graphicsDriver.ScaleFactor[0]) - 1.0f); float sy = graphicsDriver.ResolutionScale[1] + (Math.Abs(graphicsDriver.ScaleFactor[1]) - 1.0f); float x0 = -_origin.X; float y0 = -_origin.Y; float x1 = x0 + _pixelMap.Width; float y1 = y0 + _pixelMap.Height; float tx = ((x + graphicsDriver.Offset[0]) * graphicsDriver.ResolutionScale[0]) + graphicsDriver.ResolutionOffset[0]; float ty = ((y + graphicsDriver.Offset[1]) * graphicsDriver.ResolutionScale[0]) + graphicsDriver.ResolutionOffset[1]; float ix = (float)_dx9Driver.RotationAngleCos * sx; float iy = -(float)_dx9Driver.RotationAngleSin * sy; float jx = (float)_dx9Driver.RotationAngleSin * sx; float jy = (float)_dx9Driver.RotationAngleCos * sy; float z0 = z + graphicsDriver.Offset[2]; float tu = (float)_pixelMap.Width / (float)_textureWidth; float tv = (float)_pixelMap.Height / (float)_textureHeight; _vertexArray[0].Color = graphicsDriver.VertexColors[0]; _vertexArray[0].X = x0 * ix + y0 * iy + tx; _vertexArray[0].Y = x0 * jx + y0 * jy + ty; _vertexArray[0].Z = z0; _vertexArray[0].Tu = graphicsDriver.ScaleFactor[0] >= 0.0f ? 0 : tu; _vertexArray[0].Tv = graphicsDriver.ScaleFactor[1] >= 0.0f ? 0 : tv; _vertexArray[1].Color = graphicsDriver.VertexColors[1]; _vertexArray[1].X = x1 * ix + y0 * iy + tx; _vertexArray[1].Y = x1 * jx + y0 * jy + ty; _vertexArray[1].Z = z0; _vertexArray[1].Tu = graphicsDriver.ScaleFactor[0] >= 0.0f ? tu : 0; _vertexArray[1].Tv = graphicsDriver.ScaleFactor[1] >= 0.0f ? 0 : tv; _vertexArray[2].Color = graphicsDriver.VertexColors[2]; _vertexArray[2].X = x1 * ix + y1 * iy + tx; _vertexArray[2].Y = x1 * jx + y1 * jy + ty; _vertexArray[2].Z = z0; _vertexArray[2].Tu = graphicsDriver.ScaleFactor[0] >= 0.0f ? tu : 0; _vertexArray[2].Tv = graphicsDriver.ScaleFactor[1] >= 0.0f ? tv : 0; _vertexArray[3].Color = graphicsDriver.VertexColors[3]; _vertexArray[3].X = x0 * ix + y1 * iy + tx; _vertexArray[3].Y = x0 * jx + y1 * jy + ty; _vertexArray[3].Z = z0; _vertexArray[3].Tu = graphicsDriver.ScaleFactor[0] >= 0.0f ? 0 : tu; _vertexArray[3].Tv = graphicsDriver.ScaleFactor[1] >= 0.0f ? tv : 0; // Write out vertexs into the buffer. _dx9Driver.UploadTextureAndBuffer(_texture, null); if (graphicsDriver.Shader != null) { int passes = graphicsDriver.Shader.Begin(); for (int i = 0; i < passes; i++) { graphicsDriver.Shader.BeginPass(i); _dx9Driver.DX9Device.DrawUserPrimitives(PrimitiveType.TriangleFan, 2, _vertexArray); graphicsDriver.Shader.FinishPass(); } graphicsDriver.Shader.Finish(); } else { _dx9Driver.DX9Device.DrawUserPrimitives(PrimitiveType.TriangleFan, 2, _vertexArray); } }
static GL() { Driver = DriverManager.LoadDriver <IGraphicsDriver>(GameConfig.GraphicsDriver, ExpectedDriverVersion); Driver.Initialize(); RuntimeImport(); }
public GraphicsRenderer(IGraphicsDriver graphicsDriver, State state, Preferences prefs) { this.graphicsDriver = graphicsDriver; this.State = state; this.renderDrivers = new List <GraphicsRendererDriver>(); this.renderDrivers.Add(new GraphicsRendererDriverEga()); this.renderDrivers.Add(new GraphicsRendererDriverCga0()); this.renderDrivers.Add(new GraphicsRendererDriverCga1()); this.renderDrivers.Add(new GraphicsRendererDriverHercules(new GraphicsColor(0xff, 0xff, 0xff))); this.renderDrivers.Add(new GraphicsRendererDriverHercules(new GraphicsColor(0x00, 0x80, 0x00))); // alternative: 0x00, 0x9a, 0x00 this.renderDrivers.Add(new GraphicsRendererDriverHercules(new GraphicsColor(0xb9, 0x80, 0x00))); // alternative: 0xdf, 0xa2, 0x00 this.renderDrivers.Add(new GraphicsRendererDriverAtariST()); this.renderDrivers.Add(new GraphicsRendererDriverAmiga1()); this.renderDrivers.Add(new GraphicsRendererDriverAmiga2()); this.renderDrivers.Add(new GraphicsRendererDriverAmiga3()); this.renderDrivers.Add(new GraphicsRendererDriverAppleIIgs()); switch (prefs.Theme) { case UserInterfaceTheme.Ega: this.renderDriverIndex = 0; break; case UserInterfaceTheme.Cga1: this.renderDriverIndex = 1; break; case UserInterfaceTheme.Cga2: this.renderDriverIndex = 2; break; case UserInterfaceTheme.Hercules: this.renderDriverIndex = 3; break; case UserInterfaceTheme.HerculesGreen: this.renderDriverIndex = 4; break; case UserInterfaceTheme.HerculesAmber: this.renderDriverIndex = 5; break; case UserInterfaceTheme.AtariST: this.renderDriverIndex = 6; break; case UserInterfaceTheme.Amiga1: this.renderDriverIndex = 7; break; case UserInterfaceTheme.Amiga2: this.renderDriverIndex = 8; break; case UserInterfaceTheme.Amiga3: this.renderDriverIndex = 9; break; case UserInterfaceTheme.AppleIIgs: this.renderDriverIndex = 10; break; } }
Window IWindowDriver.CreateWindow(WindowSettings settings, IGraphicsDriver graphicDriver) => throw this;