\hypertarget{_raspi_tex_8c}{}\section{/\+Volumes/\+W\+O\+R\+K\+\_\+\+I\+N\+\_\+\+P\+R\+O\+G\+R\+E\+S\+S/\+R\+A\+S\+P\+B\+E\+R\+R\+Y\+\_\+\+P\+I/github/userland/host\+\_\+applications/linux/apps/raspicam/\+Raspi\+Tex.c File Reference}
\label{_raspi_tex_8c}\index{/\+Volumes/\+W\+O\+R\+K\+\_\+\+I\+N\+\_\+\+P\+R\+O\+G\+R\+E\+S\+S/\+R\+A\+S\+P\+B\+E\+R\+R\+Y\+\_\+\+P\+I/github/userland/host\+\_\+applications/linux/apps/raspicam/\+Raspi\+Tex.\+c@{/\+Volumes/\+W\+O\+R\+K\+\_\+\+I\+N\+\_\+\+P\+R\+O\+G\+R\+E\+S\+S/\+R\+A\+S\+P\+B\+E\+R\+R\+Y\+\_\+\+P\+I/github/userland/host\+\_\+applications/linux/apps/raspicam/\+Raspi\+Tex.\+c}}
{\ttfamily \#include \char`\"{}Raspi\+Tex.\+h\char`\"{}}\\*
{\ttfamily \#include \char`\"{}Raspi\+C\+L\+I.\+h\char`\"{}}\\*
{\ttfamily \#include $<$math.\+h$>$}\\*
{\ttfamily \#include $<$stdio.\+h$>$}\\*
{\ttfamily \#include $<$stdlib.\+h$>$}\\*
{\ttfamily \#include $<$string.\+h$>$}\\*
{\ttfamily \#include $<$sys/time.\+h$>$}\\*
{\ttfamily \#include $<$E\+G\+L/egl.\+h$>$}\\*
{\ttfamily \#include $<$E\+G\+L/eglext.\+h$>$}\\*
{\ttfamily \#include $<$G\+L\+E\+S/gl.\+h$>$}\\*
{\ttfamily \#include $<$G\+L\+E\+S/glext.\+h$>$}\\*
{\ttfamily \#include \char`\"{}Raspi\+Tex\+Util.\+h\char`\"{}}\\*
{\ttfamily \#include \char`\"{}interface/vcos/vcos.\+h\char`\"{}}\\*
{\ttfamily \#include \char`\"{}interface/mmal/mmal\+\_\+buffer.\+h\char`\"{}}\\*
{\ttfamily \#include \char`\"{}interface/mmal/util/mmal\+\_\+util.\+h\char`\"{}}\\*
{\ttfamily \#include \char`\"{}interface/mmal/util/mmal\+\_\+util\+\_\+params.\+h\char`\"{}}\\*
{\ttfamily \#include \char`\"{}tga.\+h\char`\"{}}\\*
{\ttfamily \#include \char`\"{}gl\+\_\+scenes/mirror.\+h\char`\"{}}\\*
{\ttfamily \#include \char`\"{}gl\+\_\+scenes/sobel.\+h\char`\"{}}\\*
{\ttfamily \#include \char`\"{}gl\+\_\+scenes/square.\+h\char`\"{}}\\*
{\ttfamily \#include \char`\"{}gl\+\_\+scenes/teapot.\+h\char`\"{}}\\*
{\ttfamily \#include \char`\"{}gl\+\_\+scenes/yuv.\+h\char`\"{}}\\*
\subsection*{Macros}
\begin{DoxyCompactItemize}
\item 
\hypertarget{_raspi_tex_8c_a93493eb8fae5549bd5be67f3449245e0}{}\#define {\bfseries D\+E\+F\+A\+U\+L\+T\+\_\+\+W\+I\+D\+T\+H}~640\label{_raspi_tex_8c_a93493eb8fae5549bd5be67f3449245e0}

\item 
\hypertarget{_raspi_tex_8c_a1879f9e5604a01f0983829846001ab23}{}\#define {\bfseries D\+E\+F\+A\+U\+L\+T\+\_\+\+H\+E\+I\+G\+H\+T}~480\label{_raspi_tex_8c_a1879f9e5604a01f0983829846001ab23}

\item 
\hypertarget{_raspi_tex_8c_a3d1b75660f7a044e8772818f89b2c501}{}\#define {\bfseries Command\+G\+L\+Scene}~1\label{_raspi_tex_8c_a3d1b75660f7a044e8772818f89b2c501}

\item 
\hypertarget{_raspi_tex_8c_ace3b0bd64cee995e59afef6cfb533ef5}{}\#define {\bfseries Command\+G\+L\+Win}~2\label{_raspi_tex_8c_ace3b0bd64cee995e59afef6cfb533ef5}

\end{DoxyCompactItemize}
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
int \hyperlink{_raspi_tex_8c_aeb5497eb80a286fdf9d6c8568b0e7614}{raspitex\+\_\+parse\+\_\+cmdline} (\hyperlink{struct_r_a_s_p_i_t_e_x___s_t_a_t_e}{R\+A\+S\+P\+I\+T\+E\+X\+\_\+\+S\+T\+A\+T\+E} $\ast$state, const char $\ast$arg1, const char $\ast$arg2)
\item 
void \hyperlink{_raspi_tex_8c_a98b056f0bc7e55f48ea3f95cc62ab767}{raspitex\+\_\+display\+\_\+help} ()
\item 
\hypertarget{_raspi_tex_8c_a15e5e2ea5be077d75eef95d2accf7ffb}{}int {\bfseries raspitex\+\_\+configure\+\_\+preview\+\_\+port} (\hyperlink{struct_r_a_s_p_i_t_e_x___s_t_a_t_e}{R\+A\+S\+P\+I\+T\+E\+X\+\_\+\+S\+T\+A\+T\+E} $\ast$state, M\+M\+A\+L\+\_\+\+P\+O\+R\+T\+\_\+\+T $\ast$preview\+\_\+port)\label{_raspi_tex_8c_a15e5e2ea5be077d75eef95d2accf7ffb}

\item 
\hypertarget{_raspi_tex_8c_a9222212815a7ff70aef22dcc73792639}{}int {\bfseries raspitex\+\_\+init} (\hyperlink{struct_r_a_s_p_i_t_e_x___s_t_a_t_e}{R\+A\+S\+P\+I\+T\+E\+X\+\_\+\+S\+T\+A\+T\+E} $\ast$state)\label{_raspi_tex_8c_a9222212815a7ff70aef22dcc73792639}

\item 
\hypertarget{_raspi_tex_8c_a79729992f4649430719acdd184ee41c1}{}void {\bfseries raspitex\+\_\+destroy} (\hyperlink{struct_r_a_s_p_i_t_e_x___s_t_a_t_e}{R\+A\+S\+P\+I\+T\+E\+X\+\_\+\+S\+T\+A\+T\+E} $\ast$state)\label{_raspi_tex_8c_a79729992f4649430719acdd184ee41c1}

\item 
\hypertarget{_raspi_tex_8c_ab5c15ef70a5cb2adfe9a00ba5dae5e48}{}void {\bfseries raspitex\+\_\+set\+\_\+defaults} (\hyperlink{struct_r_a_s_p_i_t_e_x___s_t_a_t_e}{R\+A\+S\+P\+I\+T\+E\+X\+\_\+\+S\+T\+A\+T\+E} $\ast$state)\label{_raspi_tex_8c_ab5c15ef70a5cb2adfe9a00ba5dae5e48}

\item 
\hypertarget{_raspi_tex_8c_a654b91398d5a12049e23c6022ec647ee}{}void {\bfseries raspitex\+\_\+stop} (\hyperlink{struct_r_a_s_p_i_t_e_x___s_t_a_t_e}{R\+A\+S\+P\+I\+T\+E\+X\+\_\+\+S\+T\+A\+T\+E} $\ast$state)\label{_raspi_tex_8c_a654b91398d5a12049e23c6022ec647ee}

\item 
int \hyperlink{_raspi_tex_8c_a011084dc0f75e0ae08b53998360b9961}{raspitex\+\_\+start} (\hyperlink{struct_r_a_s_p_i_t_e_x___s_t_a_t_e}{R\+A\+S\+P\+I\+T\+E\+X\+\_\+\+S\+T\+A\+T\+E} $\ast$state)
\item 
int \hyperlink{_raspi_tex_8c_a94b3a0f896e510831da779cdc45b8464}{raspitex\+\_\+capture} (\hyperlink{struct_r_a_s_p_i_t_e_x___s_t_a_t_e}{R\+A\+S\+P\+I\+T\+E\+X\+\_\+\+S\+T\+A\+T\+E} $\ast$state, F\+I\+L\+E $\ast$output\+\_\+file)
\end{DoxyCompactItemize}


\subsection{Detailed Description}
A simple framework for extending a M\+M\+A\+L application to render buffers via Open\+G\+L.

M\+M\+A\+L buffers are often in Y\+U\+V colour space and in either a planar or tile format which is not supported directly by V3\+D. Instead of copying the buffer from the G\+P\+U and doing a colour space / pixel format conversion the G\+L\+\_\+\+O\+E\+S\+\_\+\+E\+G\+L\+\_\+image\+\_\+external is used. This allows an E\+G\+L image to be created from G\+P\+U buffer handle (M\+M\+A\+L opaque buffer handle). The E\+G\+L image may then be used to create a texture (gl\+E\+G\+L\+Image\+Target\+Texture2\+D\+O\+E\+S) and drawn by either Open\+G\+L E\+S 1.\+0 or 2.\+0 contexts.

Notes\+: 1) G\+L\+\_\+\+O\+E\+S\+\_\+\+E\+G\+L\+\_\+image\+\_\+external textures always return pixels in R\+G\+B\+A format. This is also the case when used from a fragment shader.

2) The driver implementation creates a new R\+G\+B\+\_\+565 buffer and does the color space conversion from Y\+U\+V. This happens in G\+P\+U memory using the vector processor.

3) Each E\+G\+L external image in use will consume G\+P\+U memory for the R\+G\+B 565 buffer. In addition, the G\+L pipeline might require more than one E\+G\+L image to be retained in G\+P\+U memory until the drawing commands are flushed.

Typically 128 M\+B of G\+P\+U memory is sufficient for 720p viewfinder and 720p G\+L surface. If both the viewfinder and the G\+L surface are 1080p then 256\+M\+B of G\+P\+U memory is recommended, otherwise, for non-\/trivial scenes the system can run out of G\+P\+U memory whilst the camera is running.

4) It is important to make sure that the M\+M\+A\+L opaque buffer is not returned to M\+M\+A\+L before the G\+L driver has completed the asynchronous call to gl\+E\+G\+L\+Image\+Target\+Texture2\+D\+O\+E\+S. Deferring destruction of the E\+G\+L image and the buffer return to M\+M\+A\+L until after egl\+Swap\+Buffers is the recommended.

See also\+: \href{http://www.khronos.org/registry/gles/extensions/OES/OES_EGL_image_external.txt}{\tt http\+://www.\+khronos.\+org/registry/gles/extensions/\+O\+E\+S/\+O\+E\+S\+\_\+\+E\+G\+L\+\_\+image\+\_\+external.\+txt} 

\subsection{Function Documentation}
\hypertarget{_raspi_tex_8c_a94b3a0f896e510831da779cdc45b8464}{}\index{Raspi\+Tex.\+c@{Raspi\+Tex.\+c}!raspitex\+\_\+capture@{raspitex\+\_\+capture}}
\index{raspitex\+\_\+capture@{raspitex\+\_\+capture}!Raspi\+Tex.\+c@{Raspi\+Tex.\+c}}
\subsubsection[{raspitex\+\_\+capture}]{\setlength{\rightskip}{0pt plus 5cm}int raspitex\+\_\+capture (
\begin{DoxyParamCaption}
\item[{{\bf R\+A\+S\+P\+I\+T\+E\+X\+\_\+\+S\+T\+A\+T\+E} $\ast$}]{state, }
\item[{F\+I\+L\+E $\ast$}]{output\+\_\+file}
\end{DoxyParamCaption}
)}\label{_raspi_tex_8c_a94b3a0f896e510831da779cdc45b8464}
Writes the next G\+L frame-\/buffer to a R\+A\+W .ppm formatted file using the specified file-\/handle. 
\begin{DoxyParams}{Parameters}
{\em state} & Pointer to the G\+L preview state. \\
\hline
{\em outpt\+\_\+file} & Output file handle for the ppm image. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
Zero on success. 
\end{DoxyReturn}
\hypertarget{_raspi_tex_8c_a98b056f0bc7e55f48ea3f95cc62ab767}{}\index{Raspi\+Tex.\+c@{Raspi\+Tex.\+c}!raspitex\+\_\+display\+\_\+help@{raspitex\+\_\+display\+\_\+help}}
\index{raspitex\+\_\+display\+\_\+help@{raspitex\+\_\+display\+\_\+help}!Raspi\+Tex.\+c@{Raspi\+Tex.\+c}}
\subsubsection[{raspitex\+\_\+display\+\_\+help}]{\setlength{\rightskip}{0pt plus 5cm}void raspitex\+\_\+display\+\_\+help (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
)}\label{_raspi_tex_8c_a98b056f0bc7e55f48ea3f95cc62ab767}
Display help for command line options \hypertarget{_raspi_tex_8c_aeb5497eb80a286fdf9d6c8568b0e7614}{}\index{Raspi\+Tex.\+c@{Raspi\+Tex.\+c}!raspitex\+\_\+parse\+\_\+cmdline@{raspitex\+\_\+parse\+\_\+cmdline}}
\index{raspitex\+\_\+parse\+\_\+cmdline@{raspitex\+\_\+parse\+\_\+cmdline}!Raspi\+Tex.\+c@{Raspi\+Tex.\+c}}
\subsubsection[{raspitex\+\_\+parse\+\_\+cmdline}]{\setlength{\rightskip}{0pt plus 5cm}int raspitex\+\_\+parse\+\_\+cmdline (
\begin{DoxyParamCaption}
\item[{{\bf R\+A\+S\+P\+I\+T\+E\+X\+\_\+\+S\+T\+A\+T\+E} $\ast$}]{state, }
\item[{const char $\ast$}]{arg1, }
\item[{const char $\ast$}]{arg2}
\end{DoxyParamCaption}
)}\label{_raspi_tex_8c_aeb5497eb80a286fdf9d6c8568b0e7614}
Parse a possible command pair -\/ command and parameter 
\begin{DoxyParams}{Parameters}
{\em arg1} & Command \\
\hline
{\em arg2} & Parameter (could be N\+U\+L\+L) \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
How many parameters were used, 0,1,2 
\end{DoxyReturn}
\hypertarget{_raspi_tex_8c_a011084dc0f75e0ae08b53998360b9961}{}\index{Raspi\+Tex.\+c@{Raspi\+Tex.\+c}!raspitex\+\_\+start@{raspitex\+\_\+start}}
\index{raspitex\+\_\+start@{raspitex\+\_\+start}!Raspi\+Tex.\+c@{Raspi\+Tex.\+c}}
\subsubsection[{raspitex\+\_\+start}]{\setlength{\rightskip}{0pt plus 5cm}int raspitex\+\_\+start (
\begin{DoxyParamCaption}
\item[{{\bf R\+A\+S\+P\+I\+T\+E\+X\+\_\+\+S\+T\+A\+T\+E} $\ast$}]{state}
\end{DoxyParamCaption}
)}\label{_raspi_tex_8c_a011084dc0f75e0ae08b53998360b9961}
Starts the worker / G\+L renderer thread. \begin{DoxyPrecond}{Precondition}
raspitex\+\_\+init was successful 

raspitex\+\_\+configure\+\_\+preview\+\_\+port was successful 
\end{DoxyPrecond}

\begin{DoxyParams}{Parameters}
{\em state} & Pointer to the G\+L preview state. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
Zero on success, otherwise, -\/1 is returned 
\end{DoxyReturn}
