Draw using VBO. Add option, make default true.

This commit is contained in:
Henrik Rydgard 2013-01-10 12:51:18 +01:00
parent 3615b36a82
commit 479d1f5111
11 changed files with 93 additions and 15 deletions

View File

@ -65,6 +65,7 @@ void CConfig::Load(const char *iniFileName)
graphics->Get("HardwareTransform", &bHardwareTransform, true);
graphics->Get("LinearFiltering", &bLinearFiltering, false);
graphics->Get("SSAA", &SSAntiAlaising, 0);
graphics->Get("VBO", &bUseVBO, true);
IniFile::Section *sound = iniFile.GetOrCreateSection("Sound");
sound->Get("Enable", &bEnableSound, true);
@ -105,6 +106,7 @@ void CConfig::Save()
graphics->Set("HardwareTransform", bHardwareTransform);
graphics->Set("LinearFiltering", bLinearFiltering);
graphics->Set("SSAA", SSAntiAlaising);
graphics->Set("VBO", bUseVBO);
IniFile::Section *sound = iniFile.GetOrCreateSection("Sound");
sound->Set("Enable", bEnableSound);

View File

@ -53,6 +53,7 @@ public:
bool bBufferedRendering;
bool bDrawWireframe;
bool bLinearFiltering;
bool bUseVBO;
int iWindowZoom; // for Windows
bool SSAntiAlaising; //for Windows, too

View File

