public RendererCapabilities CreateContext(IntPtr window) { // OpenGL only allows for one thread per context, so if a context already exists it has to be cleaned up before trying to make a new one. if (ContextHandle != IntPtr.Zero) { SDL_GL_DeleteContext(ContextHandle); } else { Gl.Initialize(); } // Set OpenGL attributes. SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_RED_SIZE, 8); // Allocate 8 bits per pixel for the red color-channel. SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_GREEN_SIZE, 8); // Allocate 8 bits per pixel for the green color-channel. SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_BLUE_SIZE, 8); // Allocate 8 bits per pixel for the blue color-channel. SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_ALPHA_SIZE, 8); // Allocate 8 bits per pixel for the alpha channel. SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_BUFFER_SIZE, 32); // Therefore, one pixel in the screen buffer allocates 32 bits. SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_DEPTH_SIZE, 16); // Allocate a 16-bit depth buffer. SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_DOUBLEBUFFER, 1); // Enable double buffering. SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_CONTEXT_PROFILE_MASK, (int)SDL_GLprofile.SDL_GL_CONTEXT_PROFILE_CORE); SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_CONTEXT_MAJOR_VERSION, 3); // Set the specifications of the OpenGL context to 3.2 core. SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_CONTEXT_MINOR_VERSION, 2); // Create the context and bind it to the hwnd. ContextHandle = SDL_GL_CreateContext(window); SDL_GL_MakeCurrent(window, ContextHandle); // Disable V-Sync. SDL_GL_SetSwapInterval(0); // Setup an OpenGL debug context for easier debugging. Gl.Enable((EnableCap)Gl.DEBUG_OUTPUT); Gl.Enable((EnableCap)Gl.DEBUG_OUTPUT_SYNCHRONOUS); Gl.DebugMessageCallback(OpenGLMessageCallback, IntPtr.Zero); Gl.DebugMessageControl(DebugSource.DontCare, DebugType.DontCare, DebugSeverity.DebugSeverityNotification, 0, null, false); // Query the graphics driver for the capabilities of the GPU. RendererCapabilities caps = new RendererCapabilities(); Gl.GetInteger(GetPName.MaxTextureSize, out caps.MaxTextureSize); Gl.GetInteger(GetPName.MaxTextureImageUnits, out caps.NumTextureSlots); // Setup alpha blending and depth testing. Gl.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); Gl.CullFace(CullFaceMode.Back); Gl.Enable(EnableCap.Blend); Gl.Enable(EnableCap.DepthTest); return(caps); }
public static void Initialize(Window window) { Window = window; // Create a new graphics API context and query the capabilities. Capabilities = RenderAPI.CreateContext(window.Handle); /* * Vertex positions of a 2d quad specified in the folling order: * 3 4 * * 1 2 */ VertexPositions = new Vector4[] { new Vector4(0.0f, 0.0f, 0.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f) }; Vertices = new Vertex[MaxVerticies]; /* * The index buffer is filled in the pattern: 1, 2, 3, * 3, 4, 1 * Making 2 triangles that make out a quad. */ uint[] indices = new uint[MaxIndices]; for (uint i = 0, offset = 0; i < MaxIndices; offset += 4) { indices[i++] = offset + 0; indices[i++] = offset + 1; indices[i++] = offset + 2; indices[i++] = offset + 2; indices[i++] = offset + 3; indices[i++] = offset + 0; } // Initialize the graphics API. RenderAPI.Initialize(indices, "assets/shader.glsl"); // Create a fully white 1x1 texture. WhiteTexture = CreateTexture(new byte[] { 0xff, 0xff, 0xff, 0xff }, 1, 1, PixelFormat.RGBA); // Allocate 'Capabilities.NumTextureSlots' number of texture slots. TextureSlots = new ulong[Capabilities.NumTextureSlots]; // Set the first texture slot to the white texture. TextureSlots[0] = WhiteTexture; }
public RenderModuleAttribute(RendererCapabilities Capabilities, System.Type RendererType) { this.Capabilities = Capabilities; this.RendererType = RendererType; }