delete unused files

This commit is contained in:
Ian Curtis 2016-12-09 14:15:11 +00:00
parent 2c23268d88
commit 707e945db9
22 changed files with 0 additions and 10884 deletions

View file

@ -1,352 +0,0 @@
#include "Texture.h"
#include <stdio.h>
#include <math.h>
namespace New3D {
Texture::Texture()
{
Reset();
}
Texture::~Texture()
{
DeleteTexture(); // make sure to have valid context before destroying
}
void Texture::DeleteTexture()
{
if (m_textureID) {
glDeleteTextures(1, &m_textureID);
printf("-----> deleting %i %i %i %i %i\n", m_format, m_x, m_y, m_width, m_height);
Reset();
}
}
void Texture::Reset()
{
m_x = 0;
m_y = 0;
m_width = 0;
m_height = 0;
m_format = 0;
m_textureID = 0;
m_mirrorU = false;
m_mirrorV = false;
}
void Texture::BindTexture()
{
glBindTexture(GL_TEXTURE_2D, m_textureID);
}
void Texture::GetCoordinates(UINT16 uIn, UINT16 vIn, float uvScale, float& uOut, float& vOut)
{
uOut = (uIn*uvScale) / m_width;
vOut = (vIn*uvScale) / m_height;
}
void Texture::GetCoordinates(int width, int height, UINT16 uIn, UINT16 vIn, float uvScale, float& uOut, float& vOut)
{
uOut = (uIn*uvScale) / width;
vOut = (vIn*uvScale) / height;
}
void Texture::SetWrapMode(bool mirrorU, bool mirrorV)
{
if (mirrorU != m_mirrorU) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, mirrorU ? GL_MIRRORED_REPEAT : GL_REPEAT);
m_mirrorU = mirrorU;
}
if (mirrorV != m_mirrorV) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mirrorV ? GL_MIRRORED_REPEAT : GL_REPEAT);
m_mirrorV = mirrorV;
}
}
UINT32 Texture::UploadTexture(const UINT16* src, UINT8* scratch, int format, bool mirrorU, bool mirrorV, int x, int y, int width, int height)
{
int xi, yi, i;
GLubyte texel;
GLubyte c, a;
UINT16* scratch16;
GLenum type;
if (!src || !scratch) {
return 0; // sanity checking
}
DeleteTexture(); // free any existing texture
i = 0;
type = GL_UNSIGNED_BYTE;
scratch16 = (UINT16*)scratch;
switch (format)
{
default: // Debug texture
for (yi = y; yi < (y + height); yi++)
{
for (xi = x; xi < (x + width); xi++)
{
scratch[i++] = 255; // R
scratch[i++] = 0; // G
scratch[i++] = 0; // B
scratch[i++] = 255; // A
}
}
break;
case 0: // T1RGB5 <- correct
type = GL_UNSIGNED_SHORT_5_5_5_1;
for (yi = y; yi < (y + height); yi++)
{
for (xi = x; xi < (x + width); xi++)
{
scratch16[i++] = src[yi * 2048 + xi] << 1 | ((src[yi * 2048 + xi] >> 15) ^ 0x1); // flip alpha
}
}
break;
case 1: // Interleaved A4L4 (low byte)
for (yi = y; yi < (y + height); yi++)
{
for (xi = x; xi < (x + width); xi++)
{
// Interpret as A4L4
texel = src[yi * 2048 + xi] & 0xFF;
c = (texel & 0xF) * 17;
a = (texel >> 4) * 17;
scratch[i++] = c;
scratch[i++] = c;
scratch[i++] = c;
scratch[i++] = a;
}
}
break;
case 2: // luminance alpha texture <- this one is correct
for (yi = y; yi < (y + height); yi++)
{
for (xi = x; xi < (x + width); xi++)
{
texel = src[yi * 2048 + xi] & 0xFF;
c = ((texel >> 4) & 0xF) * 17;
a = (texel & 0xF) * 17;
scratch[i++] = c;
scratch[i++] = c;
scratch[i++] = c;
scratch[i++] = a;
}
}
break;
case 3: // 8-bit, A4L4 (high byte)
for (yi = y; yi < (y + height); yi++)
{
for (xi = x; xi < (x + width); xi++)
{
texel = src[yi * 2048 + xi] >> 8;
c = (texel & 0xF) * 17;
a = (texel >> 4) * 17;
scratch[i++] = c;
scratch[i++] = c;
scratch[i++] = c;
scratch[i++] = a;
}
}
break;
case 4: // 8-bit, L4A4 (high byte)
for (yi = y; yi < (y + height); yi++)
{
for (xi = x; xi < (x + width); xi++)
{
texel = src[yi * 2048 + xi] >> 8;
c = ((texel >> 4) & 0xF) * 17;
a = (texel & 0xF) * 17;
scratch[i++] = c;
scratch[i++] = c;
scratch[i++] = c;
scratch[i++] = a;
}
}
break;
case 5: // 8-bit grayscale
for (yi = y; yi < (y + height); yi++)
{
for (xi = x; xi < (x + width); xi++)
{
texel = src[yi * 2048 + xi] & 0xFF;
scratch[i++] = texel;
scratch[i++] = texel;
scratch[i++] = texel;
scratch[i++] = (texel==255 ? 0 : 255);
}
}
break;
case 6: // 8-bit grayscale <-- this one is correct
for (yi = y; yi < (y + height); yi++)
{
for (xi = x; xi < (x + width); xi++)
{
texel = src[yi * 2048 + xi] >> 8;
scratch[i++] = texel;
scratch[i++] = texel;
scratch[i++] = texel;
scratch[i++] = (texel == 255 ? 0 : 255);
}
}
break;
case 7: // RGBA4
type = GL_UNSIGNED_SHORT_4_4_4_4;
for (yi = y; yi < (y + height); yi++)
{
for (xi = x; xi < (x + width); xi++)
{
scratch16[i++] = src[yi * 2048 + xi];
}
}
break;
//
// 4 bit texture types - all luminance textures (no alpha), only seem to be enabled when contour is enabled ( white = contour value )
//
case 8: // low byte, low nibble
for (yi = y; yi < (y + height); yi++)
{
for (xi = x; xi < (x + width); xi++)
{
texel = src[yi * 2048 + xi] & 0xFF;
c = (texel & 0xF) * 17;
scratch[i++] = c;
scratch[i++] = c;
scratch[i++] = c;
scratch[i++] = (c == 255 ? 0 : 255);
}
}
break;
case 9: // low byte, high nibble
for (yi = y; yi < (y + height); yi++)
{
for (xi = x; xi < (x + width); xi++)
{
texel = src[yi * 2048 + xi] & 0xFF;
c = ((texel >> 4) & 0xF) * 17;
scratch[i++] = c;
scratch[i++] = c;
scratch[i++] = c;
scratch[i++] = (c == 255 ? 0 : 255);
}
}
break;
case 10: // high byte, low nibble
for (yi = y; yi < (y + height); yi++)
{
for (xi = x; xi < (x + width); xi++)
{
texel = src[yi * 2048 + xi] >> 8;
c = (texel & 0xF) * 17;
scratch[i++] = c;
scratch[i++] = c;
scratch[i++] = c;
scratch[i++] = (c == 255 ? 0 : 255);
}
}
break;
case 11: // high byte, high nibble
for (yi = y; yi < (y + height); yi++)
{
for (xi = x; xi < (x + width); xi++)
{
texel = src[yi * 2048 + xi] >> 8;
c = ((texel >> 4) & 0xF) * 17;
scratch[i++] = c;
scratch[i++] = c;
scratch[i++] = c;
scratch[i++] = (c == 255 ? 0 : 255);
}
}
break;
}
GLfloat maxAnistrophy;
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnistrophy);
if (maxAnistrophy > 8) {
maxAnistrophy = 8.0f; //anymore than 8 can get expensive for little gain
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 4); // rgba is always 4 byte aligned
glGenTextures(1, &m_textureID);
glBindTexture(GL_TEXTURE_2D, m_textureID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, mirrorU ? GL_MIRRORED_REPEAT : GL_REPEAT); //todo this in shaders?
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mirrorV ? GL_MIRRORED_REPEAT : GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, maxAnistrophy);
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, type, scratch);
// assuming successful we can copy details
m_x = x;
m_y = y;
m_width = width;
m_height = height;
m_format = format;
m_mirrorU = mirrorU;
m_mirrorV = mirrorV;
printf("create format %i x: %i y: %i width: %i height: %i\n", format, x, y, width, height);
return m_textureID;
}
void Texture::GetDetails(int& x, int&y, int& width, int& height, int& format)
{
x = m_x;
y = m_y;
width = m_width;
height = m_height;
format = m_format;
}
bool Texture::Compare(int x, int y, int width, int height, int format)
{
if (m_x == x && m_y == y && m_width == width && m_height == height && m_format == format) {
return true;
}
return false;
}
bool Texture::CheckMapPos(int ax1, int ax2, int ay1, int ay2)
{
int bx1 = m_x;
int bx2 = m_x + m_width;
int by1 = m_y;
int by2 = m_y + m_height;
if (ax1<bx2 && ax2>bx1 &&
ay1<by2 && ay2>by1) {
return true; // rectangles overlap
}
return false;
}
} // New3D

File diff suppressed because it is too large Load diff

View file