@ -1117,7 +1117,7 @@ u32 sceMpegChangeGetAuMode(u32 mpeg, int streamUid, int mode)
StreamInfo info;
info.sid = streamUid;
if (info.sid) {
if (info.sid) {
switch (info.type) {
case MPEG_AVC_STREAM:
if(mode == MPEG_AU_MODE_DECODE) {

View File

@ -23,6 +23,7 @@
#include "../Math3D.h"
#include "../GPUState.h"
#include "../ge_constants.h"
#include "../../Core/Config.h"
#include "StateMapping.h"
#include "TextureCache.h"
@ -44,6 +45,8 @@ const GLuint glprim[8] = {
TransformDrawEngine::TransformDrawEngine()
: numVerts(0),
lastVType(-1),
vbo_(0),
ebo_(0),
shaderManager_(0) {
decoded = new u8[65536 * 48];
decIndex = new u16[65536];
@ -51,13 +54,40 @@ TransformDrawEngine::TransformDrawEngine()
transformedExpanded = new TransformedVertex[65536 * 3];
indexGen.Setup(decIndex);
InitDeviceObjects();
register_gl_resource_holder(this);
}
TransformDrawEngine::~TransformDrawEngine() {
DestroyDeviceObjects();
delete [] decoded;
delete [] decIndex;
delete [] transformed;
delete [] transformedExpanded;
unregister_gl_resource_holder(this);
}
void TransformDrawEngine::InitDeviceObjects() {
if (!vbo_) {
glGenBuffers(1, &vbo_);
glGenBuffers(1, &ebo_);
} else {
ERROR_LOG(G3D, "Device objects already initialized!");
}
}
void TransformDrawEngine::DestroyDeviceObjects() {
glDeleteBuffers(1, &vbo_);
glDeleteBuffers(1, &ebo_);
vbo_ = 0;
ebo_ = 0;
}
void TransformDrawEngine::GLLost() {
// The objects have already been deleted.
vbo_ = 0;
ebo_ = 0;
InitDeviceObjects();
}
// Just to get something on the screen, we'll just not subdivide correctly.
@ -582,15 +612,23 @@ void TransformDrawEngine::SoftwareTransformAndDraw(
// TODO: Make a cache for glEnableVertexAttribArray and glVertexAttribPtr states,
// these spam the gDebugger log.
const int vertexSize = sizeof(transformed[0]);
glBindBuffer(GL_ARRAY_BUFFER, vbo_);
glBufferData(GL_ARRAY_BUFFER, vertexSize * numTrans, drawBuffer, GL_STREAM_DRAW);
drawBuffer = 0; // so that the calls use offsets instead.
glVertexAttribPointer(program->a_position, 3, GL_FLOAT, GL_FALSE, vertexSize, drawBuffer);
if (program->a_texcoord != -1) glVertexAttribPointer(program->a_texcoord, 2, GL_FLOAT, GL_FALSE, vertexSize, ((uint8_t*)drawBuffer) + 3 * 4);
if (program->a_color0 != -1) glVertexAttribPointer(program->a_color0, 4, GL_FLOAT, GL_FALSE, vertexSize, ((uint8_t*)drawBuffer) + 5 * 4);
if (program->a_color1 != -1) glVertexAttribPointer(program->a_color1, 3, GL_FLOAT, GL_FALSE, vertexSize, ((uint8_t*)drawBuffer) + 9 * 4);
if (drawIndexed) {
glDrawElements(glprim[prim], numTrans, GL_UNSIGNED_SHORT, (GLvoid *)inds);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo_);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(short) * numTrans, inds, GL_STREAM_DRAW);
glDrawElements(glprim[prim], numTrans, GL_UNSIGNED_SHORT, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
} else {
glDrawArrays(glprim[prim], 0, numTrans);
}
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
void TransformDrawEngine::SubmitPrim(void *verts, void *inds, int prim, int vertexCount, u32 vertType, int forceIndexType, int *bytesRead) {
@ -691,8 +729,14 @@ void TransformDrawEngine::Flush() {
DEBUG_LOG(G3D, "Flush prim %i! %i verts in one go", prim, numVerts);
bool useVBO = g_Config.bUseVBO;
if (CanUseHardwareTransform(prim)) {
SetupDecFmtForDraw(program, dec.GetDecVtxFmt(), decoded);
if (useVBO) {
glBindBuffer(GL_ARRAY_BUFFER, vbo_);
glBufferData(GL_ARRAY_BUFFER, dec.GetDecVtxFmt().stride * indexGen.MaxIndex(), decoded, GL_STREAM_DRAW);
}
SetupDecFmtForDraw(program, dec.GetDecVtxFmt(), useVBO ? 0 : decoded);
// If there's only been one primitive type, and it's either TRIANGLES, LINES or POINTS,
// there is no need for the index buffer we built. We can then use glDrawArrays instead
// for a very minor speed boost.
@ -700,7 +744,17 @@ void TransformDrawEngine::Flush() {
if (seen == (1 << GE_PRIM_TRIANGLES) || seen == (1 << GE_PRIM_LINES) || seen == (1 << GE_PRIM_POINTS)) {
glDrawArrays(glprim[prim], 0, indexGen.VertexCount());
} else {
glDrawElements(glprim[prim], indexGen.VertexCount(), GL_UNSIGNED_SHORT, (GLvoid *)decIndex);
if (useVBO) {
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo_);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(short) * indexGen.VertexCount(), (GLvoid *)decIndex, GL_STREAM_DRAW);
}
glDrawElements(glprim[prim], indexGen.VertexCount(), GL_UNSIGNED_SHORT, useVBO ? 0 : (GLvoid*)decIndex);
if (useVBO) {
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
}
if (useVBO) {
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
} else {
SoftwareTransformAndDraw(prim, decoded, program, indexGen.VertexCount(), dec.VertexType(), (void *)decIndex, GE_VTYPE_IDX_16BIT, dec.GetDecVtxFmt(),

View File

@ -19,13 +19,14 @@
#include "IndexGenerator.h"
#include "VertexDecoder.h"
#include "gfx/gl_lost_manager.h"
class LinkedShader;
class ShaderManager;
struct DecVtxFormat;
// Handles transform, lighting and drawing.
class TransformDrawEngine {
class TransformDrawEngine : public GfxResourceHolder {
public:
TransformDrawEngine();
~TransformDrawEngine();
@ -37,6 +38,10 @@ public:
shaderManager_ = shaderManager;
}
void InitDeviceObjects();
void DestroyDeviceObjects();
void GLLost();
private:
void SoftwareTransformAndDraw(int prim, u8 *decoded, LinkedShader *program, int vertexCount, u32 vertexType, void *inds, int indexType, const DecVtxFormat &decVtxFormat, int maxIndex);
@ -53,6 +58,11 @@ private:
TransformedVertex *transformed;
TransformedVertex *transformedExpanded;
// Vertex buffer objects
// Element buffer objects
GLuint vbo_; // Single one for now, might want to rotate later.
GLuint ebo_; // Same here.
// Other
ShaderManager *shaderManager_;
};

View File

@ -495,6 +495,10 @@ namespace MainWindow
g_Config.bFastMemory = !g_Config.bFastMemory;
UpdateMenus();
break;
case ID_OPTIONS_USEVBO:
g_Config.bUseVBO = !g_Config.bUseVBO;
UpdateMenus();
break;
case ID_OPTIONS_LINEARFILTERING:
g_Config.bLinearFiltering = !g_Config.bLinearFiltering;
UpdateMenus();
@ -648,6 +652,7 @@ namespace MainWindow
CHECKITEM(ID_OPTIONS_LINEARFILTERING, g_Config.bLinearFiltering);
CHECKITEM(ID_OPTIONS_SIMPLE2XSSAA, g_Config.SSAntiAlaising);
CHECKITEM(ID_EMULATION_RUNONLOAD, g_Config.bAutoRun);
CHECKITEM(ID_OPTIONS_USEVBO, g_Config.bUseVBO);
UINT enable = !Core_IsStepping() ? MF_GRAYED : MF_ENABLED;
EnableMenuItem(menu,ID_EMULATION_RUN, g_State.bEmuThreadStarted ? enable : MF_GRAYED);

View File

@ -256,6 +256,7 @@ BEGIN
MENUITEM "&Hardware Transform\tF6", ID_OPTIONS_HARDWARETRANSFORM
MENUITEM "&Linear Filtering", ID_OPTIONS_LINEARFILTERING
MENUITEM "Si&mple 2x SSAA", ID_OPTIONS_SIMPLE2XSSAA
MENUITEM "&Use VBO", ID_OPTIONS_USEVBO
MENUITEM SEPARATOR
MENUITEM "&Wireframe (experimental)", ID_OPTIONS_WIREFRAME
MENUITEM "&Display Raw Framebuffer", ID_OPTIONS_DISPLAYRAWFRAMEBUFFER

View File

@ -255,6 +255,7 @@
#define ID_EMULATION_RUNONLOAD 40131
#define ID_DEBUG_DUMPNEXTFRAME 40132
#define ID_OPTIONS_SIMPLE2XSSAA 40133
#define ID_OPTIONS_USEVBO 40134
#define IDC_STATIC -1
// Next default values for new objects
@ -262,7 +263,7 @@
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 233
#define _APS_NEXT_COMMAND_VALUE 40133
#define _APS_NEXT_COMMAND_VALUE 40135
#define _APS_NEXT_CONTROL_VALUE 1163
#define _APS_NEXT_SYMED_VALUE 101
#endif

View File

@ -273,24 +273,28 @@ void SettingsScreen::render() {
ui_draw2d.DrawText(UBUNTU48, "Settings", dp_xres / 2, 30, 0xFFFFFFFF, ALIGN_HCENTER);
// TODO: Need to add tabs soon...
// VLinear vlinear(10, 80, 10);
int x = 30;
int y = 50;
UICheckBox(GEN_ID, x, y += 45, "Sound Emulation", ALIGN_TOPLEFT, &g_Config.bEnableSound);
UICheckBox(GEN_ID, x, y += 45, "Buffered Rendering", ALIGN_TOPLEFT, &g_Config.bBufferedRendering);
int stride = 40;
UICheckBox(GEN_ID, x, y += stride, "Sound Emulation", ALIGN_TOPLEFT, &g_Config.bEnableSound);
UICheckBox(GEN_ID, x, y += stride, "Buffered Rendering", ALIGN_TOPLEFT, &g_Config.bBufferedRendering);
if (g_Config.bBufferedRendering) {
bool doubleRes = g_Config.iWindowZoom == 2;
UICheckBox(GEN_ID, x + 50, y += 50, "2x Render Resolution", ALIGN_TOPLEFT, &doubleRes);
UICheckBox(GEN_ID, x + 50, y += stride, "2x Render Resolution", ALIGN_TOPLEFT, &doubleRes);
g_Config.iWindowZoom = doubleRes ? 2 : 1;
}
UICheckBox(GEN_ID, x, y += 45, "Hardware Transform", ALIGN_TOPLEFT, &g_Config.bHardwareTransform);
UICheckBox(GEN_ID, x, y += stride, "Hardware Transform", ALIGN_TOPLEFT, &g_Config.bHardwareTransform);
UICheckBox(GEN_ID, x, y += stride, "Use VBO for drawing", ALIGN_TOPLEFT, &g_Config.bUseVBO);
bool useFastInt = g_Config.iCpuCore == CPU_FASTINTERPRETER;
UICheckBox(GEN_ID, x, y += 45, "Slightly faster interpreter (may crash)", ALIGN_TOPLEFT, &useFastInt);
UICheckBox(GEN_ID, x, y += stride, "Slightly faster interpreter (may crash)", ALIGN_TOPLEFT, &useFastInt);
// ui_draw2d.DrawText(UBUNTU48, "much faster JIT coming later", x, y+=50, 0xcFFFFFFF, ALIGN_LEFT);
UICheckBox(GEN_ID, x, y += 45, "On-screen Touch Controls", ALIGN_TOPLEFT, &g_Config.bShowTouchControls);
UICheckBox(GEN_ID, x, y += stride, "On-screen Touch Controls", ALIGN_TOPLEFT, &g_Config.bShowTouchControls);
if (g_Config.bShowTouchControls)
UICheckBox(GEN_ID, x + 50, y += 50, "Show Analog Stick", ALIGN_TOPLEFT, &g_Config.bShowAnalogStick);
UICheckBox(GEN_ID, x + 50, y += stride, "Show Analog Stick", ALIGN_TOPLEFT, &g_Config.bShowAnalogStick);
g_Config.iCpuCore = useFastInt ? CPU_FASTINTERPRETER : CPU_INTERPRETER;
// UICheckBox(GEN_ID, x, y += 50, "Draw raw framebuffer (for some homebrew)", ALIGN_TOPLEFT, &g_Config.bDisplayFramebuffer);

2
native

@ -1 +1 @@
Subproject commit 11a1e3578345468ec041e72892f0a84032e2e361
Subproject commit c63061ddfd5aec3b9dd51aa4c71150de905d8d1e

@ -1 +1 @@
Subproject commit a3ad3112cfbd7130b3af9e6e7a132674cdb41c21
Subproject commit 3da47629d441b8f2f7f92e51e093a8727a3c3811