CSEngine
Loading...
Searching...
No Matches
STexture.h
1//
2// Created by ounols on 19. 4. 18.
3//
4
5#pragma once
6
7
8#include <vector>
9#include "../../Object/SResource.h"
10#include "../../OGLDef.h"
11
12namespace CSE {
13
14 class STexture : public SResource {
15 public:
16 enum Type {
17 TEX_2D = 0, TEX_CUBE = 1
18 };
19 public:
20 STexture();
21 explicit STexture(Type type);
22
23 ~STexture() override;
24
25 bool LoadFile(const char* path);
26
27 bool LoadFromMemory(const unsigned char* rawData, int length);
28
29 virtual bool Load(unsigned char* data);
30
31 bool ReloadFile(const char* path);
32
33 bool Reload(unsigned char* data);
34
35 unsigned int GetTextureID() const {
36 return m_texId;
37 }
38
39 virtual bool InitTexture(int width, int height, int channel = GL_RGB, int internalFormat = GL_RGB8,
40 int glType = GL_UNSIGNED_BYTE);
41
42 bool InitTextureMipmap(int width, int height, int channel = GL_RGB, int internalFormat = GL_RGB8,
43 int glType = GL_UNSIGNED_BYTE);
44
45 virtual void SetParameteri(int targetName, int value) const;
46
47 virtual void SetParameterfv(int targetName, float* value) const;
48
49 void Release();
50
51 void Exterminate() override;
52
53 virtual void Bind(GLint location, int layout);
54
55 static void BindEmpty(GLint location, int layout, STexture::Type type = TEX_2D);
56
57 void GenerateMipmap() const;
58
59 Type GetType() const;
60
61 void SetType(Type type);
62
63 int getMWidth() const;
64
65 int getMHeight() const;
66
67 protected:
68 void Init(const AssetMgr::AssetReference* asset) override;
69
70 private:
71 static void LoadEmpty();
72
73 static int GetTypeToTargetGL(STexture::Type type);
74
75 protected:
76 Type m_type = TEX_2D;
77 int m_targetGL = GL_TEXTURE_2D;
78 int m_width = 0;
79 int m_height = 0;
80 int m_channels = 0;
81 int m_internalFormat = 0;
82 int m_glType = GL_UNSIGNED_BYTE;
83
84 unsigned int m_texId = 0;
85
86 private:
87 static unsigned int m_emptyTextureId;
88 };
89
90}