@ -1,239 +0,0 @@
/**
** Supermodel
** A Sega Model 3 Arcade Emulator.
** Copyright 2011 Bart Trzynadlowski, Nik Henson
**
** This file is part of Supermodel.
**
** Supermodel is free software: you can redistribute it and/or modify it under
** the terms of the GNU General Public License as published by the Free
** Software Foundation, either version 3 of the License, or (at your option)
** any later version.
**
** Supermodel is distributed in the hope that it will be useful, but WITHOUT
** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
** more details.
**
** You should have received a copy of the GNU General Public License along
** with Supermodel. If not, see <http://www.gnu.org/licenses/>.
**/
/*
* New3D.h
*
* Header file defining the CNew3D class: OpenGL Real3D graphics engine.
*/
#ifndef INCLUDED_NEW3D_H
#define INCLUDED_NEW3D_H
#include "Pkgs/glew.h"
#include "Types.h"
#include "TextureSheet.h"
#include "Graphics/IRender3D.h"
#include "Model.h"
#include "Mat4.h"
#include "R3DShader.h"
#include "VBO.h"
#include "R3DData.h"
#include "Plane.h"
#include "Vec.h"
namespace New3D {
class CNew3D : public IRender3D
{
public:
/*
* RenderFrame(void):
*
* Renders the complete scene database. Must be called between BeginFrame() and
* EndFrame(). This function traverses the scene database and builds up display
* lists.
*/
void RenderFrame(void);
/*
* BeginFrame(void):
*
* Prepare to render a new frame. Must be called once per frame prior to
* drawing anything.
*/
void BeginFrame(void);
/*
* EndFrame(void):
*
* Signals the end of rendering for this frame. Must be called last during
* the frame.
*/
void EndFrame(void);
/*
* UploadTextures(x, y, width, height):
*
* Signals that a portion of texture RAM has been updated.
*
* Parameters:
* x X position within texture RAM.
* y Y position within texture RAM.
* width Width of texture data in texels.
* height Height.
*/
void UploadTextures(unsigned x, unsigned y, unsigned width, unsigned height);
/*
* AttachMemory(cullingRAMLoPtr, cullingRAMHiPtr, polyRAMPtr, vromPtr,
* textureRAMPtr):
*
* Attaches RAM and ROM areas. This must be done prior to any rendering
* otherwise the program may crash with an access violation.
*
* Parameters:
* cullingRAMLoPtr Pointer to low culling RAM (4 MB).
* cullingRAMHiPtr Pointer to high culling RAM (1 MB).
* polyRAMPtr Pointer to polygon RAM (4 MB).
* vromPtr Pointer to video ROM (64 MB).
* textureRAMPtr Pointer to texture RAM (8 MB).
*/
void AttachMemory(const UINT32 *cullingRAMLoPtr,
const UINT32 *cullingRAMHiPtr, const UINT32 *polyRAMPtr,
const UINT32 *vromPtr, const UINT16 *textureRAMPtr);
/*
* SetStep(stepID):
*
* Sets the Model 3 hardware stepping, which also determines the Real3D
* functionality. The default is Step 1.0. This should be called prior to
* any other emulation functions and after Init().
*
* Parameters:
* stepID 0x10 for Step 1.0, 0x15 for Step 1.5, 0x20 for Step 2.0,
* or 0x21 for Step 2.1. Anything else defaults to 1.0.
*/
void SetStep(int stepID);
/*
* Init(xOffset, yOffset, xRes, yRes, totalXRes, totalYRes):
*
* One-time initialization of the context. Must be called before any other
* members (meaning it should be called even before being attached to any
* other objects that want to use it).
*
* External shader files are loaded according to configuration settings.
*
* Parameters:
* xOffset X offset of the viewable area within OpenGL display
* surface, in pixels.
* yOffset Y offset.
* xRes Horizontal resolution of the viewable area.
* yRes Vertical resolution.
* totalXRes Horizontal resolution of the complete display area.
* totalYRes Vertical resolution.
*
* Returns:
* OKAY is successful, otherwise FAILED if a non-recoverable error
* occurred. Any allocated memory will not be freed until the
* destructor is called. Prints own error messages.
*/
bool Init(unsigned xOffset, unsigned yOffset, unsigned xRes, unsigned yRes, unsigned totalXRes, unsigned totalYRes);
/*
* CRender3D(void):
* ~CRender3D(void):
*
* Constructor and destructor.
*/
CNew3D(void);
~CNew3D(void);
private:
/*
* Private Members
*/
// Real3D address translation
const UINT32 *TranslateCullingAddress(UINT32 addr);
const UINT32 *TranslateModelAddress(UINT32 addr);
// Matrix stack
void MultMatrix(UINT32 matrixOffset, Mat4& mat);
void InitMatrixStack(UINT32 matrixBaseAddr, Mat4& mat);
// Scene database traversal
bool DrawModel(UINT32 modelAddr);
void DescendCullingNode(UINT32 addr);
void DescendPointerList(UINT32 addr);
void DescendNodePtr(UINT32 nodeAddr);
void RenderViewport(UINT32 addr);
// building the scene
void CacheModel(Model *m, const UINT32 *data);
void CopyVertexData(const R3DPoly& r3dPoly, std::vector<Poly>& polyArray);
void OffsetTexCoords(R3DPoly& r3dPoly, float offset[2]);
void RenderScene(int priority, bool alpha);
float Determinant3x3(const float m[16]);
bool IsDynamicModel(UINT32 *data); // check if the model has a colour palette
bool IsVROMModel(UINT32 modelAddr);
void CalcTexOffset(int offX, int offY, int page, int x, int y, int& newX, int& newY);
/*
* Data
*/
// Stepping
int m_step;
int m_offset; // offset to subtract for words 3 and higher of culling nodes
float m_vertexFactor; // fixed-point conversion factor for vertices
// Memory (passed from outside)
const UINT32 *m_cullingRAMLo; // 4 MB
const UINT32 *m_cullingRAMHi; // 1 MB
const UINT32 *m_polyRAM; // 4 MB
const UINT32 *m_vrom; // 64 MB
const UINT16 *m_textureRAM; // 8 MB
// Resolution and scaling factors (to support resolutions higher than 496x384) and offsets
float m_xRatio, m_yRatio;
unsigned m_xOffs, m_yOffs;
unsigned m_totalXRes, m_totalYRes;
// Real3D Base Matrix Pointer
const float *m_matrixBasePtr;
UINT32 m_colorTableAddr = 0x400; // address of color table in polygon RAM
TextureSheet m_texSheet;
NodeAttributes m_nodeAttribs;
Mat4 m_modelMat; // current modelview matrix
std::vector<Node> m_nodes; // this represents the entire render frame
std::vector<Poly> m_polyBufferRam; // dynamic polys
std::vector<Poly> m_polyBufferRom; // rom polys
std::unordered_map<UINT32, std::shared_ptr<std::vector<Mesh>>> m_romMap; // a hash table for all the ROM models. The meshes don't have model matrices or tex offsets yet
VBO m_vbo; // large VBO to hold our poly data, start of VBO is ROM data, ram polys follow
R3DShader m_r3dShader;
Plane m_planes[6];
struct BBox
{
V4::Vec4 points[8];
};
void CalcFrustumPlanes (Plane p[6], const float* matrix);
void CalcBox (float distance, BBox& box);
void TransformBox (const float *m, BBox& box);
void MultVec (const float matrix[16], const float in[4], float out[4]);
Clip ClipBox (BBox& box, Plane planes[6]);
float layerMax[4];
int cLayer;
};
} // New3D
#endif // INCLUDED_NEW3D_H

View file

@ -1,311 +0,0 @@
#include "Texture.h"
#include <stdio.h>
#include <math.h>
namespace New3D {
Texture::Texture()
{
Reset();
}
Texture::~Texture()
{
DeleteTexture(); // make sure to have valid context before destroying
}
void Texture::DeleteTexture()
{
if (m_textureID) {
glDeleteTextures(1, &m_textureID);
printf("-----> deleting %i %i %i %i %i\n", m_format, m_x, m_y, m_width, m_height);
Reset();
}
}
void Texture::Reset()
{
m_x = 0;
m_y = 0;
m_width = 0;
m_height = 0;
m_format = 0;
m_textureID = 0;
m_mirrorU = false;
m_mirrorV = false;
}
void Texture::BindTexture()
{
glBindTexture(GL_TEXTURE_2D, m_textureID);
}
void Texture::GetCoordinates(UINT16 uIn, UINT16 vIn, float uvScale, float& uOut, float& vOut)
{
uOut = (uIn*uvScale) / m_width;
vOut = (vIn*uvScale) / m_height;
}
void Texture::GetCoordinates(bool mirror, int width, int height, UINT16 uIn, UINT16 vIn, float uvScale, float& uOut, float& vOut)
{
uOut = (uIn*uvScale) / width;
vOut = (vIn*uvScale) / height;
/*
if (!mirror) {
float flu = uOut - floor(uOut);
float flv = uOut - floor(uOut);
int iu = (int)uOut;
int iv = (int)vOut;
float offu = 1 / (width*2.f);
float offv = 1 / (height*2.f);
if (iu % 2) {
if (!flu) {
flu = 1.0f;
}
}
if ((iv % 2)) {
if (!flv) {
flv = -1.0f;
}
}
uOut = flu;
vOut = flv;
if (flu < 0.5f) {
uOut += offu;
}
else {
uOut -= offu;
}
if (flv < 0.5f) {
vOut += offu;
}
else {
vOut -= offu;
}
}
*/
}
void Texture::SetWrapMode(bool mirrorU, bool mirrorV)
{
if (mirrorU != m_mirrorU) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, mirrorU ? GL_MIRRORED_REPEAT : GL_REPEAT);
m_mirrorU = mirrorU;
}
if (mirrorV != m_mirrorV) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mirrorV ? GL_MIRRORED_REPEAT : GL_REPEAT);
m_mirrorV = mirrorV;
}
}
UINT32 Texture::UploadTexture(const UINT16* src, UINT8* scratch, int format, bool mirrorU, bool mirrorV, int x, int y, int width, int height)
{
int xi, yi, i;
GLubyte texel;
GLubyte c, a;
if (!src || !scratch) {
return 0; // sanity checking
}
DeleteTexture(); // free any existing texture
i = 0;
switch (format)
{
default: // Debug texture, use TEXTURE_DEBUG mask
for (yi = y; yi < (y + height); yi++)
{
for (xi = x; xi < (x + width); xi++)
{
scratch[i++] = 255; // R
scratch[i++] = 0; // G
scratch[i++] = 0; // B
scratch[i++] = 255; // A
}
}
break;
case 0: // T1RGB5 <- correct
for (yi = y; yi < (y + height); yi++)
{
for (xi = x; xi < (x + width); xi++)
{
scratch[i++] = (GLubyte)(((src[yi * 2048 + xi] >> 10) & 0x1F) * 255.f / 0x1F); // R
scratch[i++] = (GLubyte)(((src[yi * 2048 + xi] >> 5) & 0x1F) * 255.f / 0x1F); // G
scratch[i++] = (GLubyte)(((src[yi * 2048 + xi] >> 0) & 0x1F) * 255.f / 0x1F); // B
scratch[i++] = ((src[yi * 2048 + xi] & 0x8000) ? 0 : 255); // T
}
}
break;
case 1: // Interleaved A4L4 (low byte)
for (yi = y; yi < (y + height); yi++)
{
for (xi = x; xi < (x + width); xi++)
{
// Interpret as A4L4
texel = src[yi * 2048 + xi] & 0xFF;
c = (texel & 0xF) * 17;
a = (texel >> 4) * 17;
scratch[i++] = c;
scratch[i++] = c;
scratch[i++] = c;
scratch[i++] = a;
}
}
break;
case 2: // luminance alpha texture <- this one is correct
for (yi = y; yi < (y + height); yi++)
{
for (xi = x; xi < (x + width); xi++)
{
texel = src[yi * 2048 + xi] & 0xFF;
c = ((texel >> 4) & 0xF) * 17;
a = (texel & 0xF) * 17;
scratch[i++] = c;
scratch[i++] = c;
scratch[i++] = c;
scratch[i++] = a;
}
}
break;
case 3: // 8-bit, A4L4 (high byte)
for (yi = y; yi < (y + height); yi++)
{
for (xi = x; xi < (x + width); xi++)
{
texel = src[yi * 2048 + xi] >> 8;
c = (texel & 0xF) * 17;
a = (texel >> 4) * 17;
scratch[i++] = c;
scratch[i++] = c;
scratch[i++] = c;
scratch[i++] = a;
}
}
break;
case 4: // 8-bit, L4A4 (high byte)
for (yi = y; yi < (y + height); yi++)
{
for (xi = x; xi < (x + width); xi++)
{
texel = src[yi * 2048 + xi] >> 8;
c = ((texel >> 4) & 0xF) * 17;
a = (texel & 0xF) * 17;
scratch[i++] = c;
scratch[i++] = c;
scratch[i++] = c;
scratch[i++] = a;
}
}
break;
case 5: // 8-bit grayscale
for (yi = y; yi < (y + height); yi++)
{
for (xi = x; xi < (x + width); xi++)
{
texel = src[yi * 2048 + xi] & 0xFF;
scratch[i++] = texel;
scratch[i++] = texel;
scratch[i++] = texel;
scratch[i++] = (texel==255 ? 0 : 255);
}
}
break;
case 6: // 8-bit grayscale <-- this one is correct
for (yi = y; yi < (y + height); yi++)
{
for (xi = x; xi < (x + width); xi++)
{
texel = src[yi * 2048 + xi] >> 8;
scratch[i++] = texel;
scratch[i++] = texel;
scratch[i++] = texel;
scratch[i++] = (texel == 255 ? 0 : 255);
}
}
break;
case 7: // RGBA4
for (yi = y; yi < (y + height); yi++)
{
for (xi = x; xi < (x + width); xi++)
{
scratch[i++] = ((src[yi * 2048 + xi] >> 12) & 0xF) * 17;// R
scratch[i++] = ((src[yi * 2048 + xi] >> 8) & 0xF) * 17; // G
scratch[i++] = ((src[yi * 2048 + xi] >> 4) & 0xF) * 17; // B
scratch[i++] = ((src[yi * 2048 + xi] >> 0) & 0xF) * 17; // A
}
}
break;
}
//remove debug mask
format &= 7;
GLfloat maxAnistrophy;
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnistrophy);
if (maxAnistrophy > 8) {
maxAnistrophy = 8.0f; //anymore than 8 can get expensive for little gain
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 4); // rgba is always 4 byte aligned
glActiveTexture(GL_TEXTURE0); // activate correct texture unit
glGenTextures(1, &m_textureID);
glBindTexture(GL_TEXTURE_2D, m_textureID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, mirrorU ? GL_MIRRORED_REPEAT : GL_REPEAT); //todo this in shaders?
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mirrorV ? GL_MIRRORED_REPEAT : GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, maxAnistrophy);
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, scratch);
// assuming successful we can copy details
m_x = x;
m_y = y;
m_width = width;
m_height = height;
m_format = format;
m_mirrorU = mirrorU;
m_mirrorV = mirrorV;
printf("create format %i x: %i y: %i width: %i height: %i\n", format, x, y, width, height);
return m_textureID;
}
void Texture::GetDetails(int& x, int&y, int& width, int& height, int& format)
{
x = m_x;
y = m_y;
width = m_width;
height = m_height;
format = m_format;
}
} // New3D

View file

@ -1,44 +0,0 @@
#ifndef _TEXTURE_H_
#define _TEXTURE_H_
#include "Types.h"
#include "Pkgs/glew.h" //arg
namespace New3D {
#define TEXTURE_DEBUG 0x8
#define TEXTURE_DEBUG_MASK 0x7
class Texture
{
public:
Texture();
~Texture();
UINT32 UploadTexture (const UINT16* src, UINT8* scratch, int format, bool mirrorU, bool mirrorV, int x, int y, int width, int height);
void DeleteTexture ();
void BindTexture ();
void GetCoordinates (UINT16 uIn, UINT16 vIn, float uvScale, float& uOut, float& vOut);
void GetDetails (int& x, int&y, int& width, int& height, int& format);
void SetWrapMode (bool mirrorU, bool mirrorV);
static void GetCoordinates(bool mirror, int width, int height, UINT16 uIn, UINT16 vIn, float uvScale, float& uOut, float& vOut);
private:
void Reset();
int m_x;
int m_y;
int m_width;
int m_height;
int m_format;
bool m_mirrorU;
bool m_mirrorV;
GLuint m_textureID;
};
} // New3D
#endif

View file

@ -1,84 +0,0 @@
#include "VBO.h"
namespace New3D {
VBO::VBO()
{
m_id = 0;
m_target = 0;
m_capacity = 0;
m_size = 0;
}
void VBO::Create(GLenum target, GLenum usage, GLsizeiptr size, const void* data)
{
glGenBuffers(1, &m_id); // create a vbo
glBindBuffer(target, m_id); // activate vbo id to use
glBufferData(target, size, data, usage); // upload data to video card
m_target = target;
m_capacity = size;
m_size = 0;
Bind(false); // unbind
}
void VBO::BufferSubData(GLintptr offset, GLsizeiptr size, const GLvoid* data)
{
glBufferSubData(m_target, offset, size, data);
}
bool VBO::AppendData(GLsizeiptr size, const GLvoid* data)
{
if (size == 0 || !data) {
return true; // nothing to do
}
if (m_size + size >= m_capacity) {
return false;
}
BufferSubData(m_size, size, data);
m_size += size;
return true;
}
void VBO::Reset()
{
m_size = 0;
}
void VBO::Destroy()
{
if (m_id) {
glDeleteBuffers(1, &m_id);
m_id = 0;
m_target = 0;
m_capacity = 0;
m_size = 0;
}
}
void VBO::Bind(bool enable)
{
if (enable) {
glBindBuffer(m_target, m_id);
}
else {
glBindBuffer(m_target, 0);
}
}
int VBO::GetSize()
{
return m_size;
}
int VBO::GetCapacity()
{
return m_capacity;
}
} // New3D

View file

@ -1,52 +0,0 @@
#ifndef _MAT4_H_
#define _MAT4_H_
#include <vector>
namespace New3D {
class Mat4
{
public:
Mat4();
void LoadIdentity ();
void Translate (float x, float y, float z);
void Rotate (float angle, float x, float y, float z);
void Scale (float x, float y, float z);
void Frustum (float left, float right, float bottom, float top, float nearVal, float farVal);
void Ortho (float left, float right, float bottom, float top, float nearVal, float farVal);
void Perspective (float fovy, float aspect, float zNear, float zFar);
void MultMatrix (const float *m);
void LoadMatrix (const float *m);
void LoadTransposeMatrix (const float *m);
void MultTransposeMatrix (const float *m);
void PushMatrix ();
void PopMatrix ();
void Release ();
operator const float* () { return currentMatrix; }
float currentMatrix[16];
struct Mat4Container {
float mat[16]; // we must wrap the matrix inside a struct otherwise vector doesn't work
};
std::vector<Mat4Container> m_vMat4;
private:
void MultiMatrices (const float a[16], const float b[16], float r[16]);
void Copy (const float in[16], float out[16]);
void Transpose (float m[16]);
};
} // New3D
#endif

File diff suppressed because it is too large Load diff

View file

@ -1,237 +0,0 @@
/**
** Supermodel
** A Sega Model 3 Arcade Emulator.
** Copyright 2011 Bart Trzynadlowski, Nik Henson
**
** This file is part of Supermodel.
**
** Supermodel is free software: you can redistribute it and/or modify it under
** the terms of the GNU General Public License as published by the Free
** Software Foundation, either version 3 of the License, or (at your option)
** any later version.
**
** Supermodel is distributed in the hope that it will be useful, but WITHOUT
** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
** more details.
**
** You should have received a copy of the GNU General Public License along
** with Supermodel. If not, see <http://www.gnu.org/licenses/>.
**/
/*
* New3D.h
*
* Header file defining the CNew3D class: OpenGL Real3D graphics engine.
*/
#ifndef INCLUDED_NEW3D_H
#define INCLUDED_NEW3D_H
#include "Pkgs/glew.h"
#include "Types.h"
#include "TextureSheet.h"
#include "Graphics/IRender3D.h"
#include "Model.h"
#include "Mat4.h"
#include "R3DShader.h"
#include "VBO.h"
#include "R3DData.h"
#include "Vec.h"
namespace New3D {
class CNew3D : public IRender3D
{
public:
/*
* RenderFrame(void):
*
* Renders the complete scene database. Must be called between BeginFrame() and
* EndFrame(). This function traverses the scene database and builds up display
* lists.
*/
void RenderFrame(void);
/*
* BeginFrame(void):
*
* Prepare to render a new frame. Must be called once per frame prior to
* drawing anything.
*/
void BeginFrame(void);
/*
* EndFrame(void):
*
* Signals the end of rendering for this frame. Must be called last during
* the frame.
*/
void EndFrame(void);
/*
* UploadTextures(x, y, width, height):
*
* Signals that a portion of texture RAM has been updated.
*
* Parameters:
* x X position within texture RAM.
* y Y position within texture RAM.
* width Width of texture data in texels.
* height Height.
*/
void UploadTextures(unsigned x, unsigned y, unsigned width, unsigned height);
/*
* AttachMemory(cullingRAMLoPtr, cullingRAMHiPtr, polyRAMPtr, vromPtr,
* textureRAMPtr):
*
* Attaches RAM and ROM areas. This must be done prior to any rendering
* otherwise the program may crash with an access violation.
*
* Parameters:
* cullingRAMLoPtr Pointer to low culling RAM (4 MB).
* cullingRAMHiPtr Pointer to high culling RAM (1 MB).
* polyRAMPtr Pointer to polygon RAM (4 MB).
* vromPtr Pointer to video ROM (64 MB).
* textureRAMPtr Pointer to texture RAM (8 MB).
*/
void AttachMemory(const UINT32 *cullingRAMLoPtr,
const UINT32 *cullingRAMHiPtr, const UINT32 *polyRAMPtr,
const UINT32 *vromPtr, const UINT16 *textureRAMPtr);
/*
* SetStep(stepID):
*
* Sets the Model 3 hardware stepping, which also determines the Real3D
* functionality. The default is Step 1.0. This should be called prior to
* any other emulation functions and after Init().
*
* Parameters:
* stepID 0x10 for Step 1.0, 0x15 for Step 1.5, 0x20 for Step 2.0,
* or 0x21 for Step 2.1. Anything else defaults to 1.0.
*/
void SetStep(int stepID);
/*
* Init(xOffset, yOffset, xRes, yRes, totalXRes, totalYRes):
*
* One-time initialization of the context. Must be called before any other
* members (meaning it should be called even before being attached to any
* other objects that want to use it).
*
* External shader files are loaded according to configuration settings.
*
* Parameters:
* xOffset X offset of the viewable area within OpenGL display
* surface, in pixels.
* yOffset Y offset.
* xRes Horizontal resolution of the viewable area.
* yRes Vertical resolution.
* totalXRes Horizontal resolution of the complete display area.
* totalYRes Vertical resolution.
*
* Returns:
* OKAY is successful, otherwise FAILED if a non-recoverable error
* occurred. Any allocated memory will not be freed until the
* destructor is called. Prints own error messages.
*/
bool Init(unsigned xOffset, unsigned yOffset, unsigned xRes, unsigned yRes, unsigned totalXRes, unsigned totalYRes);
/*
* CRender3D(void):
* ~CRender3D(void):
*
* Constructor and destructor.
*/
CNew3D(void);
~CNew3D(void);
private:
/*
* Private Members
*/
// Real3D address translation
const UINT32 *TranslateCullingAddress(UINT32 addr);
const UINT32 *TranslateModelAddress(UINT32 addr);
// Matrix stack
void MultMatrix(UINT32 matrixOffset, Mat4& mat);
void InitMatrixStack(UINT32 matrixBaseAddr, Mat4& mat);
// Scene database traversal
bool DrawModel(UINT32 modelAddr);
void DescendCullingNode(UINT32 addr);
void DescendPointerList(UINT32 addr);
void DescendNodePtr(UINT32 nodeAddr);
void RenderViewport(UINT32 addr);
void DrawBoundingBoxes();
// building the scene
void CacheModel(Model *m, const UINT32 *data);
void CopyVertexData(const R3DPoly& r3dPoly, std::vector<Poly>& polyArray);
void OffsetTexCoords(R3DPoly& r3dPoly, float offset[2]);
void RenderScene(int priority, bool alpha);
float Determinant3x3(const float m[16]);
bool IsDynamicModel(UINT32 *data); // check if the model has a colour palette
bool IsVROMModel(UINT32 modelAddr);
void CalcTexOffset(int offX, int offY, int page, int x, int y, int& newX, int& newY);
UINT32 ConvertProFloat(UINT32 a1); // return float in hex or integer format
UINT32 Convert16BitProFloat(UINT32 a1);
float ToFloat(UINT32 a1); // integer float to actual IEEE 754 float
/*
* Data
*/
// Stepping
int m_step;
int m_offset; // offset to subtract for words 3 and higher of culling nodes
float m_vertexFactor; // fixed-point conversion factor for vertices
// Memory (passed from outside)
const UINT32 *m_cullingRAMLo; // 4 MB
const UINT32 *m_cullingRAMHi; // 1 MB
const UINT32 *m_polyRAM; // 4 MB
const UINT32 *m_vrom; // 64 MB
const UINT16 *m_textureRAM; // 8 MB
// Resolution and scaling factors (to support resolutions higher than 496x384) and offsets
float m_xRatio, m_yRatio;
unsigned m_xOffs, m_yOffs;
unsigned m_totalXRes, m_totalYRes;
// Real3D Base Matrix Pointer
const float *m_matrixBasePtr;
UINT32 m_colorTableAddr = 0x400; // address of color table in polygon RAM
TextureSheet m_texSheet;
NodeAttributes m_nodeAttribs;
Mat4 m_modelMat; // current modelview matrix
std::vector<Node> m_nodes; // this represents the entire render frame
std::vector<Poly> m_polyBufferRam; // dynamic polys
std::vector<Poly> m_polyBufferRom; // rom polys
std::unordered_map<UINT32, std::shared_ptr<std::vector<Mesh>>> m_romMap; // a hash table for all the ROM models. The meshes don't have model matrices or tex offsets yet
VBO m_vbo; // large VBO to hold our poly data, start of VBO is ROM data, ram polys follow
R3DShader m_r3dShader;
struct BBox
{
V3::Vec3 points[8];
Mat4 mat;
};
void CalcBox(float distance, BBox& box);
std::vector<BBox> m_bBoxes;
};
} // New3D
#endif // INCLUDED_NEW3D_H

