Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
…into mar753/render-to-texture-with-options
  • Loading branch information
mar753 committed Feb 6, 2019
2 parents 88b9deb + 3c8e111 commit b26b120
Show file tree
Hide file tree
Showing 18 changed files with 617 additions and 78 deletions.
27 changes: 16 additions & 11 deletions core/linux-dist/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,25 +144,30 @@ void UpdateInputState(u32 port)

void UpdateVibration(u32 port, u32 value)
{
#if defined(USE_EVDEV)
u8 POW_POS = (value >> 8) & 0x3;
u8 POW_NEG = (value >> 12) & 0x3;
u8 FREQ = (value >> 16) & 0xFF;
u8 POW_POS = (value >> 8) & 0x3;
u8 POW_NEG = (value >> 12) & 0x3;
u8 FREQ = (value >> 16) & 0xFF;

double pow = (POW_POS + POW_NEG) / 7.0;
double pow_l = pow * (0x3B - FREQ) / 17.0;
double pow_r = pow * (FREQ - 0x07) / 15.0;
double pow = (POW_POS + POW_NEG) / 7.0;
double pow_l = pow * (0x3B - FREQ) / 17.0;
double pow_r = pow * (FREQ - 0x07) / 15.0;

if (pow_l > 1.0) pow_l = 1.0;
if (pow_r > 1.0) pow_r = 1.0;
if (pow_l > 1.0) pow_l = 1.0;
if (pow_r > 1.0) pow_r = 1.0;

u16 pow_strong = (u16)(65535 * pow_l);
u16 pow_weak = (u16)(65535 * pow_r);
u16 pow_strong = (u16)(65535 * pow_l);
u16 pow_weak = (u16)(65535 * pow_r);

#if defined(USE_EVDEV)
input_evdev_rumble(port, pow_strong, pow_weak);
#endif

#if defined(USE_SDL)
input_sdl_rumble(port, pow_strong, pow_weak);
#endif
}


void os_DoEvents()
{
#if defined(SUPPORT_X11)
Expand Down
4 changes: 4 additions & 0 deletions core/nullDC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ void LoadSettings()
settings.rend.UseMipmaps = cfgLoadInt("config", "rend.UseMipmaps", 1);
settings.rend.WideScreen = cfgLoadInt("config", "rend.WideScreen", 0);
settings.rend.Clipping = cfgLoadInt("config", "rend.Clipping", 1);
settings.rend.
VerticalResolution = cfgLoadInt("config", "rend.ResolutionPercentage", 100);
settings.rend.
HorizontalResolution = cfgLoadInt("config", "rend.ResolutionPercentage", 100);

settings.pvr.subdivide_transp = cfgLoadInt("config", "pvr.Subdivide", 0);

Expand Down
46 changes: 34 additions & 12 deletions core/oslib/audiobackend_alsa.cpp
Original file line number Diff line number Diff line change
@@ -1,36 +1,58 @@
#include "oslib/audiobackend_alsa.h"
#if USE_ALSA
#include <alsa/asoundlib.h>
#include "cfg/cfg.h"

snd_pcm_t *handle;

// We're making these functions static - there's no need to pollute the global namespace
static void alsa_init()
{

long loops;
int size;

snd_pcm_hw_params_t *params;
unsigned int val;
int dir=-1;
snd_pcm_uframes_t frames;

/* Open PCM device for playback. */
int rc = snd_pcm_open(&handle, "default", SND_PCM_STREAM_PLAYBACK, 0);
string device = cfgLoadStr("alsa", "device", "");

if (rc<0)
rc = snd_pcm_open(&handle, "plughw:0,0,0", SND_PCM_STREAM_PLAYBACK, 0);

if (rc<0)
rc = snd_pcm_open(&handle, "plughw:0,0", SND_PCM_STREAM_PLAYBACK, 0);
int rc = -1;
if (device == "")
{
printf("ALSA: trying to determine audio device\n");
/* Open PCM device for playback. */
device = "default";
rc = snd_pcm_open(&handle, device.c_str(), SND_PCM_STREAM_PLAYBACK, 0);

if (rc < 0)
{
device = "plughw:0,0,0";
rc = snd_pcm_open(&handle, device.c_str(), SND_PCM_STREAM_PLAYBACK, 0);
}

if (rc < 0)
{
device = "plughw:0,0";
rc = snd_pcm_open(&handle, device.c_str(), SND_PCM_STREAM_PLAYBACK, 0);
}

if (rc >= 0)
{
// init successfull, write value back to config
cfgSaveStr("alsa", "device", device.c_str());
}
}
else {
rc = snd_pcm_open(&handle, device.c_str(), SND_PCM_STREAM_PLAYBACK, 0);
}

if (rc < 0)
{
fprintf(stderr, "unable to open PCM device: %s\n", snd_strerror(rc));
fprintf(stderr, "unable to open PCM device %s: %s\n", device.c_str(), snd_strerror(rc));
return;
}

printf("ALSA: Successfully initialized \"%s\"\n", device.c_str());

/* Allocate a hardware parameters object. */
snd_pcm_hw_params_alloca(&params);

Expand Down
88 changes: 87 additions & 1 deletion core/rend/gles/gldraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ void DrawModVols()
glStencilFunc(GL_EQUAL,0x81,0x81); //only pixels that are Modvol enabled, and in area 1

//clear the stencil result bit
glStencilMask(0x3); //write to lsb
glStencilMask(0x3); //write to lsb
glStencilOp(GL_ZERO,GL_ZERO,GL_ZERO);
#ifndef NO_STENCIL_WORKAROUND
//looks like a driver bug ?
Expand Down Expand Up @@ -1158,3 +1158,89 @@ void DrawStrips()
#endif
}
}

