summaryrefslogtreecommitdiffstats
path: root/libvo/gl_common.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-11-01 02:12:47 +0100
committerwm4 <wm4@nowhere>2012-11-01 02:12:47 +0100
commit84829a4ea1903e5db5782b72861fabc503a589cb (patch)
tree26b4acbaf6dd4b255278dcc67f28bd83357c3b86 /libvo/gl_common.c
parente45dd051c304dec189d0d4d792a89c2988c3fa71 (diff)
parentf4069259cf7ffd24ac2a5b64e26a386185e94c7b (diff)
downloadmpv-84829a4ea1903e5db5782b72861fabc503a589cb.tar.bz2
mpv-84829a4ea1903e5db5782b72861fabc503a589cb.tar.xz
Merge branch 'osd_changes' into master
Conflicts: DOCS/man/en/options.rst
Diffstat (limited to 'libvo/gl_common.c')
-rw-r--r--libvo/gl_common.c47
1 files changed, 46 insertions, 1 deletions
diff --git a/libvo/gl_common.c b/libvo/gl_common.c
index 20c3d44af2..80db2eacc4 100644
--- a/libvo/gl_common.c
+++ b/libvo/gl_common.c
@@ -46,6 +46,8 @@
#include "aspect.h"
#include "pnm_loader.h"
#include "options.h"
+#include "sub/sub.h"
+#include "bitmap_packer.h"
//! \defgroup glgeneral OpenGL general helper functions
@@ -904,6 +906,31 @@ void glUploadTex(GL *gl, GLenum target, GLenum format, GLenum type,
gl->TexSubImage2D(target, 0, x, y, w, y_max - y, format, type, data);
}
+// Like glUploadTex, but upload a byte array with all elements set to val.
+// If scratch is not NULL, points to a resizeable talloc memory block than can
+// be freely used by the function (for avoiding temporary memory allocations).
+void glClearTex(GL *gl, GLenum target, GLenum format, GLenum type,
+ int x, int y, int w, int h, uint8_t val, void **scratch)
+{
+ int bpp = glFmt2bpp(format, type);
+ int stride = w * bpp;
+ int size = h * stride;
+ if (size < 1)
+ return;
+ void *data = scratch ? *scratch : NULL;
+ if (talloc_get_size(data) < size)
+ data = talloc_realloc(NULL, data, char *, size);
+ memset(data, val, size);
+ glAdjustAlignment(gl, stride);
+ gl->PixelStorei(GL_UNPACK_ROW_LENGTH, w);
+ gl->TexSubImage2D(target, 0, x, y, w, h, format, type, data);
+ if (scratch) {
+ *scratch = data;
+ } else {
+ talloc_free(data);
+ }
+}
+
/**
* \brief download a texture, handling things like stride and slices
* \param target texture target, usually GL_TEXTURE_2D
@@ -1853,7 +1880,7 @@ void glDisable3D(GL *gl, int type)
gl->ColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
break;
case GL_3D_QUADBUFFER:
- gl->DrawBuffer(vo_doublebuffering ? GL_BACK : GL_FRONT);
+ gl->DrawBuffer(GL_BACK);
gl->GetIntegerv(GL_DRAW_BUFFER, &buffer);
switch (buffer) {
case GL_FRONT:
@@ -1938,6 +1965,24 @@ void glDrawTex(GL *gl, GLfloat x, GLfloat y, GLfloat w, GLfloat h,
gl->End();
}
+mp_image_t *glGetWindowScreenshot(GL *gl)
+{
+ GLint vp[4]; //x, y, w, h
+ gl->GetIntegerv(GL_VIEWPORT, vp);
+ mp_image_t *image = alloc_mpi(vp[2], vp[3], IMGFMT_RGB24);
+ gl->BindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
+ gl->PixelStorei(GL_PACK_ALIGNMENT, 0);
+ gl->PixelStorei(GL_PACK_ROW_LENGTH, 0);
+ gl->ReadBuffer(GL_FRONT);
+ //flip image while reading
+ for (int y = 0; y < vp[3]; y++) {
+ gl->ReadPixels(vp[0], vp[1] + vp[3] - y - 1, vp[2], 1,
+ GL_RGB, GL_UNSIGNED_BYTE,
+ image->planes[0] + y * image->stride[0]);
+ }
+ return image;
+}
+
#ifdef CONFIG_GL_COCOA
#include "cocoa_common.h"