View file

@ -1,147 +0,0 @@
#ifndef _MODEL_H_
#define _MODEL_H_
#include "Types.h"
#include <vector>
#include <unordered_map>
#include <map>
#include <memory>
#include "Texture.h"
#include "Mat4.h"
namespace New3D {
struct Vertex
{
float pos[3];
float normal[3];
float texcoords[2];
float color[4]; //rgba
};
struct Poly // our polys are always 3 triangles, unlike the real h/w
{
Vertex p1;
Vertex p2;
Vertex p3;
};
struct R3DPoly
{
Vertex v[4]; // just easier to have them as an array
float faceNormal[3]; // we need this to help work out poly winding, i assume the h/w uses this instead of calculating normals itself
float faceColour[4]; // per face colour
int number = 4;
};
struct Mesh
{
// texture
int format, x, y, width, height = 0;
bool microTexture = false;
int microTextureID = 0;
bool mirrorU = false;
bool mirrorV = false;
// attributes
bool doubleSided = false;
bool textured = false;
bool polyAlpha = false; // specified in the rgba colour
bool textureAlpha = false; // use alpha in texture
bool alphaTest = false; // discard fragment based on alpha (ogl does this with fixed function)
bool clockWise = true; // we need to check if the matrix will change the winding
bool layered = false; // stencil poly
// lighting
bool lighting = false;
bool specular = false;
float shininess = 0;
float specularCoefficient = 0;
// fog
float fogIntensity = 1.0f;
// opengl resources
int vboOffset = 0; // this will be calculated later
int triangleCount = 0;
};
struct SortingMesh : public Mesh // This struct temporarily holds the model data, before it gets copied to the main buffer
{
std::vector<Poly> polys;
};
struct Model
{
std::shared_ptr<std::vector<Mesh>> meshes; // this reason why this is a shared ptr to an array, is that multiple models might use the same meshes
//which memory are we in
bool dynamic = true;
// texture offsets for model
int textureOffsetX = 0;
int textureOffsetY = 0;
int page = 0;
//matrices
float modelMat[16];
float determinant; // we check if the determinant of the matrix is negative, if it is, the matrix will swap the axis order
};
struct Viewport
{
int vpX, vpY, vpWidth, vpHeight;// real3d viewport paramaters
float left, right, bottom, top; // angles for projection matrix - near/far calculated later
Mat4 projectionMatrix; // projection matrix
float lightingParams[6]; // lighting parameters (see RenderViewport() and vertex shader)
float spotEllipse[4]; // spotlight ellipse (see RenderViewport())
float spotRange[2]; // Z range
float spotColor[3]; // color
float fogParams[5]; // fog parameters (...)
float scrollFog; // a transparency value that determines if fog is blended over the bottom 2D layer
int x, y; // viewport coordinates (scaled and in OpenGL format)
int width, height; // viewport dimensions (scaled for display surface size)
int priority;
};
enum class Clip { INSIDE, OUTSIDE, INTERCEPT };
class NodeAttributes
{
public:
NodeAttributes();
bool Push();
bool Pop();
bool StackLimit();
void Reset();
int currentTexOffsetX;
int currentTexOffsetY;
int currentPage;
Clip currentClipStatus;
private:
struct NodeAttribs
{
int texOffsetX;
int texOffsetY;
int page;
Clip clip;
};
std::vector<NodeAttribs> m_vecAttribs;
};
struct Node
{
Viewport viewport;
std::vector<Model> models;
};
} // New3D
#endif

File diff suppressed because it is too large Load diff

View file

@ -1,252 +0,0 @@
/**
** Supermodel
** A Sega Model 3 Arcade Emulator.
** Copyright 2011 Bart Trzynadlowski, Nik Henson
**
** This file is part of Supermodel.
**
** Supermodel is free software: you can redistribute it and/or modify it under
** the terms of the GNU General Public License as published by the Free
** Software Foundation, either version 3 of the License, or (at your option)
** any later version.
**
** Supermodel is distributed in the hope that it will be useful, but WITHOUT
** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
** more details.
**
** You should have received a copy of the GNU General Public License along
** with Supermodel. If not, see <http://www.gnu.org/licenses/>.
**/
/*
* New3D.h
*
* Header file defining the CNew3D class: OpenGL Real3D graphics engine.
*/
#ifndef INCLUDED_NEW3D_H
#define INCLUDED_NEW3D_H
#include "Pkgs/glew.h"
#include "Types.h"
#include "TextureSheet.h"
#include "Graphics/IRender3D.h"
#include "Model.h"
#include "Mat4.h"
#include "R3DShader.h"
#include "VBO.h"
#include "R3DData.h"
#include "Plane.h"
#include "Vec.h"
#include "R3DScrollFog.h"
namespace New3D {
class CNew3D : public IRender3D
{
public:
/*
* RenderFrame(void):
*
* Renders the complete scene database. Must be called between BeginFrame() and
* EndFrame(). This function traverses the scene database and builds up display
* lists.
*/
void RenderFrame(void);
/*
* BeginFrame(void):
*
* Prepare to render a new frame. Must be called once per frame prior to
* drawing anything.
*/
void BeginFrame(void);
/*
* EndFrame(void):
*
* Signals the end of rendering for this frame. Must be called last during
* the frame.
*/
void EndFrame(void);
/*
* UploadTextures(x, y, width, height):
*
* Signals that a portion of texture RAM has been updated.
*
* Parameters:
* x X position within texture RAM.
* y Y position within texture RAM.
* width Width of texture data in texels.
* height Height.
*/
void UploadTextures(unsigned x, unsigned y, unsigned width, unsigned height);
/*
* AttachMemory(cullingRAMLoPtr, cullingRAMHiPtr, polyRAMPtr, vromPtr,
* textureRAMPtr):
*
* Attaches RAM and ROM areas. This must be done prior to any rendering
* otherwise the program may crash with an access violation.
*
* Parameters:
* cullingRAMLoPtr Pointer to low culling RAM (4 MB).
* cullingRAMHiPtr Pointer to high culling RAM (1 MB).
* polyRAMPtr Pointer to polygon RAM (4 MB).
* vromPtr Pointer to video ROM (64 MB).
* textureRAMPtr Pointer to texture RAM (8 MB).
*/
void AttachMemory(const UINT32 *cullingRAMLoPtr,
const UINT32 *cullingRAMHiPtr, const UINT32 *polyRAMPtr,
const UINT32 *vromPtr, const UINT16 *textureRAMPtr);
/*
* SetStep(stepID):
*
* Sets the Model 3 hardware stepping, which also determines the Real3D
* functionality. The default is Step 1.0. This should be called prior to
* any other emulation functions and after Init().
*
* Parameters:
* stepID 0x10 for Step 1.0, 0x15 for Step 1.5, 0x20 for Step 2.0,
* or 0x21 for Step 2.1. Anything else defaults to 1.0.
*/
void SetStep(int stepID);
/*
* Init(xOffset, yOffset, xRes, yRes, totalXRes, totalYRes):
*
* One-time initialization of the context. Must be called before any other
* members (meaning it should be called even before being attached to any
* other objects that want to use it).
*
* External shader files are loaded according to configuration settings.
*
* Parameters:
* xOffset X offset of the viewable area within OpenGL display
* surface, in pixels.
* yOffset Y offset.
* xRes Horizontal resolution of the viewable area.
* yRes Vertical resolution.
* totalXRes Horizontal resolution of the complete display area.
* totalYRes Vertical resolution.
*
* Returns:
* OKAY is successful, otherwise FAILED if a non-recoverable error
* occurred. Any allocated memory will not be freed until the
* destructor is called. Prints own error messages.
*/
bool Init(unsigned xOffset, unsigned yOffset, unsigned xRes, unsigned yRes, unsigned totalXRes, unsigned totalYRes);
/*
* CRender3D(void):
* ~CRender3D(void):
*
* Constructor and destructor.
*/
CNew3D(void);
~CNew3D(void);
private:
/*
* Private Members
*/
// Real3D address translation
const UINT32 *TranslateCullingAddress(UINT32 addr);
const UINT32 *TranslateModelAddress(UINT32 addr);
// Matrix stack
void MultMatrix(UINT32 matrixOffset, Mat4& mat);
void InitMatrixStack(UINT32 matrixBaseAddr, Mat4& mat);
// Scene database traversal
bool DrawModel(UINT32 modelAddr);
void DescendCullingNode(UINT32 addr);
void DescendPointerList(UINT32 addr);
void DescendNodePtr(UINT32 nodeAddr);
void RenderViewport(UINT32 addr);
void CalcViewports();
// building the scene
void CacheModel(Model *m, const UINT32 *data);
void CopyVertexData(const R3DPoly& r3dPoly, std::vector<Poly>& polyArray);
void OffsetTexCoords(R3DPoly& r3dPoly, float offset[2]);
void RenderScene(int priority, bool alpha);
float Determinant3x3(const float m[16]);
bool IsDynamicModel(UINT32 *data); // check if the model has a colour palette
bool IsVROMModel(UINT32 modelAddr);
void DrawScrollFog();
void CalcTexOffset(int offX, int offY, int page, int x, int y, int& newX, int& newY);
/*
* Data
*/
// Stepping
int m_step;
int m_offset; // offset to subtract for words 3 and higher of culling nodes
float m_vertexFactor; // fixed-point conversion factor for vertices
// Memory (passed from outside)
const UINT32 *m_cullingRAMLo; // 4 MB
const UINT32 *m_cullingRAMHi; // 1 MB
const UINT32 *m_polyRAM; // 4 MB
const UINT32 *m_vrom; // 64 MB
const UINT16 *m_textureRAM; // 8 MB
// Resolution and scaling factors (to support resolutions higher than 496x384) and offsets
float m_xRatio, m_yRatio;
unsigned m_xOffs, m_yOffs;
unsigned m_totalXRes, m_totalYRes;
// Real3D Base Matrix Pointer
const float *m_matrixBasePtr;
UINT32 m_colorTableAddr = 0x400; // address of color table in polygon RAM
TextureSheet m_texSheet;
NodeAttributes m_nodeAttribs;
Mat4 m_modelMat; // current modelview matrix
std::vector<Node> m_nodes; // this represents the entire render frame
std::vector<Poly> m_polyBufferRam; // dynamic polys
std::vector<Poly> m_polyBufferRom; // rom polys
std::unordered_map<UINT32, std::shared_ptr<std::vector<Mesh>>> m_romMap; // a hash table for all the ROM models. The meshes don't have model matrices or tex offsets yet
VBO m_vbo; // large VBO to hold our poly data, start of VBO is ROM data, ram polys follow
R3DShader m_r3dShader;
R3DScrollFog m_r3dScrollFog;
Plane m_planes[5];
struct NFPair
{
float nearVal;
float farVal;
};
NFPair m_nfPair[4]; // near/far value for each priority layer
int m_currentPriority;
struct BBox
{
V4::Vec4 points[8];
};
void CalcFrustumPlanes (Plane p[6], const float *vpNodeData);
void CalcBox (float distance, BBox& box);
void TransformBox (const float *m, BBox& box);
void MultVec (const float matrix[16], const float in[4], float out[4]);
Clip ClipBox (BBox& box, Plane planes[6]);
void GetBBMaxZ (float &compare, BBox &box);
float m_minTest;
};
} // New3D
#endif // INCLUDED_NEW3D_H

