2009-07-28 21:32:10 +00:00
|
|
|
// Copyright (C) 2003 Dolphin Project.
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
// This program 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, version 2.0.
|
|
|
|
|
|
|
|
// This program 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 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
2009-01-30 07:35:47 +00:00
|
|
|
#include "GLUtil.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
#include "x64Emitter.h"
|
|
|
|
#include "ABI.h"
|
|
|
|
#include "MemoryUtil.h"
|
2011-12-01 03:00:21 +00:00
|
|
|
#include "ProgramShaderCache.h"
|
2008-12-26 17:33:53 +00:00
|
|
|
#include "VertexShaderGen.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
#include "CPMemory.h"
|
|
|
|
#include "NativeVertexFormat.h"
|
2010-11-26 09:25:08 +00:00
|
|
|
#include "VertexManager.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
// Here's some global state. We only use this to keep track of what we've sent to the OpenGL state
|
|
|
|
// machine.
|
|
|
|
|
2010-11-26 09:25:08 +00:00
|
|
|
namespace OGL
|
|
|
|
{
|
2008-12-25 15:56:36 +00:00
|
|
|
|
2010-11-26 09:25:08 +00:00
|
|
|
NativeVertexFormat* VertexManager::CreateNativeVertexFormat()
|
2008-12-25 15:56:36 +00:00
|
|
|
{
|
|
|
|
return new GLVertexFormat();
|
|
|
|
}
|
|
|
|
|
|
|
|
GLVertexFormat::GLVertexFormat()
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2012-12-15 13:43:01 +00:00
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
2008-12-25 15:56:36 +00:00
|
|
|
GLVertexFormat::~GLVertexFormat()
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2012-12-15 16:28:58 +00:00
|
|
|
glDeleteVertexArrays(1, &VAO);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline GLuint VarToGL(VarType t)
|
|
|
|
{
|
2010-01-12 00:08:02 +00:00
|
|
|
static const GLuint lookup[5] = {
|
|
|
|
GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT, GL_UNSIGNED_SHORT, GL_FLOAT
|
|
|
|
};
|
2008-12-08 05:25:12 +00:00
|
|
|
return lookup[t];
|
|
|
|
}
|
|
|
|
|
2008-12-25 15:56:36 +00:00
|
|
|
void GLVertexFormat::Initialize(const PortableVertexDeclaration &_vtx_decl)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2012-12-15 13:43:01 +00:00
|
|
|
this->vtx_decl = _vtx_decl;
|
|
|
|
vertex_stride = vtx_decl.stride;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-04-03 14:35:49 +00:00
|
|
|
// We will not allow vertex components causing uneven strides.
|
2012-12-15 13:43:01 +00:00
|
|
|
if (vertex_stride & 3)
|
|
|
|
PanicAlert("Uneven vertex stride: %i", vertex_stride);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2012-12-15 13:43:01 +00:00
|
|
|
VertexManager *vm = (OGL::VertexManager*)g_vertex_manager;
|
|
|
|
|
2012-12-15 16:28:58 +00:00
|
|
|
glGenVertexArrays(1, &VAO);
|
|
|
|
glBindVertexArray(VAO);
|
2012-12-15 13:43:01 +00:00
|
|
|
|
2012-12-15 16:28:58 +00:00
|
|
|
// the element buffer is bound directly to the vao, so we must it set for every vao
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vm->m_index_buffers);
|
2013-01-14 20:36:31 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, vm->m_vertex_buffers);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2012-12-15 16:28:58 +00:00
|
|
|
glEnableClientState(GL_VERTEX_ARRAY);
|
|
|
|
glVertexPointer(3, GL_FLOAT, vtx_decl.stride, (u8*)NULL);
|
2012-12-09 21:49:58 +00:00
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
if (vtx_decl.num_normals >= 1) {
|
2012-12-15 16:28:58 +00:00
|
|
|
glEnableClientState(GL_NORMAL_ARRAY);
|
|
|
|
glNormalPointer(VarToGL(vtx_decl.normal_gl_type), vtx_decl.stride, (u8*)NULL + vtx_decl.normal_offset[0]);
|
2008-12-08 05:25:12 +00:00
|
|
|
if (vtx_decl.num_normals == 3) {
|
2012-12-15 16:28:58 +00:00
|
|
|
glEnableVertexAttribArray(SHADER_NORM1_ATTRIB);
|
|
|
|
glEnableVertexAttribArray(SHADER_NORM2_ATTRIB);
|
|
|
|
glVertexAttribPointer(SHADER_NORM1_ATTRIB, vtx_decl.normal_gl_size, VarToGL(vtx_decl.normal_gl_type), GL_TRUE, vtx_decl.stride, (u8*)NULL + vtx_decl.normal_offset[1]);
|
|
|
|
glVertexAttribPointer(SHADER_NORM2_ATTRIB, vtx_decl.normal_gl_size, VarToGL(vtx_decl.normal_gl_type), GL_TRUE, vtx_decl.stride, (u8*)NULL + vtx_decl.normal_offset[2]);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
if (vtx_decl.color_offset[i] != -1) {
|
2012-12-15 16:28:58 +00:00
|
|
|
if (i == 0) {
|
|
|
|
glEnableClientState(GL_COLOR_ARRAY);
|
|
|
|
glColorPointer(4, GL_UNSIGNED_BYTE, vtx_decl.stride, (u8*)NULL + vtx_decl.color_offset[i]);
|
|
|
|
} else {
|
|
|
|
glEnableClientState(GL_SECONDARY_COLOR_ARRAY);
|
|
|
|
glSecondaryColorPointer(4, GL_UNSIGNED_BYTE, vtx_decl.stride, (u8*)NULL + vtx_decl.color_offset[i]);
|
2009-07-03 18:33:28 +00:00
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 8; i++) {
|
|
|
|
if (vtx_decl.texcoord_offset[i] != -1) {
|
|
|
|
int id = GL_TEXTURE0 + i;
|
|
|
|
glClientActiveTexture(id);
|
2012-12-15 16:28:58 +00:00
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
2008-12-08 05:25:12 +00:00
|
|
|
glTexCoordPointer(vtx_decl.texcoord_size[i], VarToGL(vtx_decl.texcoord_gl_type[i]),
|
2012-12-15 16:28:58 +00:00
|
|
|
vtx_decl.stride, (u8*)NULL + vtx_decl.texcoord_offset[i]);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vtx_decl.posmtx_offset != -1) {
|
2012-12-15 16:28:58 +00:00
|
|
|
glEnableVertexAttribArray(SHADER_POSMTX_ATTRIB);
|
|
|
|
glVertexAttribPointer(SHADER_POSMTX_ATTRIB, 4, GL_UNSIGNED_BYTE, GL_FALSE, vtx_decl.stride, (u8*)NULL + vtx_decl.posmtx_offset);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2008-12-26 17:02:46 +00:00
|
|
|
|
2012-12-15 16:28:58 +00:00
|
|
|
vm->m_last_vao = VAO;
|
2008-12-26 17:02:46 +00:00
|
|
|
}
|
|
|
|
|
2012-12-15 13:43:01 +00:00
|
|
|
void GLVertexFormat::SetupVertexPointers() {
|
2012-10-26 14:34:02 +00:00
|
|
|
}
|
2008-12-26 17:02:46 +00:00
|
|
|
|
|
|
|
}
|