view paper/rendering.tex @ 15:599e461dcb09

chapter "compare" add
author admin@mb22-no-macbook.local
date Mon, 23 Mar 2009 01:52:05 +0900
parents 08e4a7952793
children
line wrap: on
line source

\section{Rendering 部分の高速化}

\subsection{Texture の分割}
SPE の Local Store は 256KB しかないので、Texture データを
一度に転送すると容量を超えてしまう可能性がある。そこで、描画に必要な Texture データ
を分割し、転送するという手法を用いる。

\newpage

\begin{figure}[!h]
  \begin{center}
    \includegraphics[scale=0.45]{image/cerium_rendering_tile.pdf}
    \caption{Texture の分割}
    \label{fig:cerium-rendering}
  \end{center}
\end{figure}

Texture を 8 x 8 pixel 単位に分割するという手法を用いる。
また、分割した 8 x 8 pixel の Texture を Tile とし、
Tile Array に格納する(図\ref{fig:cerium-rendering})

\subsection{Tile Array を用いた Rendering}

\begin{figure}[!h]
  \begin{center}
    \includegraphics[scale=0.35]{image/Span-tile.pdf}
    \caption{Span から描画に必要な Tile の計算}
    \label{fig:span-tile}
  \end{center}
\end{figure}

\newpage

\begin{enumerate}
\item Polygon の Span から、描画に必要な pixel A を含む Tile を計算する。
\item pixel A を含む Tile 0 を DMA で取得する。
\item Tile 0 の pixel A の 情報 (RGBα値) を取得して描画を行う。
\end{enumerate}

\subsection{Texture の縮小画像の作成 ( Scale )}

描画されるオブジェクトが小さい場合、そのオブジェクトに
使用される Texture はそのままの大きさである必要はない。
そこで、読み込んだ Texture を2分の1ずつ縮小させた Scale を用意する (最小 8 x 8 pixel)。
描画に必要な Scale の Texture は、Span の長さから選択する。

\begin{figure}[!h]
  \begin{center}
    \includegraphics[scale=0.4]{image/Scale-A.pdf}
    \caption{Texture の縮小画像の作成}
    \label{fig:scale-a}
  \end{center}
\end{figure}

以下に Scale の作成と選択のプログラムを示す。
 \\
\begin{itemize}
\item Scale の作成
{\scriptsize
\begin{verbatim}

static uint32*
makeTapestry(int tex_w, int tex_h, uint32 *tex_src,
       int all_pixel_num, int scale_cnt)
{
 uint32 *tex_dest;

 int t = 0;
 int diff = TEXTURE_SPLIT_PIXEL;
 int p_diff = 1;
	
 tex_dest = (uint32*)manager->allocate(sizeof(int)*all_pixel_num);

 while (scale_cnt) {
  for (int y = 0; y < tex_h; y += diff) {
   for (int x = 0; x < tex_w; x += diff) {
    for (int j = 0; j < diff; j += p_diff) {
     for (int i = 0; i < diff; i += p_diff) {
      tex_dest[t++] = tex_src[(x+i) + tex_w*(y+j)];
     }
    }
   }
  }
			
 diff <<= 1;
 p_diff <<= 1;
 scale_cnt >>= 1;
 }
    
 return tex_dest;
}
\end{verbatim}
}
 \\
\item 最適 Scale の選択

{\scriptsize
\begin{verbatim}

static int
getScale(int width, int height, int tex_width, int tex_height, int scale_max)
{
 int base, tex_base;
 int scale = 1;

 /**
  * width と height で、長い方を基準に、
  * texture の scale を決める
  */
 if (width > height) {
  base = width;
  tex_base = tex_width;
 } else {
  base = height;
  tex_base = tex_height;
 }

 if (tex_base > base) {
  int t_scale = tex_base/base;
  while (t_scale >>= 1) {
   scale <<= 1;
  }
 }

 return (scale > scale_max) ? scale_max : scale;
}
\end{verbatim}
}
\end{itemize}