File diff suppressed because it is too large Load diff

View file

@ -1,241 +0,0 @@
/**
** Supermodel
** A Sega Model 3 Arcade Emulator.
** Copyright 2011 Bart Trzynadlowski, Nik Henson
**
** This file is part of Supermodel.
**
** Supermodel is free software: you can redistribute it and/or modify it under
** the terms of the GNU General Public License as published by the Free
** Software Foundation, either version 3 of the License, or (at your option)
** any later version.
**
** Supermodel is distributed in the hope that it will be useful, but WITHOUT
** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
** more details.
**
** You should have received a copy of the GNU General Public License along
** with Supermodel. If not, see <http://www.gnu.org/licenses/>.
**/
/*
* New3D.h
*
* Header file defining the CNew3D class: OpenGL Real3D graphics engine.
*/
#ifndef INCLUDED_NEW3D_H
#define INCLUDED_NEW3D_H
#include "Pkgs/glew.h"
#include "Types.h"
#include "TextureSheet.h"
#include "Graphics/IRender3D.h"
#include "Model.h"
#include "Mat4.h"
#include "R3DShader.h"
#include "VBO.h"
#include "R3DData.h"
#include "Plane.h"
#include "Vec.h"
#include "R3DScrollFog.h"
namespace New3D {
class CNew3D : public IRender3D
{
public:
/*
* RenderFrame(void):
*
* Renders the complete scene database. Must be called between BeginFrame() and
* EndFrame(). This function traverses the scene database and builds up display
* lists.
*/
void RenderFrame(void);
/*
* BeginFrame(void):
*
* Prepare to render a new frame. Must be called once per frame prior to
* drawing anything.
*/
void BeginFrame(void);
/*
* EndFrame(void):
*
* Signals the end of rendering for this frame. Must be called last during
* the frame.
*/
void EndFrame(void);
/*
* UploadTextures(x, y, width, height):
*
* Signals that a portion of texture RAM has been updated.
*
* Parameters:
* x X position within texture RAM.
* y Y position within texture RAM.
* width Width of texture data in texels.
* height Height.
*/
void UploadTextures(unsigned x, unsigned y, unsigned width, unsigned height);
/*
* AttachMemory(cullingRAMLoPtr, cullingRAMHiPtr, polyRAMPtr, vromPtr,
* textureRAMPtr):
*
* Attaches RAM and ROM areas. This must be done prior to any rendering
* otherwise the program may crash with an access violation.
*
* Parameters:
* cullingRAMLoPtr Pointer to low culling RAM (4 MB).
* cullingRAMHiPtr Pointer to high culling RAM (1 MB).
* polyRAMPtr Pointer to polygon RAM (4 MB).
* vromPtr Pointer to video ROM (64 MB).
* textureRAMPtr Pointer to texture RAM (8 MB).
*/
void AttachMemory(const UINT32 *cullingRAMLoPtr,
const UINT32 *cullingRAMHiPtr, const UINT32 *polyRAMPtr,
const UINT32 *vromPtr, const UINT16 *textureRAMPtr);
/*
* SetStep(stepID):
*
* Sets the Model 3 hardware stepping, which also determines the Real3D
* functionality. The default is Step 1.0. This should be called prior to
* any other emulation functions and after Init().
*
* Parameters:
* stepID 0x10 for Step 1.0, 0x15 for Step 1.5, 0x20 for Step 2.0,
* or 0x21 for Step 2.1. Anything else defaults to 1.0.
*/
void SetStep(int stepID);
/*
* Init(xOffset, yOffset, xRes, yRes, totalXRes, totalYRes):
*
* One-time initialization of the context. Must be called before any other
* members (meaning it should be called even before being attached to any
* other objects that want to use it).
*
* External shader files are loaded according to configuration settings.
*
* Parameters:
* xOffset X offset of the viewable area within OpenGL display
* surface, in pixels.
* yOffset Y offset.
* xRes Horizontal resolution of the viewable area.
* yRes Vertical resolution.
* totalXRes Horizontal resolution of the complete display area.
* totalYRes Vertical resolution.
*
* Returns:
* OKAY is successful, otherwise FAILED if a non-recoverable error
* occurred. Any allocated memory will not be freed until the
* destructor is called. Prints own error messages.
*/
bool Init(unsigned xOffset, unsigned yOffset, unsigned xRes, unsigned yRes, unsigned totalXRes, unsigned totalYRes);
/*
* CRender3D(void):
* ~CRender3D(void):
*
* Constructor and destructor.
*/
CNew3D(void);
~CNew3D(void);
private:
/*
* Private Members
*/
// Real3D address translation
const UINT32 *TranslateCullingAddress(UINT32 addr);
const UINT32 *TranslateModelAddress(UINT32 addr);
// Matrix stack
void MultMatrix(UINT32 matrixOffset, Mat4& mat);
void InitMatrixStack(UINT32 matrixBaseAddr, Mat4& mat);
// Scene database traversal
bool DrawModel(UINT32 modelAddr);
void DescendCullingNode(UINT32 addr);
void DescendPointerList(UINT32 addr);
void DescendNodePtr(UINT32 nodeAddr);
void RenderViewport(UINT32 addr);
// building the scene
void CacheModel(Model *m, const UINT32 *data);
void CopyVertexData(const R3DPoly& r3dPoly, std::vector<Poly>& polyArray);
void OffsetTexCoords(R3DPoly& r3dPoly, float offset[2]);
void RenderScene(int priority, bool alpha);
float Determinant3x3(const float m[16]);
bool IsDynamicModel(UINT32 *data); // check if the model has a colour palette
bool IsVROMModel(UINT32 modelAddr);
void DrawScrollFog();
void CalcTexOffset(int offX, int offY, int page, int x, int y, int& newX, int& newY);
/*
* Data
*/
// Stepping
int m_step;
int m_offset; // offset to subtract for words 3 and higher of culling nodes
float m_vertexFactor; // fixed-point conversion factor for vertices
// Memory (passed from outside)
const UINT32 *m_cullingRAMLo; // 4 MB
const UINT32 *m_cullingRAMHi; // 1 MB
const UINT32 *m_polyRAM; // 4 MB
const UINT32 *m_vrom; // 64 MB
const UINT16 *m_textureRAM; // 8 MB
// Resolution and scaling factors (to support resolutions higher than 496x384) and offsets
float m_xRatio, m_yRatio;
unsigned m_xOffs, m_yOffs;
unsigned m_totalXRes, m_totalYRes;
// Real3D Base Matrix Pointer
const float *m_matrixBasePtr;
UINT32 m_colorTableAddr = 0x400; // address of color table in polygon RAM
TextureSheet m_texSheet;
NodeAttributes m_nodeAttribs;
Mat4 m_modelMat; // current modelview matrix
std::vector<Node> m_nodes; // this represents the entire render frame
std::vector<Poly> m_polyBufferRam; // dynamic polys
std::vector<Poly> m_polyBufferRom; // rom polys
std::unordered_map<UINT32, std::shared_ptr<std::vector<Mesh>>> m_romMap; // a hash table for all the ROM models. The meshes don't have model matrices or tex offsets yet
VBO m_vbo; // large VBO to hold our poly data, start of VBO is ROM data, ram polys follow
R3DShader m_r3dShader;
R3DScrollFog m_r3dScrollFog;
Plane m_planes[6];
struct BBox
{
V4::Vec4 points[8];
};
void CalcFrustumPlanes (Plane p[6], const float* matrix);
void CalcBox (float distance, BBox& box);
void TransformBox (const float *m, BBox& box);
void MultVec (const float matrix[16], const float in[4], float out[4]);
Clip ClipBox (BBox& box, Plane planes[6]);
void TestDraw();
};
} // New3D
#endif // INCLUDED_NEW3D_H

