#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2013 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License #ifndef NUCLEX_GRAPHICS_RASTERIZATION_OPENGL3RASTERIZER_H #define NUCLEX_GRAPHICS_RASTERIZATION_OPENGL3RASTERIZER_H #include "../Config.h" #include "Rasterizer.h" #if defined(NUCLEX_GRAPHICS_WIN32) #define WIN32_LEAN_AND_MEAN #define VC_EXTRALEAN #define NO_MINMAX #include #endif #include #if defined(NUCLEX_GRAPHICS_LINUX) #include #endif namespace Nuclex { namespace Graphics { namespace Rasterization { // ------------------------------------------------------------------------------------------- // ///Uses OpenGL 3.0 (core profile) to render polygon-based scenes class OpenGL3Rasterizer : public Rasterizer { #if defined(NUCLEX_GRAPHICS_WIN32) /// Initializes a new OpenGL 3.0 polygon renderer /// Handle of the window into which to render public: NUCLEX_GRAPHICS_API OpenGL3Rasterizer(HWND windowHandle); #elif defined(NUCLEX_GRAPHICS_LINUX) /// Initializes a new OpenGL 3.0 polygon renderer /// Display the rasterizer will render on /// Visual on which rendering will take place /// Whether to directly connect to the graphics system public: NUCLEX_GRAPHICS_API OpenGL3Rasterizer( Display *display, XVisualInfo *visualInfo, bool direct = true ); #endif /// Frees all resources owned by the rasterizer public: NUCLEX_GRAPHICS_API virtual ~OpenGL3Rasterizer(); /// Accesses the settings management interface of the rasterizer /// The rasterizer's settings management public: NUCLEX_GRAPHICS_API const RasterizerSettings &Settings() const; /// Accesses the settings management interface of the rasterizer /// The rasterizer's settings management public: NUCLEX_GRAPHICS_API RasterizerSettings &Settings(); /// Accesses the resource management interface of the rasterizer /// The rasterizer's resource management public: NUCLEX_GRAPHICS_API const RasterizerResources &Resources() const; /// Accesses the resource management interface of the rasterizer /// The rasterizer's resource management public: NUCLEX_GRAPHICS_API RasterizerResources &Resources(); /// Counts the number of vertex streams usable by the rasterizer /// The number of vertex streams the rasterizer can access public: NUCLEX_GRAPHICS_API std::size_t CountAvailableVertexStreams() const; /// Returns the vertex buffer currently bound to the specified stream /// Index of the stream whose bound vertex buffer is returned /// The vertex buffer bound to the specified stream public: NUCLEX_GRAPHICS_API const std::shared_ptr &GetVertexBuffer( std::size_t index ) const; /// Binds a vertex buffer to the specified stream /// Index of the stream the vertex buffer will be bound to /// Vertex buffer that will be bound to the stream public: NUCLEX_GRAPHICS_API void SetVertexBuffer( std::size_t index, const std::shared_ptr &vertexBuffer ); /// Returns the index buffer currently bound /// The index buffer currently bound public: NUCLEX_GRAPHICS_API const std::shared_ptr &GetIndexBuffer() const { return this->indexBuffer; } /// Binds the index buffer that defines the vertex order /// Index buffer that will be bound public: NUCLEX_GRAPHICS_API void SetIndexBuffer( const std::shared_ptr &indexBuffer ) { this->indexBuffer = indexBuffer; this->indexBufferChanged = true; } /// /// Retrieves the vertex shader the rasterizer is using to transform vertices /// /// The vertex shader that the rasterizer is using public: NUCLEX_GRAPHICS_API const std::shared_ptr &GetVertexShader() const { return this->vertexShader; } /// Assigns the vertex shader that will be used to transform vertices /// Vertex shader the rasterizer will use public: NUCLEX_GRAPHICS_API void SetVertexShader( const std::shared_ptr &vertexShader ) { this->vertexShader = vertexShader; this->vertexShaderChanged = true; } /// /// Retrieves the pixel shader the rasterizer is using to determine pixel colors /// /// The pixel shader that the rasterizer is using public: NUCLEX_GRAPHICS_API const std::shared_ptr &GetPixelShader() const { return this->pixelShader; } /// Assigns the pixel shader that will be used to determine pixel colors /// Pixel shader the rasterizer will use public: NUCLEX_GRAPHICS_API void SetPixelShader( const std::shared_ptr &pixelShader ) { this->pixelShader = pixelShader; this->pixelShaderChanged = true; } /// Retrieves the current render target /// The current render target of the rasterizer public: NUCLEX_GRAPHICS_API const std::shared_ptr &GetRenderTarget() { return this->renderTarget; } /// Selects the render target onto which the rasterize will draw /// New render target to draw on public: NUCLEX_GRAPHICS_API void SetRenderTarget( const std::shared_ptr &renderTarget ) { this->renderTarget = renderTarget; this->renderTargetChanged = true; } /// Returns the currently configured vertex topology /// The topology currently used to connect vertices public: NUCLEX_GRAPHICS_API Topology::Enum GetTopology() const { return this->topology; } /// Changes the configured vertex topology /// The topology to be used for connecting vertices public: NUCLEX_GRAPHICS_API void SetTopology(Topology::Enum topology) { this->topology = topology; } /// Rasterizes primitives using the currently bound vertex buffers /// /// Index in the vertex buffers at which resterization will begin /// /// Number of vertices that will be rasterized public: NUCLEX_GRAPHICS_API void Rasterize( std::size_t vertexBufferStartIndex = 0, std::size_t vertexCount = static_cast(-1) ); /// /// Rasterizes primitives by indexing the bound vertex buffers through /// the bound index buffers /// /// /// Position in the index buffer rasterization will begin at /// /// Number of indices that will used for rasterization /// /// Index of the first vertex that will be accessed by this operation. /// Providing this value can speed up hardware rasterization. /// /// /// Index of the last vertex that will be accessed by this operation (exclusive). /// Providing this value can speed up hardware rasterization. /// public: NUCLEX_GRAPHICS_API void RasterizeIndexed( std::size_t indexBufferStartIndex = 0, std::size_t indexCount = static_cast(-1), std::size_t firstAccessedVertexIndex = 0, std::size_t lastAccessedVertexIndex = static_cast(-1) ); /// Presents the rasterized image in the view public: NUCLEX_GRAPHICS_API void Present(); /// Assigns the index buffer to the Direct3D device if it has changed private: void assignIndexBufferIfChanged(); /// Assigns the vertex buffer to the Direct3D device if it has changed private: void assignVertexBufferIfChanged(); /// Assigns the vertex shader to the Direct3D device if it has changed private: void assignVertexShaderIfChanged(); /// Assigns the pixel shader to the Direct3D device if it has changed private: void assignPixelShaderIfChanged(); /// Stores privates implementation details private: struct Impl; /// Private implementation details of the rasterizer private: Impl *impl; /// Manages the settings of the Direct3D 11 rasterizer private: std::unique_ptr settings; /// Controls resource management of the Direct3D 11 rasterizer private: std::unique_ptr resources; /// Topology currently selected for any Rasterize() calls private: Topology::Enum topology; /// Vertex buffers the user has currently selected private: std::unique_ptr[]> vertexBuffers; /// Whether the vertex buffers have changed since the last draw call private: bool vertexBuffersChanged; /// Index buffer the user has currently selected private: std::shared_ptr indexBuffer; /// Whether the index buffer has changed since the last draw call private: bool indexBufferChanged; /// Vertex shader that will be used to transform vertices private: std::shared_ptr vertexShader; /// Whether the vertex shader has changed since the last draw call private: bool vertexShaderChanged; /// Pixel shader that will be used for rasterization private: std::shared_ptr pixelShader; /// Whether the pixel shader has changed since the last draw call private: bool pixelShaderChanged; /// Render target onto which the rasterizer will draw private: std::shared_ptr renderTarget; /// Whether the render target has changed since the last draw call private: bool renderTargetChanged; }; // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Graphics::Rasterization #endif // NUCLEX_GRAPHICS_RASTERIZATION_OPENGL3RASTERIZER_H