void fullscreenQuadPrepareFramebuffer(float xScale, float yScale) {
// Bind the default framebuffer
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, screen_width, screen_height);

glDisable(GL_SCISSOR_TEST);
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
glDisable(GL_STENCIL_TEST);
glDisable(GL_BLEND);

glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

// Reduce width to keep 4:3 aspect ratio (640x480)
u32 reducedWidth = 4 * screen_height / 3;
u32 reducedWidthOffset = (screen_width - reducedWidth) / 2;
glScissor(reducedWidthOffset, 0, reducedWidth, screen_height);
if (settings.rend.WideScreen &&
(pvrrc.fb_X_CLIP.min==0) && ((pvrrc.fb_X_CLIP.max+1)/xScale==640) &&
(pvrrc.fb_Y_CLIP.min==0) && ((pvrrc.fb_Y_CLIP.max+1)/yScale==480 ))
{
glDisable(GL_SCISSOR_TEST);
}
else
{
glEnable(GL_SCISSOR_TEST);
}
}

void fullscreenQuadBindVertexData(float screenToNativeXScale, float screenToNativeYScale,
GLint & vsPosition, GLint & vsTexcoord, GLint & fsTexture)
{
u32 quadVerticesNumber = 4;
glUseProgram(gl.fullscreenQuadShader);

glBindBuffer(GL_ARRAY_BUFFER, fullscreenQuad.positionsBuffer);
glEnableVertexAttribArray( vsPosition );
glVertexAttribPointer(vsPosition, 3, GL_FLOAT, GL_FALSE, 0, 0);

glBindBuffer(GL_ARRAY_BUFFER, fullscreenQuad.texcoordsBuffer);
glEnableVertexAttribArray( vsTexcoord );
const float2 texcoordsArray[] =
{
{ screenToNativeXScale, screenToNativeYScale },
{ 0.0f, screenToNativeYScale },
{ 0.0f, 0.0f },
{ screenToNativeXScale, 0.0f },
};
glBufferData(GL_ARRAY_BUFFER, sizeof(float2) * quadVerticesNumber, texcoordsArray, GL_STATIC_DRAW);
glVertexAttribPointer(vsTexcoord, 2, GL_FLOAT, GL_FALSE, 0, 0);

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, fullscreenQuad.indexBuffer);

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, fullscreenQuad.framebufferTexture);
glUniform1i(fsTexture, 0);
}

void DrawFullscreenQuad(float screenToNativeXScale, float screenToNativeYScale, float xScale, float yScale) {
u32 quadIndicesNumber = 6;
GLint boundArrayBuffer = 0;
GLint boundElementArrayBuffer = 0;
GLint vsPosition= glGetAttribLocation(gl.fullscreenQuadShader, "position");
GLint vsTexcoord= glGetAttribLocation(gl.fullscreenQuadShader, "texture_coord");
GLint fsTexture = glGetUniformLocation(gl.fullscreenQuadShader, "texture_data");

glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &boundArrayBuffer);
glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &boundElementArrayBuffer);

fullscreenQuadPrepareFramebuffer(xScale, yScale);
fullscreenQuadBindVertexData(screenToNativeXScale, screenToNativeYScale, vsPosition, vsTexcoord, fsTexture);

glDrawElements(GL_TRIANGLES, quadIndicesNumber, GL_UNSIGNED_BYTE, 0);

// Unbind buffers
glBindTexture(GL_TEXTURE_2D, 0);
glBindBuffer(GL_ARRAY_BUFFER, boundArrayBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, boundElementArrayBuffer);
glDisableVertexAttribArray( vsPosition );
glDisableVertexAttribArray( vsTexcoord );

// Restore vertex attribute pointers (OSD drawing preparation)
SetupMainVBO();
}
Loading

0 comments on commit b26b120

Please sign in to comment.