Files
dolphin/Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp
T

101 lines
2.5 KiB
C++
Raw Normal View History

// Copyright 2013 Dolphin Emulator Project
// Licensed under GPLv2
// Refer to the license.txt file included.
2008-12-08 05:25:12 +00:00
#include "GLUtil.h"
2008-12-08 05:25:12 +00:00
#include "x64Emitter.h"
2013-02-26 13:49:00 -06:00
#include "x64ABI.h"
2008-12-08 05:25:12 +00:00
#include "MemoryUtil.h"
2011-11-30 21:00:21 -06: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"
#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.
namespace OGL
{
NativeVertexFormat* VertexManager::CreateNativeVertexFormat()
{
return new GLVertexFormat();
}
GLVertexFormat::GLVertexFormat()
2008-12-08 05:25:12 +00:00
{
2012-12-15 14:43:01 +01:00
2008-12-08 05:25:12 +00:00
}
GLVertexFormat::~GLVertexFormat()
2008-12-08 05:25:12 +00:00
{
glDeleteVertexArrays(1, &VAO);
2008-12-08 05:25:12 +00:00
}
inline GLuint VarToGL(VarType t)
{
static const GLuint lookup[5] = {
GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_FLOAT
};
2008-12-08 05:25:12 +00:00
return lookup[t];
}
static void SetPointer(u32 attrib, u32 stride, const AttributeFormat &format)
{
if (!format.enable)
return;
glEnableVertexAttribArray(attrib);
if (format.integer)
glVertexAttribIPointer(attrib, format.components, VarToGL(format.type), stride, (u8*)NULL + format.offset);
else
glVertexAttribPointer(attrib, format.components, VarToGL(format.type), true, stride, (u8*)NULL + format.offset);
}
void GLVertexFormat::Initialize(const PortableVertexDeclaration &_vtx_decl)
2008-12-08 05:25:12 +00:00
{
2012-12-15 14:43:01 +01:00
this->vtx_decl = _vtx_decl;
vertex_stride = vtx_decl.stride;
2008-12-08 05:25:12 +00:00
// We will not allow vertex components causing uneven strides.
if (vertex_stride & 3)
2012-12-15 14:43:01 +01:00
PanicAlert("Uneven vertex stride: %i", vertex_stride);
2012-12-15 14:43:01 +01:00
VertexManager *vm = (OGL::VertexManager*)g_vertex_manager;
glGenVertexArrays(1, &VAO);
glBindVertexArray(VAO);
// 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);
glBindBuffer(GL_ARRAY_BUFFER, vm->m_vertex_buffers);
2008-12-08 05:25:12 +00:00
SetPointer(SHADER_POSITION_ATTRIB, vertex_stride, vtx_decl.position);
2013-01-14 22:59:08 +01:00
for (int i = 0; i < 3; i++) {
SetPointer(SHADER_NORM0_ATTRIB+i, vertex_stride, vtx_decl.normals[i]);
2008-12-08 05:25:12 +00:00
}
for (int i = 0; i < 2; i++) {
SetPointer(SHADER_COLOR0_ATTRIB+i, vertex_stride, vtx_decl.colors[i]);
2008-12-08 05:25:12 +00:00
}
for (int i = 0; i < 8; i++) {
SetPointer(SHADER_TEXTURE0_ATTRIB+i, vertex_stride, vtx_decl.texcoords[i]);
2008-12-08 05:25:12 +00:00
}
if (vtx_decl.posmtx_offset != -1) {
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
vm->m_last_vao = VAO;
2008-12-08 05:25:12 +00:00
}
2008-12-26 17:02:46 +00:00
2011-01-24 11:57:17 +00:00
void GLVertexFormat::SetupVertexPointers() {
}
2008-12-26 17:02:46 +00:00
}