Skip to content

Commit 67f6758

Browse files
authored
Merge pull request #214 from RobLoach/unmanaged
Add TextureUnmanaged
2 parents 094bef1 + 2845bd0 commit 67f6758

File tree

7 files changed

+479
-404
lines changed

7 files changed

+479
-404
lines changed

examples/text/text_font_filters.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ int main(void)
2929

3030
// Generate mipmap levels to use trilinear filtering
3131
// NOTE: On 2D drawing it won't be noticeable, it looks like FILTER_BILINEAR
32-
GenTextureMipmaps(&font.texture);
32+
font.GetTexture().GenMipmaps();
3333

3434
raylib::Text msg("Loaded Font", font.GetBaseSize(), BLACK, font);
3535

3636
Vector2 fontPosition = { 40.0f, screenHeight/2.0f - 80.0f };
3737
Vector2 textSize = { 0.0f, 0.0f };
3838

3939
// Setup texture scaling filter
40-
SetTextureFilter(font.texture, TEXTURE_FILTER_POINT);
40+
font.GetTexture().SetFilter(TEXTURE_FILTER_POINT);
4141
int currentFontFilter = 0; // TEXTURE_FILTER_POINT
4242

4343
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
@@ -53,18 +53,18 @@ int main(void)
5353
// Choose font texture filter method
5454
if (IsKeyPressed(KEY_ONE))
5555
{
56-
SetTextureFilter(font.texture, TEXTURE_FILTER_POINT);
56+
font.GetTexture().SetFilter(TEXTURE_FILTER_POINT);
5757
currentFontFilter = 0;
5858
}
5959
else if (IsKeyPressed(KEY_TWO))
6060
{
61-
SetTextureFilter(font.texture, TEXTURE_FILTER_BILINEAR);
61+
font.GetTexture().SetFilter(TEXTURE_FILTER_BILINEAR);
6262
currentFontFilter = 1;
6363
}
6464
else if (IsKeyPressed(KEY_THREE))
6565
{
6666
// NOTE: Trilinear filter won't be noticed on 2D drawing
67-
SetTextureFilter(font.texture, TEXTURE_FILTER_TRILINEAR);
67+
font.GetTexture().SetFilter(TEXTURE_FILTER_TRILINEAR);
6868
currentFontFilter = 2;
6969
}
7070

include/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ install(FILES
3636
Sound.hpp
3737
Text.hpp
3838
Texture.hpp
39+
TextureUnmanaged.hpp
3940
Touch.hpp
4041
Vector2.hpp
4142
Vector3.hpp

include/Font.hpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "./raylib.hpp"
77
#include "./raylib-cpp-utils.hpp"
88
#include "./RaylibException.hpp"
9+
#include "./TextureUnmanaged.hpp"
910

1011
namespace raylib {
1112
/**
@@ -106,10 +107,23 @@ class Font : public ::Font {
106107
GETTERSETTER(int, BaseSize, baseSize)
107108
GETTERSETTER(int, GlyphCount, glyphCount)
108109
GETTERSETTER(int, GlyphPadding, glyphPadding)
109-
GETTERSETTER(::Texture2D, Texture, texture)
110110
GETTERSETTER(::Rectangle*, Recs, recs)
111111
GETTERSETTER(::GlyphInfo*, Glyphs, glyphs)
112112

113+
/**
114+
* Get the texture atlas containing the glyphs.
115+
*/
116+
inline TextureUnmanaged GetTexture() {
117+
return texture;
118+
}
119+
120+
/**
121+
* Set the texture atlas containing the glyphs.
122+
*/
123+
inline void SetTexture(const ::Texture& newTexture) {
124+
texture = newTexture;
125+
}
126+
113127
Font& operator=(const ::Font& font) {
114128
Unload();
115129
set(font);

include/RenderTexture.hpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "./raylib.hpp"
55
#include "./raylib-cpp-utils.hpp"
66
#include "./RaylibException.hpp"
7+
#include "./TextureUnmanaged.hpp"
78

89
namespace raylib {
910
/**
@@ -22,7 +23,8 @@ class RenderTexture : public ::RenderTexture {
2223
set(renderTexture);
2324
}
2425

25-
RenderTexture(unsigned int id, const ::Texture& texture, const ::Texture& depth) : ::RenderTexture{id, texture, depth} {}
26+
RenderTexture(unsigned int id, const ::Texture& texture, const ::Texture& depth) :
27+
::RenderTexture{id, texture, depth} {}
2628

2729
/**
2830
* Load texture for rendering (framebuffer)
@@ -42,8 +44,28 @@ class RenderTexture : public ::RenderTexture {
4244
}
4345

4446
GETTERSETTER(unsigned int, Id, id)
45-
GETTERSETTER(::Texture2D, Texture, texture)
46-
GETTERSETTER(::Texture2D, Depth, depth)
47+
48+
/**
49+
* Get the color buffer attachment texture.
50+
*/
51+
inline TextureUnmanaged GetTexture() {
52+
return texture;
53+
}
54+
55+
inline void SetTexture(const ::Texture& newTexture) {
56+
texture = newTexture;
57+
}
58+
59+
/**
60+
* Depth buffer attachment texture
61+
*/
62+
inline TextureUnmanaged GetDepth() {
63+
return depth;
64+
}
65+
66+
inline void SetDepth(const ::Texture& newDepth) {
67+
depth = newDepth;
68+
}
4769

4870
RenderTexture& operator=(const ::RenderTexture& texture) {
4971
set(texture);

0 commit comments

Comments
 (0)