View file

@ -1,355 +0,0 @@
#include "R3DShader.h"
#include "Graphics/Shader.h"
namespace New3D {
static const char *vertexShaderBasic =
// uniforms
"uniform float fogIntensity;\n"
"uniform float fogDensity;\n"
"uniform float fogStart;\n"
//outputs to fragment shader
"varying float fsFogFactor;\n"
"varying float fsSpecularTerm;\n" // specular light term (additive)
"varying vec3 fsViewVertex;\n"
"varying vec3 fsViewNormal;\n" // per vertex normal vector
"void main(void)\n"
"{\n"
"fsViewVertex = vec3(gl_ModelViewMatrix * gl_Vertex);\n"
"fsViewNormal = normalize(gl_NormalMatrix *gl_Normal);\n"
"float z = length(fsViewVertex);\n"
"fsFogFactor = fogIntensity * clamp(fogStart + z * fogDensity, 0.0, 1.0);\n"
"gl_FrontColor = gl_Color;\n"
"gl_TexCoord[0] = gl_MultiTexCoord0;\n"
"gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
"}\n";
static const char *fragmentShaderBasic =
"uniform sampler2D tex1;\n" // base tex
"uniform sampler2D tex2;\n" // micro tex (optional)
"uniform int textureEnabled;\n"
"uniform int microTexture;\n"
"uniform int alphaTest;\n"
"uniform int textureAlpha;\n"
"uniform vec3 fogColour;\n"
"uniform vec4 spotEllipse;\n" // spotlight ellipse position: .x=X position (screen coordinates), .y=Y position, .z=half-width, .w=half-height)
"uniform vec2 spotRange;\n" // spotlight Z range: .x=start (viewspace coordinates), .y=limit
"uniform vec3 spotColor;\n" // spotlight RGB color
"uniform vec3 lighting[2];\n" // lighting state (lighting[0] = sun direction, lighting[1].x,y = diffuse, ambient intensities from 0-1.0)
"uniform int lightEnable;\n" // lighting enabled (1.0) or luminous (0.0), drawn at full intensity
"uniform float specularCoefficient;\n" // specular coefficient
"uniform float shininess;\n" // specular shininess
//interpolated inputs from vertex shader
"varying float fsFogFactor;\n"
"varying float fsSpecularTerm;\n" // specular light term (additive)
"varying vec3 fsViewVertex;\n"
"varying vec3 fsViewNormal;\n" // per vertex normal vector
"void main()\n"
"{\n"
"vec4 tex1Data;\n"
"vec4 colData;\n"
"vec4 finalData;\n"
"bool discardFragment = false;\n"
"tex1Data = vec4(1.0, 1.0, 1.0, 1.0);\n"
"if(textureEnabled==1) {\n"
"tex1Data = texture2D( tex1, gl_TexCoord[0].st);\n"
"if (microTexture==1) {\n"
"vec4 tex2Data = texture2D( tex2, gl_TexCoord[0].st * 4.0);\n"
"tex1Data = (tex1Data+tex2Data)/2.0;\n"
"}\n"
"if (alphaTest==1) {\n" // does it make any sense to do this later?
"if (tex1Data.a < (8.0/16.0)) {\n"
"discardFragment = true;\n"
"}\n"
"}\n"
"if (textureAlpha == 0) {\n"
"tex1Data.a = 1.0;\n"
"}\n"
"}\n"
"colData = gl_Color;\n"
"finalData = tex1Data * colData;\n"
"if (finalData.a < (1.0/16.0)) {\n" // basically chuck out any totally transparent pixels value = 1/16 the smallest transparency level h/w supports
"discardFragment = true;\n"
"}\n"
"if (discardFragment) {\n"
"discard;\n"
"}\n"
"if (lightEnable==1) {\n"
"vec3 lightIntensity;\n"
"vec3 sunVector;\n" // sun lighting vector (as reflecting away from vertex)
"float sunFactor;\n" // sun light projection along vertex normal (0.0 to 1.0)
// Real3D -> OpenGL view space convention (TO-DO: do this outside of shader)
"sunVector = lighting[0] * vec3(1.0, -1.0, -1.0);\n"
// Compute diffuse factor for sunlight
"sunFactor = max(dot(sunVector, fsViewNormal), 0.0);\n"
// Total light intensity: sum of all components
"lightIntensity = vec3(sunFactor*lighting[1].x + lighting[1].y);\n" // ambient + diffuse
"lightIntensity = clamp(lightIntensity,0.0,1.0);\n"
"vec2 ellipse;\n"
"float insideSpot;\n"
// Compute spotlight and apply lighting
"ellipse = (gl_FragCoord.xy - spotEllipse.xy) / spotEllipse.zw;\n"
"insideSpot = dot(ellipse, ellipse);\n"
"if ((insideSpot <= 1.0) && (-fsViewVertex.z >= spotRange.x)) {\n"
"lightIntensity.rgb += (1.0 - insideSpot)*spotColor;\n"
"}\n"
"finalData.rgb *= lightIntensity;\n"
"if (sunFactor > 0.0 && specularCoefficient > 0.0) {\n"
"vec3 v = normalize(-fsViewVertex);\n"
"vec3 h = normalize(sunVector + v);\n" // halfway vector
"float NdotHV = max(dot(fsViewNormal,h),0.0);\n"
"finalData.rgb += vec3(specularCoefficient * pow(NdotHV,shininess));\n"
"}\n"
"}\n"
"finalData.rgb = mix(finalData.rgb, fogColour, fsFogFactor);\n"
"gl_FragColor = finalData;\n"
"}\n";
R3DShader::R3DShader()
{
m_shaderProgram = 0;
m_vertexShader = 0;
m_fragmentShader = 0;
Start(); // reset attributes
}
void R3DShader::Start()
{
m_textured1 = false;
m_textured2 = false;
m_textureAlpha = false; // use alpha in texture
m_alphaTest = false; // discard fragment based on alpha (ogl does this with fixed function)
m_doubleSided = false;
m_lightEnabled = false;
m_layered = false;
m_shininess = 0;
m_specularCoefficient = 0;
m_matDet = MatDet::notset;
m_dirtyMesh = true; // dirty means all the above are dirty, ie first run
m_dirtyModel = true;
}
bool R3DShader::LoadShader(const char* vertexShader, const char* fragmentShader)
{
const char* vShader;
const char* fShader;
bool success;
if (vertexShader) {
vShader = vertexShader;
}
else {
vShader = vertexShaderBasic;
}
if (fragmentShader) {
fShader = fragmentShader;
}
else {
fShader = fragmentShaderBasic;
}
success = LoadShaderProgram(&m_shaderProgram, &m_vertexShader, &m_fragmentShader, nullptr, nullptr, vShader, fShader);
m_locTexture1 = glGetUniformLocation(m_shaderProgram, "tex1");
m_locTexture2 = glGetUniformLocation(m_shaderProgram, "tex2");
m_locTexture1Enabled= glGetUniformLocation(m_shaderProgram, "textureEnabled");
m_locTexture2Enabled= glGetUniformLocation(m_shaderProgram, "microTexture");
m_locTextureAlpha = glGetUniformLocation(m_shaderProgram, "textureAlpha");
m_locAlphaTest = glGetUniformLocation(m_shaderProgram, "alphaTest");
m_locFogIntensity = glGetUniformLocation(m_shaderProgram, "fogIntensity");
m_locFogDensity = glGetUniformLocation(m_shaderProgram, "fogDensity");
m_locFogStart = glGetUniformLocation(m_shaderProgram, "fogStart");
m_locFogColour = glGetUniformLocation(m_shaderProgram, "fogColour");
m_locLighting = glGetUniformLocation(m_shaderProgram, "lighting");
m_locLightEnable = glGetUniformLocation(m_shaderProgram, "lightEnable");
m_locShininess = glGetUniformLocation(m_shaderProgram, "shininess");
m_locSpecCoefficient= glGetUniformLocation(m_shaderProgram, "specularCoefficient");
m_locSpotEllipse = glGetUniformLocation(m_shaderProgram, "spotEllipse");
m_locSpotRange = glGetUniformLocation(m_shaderProgram, "spotRange");
m_locSpotColor = glGetUniformLocation(m_shaderProgram, "spotColor");
return success;
}
void R3DShader::SetShader(bool enable)
{
if (enable) {
glUseProgram(m_shaderProgram);
Start();
}
else {
glUseProgram(0);
}
}
void R3DShader::SetMeshUniforms(const Mesh* m)
{
if (m == nullptr) {
return; // sanity check
}
if (m_dirtyMesh) {
glUniform1i(m_locTexture1, 0);
glUniform1i(m_locTexture2, 1);
}
if (m_dirtyMesh || m->textured != m_textured1) {
glUniform1i(m_locTexture1Enabled, m->textured);
m_textured1 = m->textured;
}
if (m_dirtyMesh || m->microTexture != m_textured2) {
glUniform1i(m_locTexture2Enabled, m->microTexture);
m_textured2 = m->microTexture;
}
if (m_dirtyMesh || m->alphaTest != m_alphaTest) {
glUniform1i(m_locAlphaTest, m->alphaTest);
m_alphaTest = m->alphaTest;
}
if (m_dirtyMesh || m->textureAlpha != m_textureAlpha) {
glUniform1i(m_locTextureAlpha, m->textureAlpha);
m_textureAlpha = m->textureAlpha;
}
if (m_dirtyMesh || m->fogIntensity != m_fogIntensity) {
glUniform1f(m_locFogIntensity, m->fogIntensity);
m_fogIntensity = m->fogIntensity;
}
if (m_dirtyMesh || m->lighting != m_lightEnabled) {
glUniform1i(m_locLightEnable, m->lighting);
m_lightEnabled = m->lighting;
}
if (m_dirtyMesh || m->shininess != m_shininess) {
glUniform1f(m_locShininess, (m->shininess + 1) * 4);
m_shininess = m->shininess;
}
if (m_dirtyMesh || m->specularCoefficient != m_specularCoefficient) {
glUniform1f(m_locSpecCoefficient, m->specularCoefficient);
m_specularCoefficient = m->specularCoefficient;
}
if (m_dirtyMesh || m->layered != m_layered) {
m_layered = m->layered;
if (m_layered) {
glEnable(GL_STENCIL_TEST);
}
else {
glDisable(GL_STENCIL_TEST);
}
}
if (m_matDet!=MatDet::zero) {
if (m_dirtyMesh || m->doubleSided != m_doubleSided) {
m_doubleSided = m->doubleSided;
if (m_doubleSided) {
glDisable(GL_CULL_FACE);
}
else {
//glEnable(GL_CULL_FACE);
}
}
}
m_dirtyMesh = false;
}
void R3DShader::SetViewportUniforms(const Viewport *vp)
{
//didn't bother caching these, they don't get frequently called anyway
glUniform1f (m_locFogDensity, vp->fogParams[3]);
glUniform1f (m_locFogStart, vp->fogParams[4]);
glUniform3fv(m_locFogColour, 1, vp->fogParams);
glUniform3fv(m_locLighting, 2, vp->lightingParams);
glUniform4fv(m_locSpotEllipse, 1, vp->spotEllipse);
glUniform2fv(m_locSpotRange, 1, vp->spotRange);
glUniform3fv(m_locSpotColor, 1, vp->spotColor);
}
void R3DShader::SetModelStates(const Model* model)
{
//==========
MatDet test;
//==========
test = MatDet::notset; // happens for bad matrices with NaN
if (model->determinant < 0) { test = MatDet::negative; }
else if (model->determinant > 0) { test = MatDet::positive; }
else if (model->determinant == 0) { test = MatDet::zero; }
if (m_dirtyModel || m_matDet!=test) {
switch (test) {
case MatDet::negative:
glCullFace(GL_FRONT);
//glEnable(GL_CULL_FACE);
m_doubleSided = false;
break;
case MatDet::positive:
glCullFace(GL_BACK);
//glEnable(GL_CULL_FACE);
m_doubleSided = false;
break;
default:
glDisable(GL_CULL_FACE);
m_doubleSided = true; // basically drawing on both sides now
}
}
m_matDet = test;
m_dirtyModel = false;
}
} // New3D

