PageRenderTime 32ms CodeModel.GetById 1ms app.highlight 24ms RepoModel.GetById 1ms app.codeStats 1ms

/opengles/src/ContextMaterial.cpp

http://ftk.googlecode.com/
C++ | 148 lines | 79 code | 29 blank | 40 comment | 14 complexity | 86caac3435153b42c5c91468e4138cde MD5 | raw file
  1// ==========================================================================
  2//
  3// ContextMaterial.cpp	Rendering Context Class for 3D Rendering Library
  4//
  5//						Material related settings
  6//
  7// --------------------------------------------------------------------------
  8//
  9// 08-02-2003	Hans-Martin Will	initial version
 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#include "RasterizerState.h"
 43#include "Utils.h"
 44
 45using namespace EGL;
 46
 47
 48// ==========================================================================
 49// Material Functions on Context
 50// ==========================================================================
 51
 52void Context :: Materialx(GLenum face, GLenum pname, GLfixed param) { 
 53
 54	if (face != GL_FRONT_AND_BACK) {
 55		RecordError(GL_INVALID_ENUM);
 56		return;
 57	}
 58
 59	Material * material = &m_FrontMaterial;
 60
 61	switch (pname) {
 62	case GL_SHININESS:
 63		if (param < 0 || param > EGL_FixedFromInt(128)) {
 64			RecordError(GL_INVALID_VALUE);
 65		} else {
 66			material->SetSpecularExponent(param);
 67		}
 68
 69		break;
 70
 71	default:
 72		RecordError(GL_INVALID_ENUM);
 73		return;
 74	}
 75}
 76
 77void Context :: Materialxv(GLenum face, GLenum pname, const GLfixed *params) { 
 78
 79	if (face != GL_FRONT_AND_BACK) {
 80		RecordError(GL_INVALID_ENUM);
 81		return;
 82	}
 83
 84	Material * material = &m_FrontMaterial;
 85
 86	switch (pname) {
 87	case GL_AMBIENT:
 88		material->SetAmbientColor(FractionalColor::Clamp(params));
 89		break;
 90
 91	case GL_DIFFUSE:
 92		material->SetDiffuseColor(FractionalColor::Clamp(params));
 93		break;
 94
 95	case GL_AMBIENT_AND_DIFFUSE:
 96		material->SetAmbientColor(FractionalColor::Clamp(params));
 97		material->SetDiffuseColor(FractionalColor::Clamp(params));
 98		break;
 99
100	case GL_SPECULAR:
101		material->SetSpecularColor(FractionalColor::Clamp(params));
102		break;
103
104	case GL_EMISSION:
105		material->SetEmissiveColor(FractionalColor::Clamp(params));
106		break;
107
108	default:
109		Materialx(face, pname, *params);
110		break;
111	}
112}
113
114bool Context :: GetMaterialxv(GLenum face, GLenum pname, GLfixed *params) {
115	if (face != GL_FRONT && face != GL_BACK) {
116		RecordError(GL_INVALID_ENUM);
117		return false;
118	}
119
120	switch (pname) {
121	case GL_AMBIENT:
122		CopyColor(m_FrontMaterial.GetAmbientColor(), params);
123		break;
124
125	case GL_DIFFUSE:
126		CopyColor(m_FrontMaterial.GetDiffuseColor(), params);
127		break;
128
129	case GL_SPECULAR:
130		CopyColor(m_FrontMaterial.GetSpecularColor(), params);
131		break;
132
133	case GL_EMISSION:
134		CopyColor(m_FrontMaterial.GetEmissiveColor(), params);
135		break;
136
137	case GL_SHININESS:
138		params[0] = m_FrontMaterial.GetSpecularExponent();
139		break;
140
141	default:
142		RecordError(GL_INVALID_ENUM);
143		return false;
144	}
145
146	return true;
147}
148