/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ // Original file Copyright Crytek GMBH or its affiliates, used under license. // Description : 2D look up table for surfaces #ifndef _SURFACES_LOOKUP_TABLE_H_ #define _SURFACES_LOOKUP_TABLE_H_ #pragma once namespace MaterialEffectsUtils { template struct SSurfacesLookupTable { void Create(size_t rows, size_t cols) { SAFE_DELETE_ARRAY(m_pData); m_nRows = rows; m_nCols = cols; m_pData = new T[m_nRows * m_nCols]; memset(m_pData, 0, m_nRows * m_nCols * sizeof(T)); } SSurfacesLookupTable() : m_pData(0) , m_nRows(0) , m_nCols(0) { } ~SSurfacesLookupTable() { SAFE_DELETE_ARRAY(m_pData); } void Free() { SAFE_DELETE_ARRAY(m_pData); } T* operator[] (const size_t row) const { CRY_ASSERT (m_pData); CRY_ASSERT ((row >= 0) && (row < m_nRows)); return &m_pData[row * m_nCols]; } T& operator() (const size_t row, const size_t col) const { CRY_ASSERT (m_pData); CRY_ASSERT ((row >= 0) && (row < m_nRows) && (col >= 0) && (col < m_nCols)); return m_pData[row * m_nCols + col]; } T GetValue(const size_t row, const size_t col, const T& defaultValue) const { return (m_pData && row >= 0 && row < m_nRows && col >= 0 && col < m_nCols) ? m_pData[row * m_nCols + col] : defaultValue; } void GetMemoryUsage(ICrySizer* s) const { s->AddObject(m_pData, sizeof(T) * m_nRows * m_nCols); } T* m_pData; size_t m_nRows; size_t m_nCols; }; } #endif //_SURFACES_LOOKUP_TABLE_H_