View file

@ -1,124 +0,0 @@
#ifndef _MODEL_H_
#define _MODEL_H_
#include "types.h"
#include <vector>
#include <unordered_map>
#include <map>
#include <memory>
#include "Texture.h"
#include "Mat4.h"
namespace New3D {
struct Vertex
{
float pos[3];
float normal[3];
float texcoords[2];
UINT8 color[4]; //rgba
};
struct Poly // our polys are always 3 triangles, unlike the real h/w
{
Vertex p1;
Vertex p2;
Vertex p3;
};
struct R3DPoly
{
Vertex v[4]; // just easier to have them as an array
float faceNormal[3]; // we need this to help work out poly winding, i assume the h/w uses this instead of calculating normals itself
int number = 4;
};
struct Mesh
{
// texture
int format, x, y, width, height;
bool mirrorU = false;
bool mirrorV = false;
// attributes
bool doubleSided = false;
bool textured = false;
bool polyAlpha = false; // specified in the rgba colour
bool textureAlpha = false; // use alpha in texture
bool alphaTest = false; // discard fragment based on alpha (ogl does this with fixed function)
bool lighting = false;
bool testBit = false;
bool clockWise = true; // we need to check if the matrix will change the winding
float fogIntensity = 1.0f;
// opengl resources
int vboOffset = 0; // this will be calculated later
int triangleCount = 0;
};
struct SortingMesh : public Mesh // This struct temporarily holds the model data, before it gets copied to the main buffer
{
std::vector<Poly> polys;
};
struct Model
{
std::vector<Mesh> meshes;
bool dynamic = true;
//matrices
float modelMat[16];
float determinant; // we check if the determinant of the matrix is negative, if it is, the matrix will swap the axis order
};
struct Viewport
{
Mat4 projectionMatrix; // projection matrix
float lightingParams[6]; // lighting parameters (see RenderViewport() and vertex shader)
float spotEllipse[4]; // spotlight ellipse (see RenderViewport())
float spotRange[2]; // Z range
float spotColor[3]; // color
float fogParams[5]; // fog parameters (...)
int x, y; // viewport coordinates (scaled and in OpenGL format)
int width, height; // viewport dimensions (scaled for display surface size)
int priority;
};
class NodeAttributes
{
public:
NodeAttributes();
bool Push();
bool Pop();
bool StackLimit();
void Reset();
int currentTexOffsetX;
int currentTexOffsetY;
int currentTexOffset; // raw value
private:
struct NodeAttribs
{
int texOffsetX;
int texOffsetY;
int texOffset;
};
std::vector<NodeAttribs> m_vecAttribs;
};
struct Node
{
Viewport viewport;
std::vector<std::shared_ptr<Model>> models;
};
} // New3D
#endif

File diff suppressed because it is too large Load diff

View file

@ -1,221 +0,0 @@
/**
** Supermodel
** A Sega Model 3 Arcade Emulator.
** Copyright 2011 Bart Trzynadlowski, Nik Henson
**
** This file is part of Supermodel.
**
** Supermodel is free software: you can redistribute it and/or modify it under
** the terms of the GNU General Public License as published by the Free
** Software Foundation, either version 3 of the License, or (at your option)
** any later version.
**
** Supermodel is distributed in the hope that it will be useful, but WITHOUT
** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
** more details.
**
** You should have received a copy of the GNU General Public License along
** with Supermodel. If not, see <http://www.gnu.org/licenses/>.
**/
/*
* New3D.h
*
* Header file defining the CNew3D class: OpenGL Real3D graphics engine.
*/
#ifndef INCLUDED_NEW3D_H
#define INCLUDED_NEW3D_H
#include "Pkgs/glew.h"
#include "Types.h"
#include "TextureSheet.h"
#include "Graphics/IRender3D.h"
#include "Model.h"
#include "Mat4.h"
#include "R3DShader.h"
#include "VBO.h"
namespace New3D {
class CNew3D : public IRender3D
{
public:
/*
* RenderFrame(void):
*
* Renders the complete scene database. Must be called between BeginFrame() and
* EndFrame(). This function traverses the scene database and builds up display
* lists.
*/
void RenderFrame(void);
/*
* BeginFrame(void):
*
* Prepare to render a new frame. Must be called once per frame prior to
* drawing anything.
*/
void BeginFrame(void);
/*
* EndFrame(void):
*
* Signals the end of rendering for this frame. Must be called last during
* the frame.
*/
void EndFrame(void);
/*
* UploadTextures(x, y, width, height):
*
* Signals that a portion of texture RAM has been updated.
*
* Parameters:
* x X position within texture RAM.
* y Y position within texture RAM.
* width Width of texture data in texels.
* height Height.
*/
void UploadTextures(unsigned x, unsigned y, unsigned width, unsigned height);
/*
* AttachMemory(cullingRAMLoPtr, cullingRAMHiPtr, polyRAMPtr, vromPtr,
* textureRAMPtr):
*
* Attaches RAM and ROM areas. This must be done prior to any rendering
* otherwise the program may crash with an access violation.
*
* Parameters:
* cullingRAMLoPtr Pointer to low culling RAM (4 MB).
* cullingRAMHiPtr Pointer to high culling RAM (1 MB).
* polyRAMPtr Pointer to polygon RAM (4 MB).
* vromPtr Pointer to video ROM (64 MB).
* textureRAMPtr Pointer to texture RAM (8 MB).
*/
void AttachMemory(const UINT32 *cullingRAMLoPtr,
const UINT32 *cullingRAMHiPtr, const UINT32 *polyRAMPtr,
const UINT32 *vromPtr, const UINT16 *textureRAMPtr);
/*
* SetStep(stepID):
*
* Sets the Model 3 hardware stepping, which also determines the Real3D
* functionality. The default is Step 1.0. This should be called prior to
* any other emulation functions and after Init().
*
* Parameters:
* stepID 0x10 for Step 1.0, 0x15 for Step 1.5, 0x20 for Step 2.0,
* or 0x21 for Step 2.1. Anything else defaults to 1.0.
*/
void SetStep(int stepID);
/*
* Init(xOffset, yOffset, xRes, yRes, totalXRes, totalYRes):
*
* One-time initialization of the context. Must be called before any other
* members (meaning it should be called even before being attached to any
* other objects that want to use it).
*
* External shader files are loaded according to configuration settings.
*
* Parameters:
* xOffset X offset of the viewable area within OpenGL display
* surface, in pixels.
* yOffset Y offset.
* xRes Horizontal resolution of the viewable area.
* yRes Vertical resolution.
* totalXRes Horizontal resolution of the complete display area.
* totalYRes Vertical resolution.
*
* Returns:
* OKAY is successful, otherwise FAILED if a non-recoverable error
* occurred. Any allocated memory will not be freed until the
* destructor is called. Prints own error messages.
*/
bool Init(unsigned xOffset, unsigned yOffset, unsigned xRes, unsigned yRes, unsigned totalXRes, unsigned totalYRes);
/*
* CRender3D(void):
* ~CRender3D(void):
*
* Constructor and destructor.
*/
CNew3D(void);
~CNew3D(void);
private:
/*
* Private Members
*/
// Real3D address translation
const UINT32 *TranslateCullingAddress(UINT32 addr);
const UINT32 *TranslateModelAddress(UINT32 addr);
// Matrix stack
void MultMatrix(UINT32 matrixOffset, Mat4& mat);
void InitMatrixStack(UINT32 matrixBaseAddr, Mat4& mat);
// Scene database traversal
bool DrawModel(UINT32 modelAddr);
void DescendCullingNode(UINT32 addr);
void DescendPointerList(UINT32 addr);
void DescendNodePtr(UINT32 nodeAddr);
void RenderViewport(UINT32 addr, int pri);
// building the scene
void CacheModel(Model *m, const UINT32 *data);
void CopyVertexData(R3DPoly& r3dPoly, std::vector<Poly>& polyArray);
void RenderScene(int priority, bool alpha);
float Determinant3x3(const float m[16]);
bool IsDynamicModel(UINT32 *data); // check if the model has a colour palette
bool IsVROMModel(UINT32 modelAddr);
UINT64 GetRomMapKey(int address, int texOffset);
/*
* Data
*/
// Stepping
int m_step;
int m_offset; // offset to subtract for words 3 and higher of culling nodes
float m_vertexFactor; // fixed-point conversion factor for vertices
// Memory (passed from outside)
const UINT32 *m_cullingRAMLo; // 4 MB
const UINT32 *m_cullingRAMHi; // 1 MB
const UINT32 *m_polyRAM; // 4 MB
const UINT32 *m_vrom; // 64 MB
const UINT16 *m_textureRAM; // 8 MB
// Resolution and scaling factors (to support resolutions higher than 496x384) and offsets
float m_xRatio, m_yRatio;
unsigned m_xOffs, m_yOffs;
unsigned m_totalXRes, m_totalYRes;
// Real3D Base Matrix Pointer
const float *m_matrixBasePtr;
TextureSheet m_texSheet;
NodeAttributes m_nodeAttribs;
Mat4 m_modelMat; // current modelview matrix
int m_listDepth;
std::vector<Node> m_nodes; // this represents the entire render frame
std::vector<Poly> m_polyBufferRam; // dynamic polys
std::vector<Poly> m_polyBufferRom; // rom polys
std::unordered_map<UINT64, std::shared_ptr<Model>> m_romMap; // a hash table for all the ROM models
VBO m_vbo; // large VBO to hold our poly data, start of VBO is ROM data, ram polys follow
R3DShader m_r3dShader;
int m_currentVPPriority;
};
} // New3D
#endif // INCLUDED_NEW3D_H

View file

