OpenGL2: Add OpenGL ES 2.0+ support

This mainly targets OpenGL ES 2.0 but it also supports compiling GLSL as
ESSL 3.00. It's missing support for framebuffer objects which should be
possible on ES 2. (Though using renderbuffers instead of textures.)

opengl1 cvars that are not supported will display a message and disable
the cvar. This has not been reviewed for new opengl2 cvars. Enabling
cvars may cause rendering issues. Some of the broken cvars may be
possible to support using OpenGL ES 3 features.

The game displays okay with the default cvars.
This commit is contained in:
Zack Middleton committed 2024-06-05 21:33:08 -05:00
1 parent 1fc83e4845
commit 3b984d2b51
14 files changed
+658 -167

No files matched your search

+67 -18
View File
@@ -451,21 +451,43 @@ Return value must be freed with ri.Hunk_FreeTempMemory()
byte *RB_ReadPixels(int x, int y, int width, int height, size_t *offset, int *padlen)
{
byte *buffer, *bufstart;
int padwidth, linelen;
GLint packAlign;
int padwidth, linelen, bytesPerPixel;
int yin, xin, xout;
GLint packAlign, format;
// OpenGL ES is only required to support reading GL_RGBA
if (qglesMajorVersion >= 1) {
format = GL_RGBA;
bytesPerPixel = 4;
} else {
format = GL_RGB;
bytesPerPixel = 3;
}
qglGetIntegerv(GL_PACK_ALIGNMENT, &packAlign);
linelen = width * 3;
linelen = width * bytesPerPixel;
padwidth = PAD(linelen, packAlign);
// Allocate a few more bytes so that we can choose an alignment we like
buffer = ri.Hunk_AllocateTempMemory(padwidth * height + *offset + packAlign - 1);
bufstart = PADP((intptr_t) buffer + *offset, packAlign);
qglReadPixels(x, y, width, height, GL_RGB, GL_UNSIGNED_BYTE, bufstart);
bufstart = PADP((intptr_t) buffer + *offset, packAlign);
qglReadPixels(x, y, width, height, format, GL_UNSIGNED_BYTE, bufstart);
linelen = width * 3;
// Convert RGBA to RGB, in place, line by line
if (format == GL_RGBA) {
for (yin = 0; yin < height; yin++) {
for (xin = 0, xout = 0; xout < linelen; xin += 4, xout += 3) {
bufstart[yin*padwidth + xout + 0] = bufstart[yin*padwidth + xin + 0];
bufstart[yin*padwidth + xout + 1] = bufstart[yin*padwidth + xin + 1];
bufstart[yin*padwidth + xout + 2] = bufstart[yin*padwidth + xin + 2];
}
}
}
*offset = bufstart - buffer;
*padlen = padwidth - linelen;
@@ -877,9 +899,10 @@ const void *RB_TakeVideoFrameCmd( const void *data )
{
const videoFrameCommand_t *cmd;
byte *cBuf;
size_t memcount, linelen;
size_t memcount, bytesPerPixel, linelen, avilinelen;
int padwidth, avipadwidth, padlen, avipadlen;
GLint packAlign;
int yin, xin, xout;
GLint packAlign, format;
// finish any 2D drawing if needed
if(tess.numIndexes)
@@ -887,20 +910,32 @@ const void *RB_TakeVideoFrameCmd( const void *data )
cmd = (const videoFrameCommand_t *)data;
// OpenGL ES is only required to support reading GL_RGBA
if (qglesMajorVersion >= 1) {
format = GL_RGBA;
bytesPerPixel = 4;
} else {
format = GL_RGB;
bytesPerPixel = 3;
}
qglGetIntegerv(GL_PACK_ALIGNMENT, &packAlign);
linelen = cmd->width * 3;
linelen = cmd->width * bytesPerPixel;
// Alignment stuff for glReadPixels
padwidth = PAD(linelen, packAlign);
padlen = padwidth - linelen;
avilinelen = cmd->width * 3;
// AVI line padding
avipadwidth = PAD(linelen, AVI_LINE_PADDING);
avipadlen = avipadwidth - linelen;
avipadwidth = PAD(avilinelen, AVI_LINE_PADDING);
avipadlen = avipadwidth - avilinelen;
cBuf = PADP(cmd->captureBuffer, packAlign);
qglReadPixels(0, 0, cmd->width, cmd->height, GL_RGB,
qglReadPixels(0, 0, cmd->width, cmd->height, format,
GL_UNSIGNED_BYTE, cBuf);
memcount = padwidth * cmd->height;
@@ -911,7 +946,21 @@ const void *RB_TakeVideoFrameCmd( const void *data )
if(cmd->motionJpeg)
{
memcount = RE_SaveJPGToBuffer(cmd->encodeBuffer, linelen * cmd->height,
// Convert RGBA to RGB, in place, line by line
if (format == GL_RGBA) {
linelen = cmd->width * 3;
padlen = padwidth - linelen;
for (yin = 0; yin < cmd->height; yin++) {
for (xin = 0, xout = 0; xout < linelen; xin += 4, xout += 3) {
cBuf[yin*padwidth + xout + 0] = cBuf[yin*padwidth + xin + 0];
cBuf[yin*padwidth + xout + 1] = cBuf[yin*padwidth + xin + 1];
cBuf[yin*padwidth + xout + 2] = cBuf[yin*padwidth + xin + 2];
}
}
}
memcount = RE_SaveJPGToBuffer(cmd->encodeBuffer, avilinelen * cmd->height,
r_aviMotionJpegQuality->integer,
cmd->width, cmd->height, cBuf, padlen);
ri.CL_WriteAVIVideoFrame(cmd->encodeBuffer, memcount);
@@ -934,7 +983,7 @@ const void *RB_TakeVideoFrameCmd( const void *data )
*destptr++ = srcptr[2];
*destptr++ = srcptr[1];
*destptr++ = srcptr[0];
srcptr += 3;
srcptr += bytesPerPixel;
}
Com_Memset(destptr, '\0', avipadlen);