Skip to content
This repository was archived by the owner on Sep 29, 2025. It is now read-only.

Commit b26b120

Browse files
committed
Merge branch 'master' of https://github.com/reicast/reicast-emulator into mar753/render-to-texture-with-options
2 parents 88b9deb + 3c8e111 commit b26b120

File tree

18 files changed

+617
-78
lines changed

18 files changed

+617
-78
lines changed

core/linux-dist/main.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,25 +144,30 @@ void UpdateInputState(u32 port)
144144

145145
void UpdateVibration(u32 port, u32 value)
146146
{
147-
#if defined(USE_EVDEV)
148-
u8 POW_POS = (value >> 8) & 0x3;
149-
u8 POW_NEG = (value >> 12) & 0x3;
150-
u8 FREQ = (value >> 16) & 0xFF;
147+
u8 POW_POS = (value >> 8) & 0x3;
148+
u8 POW_NEG = (value >> 12) & 0x3;
149+
u8 FREQ = (value >> 16) & 0xFF;
151150

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

156-
if (pow_l > 1.0) pow_l = 1.0;
157-
if (pow_r > 1.0) pow_r = 1.0;
155+
if (pow_l > 1.0) pow_l = 1.0;
156+
if (pow_r > 1.0) pow_r = 1.0;
158157

159-
u16 pow_strong = (u16)(65535 * pow_l);
160-
u16 pow_weak = (u16)(65535 * pow_r);
158+
u16 pow_strong = (u16)(65535 * pow_l);
159+
u16 pow_weak = (u16)(65535 * pow_r);
161160

161+
#if defined(USE_EVDEV)
162162
input_evdev_rumble(port, pow_strong, pow_weak);
163163
#endif
164+
165+
#if defined(USE_SDL)
166+
input_sdl_rumble(port, pow_strong, pow_weak);
167+
#endif
164168
}
165169

