summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorRay <[email protected]>2020-06-25 16:26:59 +0200
committerRay <[email protected]>2020-06-25 16:26:59 +0200
commitba39a1b304bc8af27d7cd319a06e4c4767997f4e (patch)
treec3d85f4402e3707be55a476496b890e1d21cdb7d /src
parent25fb24ba7d8cb90a32ae3b7a57f4a1a87a8f7319 (diff)
downloadraylib-ba39a1b304bc8af27d7cd319a06e4c4767997f4e.tar.gz
raylib-ba39a1b304bc8af27d7cd319a06e4c4767997f4e.zip
ADDED: UpdateTextureRec()
Diffstat (limited to 'src')
-rw-r--r--src/raylib.h1
-rw-r--r--src/rlgl.h6
-rw-r--r--src/textures.c9
3 files changed, 12 insertions, 4 deletions
diff --git a/src/raylib.h b/src/raylib.h
index 3894a4a1..e456f5fe 100644
--- a/src/raylib.h
+++ b/src/raylib.h
@@ -1172,6 +1172,7 @@ RLAPI RenderTexture2D LoadRenderTexture(int width, int height);
RLAPI void UnloadTexture(Texture2D texture); // Unload texture from GPU memory (VRAM)
RLAPI void UnloadRenderTexture(RenderTexture2D target); // Unload render texture from GPU memory (VRAM)
RLAPI void UpdateTexture(Texture2D texture, const void *pixels); // Update GPU texture with new data
+RLAPI void UpdateTextureRec(Texture2D texture, Rectangle rec, const void *pixels); // Update GPU texture rectangle with new data
RLAPI Image GetTextureData(Texture2D texture); // Get pixel data from GPU texture and return an Image
RLAPI Image GetScreenData(void); // Get pixel data from screen buffer and return an Image (screenshot)
diff --git a/src/rlgl.h b/src/rlgl.h
index e6ec4b7c..94a4d0b3 100644
--- a/src/rlgl.h
+++ b/src/rlgl.h
@@ -528,7 +528,7 @@ RLAPI Vector3 rlUnproject(Vector3 source, Matrix proj, Matrix view); // Get wor
RLAPI unsigned int rlLoadTexture(void *data, int width, int height, int format, int mipmapCount); // Load texture in GPU
RLAPI unsigned int rlLoadTextureDepth(int width, int height, int bits, bool useRenderBuffer); // Load depth texture/renderbuffer (to be attached to fbo)
RLAPI unsigned int rlLoadTextureCubemap(void *data, int size, int format); // Load texture cubemap
-RLAPI void rlUpdateTexture(unsigned int id, int width, int height, int format, const void *data); // Update GPU texture with new data
+RLAPI void rlUpdateTexture(unsigned int id, int offsetX, int offsetY, int width, int height, int format, const void *data); // Update GPU texture with new data
RLAPI void rlGetGlTextureFormats(int format, unsigned int *glInternalFormat, unsigned int *glFormat, unsigned int *glType); // Get OpenGL internal formats
RLAPI void rlUnloadTexture(unsigned int id); // Unload texture from GPU memory
@@ -2144,7 +2144,7 @@ unsigned int rlLoadTextureCubemap(void *data, int size, int format)
// Update already loaded texture in GPU with new data
// NOTE: We don't know safely if internal texture format is the expected one...
-void rlUpdateTexture(unsigned int id, int width, int height, int format, const void *data)
+void rlUpdateTexture(unsigned int id, int offsetX, int offsetY, int width, int height, int format, const void *data)
{
glBindTexture(GL_TEXTURE_2D, id);
@@ -2153,7 +2153,7 @@ void rlUpdateTexture(unsigned int id, int width, int height, int format, const v
if ((glInternalFormat != -1) && (format < COMPRESSED_DXT1_RGB))
{
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, glFormat, glType, (unsigned char *)data);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, offsetY, offsetY, width, height, glFormat, glType, (unsigned char *)data);
}
else TRACELOG(LOG_WARNING, "TEXTURE: [ID %i] Failed to update for current texture format (%i)", id, format);
}
diff --git a/src/textures.c b/src/textures.c
index 8f93383e..85a7c77e 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -2798,7 +2798,14 @@ void UnloadRenderTexture(RenderTexture2D target)
// NOTE: pixels data must match texture.format
void UpdateTexture(Texture2D texture, const void *pixels)
{
- rlUpdateTexture(texture.id, texture.width, texture.height, texture.format, pixels);
+ rlUpdateTexture(texture.id, 0, 0, texture.width, texture.height, texture.format, pixels);
+}
+
+// Update GPU texture rectangle with new data
+// NOTE: pixels data must match texture.format
+void UpdateTextureRec(Texture2D texture, Rectangle rec, const void *pixels)
+{
+ rlUpdateTexture(texture.id, (int)rec.x, (int)rec.y, (int)rec.width, (int)rec.height, texture.format, pixels);
}
// Get pixel data from GPU texture and return an Image