PageRenderTime 736ms CodeModel.GetById 573ms app.highlight 11ms RepoModel.GetById 150ms app.codeStats 0ms

/opengles/src/ContextMesh.cpp

http://ftk.googlecode.com/
C++ | 119 lines | 55 code | 22 blank | 42 comment | 9 complexity | cfa8fbc438486282f008f72e071738d6 MD5 | raw file
  1// ==========================================================================
  2//
  3// ContextMesg		Rendering Context Class for 3D Rendering Library
  4//
  5//					Mesh rendering
  6//
  7// --------------------------------------------------------------------------
  8//
  9// 03-25-2004		Hans-Martin Will	adaptation from prototype
 10//
 11// --------------------------------------------------------------------------
 12//
 13// Copyright (c) 2004, Hans-Martin Will. All rights reserved.
 14// 
 15// Redistribution and use in source and binary forms, with or without 
 16// modification, are permitted provided that the following conditions are 
 17// met:
 18// 
 19//	 *  Redistributions of source code must retain the above copyright
 20// 		notice, this list of conditions and the following disclaimer. 
 21//   *	Redistributions in binary form must reproduce the above copyright
 22// 		notice, this list of conditions and the following disclaimer in the 
 23// 		documentation and/or other materials provided with the distribution. 
 24// 
 25// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 26// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 27// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 28// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 29// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 
 30// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 31// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 32// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 33// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 34// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
 35// THE POSSIBILITY OF SUCH DAMAGE.
 36//
 37// ==========================================================================
 38
 39
 40#include "stdafx.h"
 41#include "Context.h"
 42
 43
 44using namespace EGL;
 45
 46/* 
 47   Added by Valtteri Rahkonen:
 48   This is propably legacy (not declared on Context.h) and it wont compile
 49   with gcc, so I just if it out.
 50*/
 51#if !defined(EGL_ON_LINUX)
 52
 53void Context :: DrawMesh(GLsizei count, GLenum type, GLsizei stride,
 54						 GLsizei offsetVertex, GLsizei strideVertex,
 55						 GLsizei offsetNormal, GLsizei strideNormal,
 56						 GLsizei offsetTexture, GLsizei strideTexture,
 57						 GLsizei offsetColor, GLsizei strideColor, 
 58						 const GLvoid *pointer) {
 59
 60	m_Rasterizer->PrepareTriangle();
 61	RasterPos pos[3];
 62
 63	if (type == GL_UNSIGNED_BYTE) {
 64
 65		while (count-- > 0) {
 66			const U8 * pVertexIndex = reinterpret_cast<const U8 *>(pointer) + offsetVertex; 
 67			const U8 * pNormalIndex = reinterpret_cast<const U8 *>(pointer) + offsetNormal; 
 68			const U8 * pTextureIndex = reinterpret_cast<const U8 *>(pointer) + offsetTexture; 
 69			const U8 * pColorIndex = reinterpret_cast<const U8 *>(pointer) + offsetColor; 
 70
 71			for (size_t index = 0; index < 3; ++index) {
 72				
 73				SelectArrayElement(*reinterpret_cast<const GLubyte *>(pVertexIndex),
 74								   *reinterpret_cast<const GLubyte *>(pNormalIndex),
 75								   *reinterpret_cast<const GLubyte *>(pTextureIndex),
 76								   *reinterpret_cast<const GLubyte *>(pColorIndex));
 77
 78				CurrentValuesToRasterPos(pos + index);
 79
 80				pVertexIndex += strideVertex;
 81				pNormalIndex += strideNormal;
 82				pTextureIndex += strideTexture;
 83				pColorIndex += strideColor;
 84			}
 85
 86			RenderTriangle(pos[0], pos[1], pos[2]);
 87	
 88			pointer = reinterpret_cast<const U8 *>(pointer) + stride;
 89		}
 90	} else if (type == GL_UNSIGNED_SHORT) {
 91		while (count-- > 0) {
 92			const U8 * pVertexIndex = reinterpret_cast<const U8 *>(pointer) + offsetVertex; 
 93			const U8 * pNormalIndex = reinterpret_cast<const U8 *>(pointer) + offsetNormal; 
 94			const U8 * pTextureIndex = reinterpret_cast<const U8 *>(pointer) + offsetTexture; 
 95			const U8 * pColorIndex = reinterpret_cast<const U8 *>(pointer) + offsetColor; 
 96
 97			for (size_t index = 0; index < 3; ++index) {
 98				
 99				SelectArrayElement(*reinterpret_cast<const GLushort *>(pVertexIndex),
100								   *reinterpret_cast<const GLushort *>(pNormalIndex),
101								   *reinterpret_cast<const GLushort *>(pTextureIndex),
102								   *reinterpret_cast<const GLushort *>(pColorIndex));
103
104				CurrentValuesToRasterPos(pos + index);
105
106				pVertexIndex += strideVertex;
107				pNormalIndex += strideNormal;
108				pTextureIndex += strideTexture;
109				pColorIndex += strideColor;
110			}
111
112			RenderTriangle(pos[0], pos[1], pos[2]);
113	
114			pointer = reinterpret_cast<const U8 *>(pointer) + stride;
115		}
116	}
117}
118
119#endif