Direct access to OpenGL texture memory

15
CONFIDENTIAL ©2013 GlobalLogic Inc. by Rostyslav Lesovyi OpenGL's texture DMA DMA stands for Direct Memory Access

description

This presentation regards working with graphic applications, and in particular it deals with OpenGL's texture direct memory access. Presentation by Rostyslav Lesovyi, Software engineer, GlobalLogic. Mobile TechTalk, Lviv, 2014. More details - www.globallogic.com.ua/press-releases/mobile-techtalk-lviv/

Transcript of Direct access to OpenGL texture memory

Page 1: Direct access to OpenGL texture memory

CONFIDENTIAL©2013 GlobalLogic Inc.

by Rostyslav Lesovyi

OpenGL's texture DMADMA stands for Direct Memory Access

Page 2: Direct access to OpenGL texture memory

©2013 GlobalLogic Inc. CONFIDENTIAL

Page 3: Direct access to OpenGL texture memory

CONFIDENTIAL

• Async texture upload

• Rapid updates of texture or its parts

• Texture data download

Problems

Page 4: Direct access to OpenGL texture memory

CONFIDENTIAL

• Simple download/upload

• Shared OpenGL contexts

• PBO (Pixel Buffer Objects)

• EGLImage and GraphicBuffer

Solutions

Page 5: Direct access to OpenGL texture memory

CONFIDENTIAL

Pros:

• very easy to use and understand

Cons:

• super slow!!!

• operates in a single thread

• glTexImage2D/glTexSubImage2D for upload• glReadPixels for download

Simple download/upload

Page 6: Direct access to OpenGL texture memory

CONFIDENTIAL

• create background thread

• create shared OpenGL context

• attach context to background thread

• use glTexImage2D, glTexSubImage2D or glReadPixels

What to do

Shared OpenGL contexts

Page 7: Direct access to OpenGL texture memory

CONFIDENTIAL

EGLContext context =egl.eglCreateContext(display, config, parentContext, null);

EGLSurface surface =egl.eglCreatePbufferSurface(display, config, surfaceAttributes);

Shared context creation:

Shared OpenGL contexts

Page 8: Direct access to OpenGL texture memory

CONFIDENTIAL

EGLContext context =egl.eglCreateContext(display, config, parentContext, null);

EGLSurface surface =egl.eglCreatePbufferSurface(display, config, surfaceAttributes);

Shared OpenGL contexts

Page 9: Direct access to OpenGL texture memory

CONFIDENTIAL

Pros:

• relatively easy to use

• full threading support

Cons:

• relying on slow functions

Shared OpenGL contexts

More info:https://github.com/pcwalton/test-async-texture-upload

Page 10: Direct access to OpenGL texture memory

CONFIDENTIAL

Pixel Buffer Objects

Page 11: Direct access to OpenGL texture memory

CONFIDENTIAL

Pixel Buffer ObjectsPros:

• relatively easy to use

• supports asynchronous upload/download

Cons:

• Android 4.3+ / OpenGL ES 3.0

• hard to use for two-ways texture updates

• still copies from PBO to CPU and vice versa

More info:http://www.songho.ca/opengl/gl_pbo.html

Page 12: Direct access to OpenGL texture memory

CONFIDENTIAL

EGLImage and GraphicBuffer

= Texture image data (actual pixels)

Page 13: Direct access to OpenGL texture memory

CONFIDENTIAL

EGLImage and GraphicBufferPros:

• direct access to texture’s pixel data

• can be accessed by any thread

• supported by Android 2.0.1+

Cons:

• requires NDK

• requires usage of ARM library

More info:https://wiki.mozilla.org/Platform/GFX/Gralloc

Page 14: Direct access to OpenGL texture memory

CONFIDENTIAL©2013 GlobalLogic Inc.

Q&A

Page 15: Direct access to OpenGL texture memory

CONFIDENTIAL©2013 GlobalLogic Inc.

Thank you