16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-21 12:29:18 +02:00

milek7/sim branch opengl 3.3 renderer import

This commit is contained in:
tmj-fstate
2019-10-26 15:17:09 +02:00
parent d24fccb4d7
commit 0fd23a53d9
90 changed files with 7629 additions and 549 deletions

View File

@@ -12,8 +12,8 @@ http://mozilla.org/MPL/2.0/.
#include <istream>
#include <ddraw.h>
#include <string>
#include "GL/glew.h"
#include "ResourceManager.h"
#include "gl/ubo.h"
struct opengl_texture {
static DDSURFACEDESC2 deserialize_ddsd(std::istream&);
@@ -27,12 +27,20 @@ struct opengl_texture {
void
load();
bool
bind();
bind( size_t unit );
static void
unbind( size_t unit );
bool
create();
// releases resources allocated on the opengl end, storing local copy if requested
void
release();
void
alloc_rendertarget( GLint format, GLint components, int width, int height, int samples = 1, GLint wrap = GL_CLAMP_TO_BORDER );
void
set_components_hint( GLint hint );
static void
reset_unit_cache();
inline
int
width() const {
@@ -49,6 +57,10 @@ struct opengl_texture {
std::string name; // name of the texture source file
std::string type; // type of the texture source file
std::size_t size{ 0 }; // size of the texture data, in kb
GLint components_hint = 0; // components that material wants
GLenum target = GL_TEXTURE_2D;
static std::array<GLuint, gl::MAX_TEXTURES + 2> units;
private:
// methods
@@ -63,6 +75,8 @@ private:
void flip_vertical();
// members
bool is_rendertarget = false; // is used as postfx rendertarget, without loaded data
int samples = 1;
std::vector<char> data; // texture data (stored GL-style, bottom-left origin)
resource_state data_state{ resource_state::none }; // current state of texture data
int data_width{ 0 },
@@ -70,10 +84,18 @@ private:
data_mapcount{ 0 };
GLint data_format{ 0 },
data_components{ 0 };
GLint data_type = GL_UNSIGNED_BYTE;
GLint wrap_mode_s = GL_REPEAT;
GLint wrap_mode_t = GL_REPEAT;
/*
std::atomic<bool> is_loaded{ false }; // indicates the texture data was loaded and can be processed
std::atomic<bool> is_good{ false }; // indicates the texture data was retrieved without errors
*/
static std::unordered_map<GLint, int> precompressed_formats;
static std::unordered_map<GLint, GLint> drivercompressed_formats;
static std::unordered_map<GLint, std::unordered_map<GLint, GLint>> mapping;
static GLint m_activeunit;
};
typedef int texture_handle;
@@ -91,10 +113,12 @@ public:
unit( GLint const Textureunit );
// creates texture object out of data stored in specified file
texture_handle
create( std::string Filename, bool const Loadnow = true );
create( std::string Filename, bool const Loadnow = true, GLint Formathint = GL_SRGB_ALPHA );
// binds specified texture to specified texture unit
void
bind( std::size_t const Unit, texture_handle const Texture );
opengl_texture &
mark_as_used( texture_handle const Texture );
// provides direct access to specified texture object
opengl_texture &
texture( texture_handle const Texture ) const { return *(m_textures[ Texture ].first); }