2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 03:29:41 +00:00
|
|
|
// Refer to the license.txt file included.
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2014-02-19 11:14:09 +00:00
|
|
|
#include "Common/MemoryUtil.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Common/x64ABI.h"
|
|
|
|
#include "Common/x64Emitter.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoBackends/OGL/GLUtil.h"
|
|
|
|
#include "VideoBackends/OGL/ProgramShaderCache.h"
|
|
|
|
#include "VideoBackends/OGL/VertexManager.h"
|
|
|
|
|
|
|
|
#include "VideoCommon/CPMemory.h"
|
|
|
|
#include "VideoCommon/NativeVertexFormat.h"
|
|
|
|
#include "VideoCommon/VertexShaderGen.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
|
|
|
}
|
|
|
|
|
2014-08-15 18:16:04 +00:00
|
|
|
static inline GLuint VarToGL(VarType t)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2010-01-12 00:08:02 +00:00
|
|
|
static const GLuint lookup[5] = {
|
2014-01-24 13:18:55 +00:00
|
|
|
GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_FLOAT
|
2010-01-12 00:08:02 +00:00
|
|
|
};
|
2008-12-08 05:25:12 +00:00
|
|
|
return lookup[t];
|
|
|
|
}
|
|
|
|
|
2014-01-24 13:46:05 +00:00
|
|
|
static void SetPointer(u32 attrib, u32 stride, const AttributeFormat &format)
|
|
|
|
{
|
|
|
|
if (!format.enable)
|
|
|
|
return;
|
|
|
|
|
|
|
|
glEnableVertexAttribArray(attrib);
|
|
|
|
if (format.integer)
|
2014-03-09 20:14:26 +00:00
|
|
|
glVertexAttribIPointer(attrib, format.components, VarToGL(format.type), stride, (u8*)nullptr + format.offset);
|
2014-01-24 13:46:05 +00:00
|
|
|
else
|
2014-03-09 20:14:26 +00:00
|
|
|
glVertexAttribPointer(attrib, format.components, VarToGL(format.type), true, stride, (u8*)nullptr + format.offset);
|
2014-01-24 13:46:05 +00:00
|
|
|
}
|
|
|
|
|
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;
|
2015-01-23 14:15:09 +00:00
|
|
|
u32 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.
|
2013-10-29 05:23:17 +00:00
|
|
|
if (vertex_stride & 3)
|
2012-12-15 13:43:01 +00:00
|
|
|
PanicAlert("Uneven vertex stride: %i", vertex_stride);
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2012-12-15 13:43:01 +00:00
|
|
|
VertexManager *vm = (OGL::VertexManager*)g_vertex_manager;
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2012-12-15 16:28:58 +00:00
|
|
|
glGenVertexArrays(1, &VAO);
|
|
|
|
glBindVertexArray(VAO);
|
2013-10-29 05:23:17 +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
|
|
|
|
2014-01-24 13:46:05 +00:00
|
|
|
SetPointer(SHADER_POSITION_ATTRIB, vertex_stride, vtx_decl.position);
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2014-08-15 18:09:53 +00:00
|
|
|
for (int i = 0; i < 3; i++)
|
2014-01-24 14:16:52 +00:00
|
|
|
SetPointer(SHADER_NORM0_ATTRIB+i, vertex_stride, vtx_decl.normals[i]);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2014-08-15 18:09:53 +00:00
|
|
|
for (int i = 0; i < 2; i++)
|
2014-01-24 14:23:50 +00:00
|
|
|
SetPointer(SHADER_COLOR0_ATTRIB+i, vertex_stride, vtx_decl.colors[i]);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2014-08-15 18:09:53 +00:00
|
|
|
for (int i = 0; i < 8; i++)
|
2014-01-24 14:32:27 +00:00
|
|
|
SetPointer(SHADER_TEXTURE0_ATTRIB+i, vertex_stride, vtx_decl.texcoords[i]);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2014-01-24 14:41:08 +00:00
|
|
|
SetPointer(SHADER_POSMTX_ATTRIB, vertex_stride, vtx_decl.posmtx);
|
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
|
|
|
}
|
|
|
|
|
2014-08-15 18:09:53 +00:00
|
|
|
void GLVertexFormat::SetupVertexPointers()
|
|
|
|
{
|
2012-10-26 14:34:02 +00:00
|
|
|
}
|
2008-12-26 17:02:46 +00:00
|
|
|
|
|
|
|
}
|