170+
166171
void os_DoEvents()
167172
{
168173
#if defined(SUPPORT_X11)

core/nullDC.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ void LoadSettings()
300300
settings.rend.UseMipmaps = cfgLoadInt("config", "rend.UseMipmaps", 1);
301301
settings.rend.WideScreen = cfgLoadInt("config", "rend.WideScreen", 0);
302302
settings.rend.Clipping = cfgLoadInt("config", "rend.Clipping", 1);
303+
settings.rend.
304+
VerticalResolution = cfgLoadInt("config", "rend.ResolutionPercentage", 100);
305+
settings.rend.
306+
HorizontalResolution = cfgLoadInt("config", "rend.ResolutionPercentage", 100);
303307

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

core/oslib/audiobackend_alsa.cpp

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,58 @@
11
#include "oslib/audiobackend_alsa.h"
22
#if USE_ALSA
33
#include <alsa/asoundlib.h>
4+
#include "cfg/cfg.h"
45

56
snd_pcm_t *handle;
67

78
// We're making these functions static - there's no need to pollute the global namespace
89
static void alsa_init()
910
{
10-
11-
long loops;
12-
int size;
13-
1411
snd_pcm_hw_params_t *params;
1512
unsigned int val;
1613
int dir=-1;
1714
snd_pcm_uframes_t frames;
1815

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

22-
if (rc<0)
23-
rc = snd_pcm_open(&handle, "plughw:0,0,0", SND_PCM_STREAM_PLAYBACK, 0);
24-
25-
if (rc<0)
26-
rc = snd_pcm_open(&handle, "plughw:0,0", SND_PCM_STREAM_PLAYBACK, 0);
18+
int rc = -1;
19+
if (device == "")
20+
{
21+
printf("ALSA: trying to determine audio device\n");
22+
/* Open PCM device for playback. */
23+
device = "default";
24+
rc = snd_pcm_open(&handle, device.c_str(), SND_PCM_STREAM_PLAYBACK, 0);
25+
26+
if (rc < 0)
27+
{
28+
device = "plughw:0,0,0";
29+
rc = snd_pcm_open(&handle, device.c_str(), SND_PCM_STREAM_PLAYBACK, 0);
30+
}
31+
32+
if (rc < 0)
33+
{
34+
device = "plughw:0,0";
35+
rc = snd_pcm_open(&handle, device.c_str(), SND_PCM_STREAM_PLAYBACK, 0);
36+
}
37+
38+
if (rc >= 0)
39+
{
40+
// init successfull, write value back to config
41+
cfgSaveStr("alsa", "device", device.c_str());
42+
}
43+
}
44+
else {
45+
rc = snd_pcm_open(&handle, device.c_str(), SND_PCM_STREAM_PLAYBACK, 0);
46+
}
2747

2848
if (rc < 0)
2949
{
30-
fprintf(stderr, "unable to open PCM device: %s\n", snd_strerror(rc));
50+
fprintf(stderr, "unable to open PCM device %s: %s\n", device.c_str(), snd_strerror(rc));
3151
return;
3252
}
3353

54+
printf("ALSA: Successfully initialized \"%s\"\n", device.c_str());
55+
3456
/* Allocate a hardware parameters object. */
3557
snd_pcm_hw_params_alloca(&params);
3658

core/rend/gles/gldraw.cpp

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ void DrawModVols()
10841084
glStencilFunc(GL_EQUAL,0x81,0x81); //only pixels that are Modvol enabled, and in area 1
10851085

10861086
//clear the stencil result bit
1087-
glStencilMask(0x3); //write to lsb
1087+
glStencilMask(0x3); //write to lsb
10881088
glStencilOp(GL_ZERO,GL_ZERO,GL_ZERO);
10891089
#ifndef NO_STENCIL_WORKAROUND
10901090
//looks like a driver bug ?
@@ -1158,3 +1158,89 @@ void DrawStrips()
11581158
#endif
11591159
}
11601160
}
1161+
1162+
void fullscreenQuadPrepareFramebuffer(float xScale, float yScale) {
1163+
// Bind the default framebuffer
1164+
glBindFramebuffer(GL_FRAMEBUFFER, 0);
1165+
glViewport(0, 0, screen_width, screen_height);
1166+
1167+
glDisable(GL_SCISSOR_TEST);
1168+
glDisable(GL_CULL_FACE);
1169+
glDisable(GL_DEPTH_TEST);
1170+
glDisable(GL_STENCIL_TEST);
1171+
glDisable(GL_BLEND);
1172+
1173+
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
1174+
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1175+
1176+
// Reduce width to keep 4:3 aspect ratio (640x480)
1177+
u32 reducedWidth = 4 * screen_height / 3;
1178+
u32 reducedWidthOffset = (screen_width - reducedWidth) / 2;
1179+
glScissor(reducedWidthOffset, 0, reducedWidth, screen_height);
1180+
if (settings.rend.WideScreen &&
1181+
(pvrrc.fb_X_CLIP.min==0) && ((pvrrc.fb_X_CLIP.max+1)/xScale==640) &&
1182+
(pvrrc.fb_Y_CLIP.min==0) && ((pvrrc.fb_Y_CLIP.max+1)/yScale==480 ))
1183+
{
1184+
glDisable(GL_SCISSOR_TEST);
1185+
}
1186+
else
1187+
{
1188+
glEnable(GL_SCISSOR_TEST);
1189+
}
1190+
}
1191+
1192+
void fullscreenQuadBindVertexData(float screenToNativeXScale, float screenToNativeYScale,
1193+
GLint & vsPosition, GLint & vsTexcoord, GLint & fsTexture)
1194+
{
1195+
u32 quadVerticesNumber = 4;
1196+
glUseProgram(gl.fullscreenQuadShader);
1197+
1198+
glBindBuffer(GL_ARRAY_BUFFER, fullscreenQuad.positionsBuffer);
1199+
glEnableVertexAttribArray( vsPosition );
1200+
glVertexAttribPointer(vsPosition, 3, GL_FLOAT, GL_FALSE, 0, 0);
1201+
1202+
glBindBuffer(GL_ARRAY_BUFFER, fullscreenQuad.texcoordsBuffer);
1203+
glEnableVertexAttribArray( vsTexcoord );
1204+
const float2 texcoordsArray[] =
1205+
{
1206+
{ screenToNativeXScale, screenToNativeYScale },
1207+
{ 0.0f, screenToNativeYScale },
1208+
{ 0.0f, 0.0f },
1209+
{ screenToNativeXScale, 0.0f },
1210+
};
1211+
glBufferData(GL_ARRAY_BUFFER, sizeof(float2) * quadVerticesNumber, texcoordsArray, GL_STATIC_DRAW);
1212+
glVertexAttribPointer(vsTexcoord, 2, GL_FLOAT, GL_FALSE, 0, 0);
1213+
1214+
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, fullscreenQuad.indexBuffer);
1215+
1216+
glActiveTexture(GL_TEXTURE0);
1217+
glBindTexture(GL_TEXTURE_2D, fullscreenQuad.framebufferTexture);
1218+
glUniform1i(fsTexture, 0);
1219+
}
1220+
1221+
void DrawFullscreenQuad(float screenToNativeXScale, float screenToNativeYScale, float xScale, float yScale) {
1222+
u32 quadIndicesNumber = 6;
1223+
GLint boundArrayBuffer = 0;
1224+
GLint boundElementArrayBuffer = 0;
1225+
GLint vsPosition= glGetAttribLocation(gl.fullscreenQuadShader, "position");
1226+
GLint vsTexcoord= glGetAttribLocation(gl.fullscreenQuadShader, "texture_coord");
1227+
GLint fsTexture = glGetUniformLocation(gl.fullscreenQuadShader, "texture_data");
1228+
1229+
glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &boundArrayBuffer);
1230+
glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &boundElementArrayBuffer);
1231+
1232+
fullscreenQuadPrepareFramebuffer(xScale, yScale);
1233+
fullscreenQuadBindVertexData(screenToNativeXScale, screenToNativeYScale, vsPosition, vsTexcoord, fsTexture);
1234+
1235+
glDrawElements(GL_TRIANGLES, quadIndicesNumber, GL_UNSIGNED_BYTE, 0);
1236+
1237+
// Unbind buffers
1238+
glBindTexture(GL_TEXTURE_2D, 0);
1239+
glBindBuffer(GL_ARRAY_BUFFER, boundArrayBuffer);
1240+
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, boundElementArrayBuffer);
1241+
glDisableVertexAttribArray( vsPosition );
1242+
glDisableVertexAttribArray( vsTexcoord );
1243+
1244+
// Restore vertex attribute pointers (OSD drawing preparation)
1245+
SetupMainVBO();
1246+
}

0 commit comments

Comments
 (0)