@ -1,84 +0,0 @@
#include "VBO.h"
namespace New3D {
VBO::VBO()
{
m_id = 0;
m_target = 0;
m_capacity = 0;
m_size = 0;
}
void VBO::Create(GLenum target, GLenum usage, GLsizeiptr size, const void* data)
{
glGenBuffers(1, &m_id); // create a vbo
glBindBuffer(target, m_id); // activate vbo id to use
glBufferData(target, size, data, usage); // upload data to video card
m_target = target;
m_capacity = size;
m_size = 0;
Bind(false); // unbind
}
void VBO::BufferSubData(GLintptr offset, GLsizeiptr size, const GLvoid* data)
{
glBufferSubData(m_target, offset, size, data);
}
bool VBO::AppendData(GLsizeiptr size, const GLvoid* data)
{
if (size == 0 || !data) {
return true; // nothing to do
}
if (m_size + size >= m_capacity) {
return false;
}
BufferSubData(m_size, size, data);
m_size += size;
return true;
}
void VBO::Reset()
{
m_size = 0;
}
void VBO::Destroy()
{
if (m_id) {
glDeleteBuffers(1, &m_id);
m_id = 0;
m_target = 0;
m_capacity = 0;
m_size = 0;
}
}
void VBO::Bind(bool enable)
{
if (enable) {
glBindBuffer(m_target, m_id);
}
else {
glBindBuffer(m_target, 0);
}
}
int VBO::GetSize()
{
return m_size;
}
int VBO::GetCapacity()
{
return m_capacity;
}
} // New3D

View file

@ -1,125 +0,0 @@
#ifndef _MODEL_H_
#define _MODEL_H_
#include "types.h"
#include <vector>
#include <unordered_map>
#include <map>
#include <memory>
#include "Texture.h"
#include "Mat4.h"
namespace New3D {
struct Vertex
{
float pos[3];
float normal[3];
float texcoords[2];
UINT8 color[4]; //rgba
};
struct Poly // our polys are always 3 triangles, unlike the real h/w
{
Vertex p1;
Vertex p2;
Vertex p3;
};
struct R3DPoly
{
Vertex v[4]; // just easier to have them as an array
float faceNormal[3]; // we need this to help work out poly winding, i assume the h/w uses this instead of calculating normals itself
int number = 4;
};
struct Mesh
{
std::shared_ptr<Texture> texture;
// attributes
bool doubleSided = false;
bool textured = false;
bool polyAlpha = false; // specified in the rgba colour
bool textureAlpha = false; // use alpha in texture
bool alphaTest = false; // discard fragment based on alpha (ogl does this with fixed function)
bool lighting = false;
bool testBit = false;
bool clockWise = true; // we need to check if the matrix will change the winding
float fogIntensity = 1.0f;
// texture
bool mirrorU = false;
bool mirrorV = false;
// opengl resources
int vboOffset = 0; // this will be calculated later
int triangleCount = 0;
};
struct SortingMesh : public Mesh // This struct temporarily holds the model data, before it gets copied to the main buffer
{
std::vector<Poly> polys;
};
struct Model
{
std::vector<Mesh> meshes;
bool dynamic = true;
//matrices
float modelMat[16];
float determinant; // we check if the determinant of the matrix is negative, if it is, the matrix will swap the axis order
};
struct Viewport
{
Mat4 projectionMatrix; // projection matrix
float lightingParams[6]; // lighting parameters (see RenderViewport() and vertex shader)
float spotEllipse[4]; // spotlight ellipse (see RenderViewport())
float spotRange[2]; // Z range
float spotColor[3]; // color
float fogParams[5]; // fog parameters (...)
int x, y; // viewport coordinates (scaled and in OpenGL format)
int width, height; // viewport dimensions (scaled for display surface size)
int priority;
};
class NodeAttributes
{
public:
NodeAttributes();
bool Push();
bool Pop();
bool StackLimit();
void Reset();
int currentTexOffsetX;
int currentTexOffsetY;
int currentTexOffset; // raw value
private:
struct NodeAttribs
{
int texOffsetX;
int texOffsetY;
int texOffset;
};
std::vector<NodeAttribs> m_vecAttribs;
};
struct Node
{
Viewport viewport;
std::vector<Model> models;
};
} // New3D
#endif

File diff suppressed because it is too large Load diff

View file

@ -1,226 +0,0 @@
/**
** Supermodel
** A Sega Model 3 Arcade Emulator.
** Copyright 2011 Bart Trzynadlowski, Nik Henson
**
** This file is part of Supermodel.
**
** Supermodel is free software: you can redistribute it and/or modify it under
** the terms of the GNU General Public License as published by the Free
** Software Foundation, either version 3 of the License, or (at your option)
** any later version.
**
** Supermodel is distributed in the hope that it will be useful, but WITHOUT
** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
** more details.
**
** You should have received a copy of the GNU General Public License along
** with Supermodel. If not, see <http://www.gnu.org/licenses/>.
**/
/*
* New3D.h
*
* Header file defining the CNew3D class: OpenGL Real3D graphics engine.
*/
#ifndef INCLUDED_NEW3D_H
#define INCLUDED_NEW3D_H
#include "Pkgs/glew.h"
#include "Types.h"
#include "TextureSheet.h"
#include "Graphics/IRender3D.h"
#include "Model.h"
#include "Mat4.h"
#include "R3DShader.h"
#include "VBO.h"
namespace New3D {
class CNew3D : public IRender3D
{
public:
/*
* RenderFrame(void):
*
* Renders the complete scene database. Must be called between BeginFrame() and
* EndFrame(). This function traverses the scene database and builds up display
* lists.
*/
void RenderFrame(void);
/*
* BeginFrame(void):
*
* Prepare to render a new frame. Must be called once per frame prior to
* drawing anything.
*/
void BeginFrame(void);
/*
* EndFrame(void):
*
* Signals the end of rendering for this frame. Must be called last during
* the frame.
*/
void EndFrame(void);
/*
* UploadTextures(x, y, width, height):
*
* Signals that a portion of texture RAM has been updated.
*
* Parameters:
* x X position within texture RAM.
* y Y position within texture RAM.
* width Width of texture data in texels.
* height Height.
*/
void UploadTextures(unsigned x, unsigned y, unsigned width, unsigned height);
/*
* AttachMemory(cullingRAMLoPtr, cullingRAMHiPtr, polyRAMPtr, vromPtr,
* textureRAMPtr):
*
* Attaches RAM and ROM areas. This must be done prior to any rendering
* otherwise the program may crash with an access violation.
*
* Parameters:
* cullingRAMLoPtr Pointer to low culling RAM (4 MB).
* cullingRAMHiPtr Pointer to high culling RAM (1 MB).
* polyRAMPtr Pointer to polygon RAM (4 MB).
* vromPtr Pointer to video ROM (64 MB).
* textureRAMPtr Pointer to texture RAM (8 MB).
*/
void AttachMemory(const UINT32 *cullingRAMLoPtr,
const UINT32 *cullingRAMHiPtr, const UINT32 *polyRAMPtr,
const UINT32 *vromPtr, const UINT16 *textureRAMPtr);
/*
* SetStep(stepID):
*
* Sets the Model 3 hardware stepping, which also determines the Real3D
* functionality. The default is Step 1.0. This should be called prior to
* any other emulation functions and after Init().
*
* Parameters:
* stepID 0x10 for Step 1.0, 0x15 for Step 1.5, 0x20 for Step 2.0,
* or 0x21 for Step 2.1. Anything else defaults to 1.0.
*/
void SetStep(int stepID);
/*
* Init(xOffset, yOffset, xRes, yRes, totalXRes, totalYRes):
*
* One-time initialization of the context. Must be called before any other
* members (meaning it should be called even before being attached to any
* other objects that want to use it).
*
* External shader files are loaded according to configuration settings.
*
* Parameters:
* xOffset X offset of the viewable area within OpenGL display
* surface, in pixels.
* yOffset Y offset.
* xRes Horizontal resolution of the viewable area.
* yRes Vertical resolution.
* totalXRes Horizontal resolution of the complete display area.
* totalYRes Vertical resolution.
*
* Returns:
* OKAY is successful, otherwise FAILED if a non-recoverable error
* occurred. Any allocated memory will not be freed until the
* destructor is called. Prints own error messages.
*/
bool Init(unsigned xOffset, unsigned yOffset, unsigned xRes, unsigned yRes, unsigned totalXRes, unsigned totalYRes);
/*
* CRender3D(void):
* ~CRender3D(void):
*
* Constructor and destructor.
*/
CNew3D(void);
~CNew3D(void);
private:
/*
* Private Members
*/
// Real3D address translation
const UINT32 *TranslateCullingAddress(UINT32 addr);
const UINT32 *TranslateModelAddress(UINT32 addr);
// Matrix stack
void MultMatrix(UINT32 matrixOffset, Mat4& mat);
void InitMatrixStack(UINT32 matrixBaseAddr, Mat4& mat);
// Scene database traversal
bool DrawModel(UINT32 modelAddr);
void DescendCullingNode(UINT32 addr);
void DescendPointerList(UINT32 addr);
void DescendNodePtr(UINT32 nodeAddr);
void RenderViewport(UINT32 addr, int pri);
// building the scene
void CacheModel(Model *m, const UINT32 *data);
void CopyVertexData(R3DPoly& r3dPoly, std::vector<Poly>& polyArray);
void RenderScene(int priority, bool alpha);
float Determinant3x3(const float m[16]);
bool IsDynamicModel(UINT32 *data); // check if the model has a colour palette
bool IsVROMModel(UINT32 modelAddr);
UINT64 GetRomMapKey(int address, int texOffset);
/*
* Data
*/
// Stepping
int m_step;
int m_offset; // offset to subtract for words 3 and higher of culling nodes
float m_vertexFactor; // fixed-point conversion factor for vertices
// Memory (passed from outside)
const UINT32 *m_cullingRAMLo; // 4 MB
const UINT32 *m_cullingRAMHi; // 1 MB
const UINT32 *m_polyRAM; // 4 MB
const UINT32 *m_vrom; // 64 MB
const UINT16 *m_textureRAM; // 8 MB
// Resolution and scaling factors (to support resolutions higher than 496x384) and offsets
float m_xRatio, m_yRatio;
unsigned m_xOffs, m_yOffs;
unsigned m_totalXRes, m_totalYRes;
// Real3D Base Matrix Pointer
const float *m_matrixBasePtr;
TextureSheet m_texSheet;
NodeAttributes m_nodeAttribs;
Mat4 m_modelMat; // current modelview matrix
int m_listDepth;
std::vector<Node> m_nodes; // build the scene
std::vector<Poly> m_polyBufferRam;
std::vector<Poly> m_polyBufferRom;
VBO m_vbo; // large VBO to hold our poly data, start of VBO is ROM data, ram polys follow
struct ModelKey {
int lutIdx;
int texOffset;
};
std::unordered_map<UINT64, Model> m_romMap;
R3DShader m_r3dShader;
int m_currentVPPriority;
};
} // New3D
#endif // INCLUDED_NEW3D_H