mirror of
https://gitlab.com/shinovon/re3-symbian.git
synced 2026-05-22 17:47:20 +03:00
Restore gl1 implementation
This commit is contained in:
parent
af4ab6f1ac
commit
cbc14ed824
10 changed files with 293 additions and 449 deletions
10
vendor/librw/src/engine.cpp
vendored
10
vendor/librw/src/engine.cpp
vendored
|
|
@ -268,13 +268,13 @@ Engine::open(EngineOpenParams *p)
|
|||
|
||||
// Initialize device
|
||||
// Device and possibly OS specific!
|
||||
#ifdef RW_PS2
|
||||
#if defined RW_PS2
|
||||
engine->device = ps2::renderdevice;
|
||||
#elif RW_GL3
|
||||
#elif defined RW_GL3
|
||||
engine->device = gl3::renderdevice;
|
||||
#elif RW_GLES1
|
||||
//engine->device = gles1::renderdevice;
|
||||
#elif RW_D3D9
|
||||
#elif defined RW_GLES1
|
||||
engine->device = gles1::renderdevice;
|
||||
#elif defined RW_D3D9
|
||||
engine->device = d3d::renderdevice;
|
||||
#else
|
||||
engine->device = null::renderdevice;
|
||||
|
|
|
|||
82
vendor/librw/src/gles1/gl1raster.cpp
vendored
82
vendor/librw/src/gles1/gl1raster.cpp
vendored
|
|
@ -132,10 +132,10 @@ rasterCreateTexture(Raster *raster)
|
|||
|
||||
glGenTextures(1, &natras->texid);
|
||||
uint32 prev = bindTexture(natras->texid);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, natras->internalFormat,
|
||||
// raster->width, raster->height,
|
||||
1,1,
|
||||
0, natras->format, natras->type, nil);
|
||||
// glTexImage2D(GL_TEXTURE_2D, 0, natras->internalFormat,
|
||||
//// raster->width, raster->height,
|
||||
// 1,1,
|
||||
// 0, natras->format, natras->type, nil);
|
||||
// TODO: allocate other levels...probably
|
||||
natras->filterMode = 0;
|
||||
natras->addressU = 0;
|
||||
|
|
@ -372,16 +372,12 @@ rasterLock(Raster *raster, int32 level, int32 lockMode)
|
|||
raster->pixels = px;
|
||||
|
||||
if(lockMode & Raster::LOCKREAD || !(lockMode & Raster::LOCKNOFETCH)){
|
||||
if(natras->isCompressed){
|
||||
if(natras->backingStore){
|
||||
assert(level < natras->backingStore->numlevels);
|
||||
assert(allocSz >= natras->backingStore->levels[level].size);
|
||||
memcpy(px, natras->backingStore->levels[level].data, allocSz);
|
||||
}else{
|
||||
// GLES is losing here
|
||||
}
|
||||
if(natras->backingStore){
|
||||
assert(level < natras->backingStore->numlevels);
|
||||
assert(allocSz >= natras->backingStore->levels[level].size);
|
||||
memcpy(px, natras->backingStore->levels[level].data, allocSz);
|
||||
} else {
|
||||
// TODO
|
||||
memset(px, 0, allocSz);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -440,37 +436,49 @@ rasterUnlock(Raster *raster, int32 level)
|
|||
raster->width, raster->height, 0,
|
||||
getLevelSize(raster, level),
|
||||
raster->pixels);
|
||||
if(natras->backingStore){
|
||||
assert(level < natras->backingStore->numlevels);
|
||||
memcpy(natras->backingStore->levels[level].data, raster->pixels,
|
||||
natras->backingStore->levels[level].size);
|
||||
}
|
||||
}else{
|
||||
// if (raster->pixels != nil && natras->format == GL_RGBA && natras->type == GL_UNSIGNED_BYTE) {
|
||||
// // convert to 16-bit
|
||||
// uint16_t* pixels16 = (uint16_t*)malloc(raster->width * raster->height * sizeof(uint16_t));
|
||||
// uint8_t* pixels8 = (uint8_t*)raster->pixels;
|
||||
//
|
||||
// for (int i = 0; i < raster->width * raster->height; i++) {
|
||||
// uint8_t r = pixels8[i * 4 + 0];
|
||||
// uint8_t g = pixels8[i * 4 + 1];
|
||||
// uint8_t b = pixels8[i * 4 + 2];
|
||||
// uint8_t a = pixels8[i * 4 + 3];
|
||||
//
|
||||
// pixels16[i] = ((r >> 4) << 12) | ((g >> 4) << 8) | ((b >> 4) << 4) | (a >> 4);
|
||||
// }
|
||||
// glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, raster->width, raster->height, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, pixels16);
|
||||
// free(pixels16);
|
||||
// } else
|
||||
int stride = raster->width * natras->bpp;
|
||||
uint8_t* tmp = (uint8_t*)malloc(stride);
|
||||
for (int y = 0; y < raster->height / 2; y++) {
|
||||
uint8_t* a = (uint8_t*)raster->pixels + y * stride;
|
||||
uint8_t* b = (uint8_t*)raster->pixels + (raster->height - 1 - y) * stride;
|
||||
|
||||
memcpy(tmp, a, stride);
|
||||
memcpy(a, b, stride);
|
||||
memcpy(b, tmp, stride);
|
||||
}
|
||||
free(tmp);
|
||||
|
||||
if (raster->pixels != nil && natras->format == GL_RGBA && natras->type == GL_UNSIGNED_BYTE) {
|
||||
// convert to 16-bit
|
||||
uint16_t* pixels16 = (uint16_t*)malloc(raster->width * raster->height * sizeof(uint16_t));
|
||||
uint8_t* pixels8 = (uint8_t*)raster->pixels;
|
||||
|
||||
for (int i = 0; i < raster->width * raster->height; i++) {
|
||||
uint8_t r = pixels8[i * 4 + 0];
|
||||
uint8_t g = pixels8[i * 4 + 1];
|
||||
uint8_t b = pixels8[i * 4 + 2];
|
||||
uint8_t a = pixels8[i * 4 + 3];
|
||||
|
||||
pixels16[i] = ((r >> 4) << 12) | ((g >> 4) << 8) | ((b >> 4) << 4) | (a >> 4);
|
||||
}
|
||||
glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, raster->width, raster->height, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, pixels16);
|
||||
free(pixels16);
|
||||
} else
|
||||
{
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
// glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glTexImage2D(GL_TEXTURE_2D, level, natras->internalFormat,
|
||||
raster->width, raster->height,
|
||||
0, natras->format, natras->type, raster->pixels);
|
||||
}
|
||||
}
|
||||
// if(level == 0 && natras->autogenMipmap)
|
||||
// glGenerateMipmap(GL_TEXTURE_2D);
|
||||
|
||||
if(natras->backingStore){
|
||||
assert(level < natras->backingStore->numlevels);
|
||||
memcpy(natras->backingStore->levels[level].data, raster->pixels,
|
||||
natras->backingStore->levels[level].size);
|
||||
}
|
||||
|
||||
bindTexture(prev);
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
54
vendor/librw/src/gles1/rwgles1.cpp
vendored
54
vendor/librw/src/gles1/rwgles1.cpp
vendored
|
|
@ -1,54 +0,0 @@
|
|||
#include "rwgles1.h"
|
||||
|
||||
namespace rw {
|
||||
|
||||
namespace gles1 {
|
||||
|
||||
// --- Funciones dummy (para linkear después) ---
|
||||
|
||||
inline void im2DRenderPrimitive(int, void*, int) {}
|
||||
inline void im2DRenderIndexedPrimitive(int, void*, int, void*, int) {}
|
||||
inline void im3DTransform(void*, int, void*, unsigned int) {}
|
||||
inline void im3DRenderPrimitive(int) {}
|
||||
inline void im3DRenderIndexedPrimitive(int, void*, int) {}
|
||||
inline void im3DEnd(void) {}
|
||||
|
||||
// --- Driver lifecycle ---
|
||||
static void*
|
||||
driverOpen(void* object, int32 offset, int32 size)
|
||||
{
|
||||
// stub: no hace nada
|
||||
return object;
|
||||
}
|
||||
|
||||
static void*
|
||||
driverClose(void* object, int32 offset, int32 size)
|
||||
{
|
||||
// stub: no hace nada
|
||||
return object;
|
||||
}
|
||||
|
||||
// --- Raster ---
|
||||
static void
|
||||
registerNativeRaster(void)
|
||||
{
|
||||
// stub por ahora
|
||||
}
|
||||
|
||||
void
|
||||
registerPlatformPlugins(void)
|
||||
{
|
||||
Driver::registerPlugin(PLATFORM_GLES1, 0, PLATFORM_GLES1,
|
||||
driverOpen, driverClose);
|
||||
registerNativeRaster();
|
||||
}
|
||||
|
||||
void*
|
||||
destroyNativeData(void *object, int32, int32)
|
||||
{
|
||||
//freeInstanceData((Geometry*)object);
|
||||
return object;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
329
vendor/librw/src/gles1/rwgles1.h
vendored
329
vendor/librw/src/gles1/rwgles1.h
vendored
|
|
@ -1,28 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "../rwbase.h"
|
||||
#include "../rwerror.h"
|
||||
#include "../rwplg.h"
|
||||
#include "../rwpipeline.h"
|
||||
#include "../rwobjects.h"
|
||||
#include "../rwengine.h"
|
||||
|
||||
#ifdef RW_GLES1
|
||||
#include <GLES/gl.h>
|
||||
#include <GLES/egl.h>
|
||||
#ifdef __SYMBIAN32__
|
||||
|
||||
#define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0
|
||||
#define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1
|
||||
#define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2
|
||||
#define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3
|
||||
|
||||
#endif
|
||||
#include <gles/gl.h>
|
||||
//#include <gles/glext.h>
|
||||
#include <gles/egl.h>
|
||||
#endif
|
||||
|
||||
namespace rw {
|
||||
|
|
@ -30,83 +9,247 @@ namespace rw {
|
|||
#ifdef RW_GLES1
|
||||
struct EngineOpenParams
|
||||
{
|
||||
#ifdef __SYMBIAN32__
|
||||
void *window; // en Symbian no hay GLFW/SDL
|
||||
#else
|
||||
void *window; // stub igual
|
||||
#endif
|
||||
int width, height;
|
||||
int width, height;
|
||||
const char *windowtitle;
|
||||
};
|
||||
#endif
|
||||
|
||||
namespace gles1 {
|
||||
|
||||
// --- Tipos básicos que charset.cpp y otros esperan ---
|
||||
|
||||
struct Im2DVertex {
|
||||
float x, y, z, w;
|
||||
float camZ;
|
||||
float recipCamZ;
|
||||
unsigned char r, g, b, a;
|
||||
float u, v;
|
||||
|
||||
// --- setters esperados por librw ---
|
||||
|
||||
void setScreenX(float v) { x = v; }
|
||||
void setScreenY(float v) { y = v; }
|
||||
void setScreenZ(float v) { z = v; }
|
||||
|
||||
void setCameraZ(float v) { camZ = v; }
|
||||
void setRecipCameraZ(float v) { recipCamZ = v; }
|
||||
|
||||
void setColor(unsigned char _r, unsigned char _g, unsigned char _b, unsigned char _a) {
|
||||
r = _r; g = _g; b = _b; a = _a;
|
||||
}
|
||||
|
||||
void setU(float val, float recipZ) { u = val; }
|
||||
void setV(float val, float recipZ) { v = val; }
|
||||
};
|
||||
|
||||
struct Im3DVertex {
|
||||
float x, y, z;
|
||||
float u, v;
|
||||
uint32 color;
|
||||
|
||||
void setX(float v) { x = v; }
|
||||
void setY(float v) { y = v; }
|
||||
void setZ(float v) { z = v; }
|
||||
|
||||
void setU(float v) { u = v; }
|
||||
void setV(float v) { this->v = v; }
|
||||
|
||||
void setColor(uint8 r, uint8 g, uint8 b, uint8 a) {
|
||||
color = (a<<24) | (r<<16) | (g<<8) | b;
|
||||
}
|
||||
};
|
||||
|
||||
// --- Funciones dummy (para linkear después) ---
|
||||
|
||||
inline void im2DRenderPrimitive(int, void*, int);
|
||||
inline void im2DRenderIndexedPrimitive(int, void*, int, void*, int);
|
||||
inline void im3DTransform(void*, int, void*, unsigned int);
|
||||
inline void im3DRenderPrimitive(int);
|
||||
inline void im3DRenderIndexedPrimitive(int, void*, int);
|
||||
inline void im3DEnd(void);
|
||||
|
||||
// --- Driver lifecycle ---
|
||||
static void*
|
||||
driverOpen(void* object, int32 offset, int32 size);
|
||||
|
||||
static void*
|
||||
driverClose(void* object, int32 offset, int32 size);
|
||||
|
||||
// --- Raster ---
|
||||
static void
|
||||
registerNativeRaster(void);
|
||||
|
||||
void registerPlatformPlugins(void);
|
||||
|
||||
extern Device renderdevice;
|
||||
|
||||
// arguments to glVertexAttribPointer basically
|
||||
struct AttribDesc
|
||||
{
|
||||
uint32 index;
|
||||
int32 type;
|
||||
bool32 normalized;
|
||||
int32 size;
|
||||
uint32 stride;
|
||||
uint32 offset;
|
||||
};
|
||||
|
||||
enum AttribIndices
|
||||
{
|
||||
ATTRIB_POS = 0,
|
||||
ATTRIB_NORMAL,
|
||||
ATTRIB_COLOR,
|
||||
ATTRIB_WEIGHTS,
|
||||
ATTRIB_INDICES,
|
||||
ATTRIB_TEXCOORDS0,
|
||||
ATTRIB_TEXCOORDS1,
|
||||
#if 0
|
||||
ATTRIB_TEXCOORDS2,
|
||||
ATTRIB_TEXCOORDS3,
|
||||
ATTRIB_TEXCOORDS4,
|
||||
ATTRIB_TEXCOORDS5,
|
||||
ATTRIB_TEXCOORDS6,
|
||||
ATTRIB_TEXCOORDS7,
|
||||
#endif
|
||||
};
|
||||
|
||||
// default uniform indices
|
||||
extern int32 u_matColor;
|
||||
extern int32 u_surfProps;
|
||||
|
||||
struct InstanceData
|
||||
{
|
||||
uint32 numIndex;
|
||||
uint32 minVert; // not used for rendering
|
||||
int32 numVertices; //
|
||||
Material *material;
|
||||
bool32 vertexAlpha;
|
||||
uint32 program;
|
||||
uint32 offset;
|
||||
};
|
||||
|
||||
struct InstanceDataHeader : rw::InstanceDataHeader
|
||||
{
|
||||
uint32 serialNumber;
|
||||
uint32 numMeshes;
|
||||
uint16 *indexBuffer;
|
||||
uint32 primType;
|
||||
uint8 *vertexBuffer;
|
||||
int32 numAttribs;
|
||||
AttribDesc *attribDesc;
|
||||
uint32 totalNumIndex;
|
||||
uint32 totalNumVertex;
|
||||
|
||||
uint32 ibo;
|
||||
uint32 vbo; // or 2?
|
||||
|
||||
InstanceData *inst;
|
||||
};
|
||||
|
||||
#ifdef RW_GLES1
|
||||
|
||||
struct Im3DVertex
|
||||
{
|
||||
V3d position;
|
||||
uint8 r, g, b, a;
|
||||
float32 u, v;
|
||||
|
||||
void setX(float32 x) { this->position.x = x; }
|
||||
void setY(float32 y) { this->position.y = y; }
|
||||
void setZ(float32 z) { this->position.z = z; }
|
||||
void setColor(uint8 r, uint8 g, uint8 b, uint8 a) {
|
||||
this->r = r; this->g = g; this->b = b; this->a = a; }
|
||||
void setU(float32 u) { this->u = u; }
|
||||
void setV(float32 v) { this->v = v; }
|
||||
|
||||
float getX(void) { return this->position.x; }
|
||||
float getY(void) { return this->position.y; }
|
||||
float getZ(void) { return this->position.z; }
|
||||
RGBA getColor(void) { return makeRGBA(this->r, this->g, this->b, this->a); }
|
||||
float getU(void) { return this->u; }
|
||||
float getV(void) { return this->v; }
|
||||
};
|
||||
|
||||
struct Im2DVertex
|
||||
{
|
||||
float32 x, y, z, w;
|
||||
uint8 r, g, b, a;
|
||||
float32 u, v;
|
||||
|
||||
void setScreenX(float32 x) { this->x = x; }
|
||||
void setScreenY(float32 y) { this->y = y; }
|
||||
void setScreenZ(float32 z) { this->z = z; }
|
||||
// This is a bit unefficient but we have to counteract GL's divide, so multiply
|
||||
void setCameraZ(float32 z) { this->w = z; }
|
||||
void setRecipCameraZ(float32 recipz) { this->w = 1.0f/recipz; }
|
||||
void setColor(uint8 r, uint8 g, uint8 b, uint8 a) {
|
||||
this->r = r; this->g = g; this->b = b; this->a = a; }
|
||||
void setU(float32 u, float recipz) { this->u = u; }
|
||||
void setV(float32 v, float recipz) { this->v = v; }
|
||||
|
||||
float getScreenX(void) { return this->x; }
|
||||
float getScreenY(void) { return this->y; }
|
||||
float getScreenZ(void) { return this->z; }
|
||||
float getCameraZ(void) { return this->w; }
|
||||
float getRecipCameraZ(void) { return 1.0f/this->w; }
|
||||
RGBA getColor(void) { return makeRGBA(this->r, this->g, this->b, this->a); }
|
||||
float getU(void) { return this->u; }
|
||||
float getV(void) { return this->v; }
|
||||
};
|
||||
|
||||
void setupVertexInput(InstanceDataHeader *header);
|
||||
void teardownVertexInput(InstanceDataHeader *header);
|
||||
|
||||
// Render state
|
||||
|
||||
// Vertex shader bits
|
||||
enum
|
||||
{
|
||||
// These should be low so they could be used as indices
|
||||
VSLIGHT_DIRECT = 1,
|
||||
VSLIGHT_POINT = 2,
|
||||
VSLIGHT_SPOT = 4,
|
||||
VSLIGHT_MASK = 7, // all the above
|
||||
// less critical
|
||||
VSLIGHT_AMBIENT = 8,
|
||||
};
|
||||
// per Scene
|
||||
void setProjectionMatrix(float32*);
|
||||
void setViewMatrix(float32*);
|
||||
|
||||
// per Object
|
||||
void setWorldMatrix(Matrix*);
|
||||
int32 setLights(WorldLights *lightData);
|
||||
|
||||
// per Mesh
|
||||
void setTexture(int32 n, Texture *tex);
|
||||
void setMaterial(const RGBA &color, const SurfaceProperties &surfaceprops, float extraSurfProp = 0.0f);
|
||||
inline void setMaterial(uint32 flags, const RGBA &color, const SurfaceProperties &surfaceprops, float extraSurfProp = 0.0f)
|
||||
{
|
||||
static RGBA white = { 255, 255, 255, 255 };
|
||||
if(flags & Geometry::MODULATE)
|
||||
setMaterial(color, surfaceprops, extraSurfProp);
|
||||
else
|
||||
setMaterial(white, surfaceprops, extraSurfProp);
|
||||
}
|
||||
|
||||
void setAlphaBlend(bool32 enable);
|
||||
bool32 getAlphaBlend(void);
|
||||
|
||||
bool32 getAlphaTest(void);
|
||||
|
||||
void bindFramebuffer(uint32 fbo);
|
||||
uint32 bindTexture(uint32 texid);
|
||||
|
||||
void flushCache(void);
|
||||
|
||||
#endif
|
||||
|
||||
class ObjPipeline : public rw::ObjPipeline
|
||||
{
|
||||
public:
|
||||
void init(void);
|
||||
static ObjPipeline *create(void);
|
||||
|
||||
void (*instanceCB)(Geometry *geo, InstanceDataHeader *header, bool32 reinstance);
|
||||
void (*uninstanceCB)(Geometry *geo, InstanceDataHeader *header);
|
||||
void (*renderCB)(Atomic *atomic, InstanceDataHeader *header);
|
||||
};
|
||||
|
||||
void defaultInstanceCB(Geometry *geo, InstanceDataHeader *header, bool32 reinstance);
|
||||
void defaultUninstanceCB(Geometry *geo, InstanceDataHeader *header);
|
||||
void defaultRenderCB(Atomic *atomic, InstanceDataHeader *header);
|
||||
int32 lightingCB(Atomic *atomic);
|
||||
|
||||
void drawInst_simple(InstanceDataHeader *header, InstanceData *inst);
|
||||
// Emulate PS2 GS alpha test FB_ONLY case: failed alpha writes to frame- but not to depth buffer
|
||||
void drawInst_GSemu(InstanceDataHeader *header, InstanceData *inst);
|
||||
// This one switches between the above two depending on render state;
|
||||
void drawInst(InstanceDataHeader *header, InstanceData *inst);
|
||||
|
||||
|
||||
void *destroyNativeData(void *object, int32, int32);
|
||||
|
||||
ObjPipeline *makeDefaultPipeline(void);
|
||||
|
||||
void setVertexAlpha(bool32 enable);
|
||||
|
||||
// Native Texture and Raster
|
||||
|
||||
struct Gl1Raster
|
||||
{
|
||||
// arguments to glTexImage2D
|
||||
int32 internalFormat;
|
||||
int32 type;
|
||||
int32 format;
|
||||
int32 bpp; // bytes per pixel
|
||||
// texture object
|
||||
uint32 texid;
|
||||
|
||||
bool isCompressed;
|
||||
bool hasAlpha;
|
||||
bool autogenMipmap;
|
||||
int8 numLevels;
|
||||
// cached filtermode and addressing
|
||||
uint8 filterMode;
|
||||
uint8 addressU;
|
||||
uint8 addressV;
|
||||
int32 maxAnisotropy;
|
||||
|
||||
uint32 fbo; // used for camera texture only!
|
||||
Raster *fboMate; // color or zbuffer raster mate of this one
|
||||
RasterLevels *backingStore; // if we can't read back GPU memory but have to
|
||||
};
|
||||
|
||||
// GLES can't read back textures very nicely.
|
||||
// In most cases that's not an issue, but when it is,
|
||||
// this has to be set before the texture is filled:
|
||||
extern bool32 needToReadBackTextures;
|
||||
|
||||
Texture *readNativeTexture(Stream *stream);
|
||||
void writeNativeTexture(Texture *tex, Stream *stream);
|
||||
uint32 getSizeNativeTexture(Texture *tex);
|
||||
|
||||
extern int32 nativeRasterOffset;
|
||||
void registerNativeRaster(void);
|
||||
#define GETGL1RASTEREXT(raster) PLUGINOFFSET(Gl1Raster, raster, rw::gles1::nativeRasterOffset)
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
255
vendor/librw/src/gles1/rwgles1NEW.h
vendored
255
vendor/librw/src/gles1/rwgles1NEW.h
vendored
|
|
@ -1,255 +0,0 @@
|
|||
#ifdef RW_GLES1
|
||||
#include <gles/gl.h>
|
||||
//#include <gles/glext.h>
|
||||
#include <gles/egl.h>
|
||||
#endif
|
||||
|
||||
namespace rw {
|
||||
|
||||
#ifdef RW_GLES1
|
||||
struct EngineOpenParams
|
||||
{
|
||||
int width, height;
|
||||
const char *windowtitle;
|
||||
};
|
||||
#endif
|
||||
|
||||
namespace gles1 {
|
||||
|
||||
void registerPlatformPlugins(void);
|
||||
|
||||
extern Device renderdevice;
|
||||
|
||||
// arguments to glVertexAttribPointer basically
|
||||
struct AttribDesc
|
||||
{
|
||||
uint32 index;
|
||||
int32 type;
|
||||
bool32 normalized;
|
||||
int32 size;
|
||||
uint32 stride;
|
||||
uint32 offset;
|
||||
};
|
||||
|
||||
enum AttribIndices
|
||||
{
|
||||
ATTRIB_POS = 0,
|
||||
ATTRIB_NORMAL,
|
||||
ATTRIB_COLOR,
|
||||
ATTRIB_WEIGHTS,
|
||||
ATTRIB_INDICES,
|
||||
ATTRIB_TEXCOORDS0,
|
||||
ATTRIB_TEXCOORDS1,
|
||||
#if 0
|
||||
ATTRIB_TEXCOORDS2,
|
||||
ATTRIB_TEXCOORDS3,
|
||||
ATTRIB_TEXCOORDS4,
|
||||
ATTRIB_TEXCOORDS5,
|
||||
ATTRIB_TEXCOORDS6,
|
||||
ATTRIB_TEXCOORDS7,
|
||||
#endif
|
||||
};
|
||||
|
||||
// default uniform indices
|
||||
extern int32 u_matColor;
|
||||
extern int32 u_surfProps;
|
||||
|
||||
struct InstanceData
|
||||
{
|
||||
uint32 numIndex;
|
||||
uint32 minVert; // not used for rendering
|
||||
int32 numVertices; //
|
||||
Material *material;
|
||||
bool32 vertexAlpha;
|
||||
uint32 program;
|
||||
uint32 offset;
|
||||
};
|
||||
|
||||
struct InstanceDataHeader : rw::InstanceDataHeader
|
||||
{
|
||||
uint32 serialNumber;
|
||||
uint32 numMeshes;
|
||||
uint16 *indexBuffer;
|
||||
uint32 primType;
|
||||
uint8 *vertexBuffer;
|
||||
int32 numAttribs;
|
||||
AttribDesc *attribDesc;
|
||||
uint32 totalNumIndex;
|
||||
uint32 totalNumVertex;
|
||||
|
||||
uint32 ibo;
|
||||
uint32 vbo; // or 2?
|
||||
|
||||
InstanceData *inst;
|
||||
};
|
||||
|
||||
#ifdef RW_GLES1
|
||||
|
||||
struct Im3DVertex
|
||||
{
|
||||
V3d position;
|
||||
uint8 r, g, b, a;
|
||||
float32 u, v;
|
||||
|
||||
void setX(float32 x) { this->position.x = x; }
|
||||
void setY(float32 y) { this->position.y = y; }
|
||||
void setZ(float32 z) { this->position.z = z; }
|
||||
void setColor(uint8 r, uint8 g, uint8 b, uint8 a) {
|
||||
this->r = r; this->g = g; this->b = b; this->a = a; }
|
||||
void setU(float32 u) { this->u = u; }
|
||||
void setV(float32 v) { this->v = v; }
|
||||
|
||||
float getX(void) { return this->position.x; }
|
||||
float getY(void) { return this->position.y; }
|
||||
float getZ(void) { return this->position.z; }
|
||||
RGBA getColor(void) { return makeRGBA(this->r, this->g, this->b, this->a); }
|
||||
float getU(void) { return this->u; }
|
||||
float getV(void) { return this->v; }
|
||||
};
|
||||
|
||||
struct Im2DVertex
|
||||
{
|
||||
float32 x, y, z, w;
|
||||
uint8 r, g, b, a;
|
||||
float32 u, v;
|
||||
|
||||
void setScreenX(float32 x) { this->x = x; }
|
||||
void setScreenY(float32 y) { this->y = y; }
|
||||
void setScreenZ(float32 z) { this->z = z; }
|
||||
// This is a bit unefficient but we have to counteract GL's divide, so multiply
|
||||
void setCameraZ(float32 z) { this->w = z; }
|
||||
void setRecipCameraZ(float32 recipz) { this->w = 1.0f/recipz; }
|
||||
void setColor(uint8 r, uint8 g, uint8 b, uint8 a) {
|
||||
this->r = r; this->g = g; this->b = b; this->a = a; }
|
||||
void setU(float32 u, float recipz) { this->u = u; }
|
||||
void setV(float32 v, float recipz) { this->v = v; }
|
||||
|
||||
float getScreenX(void) { return this->x; }
|
||||
float getScreenY(void) { return this->y; }
|
||||
float getScreenZ(void) { return this->z; }
|
||||
float getCameraZ(void) { return this->w; }
|
||||
float getRecipCameraZ(void) { return 1.0f/this->w; }
|
||||
RGBA getColor(void) { return makeRGBA(this->r, this->g, this->b, this->a); }
|
||||
float getU(void) { return this->u; }
|
||||
float getV(void) { return this->v; }
|
||||
};
|
||||
|
||||
void setupVertexInput(InstanceDataHeader *header);
|
||||
void teardownVertexInput(InstanceDataHeader *header);
|
||||
|
||||
// Render state
|
||||
|
||||
// Vertex shader bits
|
||||
enum
|
||||
{
|
||||
// These should be low so they could be used as indices
|
||||
VSLIGHT_DIRECT = 1,
|
||||
VSLIGHT_POINT = 2,
|
||||
VSLIGHT_SPOT = 4,
|
||||
VSLIGHT_MASK = 7, // all the above
|
||||
// less critical
|
||||
VSLIGHT_AMBIENT = 8,
|
||||
};
|
||||
// per Scene
|
||||
void setProjectionMatrix(float32*);
|
||||
void setViewMatrix(float32*);
|
||||
|
||||
// per Object
|
||||
void setWorldMatrix(Matrix*);
|
||||
int32 setLights(WorldLights *lightData);
|
||||
|
||||
// per Mesh
|
||||
void setTexture(int32 n, Texture *tex);
|
||||
void setMaterial(const RGBA &color, const SurfaceProperties &surfaceprops, float extraSurfProp = 0.0f);
|
||||
inline void setMaterial(uint32 flags, const RGBA &color, const SurfaceProperties &surfaceprops, float extraSurfProp = 0.0f)
|
||||
{
|
||||
static RGBA white = { 255, 255, 255, 255 };
|
||||
if(flags & Geometry::MODULATE)
|
||||
setMaterial(color, surfaceprops, extraSurfProp);
|
||||
else
|
||||
setMaterial(white, surfaceprops, extraSurfProp);
|
||||
}
|
||||
|
||||
void setAlphaBlend(bool32 enable);
|
||||
bool32 getAlphaBlend(void);
|
||||
|
||||
bool32 getAlphaTest(void);
|
||||
|
||||
void bindFramebuffer(uint32 fbo);
|
||||
uint32 bindTexture(uint32 texid);
|
||||
|
||||
void flushCache(void);
|
||||
|
||||
#endif
|
||||
|
||||
class ObjPipeline : public rw::ObjPipeline
|
||||
{
|
||||
public:
|
||||
void init(void);
|
||||
static ObjPipeline *create(void);
|
||||
|
||||
void (*instanceCB)(Geometry *geo, InstanceDataHeader *header, bool32 reinstance);
|
||||
void (*uninstanceCB)(Geometry *geo, InstanceDataHeader *header);
|
||||
void (*renderCB)(Atomic *atomic, InstanceDataHeader *header);
|
||||
};
|
||||
|
||||
void defaultInstanceCB(Geometry *geo, InstanceDataHeader *header, bool32 reinstance);
|
||||
void defaultUninstanceCB(Geometry *geo, InstanceDataHeader *header);
|
||||
void defaultRenderCB(Atomic *atomic, InstanceDataHeader *header);
|
||||
int32 lightingCB(Atomic *atomic);
|
||||
|
||||
void drawInst_simple(InstanceDataHeader *header, InstanceData *inst);
|
||||
// Emulate PS2 GS alpha test FB_ONLY case: failed alpha writes to frame- but not to depth buffer
|
||||
void drawInst_GSemu(InstanceDataHeader *header, InstanceData *inst);
|
||||
// This one switches between the above two depending on render state;
|
||||
void drawInst(InstanceDataHeader *header, InstanceData *inst);
|
||||
|
||||
|
||||
void *destroyNativeData(void *object, int32, int32);
|
||||
|
||||
ObjPipeline *makeDefaultPipeline(void);
|
||||
|
||||
void setVertexAlpha(bool32 enable);
|
||||
|
||||
// Native Texture and Raster
|
||||
|
||||
struct Gl1Raster
|
||||
{
|
||||
// arguments to glTexImage2D
|
||||
int32 internalFormat;
|
||||
int32 type;
|
||||
int32 format;
|
||||
int32 bpp; // bytes per pixel
|
||||
// texture object
|
||||
uint32 texid;
|
||||
|
||||
bool isCompressed;
|
||||
bool hasAlpha;
|
||||
bool autogenMipmap;
|
||||
int8 numLevels;
|
||||
// cached filtermode and addressing
|
||||
uint8 filterMode;
|
||||
uint8 addressU;
|
||||
uint8 addressV;
|
||||
int32 maxAnisotropy;
|
||||
|
||||
uint32 fbo; // used for camera texture only!
|
||||
Raster *fboMate; // color or zbuffer raster mate of this one
|
||||
RasterLevels *backingStore; // if we can't read back GPU memory but have to
|
||||
};
|
||||
|
||||
// GLES can't read back textures very nicely.
|
||||
// In most cases that's not an issue, but when it is,
|
||||
// this has to be set before the texture is filled:
|
||||
extern bool32 needToReadBackTextures;
|
||||
|
||||
Texture *readNativeTexture(Stream *stream);
|
||||
void writeNativeTexture(Texture *tex, Stream *stream);
|
||||
uint32 getSizeNativeTexture(Texture *tex);
|
||||
|
||||
extern int32 nativeRasterOffset;
|
||||
void registerNativeRaster(void);
|
||||
#define GETGL1RASTEREXT(raster) PLUGINOFFSET(Gl1Raster, raster, rw::gles1::nativeRasterOffset)
|
||||
|
||||
}
|
||||
}
|
||||
6
vendor/librw/src/texture.cpp
vendored
6
vendor/librw/src/texture.cpp
vendored
|
|
@ -484,7 +484,7 @@ Texture::streamReadNative(Stream *stream)
|
|||
return gl3::readNativeTexture(stream);
|
||||
#ifdef RW_GLES1
|
||||
if(platform == PLATFORM_GLES1){
|
||||
//return gles1::readNativeTexture(stream);
|
||||
return gles1::readNativeTexture(stream);
|
||||
}
|
||||
#endif
|
||||
assert(0 && "unsupported platform");
|
||||
|
|
@ -506,7 +506,7 @@ Texture::streamWriteNative(Stream *stream)
|
|||
gl3::writeNativeTexture(this, stream);
|
||||
#ifdef RW_GLES1
|
||||
else if(this->raster->platform == PLATFORM_GLES1){
|
||||
//gles1::writeNativeTexture(this, stream);
|
||||
gles1::writeNativeTexture(this, stream);
|
||||
}
|
||||
#endif
|
||||
else
|
||||
|
|
@ -528,7 +528,7 @@ Texture::streamGetSizeNative(void)
|
|||
return gl3::getSizeNativeTexture(this);
|
||||
#ifdef RW_GLES1
|
||||
if(this->raster->platform == PLATFORM_GLES1){
|
||||
//return gles1::getSizeNativeTexture(this);
|
||||
return gles1::getSizeNativeTexture(this);
|
||||
}
|
||||
#endif
|
||||
assert(0 && "unsupported platform");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue